Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "Nucleus.hpp" |
| 16 | |
| 17 | #include "Reactor.hpp" |
| 18 | #include "Routine.hpp" |
| 19 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 20 | #include "Optimizer.hpp" |
| 21 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 22 | #include "src/IceTypes.h" |
| 23 | #include "src/IceCfg.h" |
| 24 | #include "src/IceELFStreamer.h" |
| 25 | #include "src/IceGlobalContext.h" |
| 26 | #include "src/IceCfgNode.h" |
| 27 | #include "src/IceELFObjectWriter.h" |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 28 | #include "src/IceGlobalInits.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 29 | |
| 30 | #include "llvm/Support/FileSystem.h" |
| 31 | #include "llvm/Support/raw_os_ostream.h" |
| 32 | |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 33 | #if defined(_WIN32) |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 34 | #ifndef WIN32_LEAN_AND_MEAN |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 35 | #define WIN32_LEAN_AND_MEAN |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 36 | #endif // !WIN32_LEAN_AND_MEAN |
| 37 | #ifndef NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 38 | #define NOMINMAX |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 39 | #endif // !NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 40 | #include <Windows.h> |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 41 | #else |
| 42 | #include <sys/mman.h> |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 43 | #if !defined(MAP_ANONYMOUS) |
| 44 | #define MAP_ANONYMOUS MAP_ANON |
Nicolas Capens | 8b27574 | 2017-01-20 17:11:41 -0500 | [diff] [blame] | 45 | #endif |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 46 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 47 | |
| 48 | #include <mutex> |
| 49 | #include <limits> |
| 50 | #include <iostream> |
| 51 | #include <cassert> |
| 52 | |
| 53 | namespace |
| 54 | { |
| 55 | Ice::GlobalContext *context = nullptr; |
| 56 | Ice::Cfg *function = nullptr; |
| 57 | Ice::CfgNode *basicBlock = nullptr; |
| 58 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
| 59 | sw::Routine *routine = nullptr; |
| 60 | |
| 61 | std::mutex codegenMutex; |
| 62 | |
| 63 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 64 | Ice::Fdstream *out = nullptr; |
| 65 | } |
| 66 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 67 | namespace |
| 68 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 69 | #if !defined(__i386__) && defined(_M_IX86) |
| 70 | #define __i386__ 1 |
| 71 | #endif |
| 72 | |
| 73 | #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) |
| 74 | #define __x86_64__ 1 |
| 75 | #endif |
| 76 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 77 | class CPUID |
| 78 | { |
| 79 | public: |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 80 | const static bool ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 81 | const static bool SSE4_1; |
| 82 | |
| 83 | private: |
| 84 | static void cpuid(int registers[4], int info) |
| 85 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 86 | #if defined(__i386__) || defined(__x86_64__) |
| 87 | #if defined(_WIN32) |
| 88 | __cpuid(registers, info); |
| 89 | #else |
| 90 | __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); |
| 91 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 92 | #else |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 93 | registers[0] = 0; |
| 94 | registers[1] = 0; |
| 95 | registers[2] = 0; |
| 96 | registers[3] = 0; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 97 | #endif |
| 98 | } |
| 99 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 100 | static bool detectARM() |
| 101 | { |
| 102 | #if defined(__arm__) |
| 103 | return true; |
| 104 | #elif defined(__i386__) || defined(__x86_64__) |
| 105 | return false; |
| 106 | #else |
| 107 | #error "Unknown architecture" |
| 108 | #endif |
| 109 | } |
| 110 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 111 | static bool detectSSE4_1() |
| 112 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 113 | #if defined(__i386__) || defined(__x86_64__) |
| 114 | int registers[4]; |
| 115 | cpuid(registers, 1); |
| 116 | return (registers[2] & 0x00080000) != 0; |
| 117 | #else |
| 118 | return false; |
| 119 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 120 | } |
| 121 | }; |
| 122 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 123 | const bool CPUID::ARM = CPUID::detectARM(); |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 124 | const bool CPUID::SSE4_1 = CPUID::detectSSE4_1(); |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 125 | const bool emulateIntrinsics = CPUID::ARM; |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame^] | 126 | const bool emulateMismatchedBitCast = CPUID::ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 127 | } |
| 128 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 129 | namespace sw |
| 130 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 131 | enum EmulatedType |
| 132 | { |
| 133 | EmulatedShift = 16, |
| 134 | EmulatedV2 = 2 << EmulatedShift, |
| 135 | EmulatedV4 = 4 << EmulatedShift, |
| 136 | EmulatedV8 = 8 << EmulatedShift, |
| 137 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 138 | |
| 139 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 140 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 141 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 142 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 143 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 144 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 145 | }; |
| 146 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 147 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 148 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 149 | class BasicBlock : public Ice::CfgNode {}; |
| 150 | |
| 151 | Ice::Type T(Type *t) |
| 152 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 153 | static_assert(static_cast<unsigned int>(Ice::IceType_NUM) < static_cast<unsigned int>(EmulatedBits), "Ice::Type overlaps with our emulated types!"); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 154 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | Type *T(Ice::Type t) |
| 158 | { |
| 159 | return reinterpret_cast<Type*>(t); |
| 160 | } |
| 161 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 162 | Type *T(EmulatedType t) |
| 163 | { |
| 164 | return reinterpret_cast<Type*>(t); |
| 165 | } |
| 166 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 167 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 168 | { |
| 169 | return reinterpret_cast<Value*>(v); |
| 170 | } |
| 171 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 172 | BasicBlock *B(Ice::CfgNode *b) |
| 173 | { |
| 174 | return reinterpret_cast<BasicBlock*>(b); |
| 175 | } |
| 176 | |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 177 | static size_t typeSize(Type *type) |
| 178 | { |
| 179 | if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) |
| 180 | { |
| 181 | switch(reinterpret_cast<std::intptr_t>(type)) |
| 182 | { |
| 183 | case Type_v2i32: return 8; |
| 184 | case Type_v4i16: return 8; |
| 185 | case Type_v2i16: return 4; |
| 186 | case Type_v8i8: return 8; |
| 187 | case Type_v4i8: return 4; |
| 188 | case Type_v2f32: return 8; |
| 189 | default: assert(false); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return Ice::typeWidthInBytes(T(type)); |
| 194 | } |
| 195 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 196 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 197 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 198 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 199 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 200 | |
| 201 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 202 | { |
| 203 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 204 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 205 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 206 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 207 | { |
| 208 | return §ionHeader(elfHeader)[index]; |
| 209 | } |
| 210 | |
| 211 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 212 | { |
| 213 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 214 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 215 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 216 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 217 | uint32_t index = relocation.getSymbol(); |
| 218 | int table = relocationTable.sh_link; |
| 219 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 220 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 221 | if(index != SHN_UNDEF) |
| 222 | { |
| 223 | if(table == SHN_UNDEF) return nullptr; |
| 224 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 225 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 226 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 227 | if(index >= symtab_entries) |
| 228 | { |
| 229 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 230 | return nullptr; |
| 231 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 232 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 233 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 234 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 235 | uint16_t section = symbol.st_shndx; |
| 236 | |
| 237 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 238 | { |
| 239 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 240 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | return nullptr; |
| 245 | } |
| 246 | } |
| 247 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 248 | if(CPUID::ARM) |
| 249 | { |
| 250 | switch(relocation.getType()) |
| 251 | { |
| 252 | case R_ARM_NONE: |
| 253 | // No relocation |
| 254 | break; |
| 255 | case R_ARM_MOVW_ABS_NC: |
| 256 | { |
| 257 | uint32_t thumb = 0; // Calls to Thumb code not supported. |
| 258 | uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb; |
| 259 | *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF); |
| 260 | } |
| 261 | break; |
| 262 | case R_ARM_MOVT_ABS: |
| 263 | { |
| 264 | uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16; |
| 265 | *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF); |
| 266 | } |
| 267 | break; |
| 268 | default: |
| 269 | assert(false && "Unsupported relocation type"); |
| 270 | return nullptr; |
| 271 | } |
| 272 | } |
| 273 | else |
| 274 | { |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 275 | switch(relocation.getType()) |
| 276 | { |
| 277 | case R_386_NONE: |
| 278 | // No relocation |
| 279 | break; |
| 280 | case R_386_32: |
| 281 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 282 | break; |
| 283 | // case R_386_PC32: |
| 284 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 285 | // break; |
| 286 | default: |
| 287 | assert(false && "Unsupported relocation type"); |
| 288 | return nullptr; |
| 289 | } |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 290 | } |
| 291 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 292 | |
| 293 | return symbolValue; |
| 294 | } |
| 295 | |
| 296 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 297 | { |
| 298 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 299 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 300 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 301 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 302 | uint32_t index = relocation.getSymbol(); |
| 303 | int table = relocationTable.sh_link; |
| 304 | void *symbolValue = nullptr; |
| 305 | |
| 306 | if(index != SHN_UNDEF) |
| 307 | { |
| 308 | if(table == SHN_UNDEF) return nullptr; |
| 309 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 310 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 311 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 312 | if(index >= symtab_entries) |
| 313 | { |
| 314 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 315 | return nullptr; |
| 316 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 317 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 318 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 319 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 320 | uint16_t section = symbol.st_shndx; |
| 321 | |
| 322 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 323 | { |
| 324 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 325 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | return nullptr; |
| 330 | } |
| 331 | } |
| 332 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 333 | switch(relocation.getType()) |
| 334 | { |
| 335 | case R_X86_64_NONE: |
| 336 | // No relocation |
| 337 | break; |
| 338 | case R_X86_64_64: |
| 339 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 340 | break; |
| 341 | case R_X86_64_PC32: |
| 342 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 343 | break; |
| 344 | case R_X86_64_32S: |
| 345 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 346 | break; |
| 347 | default: |
| 348 | assert(false && "Unsupported relocation type"); |
| 349 | return nullptr; |
| 350 | } |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 351 | |
| 352 | return symbolValue; |
| 353 | } |
| 354 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 355 | void *loadImage(uint8_t *const elfImage, size_t &codeSize) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 356 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 357 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 358 | |
| 359 | if(!elfHeader->checkMagic()) |
| 360 | { |
| 361 | return nullptr; |
| 362 | } |
| 363 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 364 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 365 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 366 | #if defined(__i386__) |
| 367 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386); |
| 368 | #elif defined(__x86_64__) |
| 369 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64); |
| 370 | #elif defined(__arm__) |
| 371 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM); |
| 372 | #else |
| 373 | #error "Unsupported platform" |
| 374 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 375 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 376 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 377 | void *entry = nullptr; |
| 378 | |
| 379 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 380 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 381 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 382 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 383 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 384 | { |
| 385 | entry = elfImage + sectionHeader[i].sh_offset; |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 386 | codeSize = sectionHeader[i].sh_size; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 390 | { |
| 391 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 392 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 393 | for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 394 | { |
| 395 | const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index]; |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 396 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 400 | { |
| 401 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 402 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 403 | for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++) |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 404 | { |
| 405 | const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index]; |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 406 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 407 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
| 411 | return entry; |
| 412 | } |
| 413 | |
| 414 | template<typename T> |
| 415 | struct ExecutableAllocator |
| 416 | { |
| 417 | ExecutableAllocator() {}; |
| 418 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 419 | |
| 420 | using value_type = T; |
| 421 | using size_type = std::size_t; |
| 422 | |
| 423 | T *allocate(size_type n) |
| 424 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 425 | #if defined(_WIN32) |
| 426 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 427 | #else |
| 428 | return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 429 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void deallocate(T *p, size_type n) |
| 433 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 434 | #if defined(_WIN32) |
| 435 | VirtualFree(p, 0, MEM_RELEASE); |
| 436 | #else |
| 437 | munmap(p, sizeof(T) * n); |
| 438 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 439 | } |
| 440 | }; |
| 441 | |
| 442 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 443 | { |
| 444 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 445 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 446 | |
| 447 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 448 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 449 | { |
| 450 | position = 0; |
| 451 | buffer.reserve(0x1000); |
| 452 | } |
| 453 | |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 454 | ~ELFMemoryStreamer() override |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 455 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 456 | #if defined(_WIN32) |
| 457 | if(buffer.size() != 0) |
| 458 | { |
| 459 | DWORD exeProtection; |
| 460 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 461 | } |
| 462 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void write8(uint8_t Value) override |
| 466 | { |
| 467 | if(position == (uint64_t)buffer.size()) |
| 468 | { |
| 469 | buffer.push_back(Value); |
| 470 | position++; |
| 471 | } |
| 472 | else if(position < (uint64_t)buffer.size()) |
| 473 | { |
| 474 | buffer[position] = Value; |
| 475 | position++; |
| 476 | } |
| 477 | else assert(false && "UNIMPLEMENTED"); |
| 478 | } |
| 479 | |
| 480 | void writeBytes(llvm::StringRef Bytes) override |
| 481 | { |
| 482 | std::size_t oldSize = buffer.size(); |
| 483 | buffer.resize(oldSize + Bytes.size()); |
| 484 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 485 | position += Bytes.size(); |
| 486 | } |
| 487 | |
| 488 | uint64_t tell() const override { return position; } |
| 489 | |
| 490 | void seek(uint64_t Off) override { position = Off; } |
| 491 | |
| 492 | const void *getEntry() override |
| 493 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 494 | if(!entry) |
| 495 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 496 | position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 497 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 498 | size_t codeSize = 0; |
| 499 | entry = loadImage(&buffer[0], codeSize); |
| 500 | |
| 501 | #if defined(_WIN32) |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 502 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 503 | FlushInstructionCache(GetCurrentProcess(), NULL, 0); |
| 504 | #else |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 505 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 506 | __builtin___clear_cache((char*)entry, (char*)entry + codeSize); |
| 507 | #endif |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 514 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 515 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 516 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 517 | |
| 518 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 519 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 520 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | Nucleus::Nucleus() |
| 524 | { |
| 525 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 526 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 527 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 528 | Ice::ClFlags::getParsedClFlags(Flags); |
| 529 | |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 530 | #if defined(__arm__) |
| 531 | Flags.setTargetArch(Ice::Target_ARM32); |
| 532 | Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm); |
| 533 | #else // x86 |
| 534 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 535 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
| 536 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 537 | Flags.setOutFileType(Ice::FT_Elf); |
| 538 | Flags.setOptLevel(Ice::Opt_2); |
| 539 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 540 | Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None); |
| 541 | Flags.setDisableHybridAssembly(true); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 542 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 543 | static llvm::raw_os_ostream cout(std::cout); |
| 544 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 545 | |
| 546 | if(false) // Write out to a file |
| 547 | { |
| 548 | std::error_code errorCode; |
| 549 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 550 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 551 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 552 | } |
| 553 | else |
| 554 | { |
| 555 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 556 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 557 | ::routine = elfMemory; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | Nucleus::~Nucleus() |
| 562 | { |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 563 | delete ::routine; |
| 564 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 565 | delete ::allocator; |
| 566 | delete ::function; |
| 567 | delete ::context; |
| 568 | |
| 569 | delete ::elfFile; |
| 570 | delete ::out; |
| 571 | |
| 572 | ::codegenMutex.unlock(); |
| 573 | } |
| 574 | |
| 575 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 576 | { |
| 577 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 578 | { |
| 579 | createRetVoid(); |
| 580 | } |
| 581 | |
| 582 | std::wstring wideName(name); |
| 583 | std::string asciiName(wideName.begin(), wideName.end()); |
| 584 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 585 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 586 | optimize(); |
| 587 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 588 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 589 | assert(!::function->hasError()); |
| 590 | |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 591 | auto globals = ::function->getGlobalInits(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 592 | |
| 593 | if(globals && !globals->empty()) |
| 594 | { |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 595 | ::context->getGlobals()->merge(globals.get()); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 596 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 597 | |
| 598 | ::context->emitFileHeader(); |
| 599 | ::function->emitIAS(); |
| 600 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 601 | auto objectWriter = ::context->getObjectWriter(); |
| 602 | assembler->alignFunction(); |
| 603 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 604 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 605 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 606 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 607 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 608 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 609 | |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 610 | Routine *handoffRoutine = ::routine; |
| 611 | ::routine = nullptr; |
| 612 | |
| 613 | return handoffRoutine; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | void Nucleus::optimize() |
| 617 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 618 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 622 | { |
| 623 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 624 | int typeSize = Ice::typeWidthInBytes(type); |
| 625 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 626 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 627 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 628 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 629 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 630 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 631 | |
| 632 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | BasicBlock *Nucleus::createBasicBlock() |
| 636 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 637 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | BasicBlock *Nucleus::getInsertBlock() |
| 641 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 642 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 646 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 647 | // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator"); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 648 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 651 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 652 | { |
| 653 | uint32_t sequenceNumber = 0; |
| 654 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 655 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 656 | |
| 657 | for(Type *type : Params) |
| 658 | { |
| 659 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 660 | ::function->addArg(arg); |
| 661 | } |
| 662 | |
| 663 | Ice::CfgNode *node = ::function->makeNode(); |
| 664 | ::function->setEntryNode(node); |
| 665 | ::basicBlock = node; |
| 666 | } |
| 667 | |
| 668 | Value *Nucleus::getArgument(unsigned int index) |
| 669 | { |
| 670 | return V(::function->getArgs()[index]); |
| 671 | } |
| 672 | |
| 673 | void Nucleus::createRetVoid() |
| 674 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 675 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 676 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void Nucleus::createRet(Value *v) |
| 680 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 681 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 682 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void Nucleus::createBr(BasicBlock *dest) |
| 686 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 687 | auto br = Ice::InstBr::create(::function, dest); |
| 688 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 692 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 693 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 694 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 695 | } |
| 696 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 697 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 698 | { |
| 699 | switch(op) |
| 700 | { |
| 701 | case Ice::InstArithmetic::Add: |
| 702 | case Ice::InstArithmetic::Fadd: |
| 703 | case Ice::InstArithmetic::Mul: |
| 704 | case Ice::InstArithmetic::Fmul: |
| 705 | case Ice::InstArithmetic::And: |
| 706 | case Ice::InstArithmetic::Or: |
| 707 | case Ice::InstArithmetic::Xor: |
| 708 | return true; |
| 709 | default: |
| 710 | return false; |
| 711 | } |
| 712 | } |
| 713 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 714 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 715 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 716 | assert(lhs->getType() == rhs->getType() || (llvm::isa<Ice::Constant>(rhs) && (op == Ice::InstArithmetic::Shl || Ice::InstArithmetic::Lshr || Ice::InstArithmetic::Ashr))); |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 717 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 718 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 719 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 720 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 721 | Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, swapOperands ? rhs : lhs, swapOperands ? lhs : rhs); |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 722 | ::basicBlock->appendInst(arithmetic); |
| 723 | |
| 724 | return V(result); |
| 725 | } |
| 726 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 727 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 728 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 729 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 733 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 734 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 738 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 739 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 743 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 744 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 748 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 749 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 753 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 754 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 758 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 759 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 763 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 764 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 768 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 769 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 773 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 774 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 778 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 779 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 783 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 784 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 788 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 789 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 793 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 794 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 798 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 799 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 803 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 804 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 808 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 809 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 813 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 814 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | Value *Nucleus::createNeg(Value *v) |
| 818 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 819 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | Value *Nucleus::createFNeg(Value *v) |
| 823 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 824 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 825 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 826 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 827 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 828 | |
| 829 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | Value *Nucleus::createNot(Value *v) |
| 833 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 834 | if(Ice::isScalarIntegerType(v->getType())) |
| 835 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 836 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 837 | } |
| 838 | else // Vector |
| 839 | { |
Nicolas Capens | f34d1ac | 2017-05-08 17:06:11 -0400 | [diff] [blame] | 840 | int64_t c[16] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 841 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 842 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 843 | } |
| 844 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 845 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 846 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 847 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 848 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 849 | |
| 850 | if(valueType & EmulatedBits) |
| 851 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 852 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 853 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 854 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 855 | load->addArg(ptr); |
| 856 | load->addArg(::context->getConstantInt32(typeSize(type))); |
| 857 | ::basicBlock->appendInst(load); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 858 | } |
| 859 | else |
| 860 | { |
| 861 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 862 | ::basicBlock->appendInst(load); |
| 863 | } |
| 864 | |
| 865 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 866 | } |
| 867 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 868 | 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] | 869 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 870 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 871 | |
| 872 | if(valueType & EmulatedBits) |
| 873 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 874 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 875 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 876 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
| 877 | store->addArg(value); |
| 878 | store->addArg(ptr); |
| 879 | store->addArg(::context->getConstantInt32(typeSize(type))); |
| 880 | ::basicBlock->appendInst(store); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 881 | } |
| 882 | else |
| 883 | { |
| 884 | assert(T(value->getType()) == type); |
| 885 | |
| 886 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 887 | ::basicBlock->appendInst(store); |
| 888 | } |
| 889 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 890 | return value; |
| 891 | } |
| 892 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 893 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 894 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 895 | assert(index->getType() == Ice::IceType_i32); |
| 896 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 897 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 898 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 899 | int32_t offset = constant->getValue() * (int)typeSize(type); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 900 | |
| 901 | if(offset == 0) |
| 902 | { |
| 903 | return ptr; |
| 904 | } |
| 905 | |
| 906 | return createAdd(ptr, createConstantInt(offset)); |
| 907 | } |
| 908 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 909 | if(!Ice::isByteSizedType(T(type))) |
| 910 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 911 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | if(sizeof(void*) == 8) |
| 915 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 916 | if(unsignedIndex) |
| 917 | { |
| 918 | index = createZExt(index, T(Ice::IceType_i64)); |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | index = createSExt(index, T(Ice::IceType_i64)); |
| 923 | } |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 930 | { |
| 931 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 932 | } |
| 933 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 934 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 935 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 936 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 937 | { |
| 938 | return v; |
| 939 | } |
| 940 | |
| 941 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 942 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 943 | ::basicBlock->appendInst(cast); |
| 944 | |
| 945 | return V(result); |
| 946 | } |
| 947 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 948 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 949 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 950 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 954 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 955 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 959 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 960 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 964 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 965 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 966 | } |
| 967 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 968 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 969 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 970 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 974 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 975 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 979 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 980 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 984 | { |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame^] | 985 | // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need |
| 986 | // support for casting between scalars and wide vectors. For platforms where this is not supported, |
| 987 | // emulate them by writing to the stack and reading back as the destination type. |
| 988 | if(emulateMismatchedBitCast) |
| 989 | { |
| 990 | if(!Ice::isVectorType(v->getType()) && Ice::isVectorType(T(destType))) |
| 991 | { |
| 992 | Value *address = allocateStackVariable(destType); |
| 993 | createStore(v, address, T(v->getType())); |
| 994 | return createLoad(address, destType); |
| 995 | } |
| 996 | else if(Ice::isVectorType(v->getType()) && !Ice::isVectorType(T(destType))) |
| 997 | { |
| 998 | Value *address = allocateStackVariable(T(v->getType())); |
| 999 | createStore(v, address, T(v->getType())); |
| 1000 | return createLoad(address, destType); |
| 1001 | } |
| 1002 | } |
| 1003 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1004 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1007 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1008 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1009 | assert(lhs->getType() == rhs->getType()); |
| 1010 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1011 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 1012 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1013 | ::basicBlock->appendInst(cmp); |
| 1014 | |
| 1015 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1018 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 1019 | { |
| 1020 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 1021 | } |
| 1022 | |
| 1023 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 1024 | { |
| 1025 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 1026 | } |
| 1027 | |
| 1028 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 1029 | { |
| 1030 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 1031 | } |
| 1032 | |
| 1033 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 1034 | { |
| 1035 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 1036 | } |
| 1037 | |
| 1038 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 1039 | { |
| 1040 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 1041 | } |
| 1042 | |
| 1043 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 1044 | { |
| 1045 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 1046 | } |
| 1047 | |
| 1048 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 1049 | { |
| 1050 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 1051 | } |
| 1052 | |
| 1053 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 1054 | { |
| 1055 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 1056 | } |
| 1057 | |
| 1058 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 1059 | { |
| 1060 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 1061 | } |
| 1062 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1063 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 1064 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1065 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 1066 | } |
| 1067 | |
| 1068 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 1069 | { |
| 1070 | assert(lhs->getType() == rhs->getType()); |
| 1071 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 1072 | |
| 1073 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 1074 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 1075 | ::basicBlock->appendInst(cmp); |
| 1076 | |
| 1077 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 1081 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1082 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1086 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1087 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1091 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1092 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1096 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1097 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1101 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1102 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1106 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1107 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1111 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1112 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1116 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1117 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1121 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1122 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1126 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1127 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1131 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1132 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1136 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1137 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1141 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1142 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1146 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1147 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1150 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1151 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1152 | auto result = ::function->makeVariable(T(type)); |
| 1153 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1154 | ::basicBlock->appendInst(extract); |
| 1155 | |
| 1156 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1160 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1161 | auto result = ::function->makeVariable(vector->getType()); |
| 1162 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1163 | ::basicBlock->appendInst(insert); |
| 1164 | |
| 1165 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1168 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1169 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1170 | assert(V1->getType() == V2->getType()); |
| 1171 | |
| 1172 | int size = Ice::typeNumElements(V1->getType()); |
| 1173 | auto result = ::function->makeVariable(V1->getType()); |
| 1174 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1175 | |
| 1176 | for(int i = 0; i < size; i++) |
| 1177 | { |
| 1178 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1179 | } |
| 1180 | |
| 1181 | ::basicBlock->appendInst(shuffle); |
| 1182 | |
| 1183 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1187 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1188 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1189 | |
| 1190 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1191 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1192 | ::basicBlock->appendInst(select); |
| 1193 | |
| 1194 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1197 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1198 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1199 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1200 | ::basicBlock->appendInst(switchInst); |
| 1201 | |
| 1202 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1205 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1206 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1207 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | void Nucleus::createUnreachable() |
| 1211 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1212 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1213 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1214 | } |
| 1215 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1216 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1217 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1218 | int swizzle[4] = |
| 1219 | { |
| 1220 | (select >> 0) & 0x03, |
| 1221 | (select >> 2) & 0x03, |
| 1222 | (select >> 4) & 0x03, |
| 1223 | (select >> 6) & 0x03, |
| 1224 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1225 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1226 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1227 | } |
| 1228 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1229 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1230 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1231 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1232 | |
| 1233 | mask[(select >> 0) & 0x03] = -1; |
| 1234 | mask[(select >> 2) & 0x03] = -1; |
| 1235 | mask[(select >> 4) & 0x03] = -1; |
| 1236 | mask[(select >> 6) & 0x03] = -1; |
| 1237 | |
| 1238 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1239 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1240 | |
| 1241 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1244 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1245 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1246 | if(sizeof(void*) == 8) |
| 1247 | { |
| 1248 | return T(Ice::IceType_i64); |
| 1249 | } |
| 1250 | else |
| 1251 | { |
| 1252 | return T(Ice::IceType_i32); |
| 1253 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1256 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1257 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1258 | if(Ice::isVectorType(T(Ty))) |
| 1259 | { |
Nicolas Capens | 30385f0 | 2017-04-18 13:03:47 -0400 | [diff] [blame] | 1260 | assert(Ice::typeNumElements(T(Ty)) <= 16); |
| 1261 | 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] | 1262 | return createConstantVector(c, Ty); |
| 1263 | } |
| 1264 | else |
| 1265 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1266 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1267 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1270 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1271 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1272 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1275 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1276 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1277 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1280 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1281 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1282 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1285 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1286 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1287 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1290 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1291 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1292 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1295 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1296 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1297 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1298 | } |
| 1299 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1300 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1301 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1302 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1303 | } |
| 1304 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1305 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1306 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1307 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1308 | } |
| 1309 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1310 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1311 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1312 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1313 | } |
| 1314 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1315 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1316 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1317 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1320 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1321 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1322 | const int vectorSize = 16; |
| 1323 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1324 | const int alignment = vectorSize; |
| 1325 | auto globalPool = ::function->getGlobalPool(); |
| 1326 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1327 | const int64_t *i = constants; |
| 1328 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1329 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1330 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1331 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1332 | { |
| 1333 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1334 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1335 | { |
| 1336 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1337 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1338 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1339 | } |
| 1340 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1341 | case Ice::IceType_v4f32: |
| 1342 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1343 | 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] | 1344 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1345 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1346 | } |
| 1347 | break; |
| 1348 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1349 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1350 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1351 | 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] | 1352 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1353 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1354 | } |
| 1355 | break; |
| 1356 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1357 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1358 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1359 | 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] | 1360 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1361 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1362 | } |
| 1363 | break; |
| 1364 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1365 | { |
| 1366 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1367 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1368 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1369 | } |
| 1370 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1371 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1372 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1373 | 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] | 1374 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1375 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1376 | } |
| 1377 | break; |
| 1378 | case Type_v4i16: |
| 1379 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1380 | 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] | 1381 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1382 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1383 | } |
| 1384 | break; |
| 1385 | case Type_v8i8: |
| 1386 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1387 | 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] | 1388 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1389 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1390 | } |
| 1391 | break; |
| 1392 | case Type_v4i8: |
| 1393 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1394 | 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] | 1395 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1396 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1397 | } |
| 1398 | break; |
| 1399 | default: |
| 1400 | assert(false && "Unknown constant vector type" && type); |
| 1401 | } |
| 1402 | |
| 1403 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1404 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1405 | variableDeclaration->setName(name); |
| 1406 | variableDeclaration->setAlignment(alignment); |
| 1407 | variableDeclaration->setIsConstant(true); |
| 1408 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1409 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1410 | ::function->addGlobal(variableDeclaration); |
| 1411 | |
| 1412 | constexpr int32_t offset = 0; |
| 1413 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1414 | |
| 1415 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1416 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1417 | ::basicBlock->appendInst(load); |
| 1418 | |
| 1419 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1423 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1424 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | Type *Void::getType() |
| 1428 | { |
| 1429 | return T(Ice::IceType_void); |
| 1430 | } |
| 1431 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1432 | Bool::Bool(Argument<Bool> argument) |
| 1433 | { |
| 1434 | storeValue(argument.value); |
| 1435 | } |
| 1436 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1437 | Bool::Bool(bool x) |
| 1438 | { |
| 1439 | storeValue(Nucleus::createConstantBool(x)); |
| 1440 | } |
| 1441 | |
| 1442 | Bool::Bool(RValue<Bool> rhs) |
| 1443 | { |
| 1444 | storeValue(rhs.value); |
| 1445 | } |
| 1446 | |
| 1447 | Bool::Bool(const Bool &rhs) |
| 1448 | { |
| 1449 | Value *value = rhs.loadValue(); |
| 1450 | storeValue(value); |
| 1451 | } |
| 1452 | |
| 1453 | Bool::Bool(const Reference<Bool> &rhs) |
| 1454 | { |
| 1455 | Value *value = rhs.loadValue(); |
| 1456 | storeValue(value); |
| 1457 | } |
| 1458 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1459 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1460 | { |
| 1461 | storeValue(rhs.value); |
| 1462 | |
| 1463 | return rhs; |
| 1464 | } |
| 1465 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1466 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1467 | { |
| 1468 | Value *value = rhs.loadValue(); |
| 1469 | storeValue(value); |
| 1470 | |
| 1471 | return RValue<Bool>(value); |
| 1472 | } |
| 1473 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1474 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1475 | { |
| 1476 | Value *value = rhs.loadValue(); |
| 1477 | storeValue(value); |
| 1478 | |
| 1479 | return RValue<Bool>(value); |
| 1480 | } |
| 1481 | |
| 1482 | RValue<Bool> operator!(RValue<Bool> val) |
| 1483 | { |
| 1484 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1485 | } |
| 1486 | |
| 1487 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1488 | { |
| 1489 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1490 | } |
| 1491 | |
| 1492 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1493 | { |
| 1494 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1495 | } |
| 1496 | |
| 1497 | Type *Bool::getType() |
| 1498 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1499 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | Byte::Byte(Argument<Byte> argument) |
| 1503 | { |
| 1504 | storeValue(argument.value); |
| 1505 | } |
| 1506 | |
| 1507 | Byte::Byte(RValue<Int> cast) |
| 1508 | { |
| 1509 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1510 | |
| 1511 | storeValue(integer); |
| 1512 | } |
| 1513 | |
| 1514 | Byte::Byte(RValue<UInt> cast) |
| 1515 | { |
| 1516 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1517 | |
| 1518 | storeValue(integer); |
| 1519 | } |
| 1520 | |
| 1521 | Byte::Byte(RValue<UShort> cast) |
| 1522 | { |
| 1523 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1524 | |
| 1525 | storeValue(integer); |
| 1526 | } |
| 1527 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1528 | Byte::Byte(int x) |
| 1529 | { |
| 1530 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1531 | } |
| 1532 | |
| 1533 | Byte::Byte(unsigned char x) |
| 1534 | { |
| 1535 | storeValue(Nucleus::createConstantByte(x)); |
| 1536 | } |
| 1537 | |
| 1538 | Byte::Byte(RValue<Byte> rhs) |
| 1539 | { |
| 1540 | storeValue(rhs.value); |
| 1541 | } |
| 1542 | |
| 1543 | Byte::Byte(const Byte &rhs) |
| 1544 | { |
| 1545 | Value *value = rhs.loadValue(); |
| 1546 | storeValue(value); |
| 1547 | } |
| 1548 | |
| 1549 | Byte::Byte(const Reference<Byte> &rhs) |
| 1550 | { |
| 1551 | Value *value = rhs.loadValue(); |
| 1552 | storeValue(value); |
| 1553 | } |
| 1554 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1555 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1556 | { |
| 1557 | storeValue(rhs.value); |
| 1558 | |
| 1559 | return rhs; |
| 1560 | } |
| 1561 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1562 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1563 | { |
| 1564 | Value *value = rhs.loadValue(); |
| 1565 | storeValue(value); |
| 1566 | |
| 1567 | return RValue<Byte>(value); |
| 1568 | } |
| 1569 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1570 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1571 | { |
| 1572 | Value *value = rhs.loadValue(); |
| 1573 | storeValue(value); |
| 1574 | |
| 1575 | return RValue<Byte>(value); |
| 1576 | } |
| 1577 | |
| 1578 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1579 | { |
| 1580 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1581 | } |
| 1582 | |
| 1583 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1584 | { |
| 1585 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1586 | } |
| 1587 | |
| 1588 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1589 | { |
| 1590 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1591 | } |
| 1592 | |
| 1593 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1594 | { |
| 1595 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1596 | } |
| 1597 | |
| 1598 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1599 | { |
| 1600 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1601 | } |
| 1602 | |
| 1603 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1604 | { |
| 1605 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1606 | } |
| 1607 | |
| 1608 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1609 | { |
| 1610 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1611 | } |
| 1612 | |
| 1613 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1614 | { |
| 1615 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1616 | } |
| 1617 | |
| 1618 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1619 | { |
| 1620 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1621 | } |
| 1622 | |
| 1623 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1624 | { |
| 1625 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1626 | } |
| 1627 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1628 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1629 | { |
| 1630 | return lhs = lhs + rhs; |
| 1631 | } |
| 1632 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1633 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1634 | { |
| 1635 | return lhs = lhs - rhs; |
| 1636 | } |
| 1637 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1638 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1639 | { |
| 1640 | return lhs = lhs * rhs; |
| 1641 | } |
| 1642 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1643 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1644 | { |
| 1645 | return lhs = lhs / rhs; |
| 1646 | } |
| 1647 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1648 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1649 | { |
| 1650 | return lhs = lhs % rhs; |
| 1651 | } |
| 1652 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1653 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1654 | { |
| 1655 | return lhs = lhs & rhs; |
| 1656 | } |
| 1657 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1658 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1659 | { |
| 1660 | return lhs = lhs | rhs; |
| 1661 | } |
| 1662 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1663 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1664 | { |
| 1665 | return lhs = lhs ^ rhs; |
| 1666 | } |
| 1667 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1668 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1669 | { |
| 1670 | return lhs = lhs << rhs; |
| 1671 | } |
| 1672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1673 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1674 | { |
| 1675 | return lhs = lhs >> rhs; |
| 1676 | } |
| 1677 | |
| 1678 | RValue<Byte> operator+(RValue<Byte> val) |
| 1679 | { |
| 1680 | return val; |
| 1681 | } |
| 1682 | |
| 1683 | RValue<Byte> operator-(RValue<Byte> val) |
| 1684 | { |
| 1685 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1686 | } |
| 1687 | |
| 1688 | RValue<Byte> operator~(RValue<Byte> val) |
| 1689 | { |
| 1690 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1691 | } |
| 1692 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1693 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1694 | { |
| 1695 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1696 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1697 | return res; |
| 1698 | } |
| 1699 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1700 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1701 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1702 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1703 | return val; |
| 1704 | } |
| 1705 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1706 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1707 | { |
| 1708 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1709 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1710 | return res; |
| 1711 | } |
| 1712 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1713 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1714 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1715 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1716 | return val; |
| 1717 | } |
| 1718 | |
| 1719 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1720 | { |
| 1721 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1722 | } |
| 1723 | |
| 1724 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1725 | { |
| 1726 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1727 | } |
| 1728 | |
| 1729 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1730 | { |
| 1731 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1732 | } |
| 1733 | |
| 1734 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1735 | { |
| 1736 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1737 | } |
| 1738 | |
| 1739 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1740 | { |
| 1741 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1742 | } |
| 1743 | |
| 1744 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1745 | { |
| 1746 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1747 | } |
| 1748 | |
| 1749 | Type *Byte::getType() |
| 1750 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1751 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | SByte::SByte(Argument<SByte> argument) |
| 1755 | { |
| 1756 | storeValue(argument.value); |
| 1757 | } |
| 1758 | |
| 1759 | SByte::SByte(RValue<Int> cast) |
| 1760 | { |
| 1761 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1762 | |
| 1763 | storeValue(integer); |
| 1764 | } |
| 1765 | |
| 1766 | SByte::SByte(RValue<Short> cast) |
| 1767 | { |
| 1768 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1769 | |
| 1770 | storeValue(integer); |
| 1771 | } |
| 1772 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1773 | SByte::SByte(signed char x) |
| 1774 | { |
| 1775 | storeValue(Nucleus::createConstantByte(x)); |
| 1776 | } |
| 1777 | |
| 1778 | SByte::SByte(RValue<SByte> rhs) |
| 1779 | { |
| 1780 | storeValue(rhs.value); |
| 1781 | } |
| 1782 | |
| 1783 | SByte::SByte(const SByte &rhs) |
| 1784 | { |
| 1785 | Value *value = rhs.loadValue(); |
| 1786 | storeValue(value); |
| 1787 | } |
| 1788 | |
| 1789 | SByte::SByte(const Reference<SByte> &rhs) |
| 1790 | { |
| 1791 | Value *value = rhs.loadValue(); |
| 1792 | storeValue(value); |
| 1793 | } |
| 1794 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1795 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1796 | { |
| 1797 | storeValue(rhs.value); |
| 1798 | |
| 1799 | return rhs; |
| 1800 | } |
| 1801 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1802 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1803 | { |
| 1804 | Value *value = rhs.loadValue(); |
| 1805 | storeValue(value); |
| 1806 | |
| 1807 | return RValue<SByte>(value); |
| 1808 | } |
| 1809 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1810 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1811 | { |
| 1812 | Value *value = rhs.loadValue(); |
| 1813 | storeValue(value); |
| 1814 | |
| 1815 | return RValue<SByte>(value); |
| 1816 | } |
| 1817 | |
| 1818 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1819 | { |
| 1820 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1821 | } |
| 1822 | |
| 1823 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1824 | { |
| 1825 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1826 | } |
| 1827 | |
| 1828 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1829 | { |
| 1830 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1831 | } |
| 1832 | |
| 1833 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1834 | { |
| 1835 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1836 | } |
| 1837 | |
| 1838 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1839 | { |
| 1840 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1841 | } |
| 1842 | |
| 1843 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1844 | { |
| 1845 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1846 | } |
| 1847 | |
| 1848 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1849 | { |
| 1850 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1851 | } |
| 1852 | |
| 1853 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1854 | { |
| 1855 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1856 | } |
| 1857 | |
| 1858 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1859 | { |
| 1860 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1861 | } |
| 1862 | |
| 1863 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1864 | { |
| 1865 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1866 | } |
| 1867 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1868 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1869 | { |
| 1870 | return lhs = lhs + rhs; |
| 1871 | } |
| 1872 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1873 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1874 | { |
| 1875 | return lhs = lhs - rhs; |
| 1876 | } |
| 1877 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1878 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1879 | { |
| 1880 | return lhs = lhs * rhs; |
| 1881 | } |
| 1882 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1883 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1884 | { |
| 1885 | return lhs = lhs / rhs; |
| 1886 | } |
| 1887 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1888 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1889 | { |
| 1890 | return lhs = lhs % rhs; |
| 1891 | } |
| 1892 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1893 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1894 | { |
| 1895 | return lhs = lhs & rhs; |
| 1896 | } |
| 1897 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1898 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1899 | { |
| 1900 | return lhs = lhs | rhs; |
| 1901 | } |
| 1902 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1903 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1904 | { |
| 1905 | return lhs = lhs ^ rhs; |
| 1906 | } |
| 1907 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1908 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1909 | { |
| 1910 | return lhs = lhs << rhs; |
| 1911 | } |
| 1912 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1913 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1914 | { |
| 1915 | return lhs = lhs >> rhs; |
| 1916 | } |
| 1917 | |
| 1918 | RValue<SByte> operator+(RValue<SByte> val) |
| 1919 | { |
| 1920 | return val; |
| 1921 | } |
| 1922 | |
| 1923 | RValue<SByte> operator-(RValue<SByte> val) |
| 1924 | { |
| 1925 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1926 | } |
| 1927 | |
| 1928 | RValue<SByte> operator~(RValue<SByte> val) |
| 1929 | { |
| 1930 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1931 | } |
| 1932 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1933 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1934 | { |
| 1935 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1936 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1937 | return res; |
| 1938 | } |
| 1939 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1940 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1941 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1942 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1943 | return val; |
| 1944 | } |
| 1945 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1946 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1947 | { |
| 1948 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1949 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1950 | return res; |
| 1951 | } |
| 1952 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1953 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1954 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1955 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1956 | return val; |
| 1957 | } |
| 1958 | |
| 1959 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1960 | { |
| 1961 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1962 | } |
| 1963 | |
| 1964 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1965 | { |
| 1966 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1967 | } |
| 1968 | |
| 1969 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1970 | { |
| 1971 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1972 | } |
| 1973 | |
| 1974 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1975 | { |
| 1976 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1977 | } |
| 1978 | |
| 1979 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1980 | { |
| 1981 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1982 | } |
| 1983 | |
| 1984 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1985 | { |
| 1986 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1987 | } |
| 1988 | |
| 1989 | Type *SByte::getType() |
| 1990 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1991 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | Short::Short(Argument<Short> argument) |
| 1995 | { |
| 1996 | storeValue(argument.value); |
| 1997 | } |
| 1998 | |
| 1999 | Short::Short(RValue<Int> cast) |
| 2000 | { |
| 2001 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2002 | |
| 2003 | storeValue(integer); |
| 2004 | } |
| 2005 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2006 | Short::Short(short x) |
| 2007 | { |
| 2008 | storeValue(Nucleus::createConstantShort(x)); |
| 2009 | } |
| 2010 | |
| 2011 | Short::Short(RValue<Short> rhs) |
| 2012 | { |
| 2013 | storeValue(rhs.value); |
| 2014 | } |
| 2015 | |
| 2016 | Short::Short(const Short &rhs) |
| 2017 | { |
| 2018 | Value *value = rhs.loadValue(); |
| 2019 | storeValue(value); |
| 2020 | } |
| 2021 | |
| 2022 | Short::Short(const Reference<Short> &rhs) |
| 2023 | { |
| 2024 | Value *value = rhs.loadValue(); |
| 2025 | storeValue(value); |
| 2026 | } |
| 2027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2028 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2029 | { |
| 2030 | storeValue(rhs.value); |
| 2031 | |
| 2032 | return rhs; |
| 2033 | } |
| 2034 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2035 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2036 | { |
| 2037 | Value *value = rhs.loadValue(); |
| 2038 | storeValue(value); |
| 2039 | |
| 2040 | return RValue<Short>(value); |
| 2041 | } |
| 2042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2043 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2044 | { |
| 2045 | Value *value = rhs.loadValue(); |
| 2046 | storeValue(value); |
| 2047 | |
| 2048 | return RValue<Short>(value); |
| 2049 | } |
| 2050 | |
| 2051 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 2052 | { |
| 2053 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2054 | } |
| 2055 | |
| 2056 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 2057 | { |
| 2058 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2059 | } |
| 2060 | |
| 2061 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 2062 | { |
| 2063 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2064 | } |
| 2065 | |
| 2066 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 2067 | { |
| 2068 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2069 | } |
| 2070 | |
| 2071 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 2072 | { |
| 2073 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2074 | } |
| 2075 | |
| 2076 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 2077 | { |
| 2078 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2079 | } |
| 2080 | |
| 2081 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 2082 | { |
| 2083 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2084 | } |
| 2085 | |
| 2086 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2087 | { |
| 2088 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2089 | } |
| 2090 | |
| 2091 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2092 | { |
| 2093 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2094 | } |
| 2095 | |
| 2096 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2097 | { |
| 2098 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2099 | } |
| 2100 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2101 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2102 | { |
| 2103 | return lhs = lhs + rhs; |
| 2104 | } |
| 2105 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2106 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2107 | { |
| 2108 | return lhs = lhs - rhs; |
| 2109 | } |
| 2110 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2111 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2112 | { |
| 2113 | return lhs = lhs * rhs; |
| 2114 | } |
| 2115 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2116 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2117 | { |
| 2118 | return lhs = lhs / rhs; |
| 2119 | } |
| 2120 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2121 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2122 | { |
| 2123 | return lhs = lhs % rhs; |
| 2124 | } |
| 2125 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2126 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2127 | { |
| 2128 | return lhs = lhs & rhs; |
| 2129 | } |
| 2130 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2131 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2132 | { |
| 2133 | return lhs = lhs | rhs; |
| 2134 | } |
| 2135 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2136 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2137 | { |
| 2138 | return lhs = lhs ^ rhs; |
| 2139 | } |
| 2140 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2141 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2142 | { |
| 2143 | return lhs = lhs << rhs; |
| 2144 | } |
| 2145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2146 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2147 | { |
| 2148 | return lhs = lhs >> rhs; |
| 2149 | } |
| 2150 | |
| 2151 | RValue<Short> operator+(RValue<Short> val) |
| 2152 | { |
| 2153 | return val; |
| 2154 | } |
| 2155 | |
| 2156 | RValue<Short> operator-(RValue<Short> val) |
| 2157 | { |
| 2158 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2159 | } |
| 2160 | |
| 2161 | RValue<Short> operator~(RValue<Short> val) |
| 2162 | { |
| 2163 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2164 | } |
| 2165 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2166 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2167 | { |
| 2168 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2169 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2170 | return res; |
| 2171 | } |
| 2172 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2173 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2174 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2175 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2176 | return val; |
| 2177 | } |
| 2178 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2179 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2180 | { |
| 2181 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2182 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2183 | return res; |
| 2184 | } |
| 2185 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2186 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2187 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2188 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2189 | return val; |
| 2190 | } |
| 2191 | |
| 2192 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2193 | { |
| 2194 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2195 | } |
| 2196 | |
| 2197 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2198 | { |
| 2199 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2200 | } |
| 2201 | |
| 2202 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2203 | { |
| 2204 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2205 | } |
| 2206 | |
| 2207 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2208 | { |
| 2209 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2210 | } |
| 2211 | |
| 2212 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2213 | { |
| 2214 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2215 | } |
| 2216 | |
| 2217 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2218 | { |
| 2219 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2220 | } |
| 2221 | |
| 2222 | Type *Short::getType() |
| 2223 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2224 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | UShort::UShort(Argument<UShort> argument) |
| 2228 | { |
| 2229 | storeValue(argument.value); |
| 2230 | } |
| 2231 | |
| 2232 | UShort::UShort(RValue<UInt> cast) |
| 2233 | { |
| 2234 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2235 | |
| 2236 | storeValue(integer); |
| 2237 | } |
| 2238 | |
| 2239 | UShort::UShort(RValue<Int> cast) |
| 2240 | { |
| 2241 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2242 | |
| 2243 | storeValue(integer); |
| 2244 | } |
| 2245 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2246 | UShort::UShort(unsigned short x) |
| 2247 | { |
| 2248 | storeValue(Nucleus::createConstantShort(x)); |
| 2249 | } |
| 2250 | |
| 2251 | UShort::UShort(RValue<UShort> rhs) |
| 2252 | { |
| 2253 | storeValue(rhs.value); |
| 2254 | } |
| 2255 | |
| 2256 | UShort::UShort(const UShort &rhs) |
| 2257 | { |
| 2258 | Value *value = rhs.loadValue(); |
| 2259 | storeValue(value); |
| 2260 | } |
| 2261 | |
| 2262 | UShort::UShort(const Reference<UShort> &rhs) |
| 2263 | { |
| 2264 | Value *value = rhs.loadValue(); |
| 2265 | storeValue(value); |
| 2266 | } |
| 2267 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2268 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2269 | { |
| 2270 | storeValue(rhs.value); |
| 2271 | |
| 2272 | return rhs; |
| 2273 | } |
| 2274 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2275 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2276 | { |
| 2277 | Value *value = rhs.loadValue(); |
| 2278 | storeValue(value); |
| 2279 | |
| 2280 | return RValue<UShort>(value); |
| 2281 | } |
| 2282 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2283 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2284 | { |
| 2285 | Value *value = rhs.loadValue(); |
| 2286 | storeValue(value); |
| 2287 | |
| 2288 | return RValue<UShort>(value); |
| 2289 | } |
| 2290 | |
| 2291 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2292 | { |
| 2293 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2294 | } |
| 2295 | |
| 2296 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2297 | { |
| 2298 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2299 | } |
| 2300 | |
| 2301 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2302 | { |
| 2303 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2304 | } |
| 2305 | |
| 2306 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2307 | { |
| 2308 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2309 | } |
| 2310 | |
| 2311 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2312 | { |
| 2313 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2314 | } |
| 2315 | |
| 2316 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2317 | { |
| 2318 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2319 | } |
| 2320 | |
| 2321 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2322 | { |
| 2323 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2324 | } |
| 2325 | |
| 2326 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2327 | { |
| 2328 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2329 | } |
| 2330 | |
| 2331 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2332 | { |
| 2333 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2334 | } |
| 2335 | |
| 2336 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2337 | { |
| 2338 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2339 | } |
| 2340 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2341 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2342 | { |
| 2343 | return lhs = lhs + rhs; |
| 2344 | } |
| 2345 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2346 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2347 | { |
| 2348 | return lhs = lhs - rhs; |
| 2349 | } |
| 2350 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2351 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2352 | { |
| 2353 | return lhs = lhs * rhs; |
| 2354 | } |
| 2355 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2356 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2357 | { |
| 2358 | return lhs = lhs / rhs; |
| 2359 | } |
| 2360 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2361 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2362 | { |
| 2363 | return lhs = lhs % rhs; |
| 2364 | } |
| 2365 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2366 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2367 | { |
| 2368 | return lhs = lhs & rhs; |
| 2369 | } |
| 2370 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2371 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2372 | { |
| 2373 | return lhs = lhs | rhs; |
| 2374 | } |
| 2375 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2376 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2377 | { |
| 2378 | return lhs = lhs ^ rhs; |
| 2379 | } |
| 2380 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2381 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2382 | { |
| 2383 | return lhs = lhs << rhs; |
| 2384 | } |
| 2385 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2386 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2387 | { |
| 2388 | return lhs = lhs >> rhs; |
| 2389 | } |
| 2390 | |
| 2391 | RValue<UShort> operator+(RValue<UShort> val) |
| 2392 | { |
| 2393 | return val; |
| 2394 | } |
| 2395 | |
| 2396 | RValue<UShort> operator-(RValue<UShort> val) |
| 2397 | { |
| 2398 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2399 | } |
| 2400 | |
| 2401 | RValue<UShort> operator~(RValue<UShort> val) |
| 2402 | { |
| 2403 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2404 | } |
| 2405 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2406 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2407 | { |
| 2408 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2409 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2410 | return res; |
| 2411 | } |
| 2412 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2413 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2414 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2415 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2416 | return val; |
| 2417 | } |
| 2418 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2419 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2420 | { |
| 2421 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2422 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2423 | return res; |
| 2424 | } |
| 2425 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2426 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2427 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2428 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2429 | return val; |
| 2430 | } |
| 2431 | |
| 2432 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2433 | { |
| 2434 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2435 | } |
| 2436 | |
| 2437 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2438 | { |
| 2439 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2440 | } |
| 2441 | |
| 2442 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2443 | { |
| 2444 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2445 | } |
| 2446 | |
| 2447 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2448 | { |
| 2449 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2450 | } |
| 2451 | |
| 2452 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2453 | { |
| 2454 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2455 | } |
| 2456 | |
| 2457 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2458 | { |
| 2459 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2460 | } |
| 2461 | |
| 2462 | Type *UShort::getType() |
| 2463 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2464 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2465 | } |
| 2466 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2467 | Byte4::Byte4(RValue<Byte8> cast) |
| 2468 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2469 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2470 | } |
| 2471 | |
| 2472 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2473 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2474 | Value *value = rhs.loadValue(); |
| 2475 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2476 | } |
| 2477 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2478 | Type *Byte4::getType() |
| 2479 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2480 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | Type *SByte4::getType() |
| 2484 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2485 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2486 | } |
| 2487 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2488 | 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) |
| 2489 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2490 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2491 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2495 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2496 | storeValue(rhs.value); |
| 2497 | } |
| 2498 | |
| 2499 | Byte8::Byte8(const Byte8 &rhs) |
| 2500 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2501 | Value *value = rhs.loadValue(); |
| 2502 | storeValue(value); |
| 2503 | } |
| 2504 | |
| 2505 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2506 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2507 | Value *value = rhs.loadValue(); |
| 2508 | storeValue(value); |
| 2509 | } |
| 2510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2511 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2512 | { |
| 2513 | storeValue(rhs.value); |
| 2514 | |
| 2515 | return rhs; |
| 2516 | } |
| 2517 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2518 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2519 | { |
| 2520 | Value *value = rhs.loadValue(); |
| 2521 | storeValue(value); |
| 2522 | |
| 2523 | return RValue<Byte8>(value); |
| 2524 | } |
| 2525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2526 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2527 | { |
| 2528 | Value *value = rhs.loadValue(); |
| 2529 | storeValue(value); |
| 2530 | |
| 2531 | return RValue<Byte8>(value); |
| 2532 | } |
| 2533 | |
| 2534 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2535 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2536 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2540 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2541 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2545 | // { |
| 2546 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2547 | // } |
| 2548 | |
| 2549 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2550 | // { |
| 2551 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2552 | // } |
| 2553 | |
| 2554 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2555 | // { |
| 2556 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2557 | // } |
| 2558 | |
| 2559 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2560 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2561 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2562 | } |
| 2563 | |
| 2564 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2565 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2566 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2570 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2571 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2575 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2576 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2577 | // } |
| 2578 | |
| 2579 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2580 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2581 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2582 | // } |
| 2583 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2584 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2585 | { |
| 2586 | return lhs = lhs + rhs; |
| 2587 | } |
| 2588 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2589 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2590 | { |
| 2591 | return lhs = lhs - rhs; |
| 2592 | } |
| 2593 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2594 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2595 | // { |
| 2596 | // return lhs = lhs * rhs; |
| 2597 | // } |
| 2598 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2599 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2600 | // { |
| 2601 | // return lhs = lhs / rhs; |
| 2602 | // } |
| 2603 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2604 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2605 | // { |
| 2606 | // return lhs = lhs % rhs; |
| 2607 | // } |
| 2608 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2609 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2610 | { |
| 2611 | return lhs = lhs & rhs; |
| 2612 | } |
| 2613 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2614 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2615 | { |
| 2616 | return lhs = lhs | rhs; |
| 2617 | } |
| 2618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2619 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2620 | { |
| 2621 | return lhs = lhs ^ rhs; |
| 2622 | } |
| 2623 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2624 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2625 | // { |
| 2626 | // return lhs = lhs << rhs; |
| 2627 | // } |
| 2628 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2629 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2630 | // { |
| 2631 | // return lhs = lhs >> rhs; |
| 2632 | // } |
| 2633 | |
| 2634 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2635 | // { |
| 2636 | // return val; |
| 2637 | // } |
| 2638 | |
| 2639 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2640 | // { |
| 2641 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2642 | // } |
| 2643 | |
| 2644 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2645 | { |
| 2646 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2647 | } |
| 2648 | |
| 2649 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2650 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2651 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2652 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2653 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2654 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2655 | paddusb->addArg(x.value); |
| 2656 | paddusb->addArg(y.value); |
| 2657 | ::basicBlock->appendInst(paddusb); |
| 2658 | |
| 2659 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2663 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2664 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2665 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2666 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2667 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2668 | psubusw->addArg(x.value); |
| 2669 | psubusw->addArg(y.value); |
| 2670 | ::basicBlock->appendInst(psubusw); |
| 2671 | |
| 2672 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2676 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2677 | 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] | 2678 | return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2679 | } |
| 2680 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2681 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2682 | { |
| 2683 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| 2684 | } |
| 2685 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2686 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2687 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2688 | 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] | 2689 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2693 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2694 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2695 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2696 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2697 | } |
| 2698 | |
| 2699 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2700 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2701 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2702 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2703 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2704 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2705 | movmsk->addArg(x.value); |
| 2706 | ::basicBlock->appendInst(movmsk); |
| 2707 | |
| 2708 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2712 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2713 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2714 | // } |
| 2715 | |
| 2716 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2717 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2718 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | Type *Byte8::getType() |
| 2722 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2723 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2724 | } |
| 2725 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2726 | 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) |
| 2727 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2728 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2729 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2730 | |
| 2731 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2732 | } |
| 2733 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2734 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2735 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2736 | storeValue(rhs.value); |
| 2737 | } |
| 2738 | |
| 2739 | SByte8::SByte8(const SByte8 &rhs) |
| 2740 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2741 | Value *value = rhs.loadValue(); |
| 2742 | storeValue(value); |
| 2743 | } |
| 2744 | |
| 2745 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2746 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2747 | Value *value = rhs.loadValue(); |
| 2748 | storeValue(value); |
| 2749 | } |
| 2750 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2751 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2752 | { |
| 2753 | storeValue(rhs.value); |
| 2754 | |
| 2755 | return rhs; |
| 2756 | } |
| 2757 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2758 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2759 | { |
| 2760 | Value *value = rhs.loadValue(); |
| 2761 | storeValue(value); |
| 2762 | |
| 2763 | return RValue<SByte8>(value); |
| 2764 | } |
| 2765 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2766 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2767 | { |
| 2768 | Value *value = rhs.loadValue(); |
| 2769 | storeValue(value); |
| 2770 | |
| 2771 | return RValue<SByte8>(value); |
| 2772 | } |
| 2773 | |
| 2774 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2775 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2776 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2780 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2781 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2785 | // { |
| 2786 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2787 | // } |
| 2788 | |
| 2789 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2790 | // { |
| 2791 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2792 | // } |
| 2793 | |
| 2794 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2795 | // { |
| 2796 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2797 | // } |
| 2798 | |
| 2799 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2800 | { |
| 2801 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2802 | } |
| 2803 | |
| 2804 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2805 | { |
| 2806 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2807 | } |
| 2808 | |
| 2809 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2810 | { |
| 2811 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2812 | } |
| 2813 | |
| 2814 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2815 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2816 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2817 | // } |
| 2818 | |
| 2819 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2820 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2821 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2822 | // } |
| 2823 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2824 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2825 | { |
| 2826 | return lhs = lhs + rhs; |
| 2827 | } |
| 2828 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2829 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2830 | { |
| 2831 | return lhs = lhs - rhs; |
| 2832 | } |
| 2833 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2834 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2835 | // { |
| 2836 | // return lhs = lhs * rhs; |
| 2837 | // } |
| 2838 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2839 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2840 | // { |
| 2841 | // return lhs = lhs / rhs; |
| 2842 | // } |
| 2843 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2844 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2845 | // { |
| 2846 | // return lhs = lhs % rhs; |
| 2847 | // } |
| 2848 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2849 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2850 | { |
| 2851 | return lhs = lhs & rhs; |
| 2852 | } |
| 2853 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2854 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2855 | { |
| 2856 | return lhs = lhs | rhs; |
| 2857 | } |
| 2858 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2859 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2860 | { |
| 2861 | return lhs = lhs ^ rhs; |
| 2862 | } |
| 2863 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2864 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2865 | // { |
| 2866 | // return lhs = lhs << rhs; |
| 2867 | // } |
| 2868 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2869 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2870 | // { |
| 2871 | // return lhs = lhs >> rhs; |
| 2872 | // } |
| 2873 | |
| 2874 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2875 | // { |
| 2876 | // return val; |
| 2877 | // } |
| 2878 | |
| 2879 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2880 | // { |
| 2881 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2882 | // } |
| 2883 | |
| 2884 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2885 | { |
| 2886 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2887 | } |
| 2888 | |
| 2889 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2890 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2891 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2892 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2893 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2894 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2895 | paddsb->addArg(x.value); |
| 2896 | paddsb->addArg(y.value); |
| 2897 | ::basicBlock->appendInst(paddsb); |
| 2898 | |
| 2899 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2903 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2904 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2905 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2906 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2907 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2908 | psubsb->addArg(x.value); |
| 2909 | psubsb->addArg(y.value); |
| 2910 | ::basicBlock->appendInst(psubsb); |
| 2911 | |
| 2912 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2916 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2917 | 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] | 2918 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2922 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2923 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2924 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2925 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2929 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2930 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2931 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2932 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2933 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2934 | movmsk->addArg(x.value); |
| 2935 | ::basicBlock->appendInst(movmsk); |
| 2936 | |
| 2937 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2941 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2942 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2946 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2947 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | Type *SByte8::getType() |
| 2951 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2952 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2956 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2957 | storeValue(rhs.value); |
| 2958 | } |
| 2959 | |
| 2960 | Byte16::Byte16(const Byte16 &rhs) |
| 2961 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2962 | Value *value = rhs.loadValue(); |
| 2963 | storeValue(value); |
| 2964 | } |
| 2965 | |
| 2966 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2967 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2968 | Value *value = rhs.loadValue(); |
| 2969 | storeValue(value); |
| 2970 | } |
| 2971 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2972 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2973 | { |
| 2974 | storeValue(rhs.value); |
| 2975 | |
| 2976 | return rhs; |
| 2977 | } |
| 2978 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2979 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2980 | { |
| 2981 | Value *value = rhs.loadValue(); |
| 2982 | storeValue(value); |
| 2983 | |
| 2984 | return RValue<Byte16>(value); |
| 2985 | } |
| 2986 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2987 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2988 | { |
| 2989 | Value *value = rhs.loadValue(); |
| 2990 | storeValue(value); |
| 2991 | |
| 2992 | return RValue<Byte16>(value); |
| 2993 | } |
| 2994 | |
| 2995 | Type *Byte16::getType() |
| 2996 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2997 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | Type *SByte16::getType() |
| 3001 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3002 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3003 | } |
| 3004 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3005 | Short2::Short2(RValue<Short4> cast) |
| 3006 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3007 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | Type *Short2::getType() |
| 3011 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3012 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | UShort2::UShort2(RValue<UShort4> cast) |
| 3016 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3017 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | Type *UShort2::getType() |
| 3021 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3022 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3023 | } |
| 3024 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3025 | Short4::Short4(RValue<Int> cast) |
| 3026 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3027 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 3028 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 3029 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3030 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3031 | |
| 3032 | storeValue(swizzle); |
| 3033 | } |
| 3034 | |
| 3035 | Short4::Short4(RValue<Int4> cast) |
| 3036 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 3037 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 3038 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 3039 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3040 | |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3041 | Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value; |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3042 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 3043 | |
| 3044 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | // Short4::Short4(RValue<Float> cast) |
| 3048 | // { |
| 3049 | // } |
| 3050 | |
| 3051 | Short4::Short4(RValue<Float4> cast) |
| 3052 | { |
| 3053 | assert(false && "UNIMPLEMENTED"); |
| 3054 | } |
| 3055 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3056 | Short4::Short4(short xyzw) |
| 3057 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3058 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3059 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | Short4::Short4(short x, short y, short z, short w) |
| 3063 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3064 | int64_t constantVector[4] = {x, y, z, w}; |
| 3065 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | Short4::Short4(RValue<Short4> rhs) |
| 3069 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3070 | storeValue(rhs.value); |
| 3071 | } |
| 3072 | |
| 3073 | Short4::Short4(const Short4 &rhs) |
| 3074 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3075 | Value *value = rhs.loadValue(); |
| 3076 | storeValue(value); |
| 3077 | } |
| 3078 | |
| 3079 | Short4::Short4(const Reference<Short4> &rhs) |
| 3080 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3081 | Value *value = rhs.loadValue(); |
| 3082 | storeValue(value); |
| 3083 | } |
| 3084 | |
| 3085 | Short4::Short4(RValue<UShort4> rhs) |
| 3086 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3087 | storeValue(rhs.value); |
| 3088 | } |
| 3089 | |
| 3090 | Short4::Short4(const UShort4 &rhs) |
| 3091 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3092 | storeValue(rhs.loadValue()); |
| 3093 | } |
| 3094 | |
| 3095 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3096 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3097 | storeValue(rhs.loadValue()); |
| 3098 | } |
| 3099 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3100 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3101 | { |
| 3102 | storeValue(rhs.value); |
| 3103 | |
| 3104 | return rhs; |
| 3105 | } |
| 3106 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3107 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3108 | { |
| 3109 | Value *value = rhs.loadValue(); |
| 3110 | storeValue(value); |
| 3111 | |
| 3112 | return RValue<Short4>(value); |
| 3113 | } |
| 3114 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3115 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3116 | { |
| 3117 | Value *value = rhs.loadValue(); |
| 3118 | storeValue(value); |
| 3119 | |
| 3120 | return RValue<Short4>(value); |
| 3121 | } |
| 3122 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3123 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3124 | { |
| 3125 | storeValue(rhs.value); |
| 3126 | |
| 3127 | return RValue<Short4>(rhs); |
| 3128 | } |
| 3129 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3130 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3131 | { |
| 3132 | Value *value = rhs.loadValue(); |
| 3133 | storeValue(value); |
| 3134 | |
| 3135 | return RValue<Short4>(value); |
| 3136 | } |
| 3137 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3138 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3139 | { |
| 3140 | Value *value = rhs.loadValue(); |
| 3141 | storeValue(value); |
| 3142 | |
| 3143 | return RValue<Short4>(value); |
| 3144 | } |
| 3145 | |
| 3146 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3147 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3148 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3152 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3153 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3154 | } |
| 3155 | |
| 3156 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3157 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3158 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3162 | // { |
| 3163 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3164 | // } |
| 3165 | |
| 3166 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3167 | // { |
| 3168 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3169 | // } |
| 3170 | |
| 3171 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3172 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3173 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3177 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3178 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3182 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3183 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3187 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3188 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3192 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3193 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3194 | } |
| 3195 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3196 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3197 | { |
| 3198 | return lhs = lhs + rhs; |
| 3199 | } |
| 3200 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3201 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3202 | { |
| 3203 | return lhs = lhs - rhs; |
| 3204 | } |
| 3205 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3206 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3207 | { |
| 3208 | return lhs = lhs * rhs; |
| 3209 | } |
| 3210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3211 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3212 | // { |
| 3213 | // return lhs = lhs / rhs; |
| 3214 | // } |
| 3215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3216 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3217 | // { |
| 3218 | // return lhs = lhs % rhs; |
| 3219 | // } |
| 3220 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3221 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3222 | { |
| 3223 | return lhs = lhs & rhs; |
| 3224 | } |
| 3225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3226 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3227 | { |
| 3228 | return lhs = lhs | rhs; |
| 3229 | } |
| 3230 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3231 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3232 | { |
| 3233 | return lhs = lhs ^ rhs; |
| 3234 | } |
| 3235 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3236 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3237 | { |
| 3238 | return lhs = lhs << rhs; |
| 3239 | } |
| 3240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3241 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3242 | { |
| 3243 | return lhs = lhs >> rhs; |
| 3244 | } |
| 3245 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3246 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3247 | // { |
| 3248 | // return val; |
| 3249 | // } |
| 3250 | |
| 3251 | RValue<Short4> operator-(RValue<Short4> val) |
| 3252 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3253 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | RValue<Short4> operator~(RValue<Short4> val) |
| 3257 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3258 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3262 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3263 | RValue<Int4> int4 = RoundInt(cast); |
| 3264 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3268 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3269 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3270 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3271 | ::basicBlock->appendInst(cmp); |
| 3272 | |
| 3273 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3274 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3275 | ::basicBlock->appendInst(select); |
| 3276 | |
| 3277 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3281 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3282 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3283 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3284 | ::basicBlock->appendInst(cmp); |
| 3285 | |
| 3286 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3287 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3288 | ::basicBlock->appendInst(select); |
| 3289 | |
| 3290 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3294 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3295 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3296 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3297 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3298 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3299 | paddsw->addArg(x.value); |
| 3300 | paddsw->addArg(y.value); |
| 3301 | ::basicBlock->appendInst(paddsw); |
| 3302 | |
| 3303 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3307 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3308 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3309 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3310 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3311 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3312 | psubsw->addArg(x.value); |
| 3313 | psubsw->addArg(y.value); |
| 3314 | ::basicBlock->appendInst(psubsw); |
| 3315 | |
| 3316 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3320 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3321 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3322 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3323 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3324 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3325 | pmulhw->addArg(x.value); |
| 3326 | pmulhw->addArg(y.value); |
| 3327 | ::basicBlock->appendInst(pmulhw); |
| 3328 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3329 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3333 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3334 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3335 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3336 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3337 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3338 | pmaddwd->addArg(x.value); |
| 3339 | pmaddwd->addArg(y.value); |
| 3340 | ::basicBlock->appendInst(pmaddwd); |
| 3341 | |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3342 | return As<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3346 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3347 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3348 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3349 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3350 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3351 | pack->addArg(x.value); |
| 3352 | pack->addArg(y.value); |
| 3353 | ::basicBlock->appendInst(pack); |
| 3354 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3355 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3359 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3360 | 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] | 3361 | return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3365 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3366 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3367 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3368 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3372 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3373 | // Real type is v8i16 |
| 3374 | int shuffle[8] = |
| 3375 | { |
| 3376 | (select >> 0) & 0x03, |
| 3377 | (select >> 2) & 0x03, |
| 3378 | (select >> 4) & 0x03, |
| 3379 | (select >> 6) & 0x03, |
| 3380 | (select >> 0) & 0x03, |
| 3381 | (select >> 2) & 0x03, |
| 3382 | (select >> 4) & 0x03, |
| 3383 | (select >> 6) & 0x03, |
| 3384 | }; |
| 3385 | |
| 3386 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3390 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3391 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3395 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3396 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3400 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3401 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3405 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3406 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | Type *Short4::getType() |
| 3410 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3411 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | UShort4::UShort4(RValue<Int4> cast) |
| 3415 | { |
| 3416 | *this = Short4(cast); |
| 3417 | } |
| 3418 | |
| 3419 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3420 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3421 | if(saturate) |
| 3422 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3423 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3424 | { |
| 3425 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3426 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3427 | } |
| 3428 | else |
| 3429 | { |
| 3430 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3431 | } |
| 3432 | } |
| 3433 | else |
| 3434 | { |
| 3435 | *this = Short4(Int4(cast)); |
| 3436 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3437 | } |
| 3438 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3439 | UShort4::UShort4(unsigned short xyzw) |
| 3440 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3441 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3442 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3446 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3447 | int64_t constantVector[4] = {x, y, z, w}; |
| 3448 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3452 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3453 | storeValue(rhs.value); |
| 3454 | } |
| 3455 | |
| 3456 | UShort4::UShort4(const UShort4 &rhs) |
| 3457 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3458 | Value *value = rhs.loadValue(); |
| 3459 | storeValue(value); |
| 3460 | } |
| 3461 | |
| 3462 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3463 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3464 | Value *value = rhs.loadValue(); |
| 3465 | storeValue(value); |
| 3466 | } |
| 3467 | |
| 3468 | UShort4::UShort4(RValue<Short4> rhs) |
| 3469 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3470 | storeValue(rhs.value); |
| 3471 | } |
| 3472 | |
| 3473 | UShort4::UShort4(const Short4 &rhs) |
| 3474 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3475 | Value *value = rhs.loadValue(); |
| 3476 | storeValue(value); |
| 3477 | } |
| 3478 | |
| 3479 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3480 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3481 | Value *value = rhs.loadValue(); |
| 3482 | storeValue(value); |
| 3483 | } |
| 3484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3485 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3486 | { |
| 3487 | storeValue(rhs.value); |
| 3488 | |
| 3489 | return rhs; |
| 3490 | } |
| 3491 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3492 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3493 | { |
| 3494 | Value *value = rhs.loadValue(); |
| 3495 | storeValue(value); |
| 3496 | |
| 3497 | return RValue<UShort4>(value); |
| 3498 | } |
| 3499 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3500 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3501 | { |
| 3502 | Value *value = rhs.loadValue(); |
| 3503 | storeValue(value); |
| 3504 | |
| 3505 | return RValue<UShort4>(value); |
| 3506 | } |
| 3507 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3508 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3509 | { |
| 3510 | storeValue(rhs.value); |
| 3511 | |
| 3512 | return RValue<UShort4>(rhs); |
| 3513 | } |
| 3514 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3515 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3516 | { |
| 3517 | Value *value = rhs.loadValue(); |
| 3518 | storeValue(value); |
| 3519 | |
| 3520 | return RValue<UShort4>(value); |
| 3521 | } |
| 3522 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3523 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3524 | { |
| 3525 | Value *value = rhs.loadValue(); |
| 3526 | storeValue(value); |
| 3527 | |
| 3528 | return RValue<UShort4>(value); |
| 3529 | } |
| 3530 | |
| 3531 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3532 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3533 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3534 | } |
| 3535 | |
| 3536 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3537 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3538 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3542 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3543 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3544 | } |
| 3545 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3546 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3547 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3548 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3552 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3553 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3557 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3558 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3559 | } |
| 3560 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3561 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3562 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3563 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3567 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3568 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3569 | } |
| 3570 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3571 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3572 | { |
| 3573 | return lhs = lhs << rhs; |
| 3574 | } |
| 3575 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3576 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3577 | { |
| 3578 | return lhs = lhs >> rhs; |
| 3579 | } |
| 3580 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3581 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3582 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3583 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3587 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3588 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3589 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3590 | ::basicBlock->appendInst(cmp); |
| 3591 | |
| 3592 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3593 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3594 | ::basicBlock->appendInst(select); |
| 3595 | |
| 3596 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3600 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3601 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3602 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3603 | ::basicBlock->appendInst(cmp); |
| 3604 | |
| 3605 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3606 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3607 | ::basicBlock->appendInst(select); |
| 3608 | |
| 3609 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3613 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3614 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3615 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3616 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3617 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3618 | paddusw->addArg(x.value); |
| 3619 | paddusw->addArg(y.value); |
| 3620 | ::basicBlock->appendInst(paddusw); |
| 3621 | |
| 3622 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3626 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3627 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3628 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3629 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3630 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3631 | psubusw->addArg(x.value); |
| 3632 | psubusw->addArg(y.value); |
| 3633 | ::basicBlock->appendInst(psubusw); |
| 3634 | |
| 3635 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3639 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3640 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3641 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3642 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3643 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3644 | pmulhuw->addArg(x.value); |
| 3645 | pmulhuw->addArg(y.value); |
| 3646 | ::basicBlock->appendInst(pmulhuw); |
| 3647 | |
| 3648 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3649 | } |
| 3650 | |
| 3651 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3652 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3653 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3657 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3658 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3659 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3660 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3661 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3662 | pack->addArg(x.value); |
| 3663 | pack->addArg(y.value); |
| 3664 | ::basicBlock->appendInst(pack); |
| 3665 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3666 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | Type *UShort4::getType() |
| 3670 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3671 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3672 | } |
| 3673 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3674 | Short8::Short8(short c) |
| 3675 | { |
| 3676 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3677 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3678 | } |
| 3679 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3680 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3681 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3682 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3683 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | Short8::Short8(RValue<Short8> rhs) |
| 3687 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3688 | storeValue(rhs.value); |
| 3689 | } |
| 3690 | |
| 3691 | Short8::Short8(const Reference<Short8> &rhs) |
| 3692 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3693 | Value *value = rhs.loadValue(); |
| 3694 | storeValue(value); |
| 3695 | } |
| 3696 | |
| 3697 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3698 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3699 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3700 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3701 | |
| 3702 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3706 | { |
| 3707 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3708 | } |
| 3709 | |
| 3710 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3711 | { |
| 3712 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3713 | } |
| 3714 | |
| 3715 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3716 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3717 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3721 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3722 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3726 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3727 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | RValue<Int4> Abs(RValue<Int4> x) |
| 3731 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3732 | auto negative = x >> 31; |
| 3733 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3737 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3738 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | Type *Short8::getType() |
| 3742 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3743 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3744 | } |
| 3745 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3746 | UShort8::UShort8(unsigned short c) |
| 3747 | { |
| 3748 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3749 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3750 | } |
| 3751 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3752 | 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) |
| 3753 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3754 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3755 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3759 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3760 | storeValue(rhs.value); |
| 3761 | } |
| 3762 | |
| 3763 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3764 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3765 | Value *value = rhs.loadValue(); |
| 3766 | storeValue(value); |
| 3767 | } |
| 3768 | |
| 3769 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3770 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3771 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3772 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3773 | |
| 3774 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3775 | } |
| 3776 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3777 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3778 | { |
| 3779 | storeValue(rhs.value); |
| 3780 | |
| 3781 | return rhs; |
| 3782 | } |
| 3783 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3784 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3785 | { |
| 3786 | Value *value = rhs.loadValue(); |
| 3787 | storeValue(value); |
| 3788 | |
| 3789 | return RValue<UShort8>(value); |
| 3790 | } |
| 3791 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3792 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3793 | { |
| 3794 | Value *value = rhs.loadValue(); |
| 3795 | storeValue(value); |
| 3796 | |
| 3797 | return RValue<UShort8>(value); |
| 3798 | } |
| 3799 | |
| 3800 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3801 | { |
| 3802 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3803 | } |
| 3804 | |
| 3805 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3806 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3807 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3811 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3812 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3816 | { |
| 3817 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3818 | } |
| 3819 | |
| 3820 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3821 | { |
| 3822 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3823 | } |
| 3824 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3825 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3826 | { |
| 3827 | return lhs = lhs + rhs; |
| 3828 | } |
| 3829 | |
| 3830 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3831 | { |
| 3832 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3833 | } |
| 3834 | |
| 3835 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3836 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3837 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3838 | } |
| 3839 | |
| 3840 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3841 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3842 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3846 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3847 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3848 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3849 | // } |
| 3850 | |
| 3851 | Type *UShort8::getType() |
| 3852 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3853 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | Int::Int(Argument<Int> argument) |
| 3857 | { |
| 3858 | storeValue(argument.value); |
| 3859 | } |
| 3860 | |
| 3861 | Int::Int(RValue<Byte> cast) |
| 3862 | { |
| 3863 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3864 | |
| 3865 | storeValue(integer); |
| 3866 | } |
| 3867 | |
| 3868 | Int::Int(RValue<SByte> cast) |
| 3869 | { |
| 3870 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3871 | |
| 3872 | storeValue(integer); |
| 3873 | } |
| 3874 | |
| 3875 | Int::Int(RValue<Short> cast) |
| 3876 | { |
| 3877 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3878 | |
| 3879 | storeValue(integer); |
| 3880 | } |
| 3881 | |
| 3882 | Int::Int(RValue<UShort> cast) |
| 3883 | { |
| 3884 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3885 | |
| 3886 | storeValue(integer); |
| 3887 | } |
| 3888 | |
| 3889 | Int::Int(RValue<Int2> cast) |
| 3890 | { |
| 3891 | *this = Extract(cast, 0); |
| 3892 | } |
| 3893 | |
| 3894 | Int::Int(RValue<Long> cast) |
| 3895 | { |
| 3896 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3897 | |
| 3898 | storeValue(integer); |
| 3899 | } |
| 3900 | |
| 3901 | Int::Int(RValue<Float> cast) |
| 3902 | { |
| 3903 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3904 | |
| 3905 | storeValue(integer); |
| 3906 | } |
| 3907 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3908 | Int::Int(int x) |
| 3909 | { |
| 3910 | storeValue(Nucleus::createConstantInt(x)); |
| 3911 | } |
| 3912 | |
| 3913 | Int::Int(RValue<Int> rhs) |
| 3914 | { |
| 3915 | storeValue(rhs.value); |
| 3916 | } |
| 3917 | |
| 3918 | Int::Int(RValue<UInt> rhs) |
| 3919 | { |
| 3920 | storeValue(rhs.value); |
| 3921 | } |
| 3922 | |
| 3923 | Int::Int(const Int &rhs) |
| 3924 | { |
| 3925 | Value *value = rhs.loadValue(); |
| 3926 | storeValue(value); |
| 3927 | } |
| 3928 | |
| 3929 | Int::Int(const Reference<Int> &rhs) |
| 3930 | { |
| 3931 | Value *value = rhs.loadValue(); |
| 3932 | storeValue(value); |
| 3933 | } |
| 3934 | |
| 3935 | Int::Int(const UInt &rhs) |
| 3936 | { |
| 3937 | Value *value = rhs.loadValue(); |
| 3938 | storeValue(value); |
| 3939 | } |
| 3940 | |
| 3941 | Int::Int(const Reference<UInt> &rhs) |
| 3942 | { |
| 3943 | Value *value = rhs.loadValue(); |
| 3944 | storeValue(value); |
| 3945 | } |
| 3946 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3947 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3948 | { |
| 3949 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3950 | } |
| 3951 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3952 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3953 | { |
| 3954 | storeValue(rhs.value); |
| 3955 | |
| 3956 | return rhs; |
| 3957 | } |
| 3958 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3959 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3960 | { |
| 3961 | storeValue(rhs.value); |
| 3962 | |
| 3963 | return RValue<Int>(rhs); |
| 3964 | } |
| 3965 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3966 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3967 | { |
| 3968 | Value *value = rhs.loadValue(); |
| 3969 | storeValue(value); |
| 3970 | |
| 3971 | return RValue<Int>(value); |
| 3972 | } |
| 3973 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3974 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3975 | { |
| 3976 | Value *value = rhs.loadValue(); |
| 3977 | storeValue(value); |
| 3978 | |
| 3979 | return RValue<Int>(value); |
| 3980 | } |
| 3981 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3982 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3983 | { |
| 3984 | Value *value = rhs.loadValue(); |
| 3985 | storeValue(value); |
| 3986 | |
| 3987 | return RValue<Int>(value); |
| 3988 | } |
| 3989 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3990 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3991 | { |
| 3992 | Value *value = rhs.loadValue(); |
| 3993 | storeValue(value); |
| 3994 | |
| 3995 | return RValue<Int>(value); |
| 3996 | } |
| 3997 | |
| 3998 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3999 | { |
| 4000 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4001 | } |
| 4002 | |
| 4003 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 4004 | { |
| 4005 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4006 | } |
| 4007 | |
| 4008 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 4009 | { |
| 4010 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4011 | } |
| 4012 | |
| 4013 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 4014 | { |
| 4015 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4016 | } |
| 4017 | |
| 4018 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 4019 | { |
| 4020 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4021 | } |
| 4022 | |
| 4023 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 4024 | { |
| 4025 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4026 | } |
| 4027 | |
| 4028 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 4029 | { |
| 4030 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4031 | } |
| 4032 | |
| 4033 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 4034 | { |
| 4035 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4036 | } |
| 4037 | |
| 4038 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 4039 | { |
| 4040 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4041 | } |
| 4042 | |
| 4043 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 4044 | { |
| 4045 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4046 | } |
| 4047 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4048 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4049 | { |
| 4050 | return lhs = lhs + rhs; |
| 4051 | } |
| 4052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4053 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4054 | { |
| 4055 | return lhs = lhs - rhs; |
| 4056 | } |
| 4057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4058 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4059 | { |
| 4060 | return lhs = lhs * rhs; |
| 4061 | } |
| 4062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4063 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4064 | { |
| 4065 | return lhs = lhs / rhs; |
| 4066 | } |
| 4067 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4068 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4069 | { |
| 4070 | return lhs = lhs % rhs; |
| 4071 | } |
| 4072 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4073 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4074 | { |
| 4075 | return lhs = lhs & rhs; |
| 4076 | } |
| 4077 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4078 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4079 | { |
| 4080 | return lhs = lhs | rhs; |
| 4081 | } |
| 4082 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4083 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4084 | { |
| 4085 | return lhs = lhs ^ rhs; |
| 4086 | } |
| 4087 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4088 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4089 | { |
| 4090 | return lhs = lhs << rhs; |
| 4091 | } |
| 4092 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4093 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4094 | { |
| 4095 | return lhs = lhs >> rhs; |
| 4096 | } |
| 4097 | |
| 4098 | RValue<Int> operator+(RValue<Int> val) |
| 4099 | { |
| 4100 | return val; |
| 4101 | } |
| 4102 | |
| 4103 | RValue<Int> operator-(RValue<Int> val) |
| 4104 | { |
| 4105 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4106 | } |
| 4107 | |
| 4108 | RValue<Int> operator~(RValue<Int> val) |
| 4109 | { |
| 4110 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4111 | } |
| 4112 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4113 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4114 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4115 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4116 | val += 1; |
| 4117 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4118 | } |
| 4119 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4120 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4121 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4122 | val += 1; |
| 4123 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4124 | } |
| 4125 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4126 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4127 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4128 | RValue<Int> res = val; |
| 4129 | val -= 1; |
| 4130 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4131 | } |
| 4132 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4133 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4134 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4135 | val -= 1; |
| 4136 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4140 | { |
| 4141 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4142 | } |
| 4143 | |
| 4144 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4145 | { |
| 4146 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4147 | } |
| 4148 | |
| 4149 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4150 | { |
| 4151 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4152 | } |
| 4153 | |
| 4154 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4155 | { |
| 4156 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4157 | } |
| 4158 | |
| 4159 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4160 | { |
| 4161 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4162 | } |
| 4163 | |
| 4164 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4165 | { |
| 4166 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4167 | } |
| 4168 | |
| 4169 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4170 | { |
| 4171 | return IfThenElse(x > y, x, y); |
| 4172 | } |
| 4173 | |
| 4174 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4175 | { |
| 4176 | return IfThenElse(x < y, x, y); |
| 4177 | } |
| 4178 | |
| 4179 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4180 | { |
| 4181 | return Min(Max(x, min), max); |
| 4182 | } |
| 4183 | |
| 4184 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4185 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4186 | if(emulateIntrinsics) |
| 4187 | { |
| 4188 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 4189 | return Int((cast + Float(0x00C00000)) - Float(0x00C00000)); |
| 4190 | } |
| 4191 | else |
| 4192 | { |
| 4193 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 4194 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4195 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4196 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4197 | nearbyint->addArg(cast.value); |
| 4198 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4199 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4200 | return RValue<Int>(V(result)); |
| 4201 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | Type *Int::getType() |
| 4205 | { |
| 4206 | return T(Ice::IceType_i32); |
| 4207 | } |
| 4208 | |
| 4209 | Long::Long(RValue<Int> cast) |
| 4210 | { |
| 4211 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4212 | |
| 4213 | storeValue(integer); |
| 4214 | } |
| 4215 | |
| 4216 | Long::Long(RValue<UInt> cast) |
| 4217 | { |
| 4218 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4219 | |
| 4220 | storeValue(integer); |
| 4221 | } |
| 4222 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4223 | Long::Long(RValue<Long> rhs) |
| 4224 | { |
| 4225 | storeValue(rhs.value); |
| 4226 | } |
| 4227 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4228 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4229 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4230 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4231 | } |
| 4232 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4233 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4234 | { |
| 4235 | storeValue(rhs.value); |
| 4236 | |
| 4237 | return rhs; |
| 4238 | } |
| 4239 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4240 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4241 | { |
| 4242 | Value *value = rhs.loadValue(); |
| 4243 | storeValue(value); |
| 4244 | |
| 4245 | return RValue<Long>(value); |
| 4246 | } |
| 4247 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4248 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4249 | { |
| 4250 | Value *value = rhs.loadValue(); |
| 4251 | storeValue(value); |
| 4252 | |
| 4253 | return RValue<Long>(value); |
| 4254 | } |
| 4255 | |
| 4256 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4257 | { |
| 4258 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4259 | } |
| 4260 | |
| 4261 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4262 | { |
| 4263 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4264 | } |
| 4265 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4266 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4267 | { |
| 4268 | return lhs = lhs + rhs; |
| 4269 | } |
| 4270 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4271 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4272 | { |
| 4273 | return lhs = lhs - rhs; |
| 4274 | } |
| 4275 | |
| 4276 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4277 | { |
| 4278 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4279 | } |
| 4280 | |
| 4281 | Type *Long::getType() |
| 4282 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4283 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4284 | } |
| 4285 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4286 | UInt::UInt(Argument<UInt> argument) |
| 4287 | { |
| 4288 | storeValue(argument.value); |
| 4289 | } |
| 4290 | |
| 4291 | UInt::UInt(RValue<UShort> cast) |
| 4292 | { |
| 4293 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4294 | |
| 4295 | storeValue(integer); |
| 4296 | } |
| 4297 | |
| 4298 | UInt::UInt(RValue<Long> cast) |
| 4299 | { |
| 4300 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4301 | |
| 4302 | storeValue(integer); |
| 4303 | } |
| 4304 | |
| 4305 | UInt::UInt(RValue<Float> cast) |
| 4306 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4307 | // Smallest positive value representable in UInt, but not in Int |
| 4308 | const unsigned int ustart = 0x80000000u; |
| 4309 | const float ustartf = float(ustart); |
| 4310 | |
| 4311 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4312 | storeValue((~(As<Int>(cast) >> 31) & |
| 4313 | // Check if the value can be represented as an Int |
| 4314 | IfThenElse(cast >= ustartf, |
| 4315 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4316 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4317 | // Otherwise, just convert normally |
| 4318 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4319 | } |
| 4320 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4321 | UInt::UInt(int x) |
| 4322 | { |
| 4323 | storeValue(Nucleus::createConstantInt(x)); |
| 4324 | } |
| 4325 | |
| 4326 | UInt::UInt(unsigned int x) |
| 4327 | { |
| 4328 | storeValue(Nucleus::createConstantInt(x)); |
| 4329 | } |
| 4330 | |
| 4331 | UInt::UInt(RValue<UInt> rhs) |
| 4332 | { |
| 4333 | storeValue(rhs.value); |
| 4334 | } |
| 4335 | |
| 4336 | UInt::UInt(RValue<Int> rhs) |
| 4337 | { |
| 4338 | storeValue(rhs.value); |
| 4339 | } |
| 4340 | |
| 4341 | UInt::UInt(const UInt &rhs) |
| 4342 | { |
| 4343 | Value *value = rhs.loadValue(); |
| 4344 | storeValue(value); |
| 4345 | } |
| 4346 | |
| 4347 | UInt::UInt(const Reference<UInt> &rhs) |
| 4348 | { |
| 4349 | Value *value = rhs.loadValue(); |
| 4350 | storeValue(value); |
| 4351 | } |
| 4352 | |
| 4353 | UInt::UInt(const Int &rhs) |
| 4354 | { |
| 4355 | Value *value = rhs.loadValue(); |
| 4356 | storeValue(value); |
| 4357 | } |
| 4358 | |
| 4359 | UInt::UInt(const Reference<Int> &rhs) |
| 4360 | { |
| 4361 | Value *value = rhs.loadValue(); |
| 4362 | storeValue(value); |
| 4363 | } |
| 4364 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4365 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4366 | { |
| 4367 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4368 | } |
| 4369 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4370 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4371 | { |
| 4372 | storeValue(rhs.value); |
| 4373 | |
| 4374 | return rhs; |
| 4375 | } |
| 4376 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4377 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4378 | { |
| 4379 | storeValue(rhs.value); |
| 4380 | |
| 4381 | return RValue<UInt>(rhs); |
| 4382 | } |
| 4383 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4384 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4385 | { |
| 4386 | Value *value = rhs.loadValue(); |
| 4387 | storeValue(value); |
| 4388 | |
| 4389 | return RValue<UInt>(value); |
| 4390 | } |
| 4391 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4392 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4393 | { |
| 4394 | Value *value = rhs.loadValue(); |
| 4395 | storeValue(value); |
| 4396 | |
| 4397 | return RValue<UInt>(value); |
| 4398 | } |
| 4399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4400 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4401 | { |
| 4402 | Value *value = rhs.loadValue(); |
| 4403 | storeValue(value); |
| 4404 | |
| 4405 | return RValue<UInt>(value); |
| 4406 | } |
| 4407 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4408 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4409 | { |
| 4410 | Value *value = rhs.loadValue(); |
| 4411 | storeValue(value); |
| 4412 | |
| 4413 | return RValue<UInt>(value); |
| 4414 | } |
| 4415 | |
| 4416 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4417 | { |
| 4418 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4419 | } |
| 4420 | |
| 4421 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4422 | { |
| 4423 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4424 | } |
| 4425 | |
| 4426 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4427 | { |
| 4428 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4429 | } |
| 4430 | |
| 4431 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4432 | { |
| 4433 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4434 | } |
| 4435 | |
| 4436 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4437 | { |
| 4438 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4439 | } |
| 4440 | |
| 4441 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4442 | { |
| 4443 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4444 | } |
| 4445 | |
| 4446 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4447 | { |
| 4448 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4449 | } |
| 4450 | |
| 4451 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4452 | { |
| 4453 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4454 | } |
| 4455 | |
| 4456 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4457 | { |
| 4458 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4459 | } |
| 4460 | |
| 4461 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4462 | { |
| 4463 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4464 | } |
| 4465 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4466 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4467 | { |
| 4468 | return lhs = lhs + rhs; |
| 4469 | } |
| 4470 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4471 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4472 | { |
| 4473 | return lhs = lhs - rhs; |
| 4474 | } |
| 4475 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4476 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4477 | { |
| 4478 | return lhs = lhs * rhs; |
| 4479 | } |
| 4480 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4481 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4482 | { |
| 4483 | return lhs = lhs / rhs; |
| 4484 | } |
| 4485 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4486 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4487 | { |
| 4488 | return lhs = lhs % rhs; |
| 4489 | } |
| 4490 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4491 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4492 | { |
| 4493 | return lhs = lhs & rhs; |
| 4494 | } |
| 4495 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4496 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4497 | { |
| 4498 | return lhs = lhs | rhs; |
| 4499 | } |
| 4500 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4501 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4502 | { |
| 4503 | return lhs = lhs ^ rhs; |
| 4504 | } |
| 4505 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4506 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4507 | { |
| 4508 | return lhs = lhs << rhs; |
| 4509 | } |
| 4510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4511 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4512 | { |
| 4513 | return lhs = lhs >> rhs; |
| 4514 | } |
| 4515 | |
| 4516 | RValue<UInt> operator+(RValue<UInt> val) |
| 4517 | { |
| 4518 | return val; |
| 4519 | } |
| 4520 | |
| 4521 | RValue<UInt> operator-(RValue<UInt> val) |
| 4522 | { |
| 4523 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4524 | } |
| 4525 | |
| 4526 | RValue<UInt> operator~(RValue<UInt> val) |
| 4527 | { |
| 4528 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4529 | } |
| 4530 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4531 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4532 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4533 | RValue<UInt> res = val; |
| 4534 | val += 1; |
| 4535 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4536 | } |
| 4537 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4538 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4539 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4540 | val += 1; |
| 4541 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4542 | } |
| 4543 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4544 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4545 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4546 | RValue<UInt> res = val; |
| 4547 | val -= 1; |
| 4548 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4549 | } |
| 4550 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4551 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4552 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4553 | val -= 1; |
| 4554 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4558 | { |
| 4559 | return IfThenElse(x > y, x, y); |
| 4560 | } |
| 4561 | |
| 4562 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4563 | { |
| 4564 | return IfThenElse(x < y, x, y); |
| 4565 | } |
| 4566 | |
| 4567 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4568 | { |
| 4569 | return Min(Max(x, min), max); |
| 4570 | } |
| 4571 | |
| 4572 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4573 | { |
| 4574 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4575 | } |
| 4576 | |
| 4577 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4578 | { |
| 4579 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4580 | } |
| 4581 | |
| 4582 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4583 | { |
| 4584 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4585 | } |
| 4586 | |
| 4587 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4588 | { |
| 4589 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4590 | } |
| 4591 | |
| 4592 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4593 | { |
| 4594 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4595 | } |
| 4596 | |
| 4597 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4598 | { |
| 4599 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4600 | } |
| 4601 | |
| 4602 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4603 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4604 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4605 | // } |
| 4606 | |
| 4607 | Type *UInt::getType() |
| 4608 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4609 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | // Int2::Int2(RValue<Int> cast) |
| 4613 | // { |
| 4614 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4615 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4616 | // |
| 4617 | // Constant *shuffle[2]; |
| 4618 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4619 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4620 | // |
| 4621 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4622 | // |
| 4623 | // storeValue(replicate); |
| 4624 | // } |
| 4625 | |
| 4626 | Int2::Int2(RValue<Int4> cast) |
| 4627 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4628 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4629 | } |
| 4630 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4631 | Int2::Int2(int x, int y) |
| 4632 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4633 | int64_t constantVector[2] = {x, y}; |
| 4634 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | Int2::Int2(RValue<Int2> rhs) |
| 4638 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4639 | storeValue(rhs.value); |
| 4640 | } |
| 4641 | |
| 4642 | Int2::Int2(const Int2 &rhs) |
| 4643 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4644 | Value *value = rhs.loadValue(); |
| 4645 | storeValue(value); |
| 4646 | } |
| 4647 | |
| 4648 | Int2::Int2(const Reference<Int2> &rhs) |
| 4649 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4650 | Value *value = rhs.loadValue(); |
| 4651 | storeValue(value); |
| 4652 | } |
| 4653 | |
| 4654 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4655 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4656 | int shuffle[4] = {0, 4, 1, 5}; |
| 4657 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4658 | |
| 4659 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4660 | } |
| 4661 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4662 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4663 | { |
| 4664 | storeValue(rhs.value); |
| 4665 | |
| 4666 | return rhs; |
| 4667 | } |
| 4668 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4669 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4670 | { |
| 4671 | Value *value = rhs.loadValue(); |
| 4672 | storeValue(value); |
| 4673 | |
| 4674 | return RValue<Int2>(value); |
| 4675 | } |
| 4676 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4677 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4678 | { |
| 4679 | Value *value = rhs.loadValue(); |
| 4680 | storeValue(value); |
| 4681 | |
| 4682 | return RValue<Int2>(value); |
| 4683 | } |
| 4684 | |
| 4685 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4686 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4687 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4691 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4692 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4693 | } |
| 4694 | |
| 4695 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4696 | // { |
| 4697 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4698 | // } |
| 4699 | |
| 4700 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4701 | // { |
| 4702 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4703 | // } |
| 4704 | |
| 4705 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4706 | // { |
| 4707 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4708 | // } |
| 4709 | |
| 4710 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4711 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4712 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4716 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4717 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4721 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4722 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4726 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4727 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4731 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4732 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4733 | } |
| 4734 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4735 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4736 | { |
| 4737 | return lhs = lhs + rhs; |
| 4738 | } |
| 4739 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4740 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4741 | { |
| 4742 | return lhs = lhs - rhs; |
| 4743 | } |
| 4744 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4745 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4746 | // { |
| 4747 | // return lhs = lhs * rhs; |
| 4748 | // } |
| 4749 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4750 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4751 | // { |
| 4752 | // return lhs = lhs / rhs; |
| 4753 | // } |
| 4754 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4755 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4756 | // { |
| 4757 | // return lhs = lhs % rhs; |
| 4758 | // } |
| 4759 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4760 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4761 | { |
| 4762 | return lhs = lhs & rhs; |
| 4763 | } |
| 4764 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4765 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4766 | { |
| 4767 | return lhs = lhs | rhs; |
| 4768 | } |
| 4769 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4770 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4771 | { |
| 4772 | return lhs = lhs ^ rhs; |
| 4773 | } |
| 4774 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4775 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4776 | { |
| 4777 | return lhs = lhs << rhs; |
| 4778 | } |
| 4779 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4780 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4781 | { |
| 4782 | return lhs = lhs >> rhs; |
| 4783 | } |
| 4784 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4785 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4786 | // { |
| 4787 | // return val; |
| 4788 | // } |
| 4789 | |
| 4790 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4791 | // { |
| 4792 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4793 | // } |
| 4794 | |
| 4795 | RValue<Int2> operator~(RValue<Int2> val) |
| 4796 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4797 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4798 | } |
| 4799 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4800 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4801 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4802 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4803 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4804 | } |
| 4805 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4806 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4807 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 4808 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4809 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4810 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4814 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4815 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4819 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4820 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | Type *Int2::getType() |
| 4824 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4825 | return T(Type_v2i32); |
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 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4829 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4830 | int64_t constantVector[2] = {x, y}; |
| 4831 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4835 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4836 | storeValue(rhs.value); |
| 4837 | } |
| 4838 | |
| 4839 | UInt2::UInt2(const UInt2 &rhs) |
| 4840 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4841 | Value *value = rhs.loadValue(); |
| 4842 | storeValue(value); |
| 4843 | } |
| 4844 | |
| 4845 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4846 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4847 | Value *value = rhs.loadValue(); |
| 4848 | storeValue(value); |
| 4849 | } |
| 4850 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4851 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4852 | { |
| 4853 | storeValue(rhs.value); |
| 4854 | |
| 4855 | return rhs; |
| 4856 | } |
| 4857 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4858 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4859 | { |
| 4860 | Value *value = rhs.loadValue(); |
| 4861 | storeValue(value); |
| 4862 | |
| 4863 | return RValue<UInt2>(value); |
| 4864 | } |
| 4865 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4866 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4867 | { |
| 4868 | Value *value = rhs.loadValue(); |
| 4869 | storeValue(value); |
| 4870 | |
| 4871 | return RValue<UInt2>(value); |
| 4872 | } |
| 4873 | |
| 4874 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4875 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4876 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4880 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4881 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4885 | // { |
| 4886 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4887 | // } |
| 4888 | |
| 4889 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4890 | // { |
| 4891 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4892 | // } |
| 4893 | |
| 4894 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4895 | // { |
| 4896 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4897 | // } |
| 4898 | |
| 4899 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4900 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4901 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4905 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4906 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4910 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4911 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4915 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4916 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4920 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4921 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4922 | } |
| 4923 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4924 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4925 | { |
| 4926 | return lhs = lhs + rhs; |
| 4927 | } |
| 4928 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4929 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4930 | { |
| 4931 | return lhs = lhs - rhs; |
| 4932 | } |
| 4933 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4934 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4935 | // { |
| 4936 | // return lhs = lhs * rhs; |
| 4937 | // } |
| 4938 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4939 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4940 | // { |
| 4941 | // return lhs = lhs / rhs; |
| 4942 | // } |
| 4943 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4944 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4945 | // { |
| 4946 | // return lhs = lhs % rhs; |
| 4947 | // } |
| 4948 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4949 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4950 | { |
| 4951 | return lhs = lhs & rhs; |
| 4952 | } |
| 4953 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4954 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4955 | { |
| 4956 | return lhs = lhs | rhs; |
| 4957 | } |
| 4958 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4959 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4960 | { |
| 4961 | return lhs = lhs ^ rhs; |
| 4962 | } |
| 4963 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4964 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4965 | { |
| 4966 | return lhs = lhs << rhs; |
| 4967 | } |
| 4968 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4969 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4970 | { |
| 4971 | return lhs = lhs >> rhs; |
| 4972 | } |
| 4973 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4974 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4975 | // { |
| 4976 | // return val; |
| 4977 | // } |
| 4978 | |
| 4979 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4980 | // { |
| 4981 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4982 | // } |
| 4983 | |
| 4984 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4985 | { |
| 4986 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4987 | } |
| 4988 | |
| 4989 | Type *UInt2::getType() |
| 4990 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4991 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | Int4::Int4(RValue<Byte4> cast) |
| 4995 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4996 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4997 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4998 | |
| 4999 | Value *e; |
| 5000 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 5001 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5002 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 5003 | |
| 5004 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5005 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5006 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 5007 | |
| 5008 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5009 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | Int4::Int4(RValue<SByte4> cast) |
| 5013 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5014 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5015 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5016 | |
| 5017 | Value *e; |
| 5018 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 5019 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5020 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 5021 | |
| 5022 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5023 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5024 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 5025 | |
| 5026 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5027 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5028 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | Int4::Int4(RValue<Float4> cast) |
| 5032 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5033 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 5034 | |
| 5035 | storeValue(xyzw); |
| 5036 | } |
| 5037 | |
| 5038 | Int4::Int4(RValue<Short4> cast) |
| 5039 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5040 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5041 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 5042 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5043 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5044 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | Int4::Int4(RValue<UShort4> cast) |
| 5048 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5049 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5050 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5051 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5052 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5053 | } |
| 5054 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5055 | Int4::Int4(int xyzw) |
| 5056 | { |
| 5057 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5058 | } |
| 5059 | |
| 5060 | Int4::Int4(int x, int yzw) |
| 5061 | { |
| 5062 | constant(x, yzw, yzw, yzw); |
| 5063 | } |
| 5064 | |
| 5065 | Int4::Int4(int x, int y, int zw) |
| 5066 | { |
| 5067 | constant(x, y, zw, zw); |
| 5068 | } |
| 5069 | |
| 5070 | Int4::Int4(int x, int y, int z, int w) |
| 5071 | { |
| 5072 | constant(x, y, z, w); |
| 5073 | } |
| 5074 | |
| 5075 | void Int4::constant(int x, int y, int z, int w) |
| 5076 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5077 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5078 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | Int4::Int4(RValue<Int4> rhs) |
| 5082 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5083 | storeValue(rhs.value); |
| 5084 | } |
| 5085 | |
| 5086 | Int4::Int4(const Int4 &rhs) |
| 5087 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5088 | Value *value = rhs.loadValue(); |
| 5089 | storeValue(value); |
| 5090 | } |
| 5091 | |
| 5092 | Int4::Int4(const Reference<Int4> &rhs) |
| 5093 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5094 | Value *value = rhs.loadValue(); |
| 5095 | storeValue(value); |
| 5096 | } |
| 5097 | |
| 5098 | Int4::Int4(RValue<UInt4> rhs) |
| 5099 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5100 | storeValue(rhs.value); |
| 5101 | } |
| 5102 | |
| 5103 | Int4::Int4(const UInt4 &rhs) |
| 5104 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5105 | Value *value = rhs.loadValue(); |
| 5106 | storeValue(value); |
| 5107 | } |
| 5108 | |
| 5109 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5110 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5111 | Value *value = rhs.loadValue(); |
| 5112 | storeValue(value); |
| 5113 | } |
| 5114 | |
| 5115 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5116 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5117 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5118 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5119 | |
| 5120 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | Int4::Int4(RValue<Int> rhs) |
| 5124 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5125 | Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5126 | |
| 5127 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5128 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5129 | |
| 5130 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | Int4::Int4(const Int &rhs) |
| 5134 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5135 | *this = RValue<Int>(rhs.loadValue()); |
| 5136 | } |
| 5137 | |
| 5138 | Int4::Int4(const Reference<Int> &rhs) |
| 5139 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5140 | *this = RValue<Int>(rhs.loadValue()); |
| 5141 | } |
| 5142 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5143 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5144 | { |
| 5145 | storeValue(rhs.value); |
| 5146 | |
| 5147 | return rhs; |
| 5148 | } |
| 5149 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5150 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5151 | { |
| 5152 | Value *value = rhs.loadValue(); |
| 5153 | storeValue(value); |
| 5154 | |
| 5155 | return RValue<Int4>(value); |
| 5156 | } |
| 5157 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5158 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5159 | { |
| 5160 | Value *value = rhs.loadValue(); |
| 5161 | storeValue(value); |
| 5162 | |
| 5163 | return RValue<Int4>(value); |
| 5164 | } |
| 5165 | |
| 5166 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5167 | { |
| 5168 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5169 | } |
| 5170 | |
| 5171 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5172 | { |
| 5173 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5174 | } |
| 5175 | |
| 5176 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5177 | { |
| 5178 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5179 | } |
| 5180 | |
| 5181 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5182 | { |
| 5183 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5184 | } |
| 5185 | |
| 5186 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5187 | { |
| 5188 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5189 | } |
| 5190 | |
| 5191 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5192 | { |
| 5193 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5194 | } |
| 5195 | |
| 5196 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5197 | { |
| 5198 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5199 | } |
| 5200 | |
| 5201 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5202 | { |
| 5203 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5204 | } |
| 5205 | |
| 5206 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5207 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5208 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5212 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5213 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5217 | { |
| 5218 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5219 | } |
| 5220 | |
| 5221 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5222 | { |
| 5223 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5224 | } |
| 5225 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5226 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5227 | { |
| 5228 | return lhs = lhs + rhs; |
| 5229 | } |
| 5230 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5231 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5232 | { |
| 5233 | return lhs = lhs - rhs; |
| 5234 | } |
| 5235 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5236 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5237 | { |
| 5238 | return lhs = lhs * rhs; |
| 5239 | } |
| 5240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5241 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5242 | // { |
| 5243 | // return lhs = lhs / rhs; |
| 5244 | // } |
| 5245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5246 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5247 | // { |
| 5248 | // return lhs = lhs % rhs; |
| 5249 | // } |
| 5250 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5251 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5252 | { |
| 5253 | return lhs = lhs & rhs; |
| 5254 | } |
| 5255 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5256 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5257 | { |
| 5258 | return lhs = lhs | rhs; |
| 5259 | } |
| 5260 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5261 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5262 | { |
| 5263 | return lhs = lhs ^ rhs; |
| 5264 | } |
| 5265 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5266 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5267 | { |
| 5268 | return lhs = lhs << rhs; |
| 5269 | } |
| 5270 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5271 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5272 | { |
| 5273 | return lhs = lhs >> rhs; |
| 5274 | } |
| 5275 | |
| 5276 | RValue<Int4> operator+(RValue<Int4> val) |
| 5277 | { |
| 5278 | return val; |
| 5279 | } |
| 5280 | |
| 5281 | RValue<Int4> operator-(RValue<Int4> val) |
| 5282 | { |
| 5283 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5284 | } |
| 5285 | |
| 5286 | RValue<Int4> operator~(RValue<Int4> val) |
| 5287 | { |
| 5288 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5289 | } |
| 5290 | |
| 5291 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5292 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5293 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5297 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5298 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5302 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5303 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5307 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5308 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5312 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5313 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5317 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5318 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5322 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5323 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5324 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5325 | ::basicBlock->appendInst(cmp); |
| 5326 | |
| 5327 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5328 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5329 | ::basicBlock->appendInst(select); |
| 5330 | |
| 5331 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5335 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5336 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5337 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5338 | ::basicBlock->appendInst(cmp); |
| 5339 | |
| 5340 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5341 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5342 | ::basicBlock->appendInst(select); |
| 5343 | |
| 5344 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5348 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5349 | if(emulateIntrinsics) |
| 5350 | { |
| 5351 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 5352 | return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000)); |
| 5353 | } |
| 5354 | else |
| 5355 | { |
| 5356 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5357 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5358 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5359 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5360 | nearbyint->addArg(cast.value); |
| 5361 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5362 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5363 | return RValue<Int4>(V(result)); |
| 5364 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5368 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5369 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5370 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5371 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5372 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5373 | pack->addArg(x.value); |
| 5374 | pack->addArg(y.value); |
| 5375 | ::basicBlock->appendInst(pack); |
| 5376 | |
| 5377 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5381 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5382 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5386 | { |
| 5387 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5388 | } |
| 5389 | |
| 5390 | RValue<Int> SignMask(RValue<Int4> x) |
| 5391 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5392 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5393 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5394 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5395 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5396 | movmsk->addArg(x.value); |
| 5397 | ::basicBlock->appendInst(movmsk); |
| 5398 | |
| 5399 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5403 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5404 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | Type *Int4::getType() |
| 5408 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5409 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | UInt4::UInt4(RValue<Float4> cast) |
| 5413 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5414 | // Smallest positive value representable in UInt, but not in Int |
| 5415 | const unsigned int ustart = 0x80000000u; |
| 5416 | const float ustartf = float(ustart); |
| 5417 | |
| 5418 | // Check if the value can be represented as an Int |
| 5419 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5420 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5421 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5422 | // Otherwise, just convert normally |
| 5423 | (~uiValue & Int4(cast)); |
| 5424 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5425 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5426 | } |
| 5427 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5428 | UInt4::UInt4(int xyzw) |
| 5429 | { |
| 5430 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5431 | } |
| 5432 | |
| 5433 | UInt4::UInt4(int x, int yzw) |
| 5434 | { |
| 5435 | constant(x, yzw, yzw, yzw); |
| 5436 | } |
| 5437 | |
| 5438 | UInt4::UInt4(int x, int y, int zw) |
| 5439 | { |
| 5440 | constant(x, y, zw, zw); |
| 5441 | } |
| 5442 | |
| 5443 | UInt4::UInt4(int x, int y, int z, int w) |
| 5444 | { |
| 5445 | constant(x, y, z, w); |
| 5446 | } |
| 5447 | |
| 5448 | void UInt4::constant(int x, int y, int z, int w) |
| 5449 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5450 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5451 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5455 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5456 | storeValue(rhs.value); |
| 5457 | } |
| 5458 | |
| 5459 | UInt4::UInt4(const UInt4 &rhs) |
| 5460 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5461 | Value *value = rhs.loadValue(); |
| 5462 | storeValue(value); |
| 5463 | } |
| 5464 | |
| 5465 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5466 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5467 | Value *value = rhs.loadValue(); |
| 5468 | storeValue(value); |
| 5469 | } |
| 5470 | |
| 5471 | UInt4::UInt4(RValue<Int4> rhs) |
| 5472 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5473 | storeValue(rhs.value); |
| 5474 | } |
| 5475 | |
| 5476 | UInt4::UInt4(const Int4 &rhs) |
| 5477 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5478 | Value *value = rhs.loadValue(); |
| 5479 | storeValue(value); |
| 5480 | } |
| 5481 | |
| 5482 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5483 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5484 | Value *value = rhs.loadValue(); |
| 5485 | storeValue(value); |
| 5486 | } |
| 5487 | |
| 5488 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5489 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5490 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5491 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5492 | |
| 5493 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5494 | } |
| 5495 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5496 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5497 | { |
| 5498 | storeValue(rhs.value); |
| 5499 | |
| 5500 | return rhs; |
| 5501 | } |
| 5502 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5503 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5504 | { |
| 5505 | Value *value = rhs.loadValue(); |
| 5506 | storeValue(value); |
| 5507 | |
| 5508 | return RValue<UInt4>(value); |
| 5509 | } |
| 5510 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5511 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5512 | { |
| 5513 | Value *value = rhs.loadValue(); |
| 5514 | storeValue(value); |
| 5515 | |
| 5516 | return RValue<UInt4>(value); |
| 5517 | } |
| 5518 | |
| 5519 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5520 | { |
| 5521 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5522 | } |
| 5523 | |
| 5524 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5525 | { |
| 5526 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5527 | } |
| 5528 | |
| 5529 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5530 | { |
| 5531 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5532 | } |
| 5533 | |
| 5534 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5535 | { |
| 5536 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5537 | } |
| 5538 | |
| 5539 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5540 | { |
| 5541 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5542 | } |
| 5543 | |
| 5544 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5545 | { |
| 5546 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5547 | } |
| 5548 | |
| 5549 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5550 | { |
| 5551 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5552 | } |
| 5553 | |
| 5554 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5555 | { |
| 5556 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5557 | } |
| 5558 | |
| 5559 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5560 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5561 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5562 | } |
| 5563 | |
| 5564 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5565 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5566 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5567 | } |
| 5568 | |
| 5569 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5570 | { |
| 5571 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5572 | } |
| 5573 | |
| 5574 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5575 | { |
| 5576 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5577 | } |
| 5578 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5579 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5580 | { |
| 5581 | return lhs = lhs + rhs; |
| 5582 | } |
| 5583 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5584 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5585 | { |
| 5586 | return lhs = lhs - rhs; |
| 5587 | } |
| 5588 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5589 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5590 | { |
| 5591 | return lhs = lhs * rhs; |
| 5592 | } |
| 5593 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5594 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5595 | // { |
| 5596 | // return lhs = lhs / rhs; |
| 5597 | // } |
| 5598 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5599 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5600 | // { |
| 5601 | // return lhs = lhs % rhs; |
| 5602 | // } |
| 5603 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5604 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5605 | { |
| 5606 | return lhs = lhs & rhs; |
| 5607 | } |
| 5608 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5609 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5610 | { |
| 5611 | return lhs = lhs | rhs; |
| 5612 | } |
| 5613 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5614 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5615 | { |
| 5616 | return lhs = lhs ^ rhs; |
| 5617 | } |
| 5618 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5619 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5620 | { |
| 5621 | return lhs = lhs << rhs; |
| 5622 | } |
| 5623 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5624 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5625 | { |
| 5626 | return lhs = lhs >> rhs; |
| 5627 | } |
| 5628 | |
| 5629 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5630 | { |
| 5631 | return val; |
| 5632 | } |
| 5633 | |
| 5634 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5635 | { |
| 5636 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5637 | } |
| 5638 | |
| 5639 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5640 | { |
| 5641 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5642 | } |
| 5643 | |
| 5644 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5645 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5646 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5650 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5651 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5655 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5656 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5660 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5661 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5662 | } |
| 5663 | |
| 5664 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5665 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5666 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5670 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5671 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5675 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5676 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5677 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5678 | ::basicBlock->appendInst(cmp); |
| 5679 | |
| 5680 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5681 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5682 | ::basicBlock->appendInst(select); |
| 5683 | |
| 5684 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5688 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5689 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5690 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5691 | ::basicBlock->appendInst(cmp); |
| 5692 | |
| 5693 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5694 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5695 | ::basicBlock->appendInst(select); |
| 5696 | |
| 5697 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5701 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5702 | if(CPUID::SSE4_1) |
| 5703 | { |
| 5704 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5705 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5706 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5707 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5708 | pack->addArg(x.value); |
| 5709 | pack->addArg(y.value); |
| 5710 | ::basicBlock->appendInst(pack); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5711 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5712 | return RValue<UShort8>(V(result)); |
| 5713 | } |
| 5714 | else |
| 5715 | { |
| 5716 | RValue<Int4> sx = As<Int4>(x); |
| 5717 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 5718 | |
| 5719 | RValue<Int4> sy = As<Int4>(y); |
| 5720 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 5721 | |
| 5722 | return As<UShort8>(Pack(bx, by) + Short8(0x8000u)); |
| 5723 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5724 | } |
| 5725 | |
| 5726 | Type *UInt4::getType() |
| 5727 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5728 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | Float::Float(RValue<Int> cast) |
| 5732 | { |
| 5733 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5734 | |
| 5735 | storeValue(integer); |
| 5736 | } |
| 5737 | |
Alexis Hetu | cfd9632 | 2017-07-24 14:44:33 -0400 | [diff] [blame] | 5738 | Float::Float(RValue<UInt> cast) |
| 5739 | { |
| 5740 | RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) + |
| 5741 | As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u))); |
| 5742 | |
| 5743 | storeValue(result.value); |
| 5744 | } |
| 5745 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5746 | Float::Float(float x) |
| 5747 | { |
| 5748 | storeValue(Nucleus::createConstantFloat(x)); |
| 5749 | } |
| 5750 | |
| 5751 | Float::Float(RValue<Float> rhs) |
| 5752 | { |
| 5753 | storeValue(rhs.value); |
| 5754 | } |
| 5755 | |
| 5756 | Float::Float(const Float &rhs) |
| 5757 | { |
| 5758 | Value *value = rhs.loadValue(); |
| 5759 | storeValue(value); |
| 5760 | } |
| 5761 | |
| 5762 | Float::Float(const Reference<Float> &rhs) |
| 5763 | { |
| 5764 | Value *value = rhs.loadValue(); |
| 5765 | storeValue(value); |
| 5766 | } |
| 5767 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5768 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5769 | { |
| 5770 | storeValue(rhs.value); |
| 5771 | |
| 5772 | return rhs; |
| 5773 | } |
| 5774 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5775 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5776 | { |
| 5777 | Value *value = rhs.loadValue(); |
| 5778 | storeValue(value); |
| 5779 | |
| 5780 | return RValue<Float>(value); |
| 5781 | } |
| 5782 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5783 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5784 | { |
| 5785 | Value *value = rhs.loadValue(); |
| 5786 | storeValue(value); |
| 5787 | |
| 5788 | return RValue<Float>(value); |
| 5789 | } |
| 5790 | |
| 5791 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5792 | { |
| 5793 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5794 | } |
| 5795 | |
| 5796 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5797 | { |
| 5798 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5799 | } |
| 5800 | |
| 5801 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5802 | { |
| 5803 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5804 | } |
| 5805 | |
| 5806 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5807 | { |
| 5808 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5809 | } |
| 5810 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5811 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5812 | { |
| 5813 | return lhs = lhs + rhs; |
| 5814 | } |
| 5815 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5816 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5817 | { |
| 5818 | return lhs = lhs - rhs; |
| 5819 | } |
| 5820 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5821 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5822 | { |
| 5823 | return lhs = lhs * rhs; |
| 5824 | } |
| 5825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5826 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5827 | { |
| 5828 | return lhs = lhs / rhs; |
| 5829 | } |
| 5830 | |
| 5831 | RValue<Float> operator+(RValue<Float> val) |
| 5832 | { |
| 5833 | return val; |
| 5834 | } |
| 5835 | |
| 5836 | RValue<Float> operator-(RValue<Float> val) |
| 5837 | { |
| 5838 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5839 | } |
| 5840 | |
| 5841 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5842 | { |
| 5843 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5844 | } |
| 5845 | |
| 5846 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5847 | { |
| 5848 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5849 | } |
| 5850 | |
| 5851 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5852 | { |
| 5853 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5854 | } |
| 5855 | |
| 5856 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5857 | { |
| 5858 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5859 | } |
| 5860 | |
| 5861 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5862 | { |
| 5863 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5864 | } |
| 5865 | |
| 5866 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5867 | { |
| 5868 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5869 | } |
| 5870 | |
| 5871 | RValue<Float> Abs(RValue<Float> x) |
| 5872 | { |
| 5873 | return IfThenElse(x > 0.0f, x, -x); |
| 5874 | } |
| 5875 | |
| 5876 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5877 | { |
| 5878 | return IfThenElse(x > y, x, y); |
| 5879 | } |
| 5880 | |
| 5881 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5882 | { |
| 5883 | return IfThenElse(x < y, x, y); |
| 5884 | } |
| 5885 | |
| 5886 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5887 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5888 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5892 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5893 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | RValue<Float> Sqrt(RValue<Float> x) |
| 5897 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5898 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5899 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5900 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5901 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5902 | sqrt->addArg(x.value); |
| 5903 | ::basicBlock->appendInst(sqrt); |
| 5904 | |
| 5905 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | RValue<Float> Round(RValue<Float> x) |
| 5909 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5910 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | RValue<Float> Trunc(RValue<Float> x) |
| 5914 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5915 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | RValue<Float> Frac(RValue<Float> x) |
| 5919 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5920 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5921 | } |
| 5922 | |
| 5923 | RValue<Float> Floor(RValue<Float> x) |
| 5924 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5925 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5926 | } |
| 5927 | |
| 5928 | RValue<Float> Ceil(RValue<Float> x) |
| 5929 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5930 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5931 | } |
| 5932 | |
| 5933 | Type *Float::getType() |
| 5934 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5935 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5936 | } |
| 5937 | |
| 5938 | Float2::Float2(RValue<Float4> cast) |
| 5939 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5940 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | Type *Float2::getType() |
| 5944 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5945 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5946 | } |
| 5947 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5948 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5949 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5950 | Value *a = Int4(cast).loadValue(); |
| 5951 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5952 | |
| 5953 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5954 | } |
| 5955 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5956 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5957 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5958 | Value *a = Int4(cast).loadValue(); |
| 5959 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5960 | |
| 5961 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5962 | } |
| 5963 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5964 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5965 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5966 | Int4 c(cast); |
| 5967 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5968 | } |
| 5969 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5970 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5971 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5972 | Int4 c(cast); |
| 5973 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5974 | } |
| 5975 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5976 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5977 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5978 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5979 | |
| 5980 | storeValue(xyzw); |
| 5981 | } |
| 5982 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5983 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5984 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5985 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5986 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5987 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5988 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5989 | } |
| 5990 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5991 | Float4::Float4() : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5992 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5993 | } |
| 5994 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5995 | Float4::Float4(float xyzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5996 | { |
| 5997 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5998 | } |
| 5999 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6000 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6001 | { |
| 6002 | constant(x, yzw, yzw, yzw); |
| 6003 | } |
| 6004 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6005 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6006 | { |
| 6007 | constant(x, y, zw, zw); |
| 6008 | } |
| 6009 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6010 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6011 | { |
| 6012 | constant(x, y, z, w); |
| 6013 | } |
| 6014 | |
| 6015 | void Float4::constant(float x, float y, float z, float w) |
| 6016 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6017 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6018 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6019 | } |
| 6020 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6021 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6022 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6023 | storeValue(rhs.value); |
| 6024 | } |
| 6025 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6026 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6027 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6028 | Value *value = rhs.loadValue(); |
| 6029 | storeValue(value); |
| 6030 | } |
| 6031 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6032 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6033 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6034 | Value *value = rhs.loadValue(); |
| 6035 | storeValue(value); |
| 6036 | } |
| 6037 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6038 | Float4::Float4(RValue<Float> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6039 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6040 | Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6041 | |
| 6042 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6043 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6044 | |
| 6045 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6046 | } |
| 6047 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6048 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6049 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6050 | *this = RValue<Float>(rhs.loadValue()); |
| 6051 | } |
| 6052 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6053 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6054 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6055 | *this = RValue<Float>(rhs.loadValue()); |
| 6056 | } |
| 6057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6058 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6059 | { |
| 6060 | return *this = Float4(x, x, x, x); |
| 6061 | } |
| 6062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6063 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6064 | { |
| 6065 | storeValue(rhs.value); |
| 6066 | |
| 6067 | return rhs; |
| 6068 | } |
| 6069 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6070 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6071 | { |
| 6072 | Value *value = rhs.loadValue(); |
| 6073 | storeValue(value); |
| 6074 | |
| 6075 | return RValue<Float4>(value); |
| 6076 | } |
| 6077 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6078 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6079 | { |
| 6080 | Value *value = rhs.loadValue(); |
| 6081 | storeValue(value); |
| 6082 | |
| 6083 | return RValue<Float4>(value); |
| 6084 | } |
| 6085 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6086 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6087 | { |
| 6088 | return *this = Float4(rhs); |
| 6089 | } |
| 6090 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6091 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6092 | { |
| 6093 | return *this = Float4(rhs); |
| 6094 | } |
| 6095 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6096 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6097 | { |
| 6098 | return *this = Float4(rhs); |
| 6099 | } |
| 6100 | |
| 6101 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6102 | { |
| 6103 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6104 | } |
| 6105 | |
| 6106 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6107 | { |
| 6108 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6109 | } |
| 6110 | |
| 6111 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6112 | { |
| 6113 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6114 | } |
| 6115 | |
| 6116 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6117 | { |
| 6118 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6119 | } |
| 6120 | |
| 6121 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6122 | { |
| 6123 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6124 | } |
| 6125 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6126 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6127 | { |
| 6128 | return lhs = lhs + rhs; |
| 6129 | } |
| 6130 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6131 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6132 | { |
| 6133 | return lhs = lhs - rhs; |
| 6134 | } |
| 6135 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6136 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6137 | { |
| 6138 | return lhs = lhs * rhs; |
| 6139 | } |
| 6140 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6141 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6142 | { |
| 6143 | return lhs = lhs / rhs; |
| 6144 | } |
| 6145 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6146 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6147 | { |
| 6148 | return lhs = lhs % rhs; |
| 6149 | } |
| 6150 | |
| 6151 | RValue<Float4> operator+(RValue<Float4> val) |
| 6152 | { |
| 6153 | return val; |
| 6154 | } |
| 6155 | |
| 6156 | RValue<Float4> operator-(RValue<Float4> val) |
| 6157 | { |
| 6158 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6159 | } |
| 6160 | |
| 6161 | RValue<Float4> Abs(RValue<Float4> x) |
| 6162 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6163 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6164 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6165 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6166 | |
| 6167 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6168 | } |
| 6169 | |
| 6170 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6171 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6172 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6173 | 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] | 6174 | ::basicBlock->appendInst(cmp); |
| 6175 | |
| 6176 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6177 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6178 | ::basicBlock->appendInst(select); |
| 6179 | |
| 6180 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6184 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6185 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6186 | 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] | 6187 | ::basicBlock->appendInst(cmp); |
| 6188 | |
| 6189 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6190 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6191 | ::basicBlock->appendInst(select); |
| 6192 | |
| 6193 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6197 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6198 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6202 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6203 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6204 | } |
| 6205 | |
| 6206 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6207 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6208 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6209 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6210 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6211 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6212 | sqrt->addArg(x.value); |
| 6213 | ::basicBlock->appendInst(sqrt); |
| 6214 | |
| 6215 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6216 | } |
| 6217 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6218 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6219 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6220 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6221 | } |
| 6222 | |
| 6223 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6224 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6225 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6229 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6230 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6234 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6235 | int shuffle[4] = |
| 6236 | { |
| 6237 | ((imm >> 0) & 0x03) + 0, |
| 6238 | ((imm >> 2) & 0x03) + 0, |
| 6239 | ((imm >> 4) & 0x03) + 4, |
| 6240 | ((imm >> 6) & 0x03) + 4, |
| 6241 | }; |
| 6242 | |
| 6243 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6247 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6248 | int shuffle[4] = {0, 4, 1, 5}; |
| 6249 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6253 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6254 | int shuffle[4] = {2, 6, 3, 7}; |
| 6255 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6256 | } |
| 6257 | |
| 6258 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6259 | { |
| 6260 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6261 | Value *result = createMask4(vector, rhs.value, select); |
| 6262 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6263 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6264 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | RValue<Int> SignMask(RValue<Float4> x) |
| 6268 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6269 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6270 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6271 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6272 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6273 | movmsk->addArg(x.value); |
| 6274 | ::basicBlock->appendInst(movmsk); |
| 6275 | |
| 6276 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6280 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6281 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6285 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6286 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6290 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6291 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6295 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6296 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6300 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6301 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6305 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6306 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | RValue<Float4> Round(RValue<Float4> x) |
| 6310 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 6311 | if(emulateIntrinsics) |
| 6312 | { |
| 6313 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 6314 | return (x + Float4(0x00C00000)) - Float4(0x00C00000); |
| 6315 | } |
| 6316 | else if(CPUID::SSE4_1) |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6317 | { |
| 6318 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6319 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6320 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6321 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6322 | round->addArg(x.value); |
| 6323 | round->addArg(::context->getConstantInt32(0)); |
| 6324 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6325 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6326 | return RValue<Float4>(V(result)); |
| 6327 | } |
| 6328 | else |
| 6329 | { |
| 6330 | return Float4(RoundInt(x)); |
| 6331 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6335 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6336 | if(CPUID::SSE4_1) |
| 6337 | { |
| 6338 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6339 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6340 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6341 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6342 | round->addArg(x.value); |
| 6343 | round->addArg(::context->getConstantInt32(3)); |
| 6344 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6345 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6346 | return RValue<Float4>(V(result)); |
| 6347 | } |
| 6348 | else |
| 6349 | { |
| 6350 | return Float4(Int4(x)); |
| 6351 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6352 | } |
| 6353 | |
| 6354 | RValue<Float4> Frac(RValue<Float4> x) |
| 6355 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6356 | Float4 frc; |
| 6357 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6358 | if(CPUID::SSE4_1) |
| 6359 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6360 | frc = x - Floor(x); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6361 | } |
| 6362 | else |
| 6363 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6364 | frc = x - Float4(Int4(x)); // Signed fractional part. |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6365 | |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6366 | 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] | 6367 | } |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 6368 | |
| 6369 | // x - floor(x) can be 1.0 for very small negative x. |
| 6370 | // Clamp against the value just below 1.0. |
| 6371 | return Min(frc, As<Float4>(Int4(0x3F7FFFFF))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6372 | } |
| 6373 | |
| 6374 | RValue<Float4> Floor(RValue<Float4> x) |
| 6375 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6376 | if(CPUID::SSE4_1) |
| 6377 | { |
| 6378 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6379 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6380 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6381 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6382 | round->addArg(x.value); |
| 6383 | round->addArg(::context->getConstantInt32(1)); |
| 6384 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6385 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6386 | return RValue<Float4>(V(result)); |
| 6387 | } |
| 6388 | else |
| 6389 | { |
| 6390 | return x - Frac(x); |
| 6391 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6395 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6396 | if(CPUID::SSE4_1) |
| 6397 | { |
| 6398 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6399 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6400 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6401 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6402 | round->addArg(x.value); |
| 6403 | round->addArg(::context->getConstantInt32(2)); |
| 6404 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6405 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6406 | return RValue<Float4>(V(result)); |
| 6407 | } |
| 6408 | else |
| 6409 | { |
| 6410 | return -Floor(-x); |
| 6411 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6412 | } |
| 6413 | |
| 6414 | Type *Float4::getType() |
| 6415 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6416 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6420 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6421 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6425 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6426 | 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] | 6427 | } |
| 6428 | |
| 6429 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6430 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6431 | 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] | 6432 | } |
| 6433 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6434 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6435 | { |
| 6436 | return lhs = lhs + offset; |
| 6437 | } |
| 6438 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6439 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6440 | { |
| 6441 | return lhs = lhs + offset; |
| 6442 | } |
| 6443 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6444 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6445 | { |
| 6446 | return lhs = lhs + offset; |
| 6447 | } |
| 6448 | |
| 6449 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6450 | { |
| 6451 | return lhs + -offset; |
| 6452 | } |
| 6453 | |
| 6454 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6455 | { |
| 6456 | return lhs + -offset; |
| 6457 | } |
| 6458 | |
| 6459 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6460 | { |
| 6461 | return lhs + -offset; |
| 6462 | } |
| 6463 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6464 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6465 | { |
| 6466 | return lhs = lhs - offset; |
| 6467 | } |
| 6468 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6469 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6470 | { |
| 6471 | return lhs = lhs - offset; |
| 6472 | } |
| 6473 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6474 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6475 | { |
| 6476 | return lhs = lhs - offset; |
| 6477 | } |
| 6478 | |
| 6479 | void Return() |
| 6480 | { |
| 6481 | Nucleus::createRetVoid(); |
| 6482 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6483 | Nucleus::createUnreachable(); |
| 6484 | } |
| 6485 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6486 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6487 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6488 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6489 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6490 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6491 | } |
| 6492 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 6493 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6494 | { |
| 6495 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6496 | Nucleus::setInsertBlock(bodyBB); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6497 | } |
| 6498 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6499 | RValue<Long> Ticks() |
| 6500 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6501 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6502 | } |
| 6503 | } |