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 | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 128 | namespace sw |
| 129 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 130 | enum EmulatedType |
| 131 | { |
| 132 | EmulatedShift = 16, |
| 133 | EmulatedV2 = 2 << EmulatedShift, |
| 134 | EmulatedV4 = 4 << EmulatedShift, |
| 135 | EmulatedV8 = 8 << EmulatedShift, |
| 136 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 137 | |
| 138 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 139 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 140 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 141 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 142 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 143 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 144 | }; |
| 145 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 146 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 147 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 148 | class BasicBlock : public Ice::CfgNode {}; |
| 149 | |
| 150 | Ice::Type T(Type *t) |
| 151 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 152 | 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] | 153 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | Type *T(Ice::Type t) |
| 157 | { |
| 158 | return reinterpret_cast<Type*>(t); |
| 159 | } |
| 160 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 161 | Type *T(EmulatedType t) |
| 162 | { |
| 163 | return reinterpret_cast<Type*>(t); |
| 164 | } |
| 165 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 166 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 167 | { |
| 168 | return reinterpret_cast<Value*>(v); |
| 169 | } |
| 170 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 171 | BasicBlock *B(Ice::CfgNode *b) |
| 172 | { |
| 173 | return reinterpret_cast<BasicBlock*>(b); |
| 174 | } |
| 175 | |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 176 | static size_t typeSize(Type *type) |
| 177 | { |
| 178 | if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) |
| 179 | { |
| 180 | switch(reinterpret_cast<std::intptr_t>(type)) |
| 181 | { |
| 182 | case Type_v2i32: return 8; |
| 183 | case Type_v4i16: return 8; |
| 184 | case Type_v2i16: return 4; |
| 185 | case Type_v8i8: return 8; |
| 186 | case Type_v4i8: return 4; |
| 187 | case Type_v2f32: return 8; |
| 188 | default: assert(false); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return Ice::typeWidthInBytes(T(type)); |
| 193 | } |
| 194 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 195 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 196 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 197 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 198 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 199 | |
| 200 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 201 | { |
| 202 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 203 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 204 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 205 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 206 | { |
| 207 | return §ionHeader(elfHeader)[index]; |
| 208 | } |
| 209 | |
| 210 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 211 | { |
| 212 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 213 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 214 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 215 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 216 | uint32_t index = relocation.getSymbol(); |
| 217 | int table = relocationTable.sh_link; |
| 218 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 219 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 220 | if(index != SHN_UNDEF) |
| 221 | { |
| 222 | if(table == SHN_UNDEF) return nullptr; |
| 223 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 224 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 225 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 226 | if(index >= symtab_entries) |
| 227 | { |
| 228 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 229 | return nullptr; |
| 230 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 231 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 232 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 233 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 234 | uint16_t section = symbol.st_shndx; |
| 235 | |
| 236 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 237 | { |
| 238 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 239 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | return nullptr; |
| 244 | } |
| 245 | } |
| 246 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 247 | if(CPUID::ARM) |
| 248 | { |
| 249 | switch(relocation.getType()) |
| 250 | { |
| 251 | case R_ARM_NONE: |
| 252 | // No relocation |
| 253 | break; |
| 254 | case R_ARM_MOVW_ABS_NC: |
| 255 | { |
| 256 | uint32_t thumb = 0; // Calls to Thumb code not supported. |
| 257 | uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb; |
| 258 | *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF); |
| 259 | } |
| 260 | break; |
| 261 | case R_ARM_MOVT_ABS: |
| 262 | { |
| 263 | uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16; |
| 264 | *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF); |
| 265 | } |
| 266 | break; |
| 267 | default: |
| 268 | assert(false && "Unsupported relocation type"); |
| 269 | return nullptr; |
| 270 | } |
| 271 | } |
| 272 | else |
| 273 | { |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 274 | switch(relocation.getType()) |
| 275 | { |
| 276 | case R_386_NONE: |
| 277 | // No relocation |
| 278 | break; |
| 279 | case R_386_32: |
| 280 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 281 | break; |
| 282 | // case R_386_PC32: |
| 283 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 284 | // break; |
| 285 | default: |
| 286 | assert(false && "Unsupported relocation type"); |
| 287 | return nullptr; |
| 288 | } |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 291 | |
| 292 | return symbolValue; |
| 293 | } |
| 294 | |
| 295 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 296 | { |
| 297 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 298 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 299 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 300 | int32_t *patchSite = (int*)(address + relocation.r_offset); |
| 301 | uint32_t index = relocation.getSymbol(); |
| 302 | int table = relocationTable.sh_link; |
| 303 | void *symbolValue = nullptr; |
| 304 | |
| 305 | if(index != SHN_UNDEF) |
| 306 | { |
| 307 | if(table == SHN_UNDEF) return nullptr; |
| 308 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 309 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 310 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 311 | if(index >= symtab_entries) |
| 312 | { |
| 313 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 314 | return nullptr; |
| 315 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 316 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 317 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 318 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 319 | uint16_t section = symbol.st_shndx; |
| 320 | |
| 321 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 322 | { |
| 323 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 324 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | return nullptr; |
| 329 | } |
| 330 | } |
| 331 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 332 | switch(relocation.getType()) |
| 333 | { |
| 334 | case R_X86_64_NONE: |
| 335 | // No relocation |
| 336 | break; |
| 337 | case R_X86_64_64: |
| 338 | *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend; |
| 339 | break; |
| 340 | case R_X86_64_PC32: |
| 341 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend; |
| 342 | break; |
| 343 | case R_X86_64_32S: |
| 344 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend; |
| 345 | break; |
| 346 | default: |
| 347 | assert(false && "Unsupported relocation type"); |
| 348 | return nullptr; |
| 349 | } |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 350 | |
| 351 | return symbolValue; |
| 352 | } |
| 353 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 354 | void *loadImage(uint8_t *const elfImage, size_t &codeSize) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 355 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 356 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 357 | |
| 358 | if(!elfHeader->checkMagic()) |
| 359 | { |
| 360 | return nullptr; |
| 361 | } |
| 362 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 363 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 364 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 365 | #if defined(__i386__) |
| 366 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386); |
| 367 | #elif defined(__x86_64__) |
| 368 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64); |
| 369 | #elif defined(__arm__) |
| 370 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM); |
| 371 | #else |
| 372 | #error "Unsupported platform" |
| 373 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 374 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 375 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 376 | void *entry = nullptr; |
| 377 | |
| 378 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 379 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 380 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 381 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 382 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 383 | { |
| 384 | entry = elfImage + sectionHeader[i].sh_offset; |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 385 | codeSize = sectionHeader[i].sh_size; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 389 | { |
| 390 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 391 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 392 | 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] | 393 | { |
| 394 | 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] | 395 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 399 | { |
| 400 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 401 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 402 | 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] | 403 | { |
| 404 | 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] | 405 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 406 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | return entry; |
| 411 | } |
| 412 | |
| 413 | template<typename T> |
| 414 | struct ExecutableAllocator |
| 415 | { |
| 416 | ExecutableAllocator() {}; |
| 417 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 418 | |
| 419 | using value_type = T; |
| 420 | using size_type = std::size_t; |
| 421 | |
| 422 | T *allocate(size_type n) |
| 423 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 424 | #if defined(_WIN32) |
| 425 | return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); |
| 426 | #else |
| 427 | return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 428 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | void deallocate(T *p, size_type n) |
| 432 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 433 | #if defined(_WIN32) |
| 434 | VirtualFree(p, 0, MEM_RELEASE); |
| 435 | #else |
| 436 | munmap(p, sizeof(T) * n); |
| 437 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 438 | } |
| 439 | }; |
| 440 | |
| 441 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 442 | { |
| 443 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 444 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 445 | |
| 446 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 447 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 448 | { |
| 449 | position = 0; |
| 450 | buffer.reserve(0x1000); |
| 451 | } |
| 452 | |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 453 | ~ELFMemoryStreamer() override |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 454 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 455 | #if defined(_WIN32) |
| 456 | if(buffer.size() != 0) |
| 457 | { |
| 458 | DWORD exeProtection; |
| 459 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 460 | } |
| 461 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void write8(uint8_t Value) override |
| 465 | { |
| 466 | if(position == (uint64_t)buffer.size()) |
| 467 | { |
| 468 | buffer.push_back(Value); |
| 469 | position++; |
| 470 | } |
| 471 | else if(position < (uint64_t)buffer.size()) |
| 472 | { |
| 473 | buffer[position] = Value; |
| 474 | position++; |
| 475 | } |
| 476 | else assert(false && "UNIMPLEMENTED"); |
| 477 | } |
| 478 | |
| 479 | void writeBytes(llvm::StringRef Bytes) override |
| 480 | { |
| 481 | std::size_t oldSize = buffer.size(); |
| 482 | buffer.resize(oldSize + Bytes.size()); |
| 483 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 484 | position += Bytes.size(); |
| 485 | } |
| 486 | |
| 487 | uint64_t tell() const override { return position; } |
| 488 | |
| 489 | void seek(uint64_t Off) override { position = Off; } |
| 490 | |
| 491 | const void *getEntry() override |
| 492 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 493 | if(!entry) |
| 494 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 495 | 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] | 496 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 497 | size_t codeSize = 0; |
| 498 | entry = loadImage(&buffer[0], codeSize); |
| 499 | |
| 500 | #if defined(_WIN32) |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 501 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 502 | FlushInstructionCache(GetCurrentProcess(), NULL, 0); |
| 503 | #else |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 504 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 505 | __builtin___clear_cache((char*)entry, (char*)entry + codeSize); |
| 506 | #endif |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 513 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 514 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 515 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 516 | |
| 517 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 518 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 519 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | Nucleus::Nucleus() |
| 523 | { |
| 524 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 525 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 526 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 527 | Ice::ClFlags::getParsedClFlags(Flags); |
| 528 | |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 529 | #if defined(__arm__) |
| 530 | Flags.setTargetArch(Ice::Target_ARM32); |
| 531 | Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm); |
| 532 | #else // x86 |
| 533 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 534 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
| 535 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 536 | Flags.setOutFileType(Ice::FT_Elf); |
| 537 | Flags.setOptLevel(Ice::Opt_2); |
| 538 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 539 | Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None); |
| 540 | Flags.setDisableHybridAssembly(true); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 541 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 542 | static llvm::raw_os_ostream cout(std::cout); |
| 543 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 544 | |
| 545 | if(false) // Write out to a file |
| 546 | { |
| 547 | std::error_code errorCode; |
| 548 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 549 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 550 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 551 | } |
| 552 | else |
| 553 | { |
| 554 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 555 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 556 | ::routine = elfMemory; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | Nucleus::~Nucleus() |
| 561 | { |
| 562 | delete ::allocator; |
| 563 | delete ::function; |
| 564 | delete ::context; |
| 565 | |
| 566 | delete ::elfFile; |
| 567 | delete ::out; |
| 568 | |
| 569 | ::codegenMutex.unlock(); |
| 570 | } |
| 571 | |
| 572 | Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations) |
| 573 | { |
| 574 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 575 | { |
| 576 | createRetVoid(); |
| 577 | } |
| 578 | |
| 579 | std::wstring wideName(name); |
| 580 | std::string asciiName(wideName.begin(), wideName.end()); |
| 581 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName)); |
| 582 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 583 | optimize(); |
| 584 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 585 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 586 | assert(!::function->hasError()); |
| 587 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 588 | auto *globals = ::function->getGlobalInits().release(); |
| 589 | |
| 590 | if(globals && !globals->empty()) |
| 591 | { |
| 592 | ::context->getGlobals()->merge(globals); |
| 593 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 594 | |
| 595 | ::context->emitFileHeader(); |
| 596 | ::function->emitIAS(); |
| 597 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 598 | auto objectWriter = ::context->getObjectWriter(); |
| 599 | assembler->alignFunction(); |
| 600 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 601 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 602 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 603 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 604 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 605 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 606 | |
| 607 | return ::routine; |
| 608 | } |
| 609 | |
| 610 | void Nucleus::optimize() |
| 611 | { |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 612 | sw::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 616 | { |
| 617 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 618 | int typeSize = Ice::typeWidthInBytes(type); |
| 619 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 620 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 621 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 622 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 623 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 624 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 625 | |
| 626 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | BasicBlock *Nucleus::createBasicBlock() |
| 630 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 631 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | BasicBlock *Nucleus::getInsertBlock() |
| 635 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 636 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 640 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 641 | // 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] | 642 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 645 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 646 | { |
| 647 | uint32_t sequenceNumber = 0; |
| 648 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 649 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 650 | |
| 651 | for(Type *type : Params) |
| 652 | { |
| 653 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 654 | ::function->addArg(arg); |
| 655 | } |
| 656 | |
| 657 | Ice::CfgNode *node = ::function->makeNode(); |
| 658 | ::function->setEntryNode(node); |
| 659 | ::basicBlock = node; |
| 660 | } |
| 661 | |
| 662 | Value *Nucleus::getArgument(unsigned int index) |
| 663 | { |
| 664 | return V(::function->getArgs()[index]); |
| 665 | } |
| 666 | |
| 667 | void Nucleus::createRetVoid() |
| 668 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 669 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 670 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | void Nucleus::createRet(Value *v) |
| 674 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 675 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 676 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void Nucleus::createBr(BasicBlock *dest) |
| 680 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 681 | auto br = Ice::InstBr::create(::function, dest); |
| 682 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 686 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 687 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 688 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 689 | } |
| 690 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 691 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 692 | { |
| 693 | switch(op) |
| 694 | { |
| 695 | case Ice::InstArithmetic::Add: |
| 696 | case Ice::InstArithmetic::Fadd: |
| 697 | case Ice::InstArithmetic::Mul: |
| 698 | case Ice::InstArithmetic::Fmul: |
| 699 | case Ice::InstArithmetic::And: |
| 700 | case Ice::InstArithmetic::Or: |
| 701 | case Ice::InstArithmetic::Xor: |
| 702 | return true; |
| 703 | default: |
| 704 | return false; |
| 705 | } |
| 706 | } |
| 707 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 708 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 709 | { |
Nicolas Capens | 327f1df | 2016-10-21 14:26:34 -0400 | [diff] [blame] | 710 | 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] | 711 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 712 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 713 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 714 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 715 | 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] | 716 | ::basicBlock->appendInst(arithmetic); |
| 717 | |
| 718 | return V(result); |
| 719 | } |
| 720 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 721 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 722 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 723 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 727 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 728 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 732 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 733 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 737 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 738 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 742 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 743 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 747 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 748 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 752 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 753 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 757 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 758 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 762 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 763 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 767 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 768 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 772 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 773 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 777 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 778 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 782 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 783 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 787 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 788 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 792 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 793 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 797 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 798 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 802 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 803 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 807 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 808 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | Value *Nucleus::createNeg(Value *v) |
| 812 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 813 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | Value *Nucleus::createFNeg(Value *v) |
| 817 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 818 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 819 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 820 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 821 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 822 | |
| 823 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | Value *Nucleus::createNot(Value *v) |
| 827 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 828 | if(Ice::isScalarIntegerType(v->getType())) |
| 829 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 830 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 831 | } |
| 832 | else // Vector |
| 833 | { |
Nicolas Capens | f34d1ac | 2017-05-08 17:06:11 -0400 | [diff] [blame] | 834 | 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] | 835 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 836 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 839 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 840 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 841 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 842 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 843 | |
| 844 | if(valueType & EmulatedBits) |
| 845 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 846 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 847 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 848 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 849 | load->addArg(ptr); |
| 850 | load->addArg(::context->getConstantInt32(typeSize(type))); |
| 851 | ::basicBlock->appendInst(load); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 852 | } |
| 853 | else |
| 854 | { |
| 855 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 856 | ::basicBlock->appendInst(load); |
| 857 | } |
| 858 | |
| 859 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 860 | } |
| 861 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 862 | 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] | 863 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 864 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 865 | |
| 866 | if(valueType & EmulatedBits) |
| 867 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 868 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 869 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 870 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
| 871 | store->addArg(value); |
| 872 | store->addArg(ptr); |
| 873 | store->addArg(::context->getConstantInt32(typeSize(type))); |
| 874 | ::basicBlock->appendInst(store); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 875 | } |
| 876 | else |
| 877 | { |
| 878 | assert(T(value->getType()) == type); |
| 879 | |
| 880 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 881 | ::basicBlock->appendInst(store); |
| 882 | } |
| 883 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 884 | return value; |
| 885 | } |
| 886 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 887 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 888 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 889 | assert(index->getType() == Ice::IceType_i32); |
| 890 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 891 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 892 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 893 | int32_t offset = constant->getValue() * (int)typeSize(type); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 894 | |
| 895 | if(offset == 0) |
| 896 | { |
| 897 | return ptr; |
| 898 | } |
| 899 | |
| 900 | return createAdd(ptr, createConstantInt(offset)); |
| 901 | } |
| 902 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 903 | if(!Ice::isByteSizedType(T(type))) |
| 904 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 905 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | if(sizeof(void*) == 8) |
| 909 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 910 | if(unsignedIndex) |
| 911 | { |
| 912 | index = createZExt(index, T(Ice::IceType_i64)); |
| 913 | } |
| 914 | else |
| 915 | { |
| 916 | index = createSExt(index, T(Ice::IceType_i64)); |
| 917 | } |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 924 | { |
| 925 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 926 | } |
| 927 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 928 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 929 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 930 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 931 | { |
| 932 | return v; |
| 933 | } |
| 934 | |
| 935 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 936 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 937 | ::basicBlock->appendInst(cast); |
| 938 | |
| 939 | return V(result); |
| 940 | } |
| 941 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 942 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 943 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 944 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 948 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 949 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 953 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 954 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 958 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 959 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 962 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 963 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 964 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 968 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 969 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 973 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 974 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 978 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 979 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 980 | } |
| 981 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 982 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 983 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 984 | assert(lhs->getType() == rhs->getType()); |
| 985 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 986 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 987 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 988 | ::basicBlock->appendInst(cmp); |
| 989 | |
| 990 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 991 | } |
| 992 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 993 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 994 | { |
| 995 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 996 | } |
| 997 | |
| 998 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 999 | { |
| 1000 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 1001 | } |
| 1002 | |
| 1003 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 1004 | { |
| 1005 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 1006 | } |
| 1007 | |
| 1008 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 1009 | { |
| 1010 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 1011 | } |
| 1012 | |
| 1013 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 1014 | { |
| 1015 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 1016 | } |
| 1017 | |
| 1018 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 1019 | { |
| 1020 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 1021 | } |
| 1022 | |
| 1023 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 1024 | { |
| 1025 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 1026 | } |
| 1027 | |
| 1028 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 1029 | { |
| 1030 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 1031 | } |
| 1032 | |
| 1033 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 1034 | { |
| 1035 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 1036 | } |
| 1037 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1038 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 1039 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1040 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 1041 | } |
| 1042 | |
| 1043 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 1044 | { |
| 1045 | assert(lhs->getType() == rhs->getType()); |
| 1046 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 1047 | |
| 1048 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 1049 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 1050 | ::basicBlock->appendInst(cmp); |
| 1051 | |
| 1052 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 1056 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1057 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1061 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1062 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1066 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1067 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1071 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1072 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1076 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1077 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1081 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1082 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1086 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1087 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1091 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1092 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1096 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1097 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1101 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1102 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1106 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1107 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1111 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1112 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1116 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1117 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1121 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1122 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1125 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1126 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1127 | auto result = ::function->makeVariable(T(type)); |
| 1128 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1129 | ::basicBlock->appendInst(extract); |
| 1130 | |
| 1131 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1135 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1136 | auto result = ::function->makeVariable(vector->getType()); |
| 1137 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1138 | ::basicBlock->appendInst(insert); |
| 1139 | |
| 1140 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1143 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1144 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1145 | assert(V1->getType() == V2->getType()); |
| 1146 | |
| 1147 | int size = Ice::typeNumElements(V1->getType()); |
| 1148 | auto result = ::function->makeVariable(V1->getType()); |
| 1149 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1150 | |
| 1151 | for(int i = 0; i < size; i++) |
| 1152 | { |
| 1153 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1154 | } |
| 1155 | |
| 1156 | ::basicBlock->appendInst(shuffle); |
| 1157 | |
| 1158 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1162 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1163 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1164 | |
| 1165 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1166 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1167 | ::basicBlock->appendInst(select); |
| 1168 | |
| 1169 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1170 | } |
| 1171 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1172 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1173 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1174 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1175 | ::basicBlock->appendInst(switchInst); |
| 1176 | |
| 1177 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1178 | } |
| 1179 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1180 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1181 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1182 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | void Nucleus::createUnreachable() |
| 1186 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1187 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1188 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1189 | } |
| 1190 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1191 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1192 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1193 | int swizzle[4] = |
| 1194 | { |
| 1195 | (select >> 0) & 0x03, |
| 1196 | (select >> 2) & 0x03, |
| 1197 | (select >> 4) & 0x03, |
| 1198 | (select >> 6) & 0x03, |
| 1199 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1200 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1201 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1202 | } |
| 1203 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1204 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1205 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1206 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1207 | |
| 1208 | mask[(select >> 0) & 0x03] = -1; |
| 1209 | mask[(select >> 2) & 0x03] = -1; |
| 1210 | mask[(select >> 4) & 0x03] = -1; |
| 1211 | mask[(select >> 6) & 0x03] = -1; |
| 1212 | |
| 1213 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1214 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1215 | |
| 1216 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1219 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1220 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1221 | if(sizeof(void*) == 8) |
| 1222 | { |
| 1223 | return T(Ice::IceType_i64); |
| 1224 | } |
| 1225 | else |
| 1226 | { |
| 1227 | return T(Ice::IceType_i32); |
| 1228 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1229 | } |
| 1230 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1231 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1232 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1233 | if(Ice::isVectorType(T(Ty))) |
| 1234 | { |
Nicolas Capens | 30385f0 | 2017-04-18 13:03:47 -0400 | [diff] [blame] | 1235 | assert(Ice::typeNumElements(T(Ty)) <= 16); |
| 1236 | 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] | 1237 | return createConstantVector(c, Ty); |
| 1238 | } |
| 1239 | else |
| 1240 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1241 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1242 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1243 | } |
| 1244 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1245 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1246 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1247 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1250 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1251 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1252 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1255 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1256 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1257 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1258 | } |
| 1259 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1260 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1261 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1262 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1265 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1266 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1267 | return V(::context->getConstantInt8(i)); |
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::createConstantByte(unsigned char 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->getConstantInt8(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::createConstantShort(short 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->getConstantInt16(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::createConstantShort(unsigned short 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->getConstantInt16(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::createConstantFloat(float x) |
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->getConstantFloat(x)); |
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::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1291 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1292 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1295 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1296 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1297 | const int vectorSize = 16; |
| 1298 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1299 | const int alignment = vectorSize; |
| 1300 | auto globalPool = ::function->getGlobalPool(); |
| 1301 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1302 | const int64_t *i = constants; |
| 1303 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1304 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1305 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1306 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1307 | { |
| 1308 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1309 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1310 | { |
| 1311 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1312 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1313 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1314 | } |
| 1315 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1316 | case Ice::IceType_v4f32: |
| 1317 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1318 | 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] | 1319 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1320 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1321 | } |
| 1322 | break; |
| 1323 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1324 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1325 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1326 | 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] | 1327 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1328 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1329 | } |
| 1330 | break; |
| 1331 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1332 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1333 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1334 | 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] | 1335 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1336 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1337 | } |
| 1338 | break; |
| 1339 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1340 | { |
| 1341 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1342 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1343 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1344 | } |
| 1345 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1346 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1347 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1348 | 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] | 1349 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1350 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1351 | } |
| 1352 | break; |
| 1353 | case Type_v4i16: |
| 1354 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1355 | 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] | 1356 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1357 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1358 | } |
| 1359 | break; |
| 1360 | case Type_v8i8: |
| 1361 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1362 | 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] | 1363 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1364 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1365 | } |
| 1366 | break; |
| 1367 | case Type_v4i8: |
| 1368 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1369 | 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] | 1370 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1371 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1372 | } |
| 1373 | break; |
| 1374 | default: |
| 1375 | assert(false && "Unknown constant vector type" && type); |
| 1376 | } |
| 1377 | |
| 1378 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1379 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1380 | variableDeclaration->setName(name); |
| 1381 | variableDeclaration->setAlignment(alignment); |
| 1382 | variableDeclaration->setIsConstant(true); |
| 1383 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1384 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1385 | ::function->addGlobal(variableDeclaration); |
| 1386 | |
| 1387 | constexpr int32_t offset = 0; |
| 1388 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1389 | |
| 1390 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1391 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1392 | ::basicBlock->appendInst(load); |
| 1393 | |
| 1394 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1398 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1399 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | Type *Void::getType() |
| 1403 | { |
| 1404 | return T(Ice::IceType_void); |
| 1405 | } |
| 1406 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1407 | Bool::Bool(Argument<Bool> argument) |
| 1408 | { |
| 1409 | storeValue(argument.value); |
| 1410 | } |
| 1411 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1412 | Bool::Bool(bool x) |
| 1413 | { |
| 1414 | storeValue(Nucleus::createConstantBool(x)); |
| 1415 | } |
| 1416 | |
| 1417 | Bool::Bool(RValue<Bool> rhs) |
| 1418 | { |
| 1419 | storeValue(rhs.value); |
| 1420 | } |
| 1421 | |
| 1422 | Bool::Bool(const Bool &rhs) |
| 1423 | { |
| 1424 | Value *value = rhs.loadValue(); |
| 1425 | storeValue(value); |
| 1426 | } |
| 1427 | |
| 1428 | Bool::Bool(const Reference<Bool> &rhs) |
| 1429 | { |
| 1430 | Value *value = rhs.loadValue(); |
| 1431 | storeValue(value); |
| 1432 | } |
| 1433 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1434 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1435 | { |
| 1436 | storeValue(rhs.value); |
| 1437 | |
| 1438 | return rhs; |
| 1439 | } |
| 1440 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1441 | RValue<Bool> Bool::operator=(const Bool &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1442 | { |
| 1443 | Value *value = rhs.loadValue(); |
| 1444 | storeValue(value); |
| 1445 | |
| 1446 | return RValue<Bool>(value); |
| 1447 | } |
| 1448 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1449 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1450 | { |
| 1451 | Value *value = rhs.loadValue(); |
| 1452 | storeValue(value); |
| 1453 | |
| 1454 | return RValue<Bool>(value); |
| 1455 | } |
| 1456 | |
| 1457 | RValue<Bool> operator!(RValue<Bool> val) |
| 1458 | { |
| 1459 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1460 | } |
| 1461 | |
| 1462 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1463 | { |
| 1464 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1465 | } |
| 1466 | |
| 1467 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1468 | { |
| 1469 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1470 | } |
| 1471 | |
| 1472 | Type *Bool::getType() |
| 1473 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1474 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | Byte::Byte(Argument<Byte> argument) |
| 1478 | { |
| 1479 | storeValue(argument.value); |
| 1480 | } |
| 1481 | |
| 1482 | Byte::Byte(RValue<Int> cast) |
| 1483 | { |
| 1484 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1485 | |
| 1486 | storeValue(integer); |
| 1487 | } |
| 1488 | |
| 1489 | Byte::Byte(RValue<UInt> cast) |
| 1490 | { |
| 1491 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1492 | |
| 1493 | storeValue(integer); |
| 1494 | } |
| 1495 | |
| 1496 | Byte::Byte(RValue<UShort> cast) |
| 1497 | { |
| 1498 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1499 | |
| 1500 | storeValue(integer); |
| 1501 | } |
| 1502 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1503 | Byte::Byte(int x) |
| 1504 | { |
| 1505 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1506 | } |
| 1507 | |
| 1508 | Byte::Byte(unsigned char x) |
| 1509 | { |
| 1510 | storeValue(Nucleus::createConstantByte(x)); |
| 1511 | } |
| 1512 | |
| 1513 | Byte::Byte(RValue<Byte> rhs) |
| 1514 | { |
| 1515 | storeValue(rhs.value); |
| 1516 | } |
| 1517 | |
| 1518 | Byte::Byte(const Byte &rhs) |
| 1519 | { |
| 1520 | Value *value = rhs.loadValue(); |
| 1521 | storeValue(value); |
| 1522 | } |
| 1523 | |
| 1524 | Byte::Byte(const Reference<Byte> &rhs) |
| 1525 | { |
| 1526 | Value *value = rhs.loadValue(); |
| 1527 | storeValue(value); |
| 1528 | } |
| 1529 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1530 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1531 | { |
| 1532 | storeValue(rhs.value); |
| 1533 | |
| 1534 | return rhs; |
| 1535 | } |
| 1536 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1537 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1538 | { |
| 1539 | Value *value = rhs.loadValue(); |
| 1540 | storeValue(value); |
| 1541 | |
| 1542 | return RValue<Byte>(value); |
| 1543 | } |
| 1544 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1545 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1546 | { |
| 1547 | Value *value = rhs.loadValue(); |
| 1548 | storeValue(value); |
| 1549 | |
| 1550 | return RValue<Byte>(value); |
| 1551 | } |
| 1552 | |
| 1553 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1554 | { |
| 1555 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1556 | } |
| 1557 | |
| 1558 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1559 | { |
| 1560 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1561 | } |
| 1562 | |
| 1563 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1564 | { |
| 1565 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1566 | } |
| 1567 | |
| 1568 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1569 | { |
| 1570 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1571 | } |
| 1572 | |
| 1573 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1574 | { |
| 1575 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1576 | } |
| 1577 | |
| 1578 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1579 | { |
| 1580 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1581 | } |
| 1582 | |
| 1583 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1584 | { |
| 1585 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1586 | } |
| 1587 | |
| 1588 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1589 | { |
| 1590 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1591 | } |
| 1592 | |
| 1593 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1594 | { |
| 1595 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1596 | } |
| 1597 | |
| 1598 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1599 | { |
| 1600 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1601 | } |
| 1602 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1603 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1604 | { |
| 1605 | return lhs = lhs + rhs; |
| 1606 | } |
| 1607 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1608 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1609 | { |
| 1610 | return lhs = lhs - rhs; |
| 1611 | } |
| 1612 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1613 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1614 | { |
| 1615 | return lhs = lhs * rhs; |
| 1616 | } |
| 1617 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1618 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1619 | { |
| 1620 | return lhs = lhs / rhs; |
| 1621 | } |
| 1622 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1623 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1624 | { |
| 1625 | return lhs = lhs % rhs; |
| 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 | |
| 1653 | RValue<Byte> operator+(RValue<Byte> val) |
| 1654 | { |
| 1655 | return val; |
| 1656 | } |
| 1657 | |
| 1658 | RValue<Byte> operator-(RValue<Byte> val) |
| 1659 | { |
| 1660 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1661 | } |
| 1662 | |
| 1663 | RValue<Byte> operator~(RValue<Byte> val) |
| 1664 | { |
| 1665 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1666 | } |
| 1667 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1668 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1669 | { |
| 1670 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1671 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1672 | return res; |
| 1673 | } |
| 1674 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1675 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1676 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1677 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1678 | return val; |
| 1679 | } |
| 1680 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1681 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1682 | { |
| 1683 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1684 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1685 | return res; |
| 1686 | } |
| 1687 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1688 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1689 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1690 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1691 | return val; |
| 1692 | } |
| 1693 | |
| 1694 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1695 | { |
| 1696 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1697 | } |
| 1698 | |
| 1699 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1700 | { |
| 1701 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1702 | } |
| 1703 | |
| 1704 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1705 | { |
| 1706 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1707 | } |
| 1708 | |
| 1709 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1710 | { |
| 1711 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1712 | } |
| 1713 | |
| 1714 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1715 | { |
| 1716 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1717 | } |
| 1718 | |
| 1719 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1720 | { |
| 1721 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1722 | } |
| 1723 | |
| 1724 | Type *Byte::getType() |
| 1725 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1726 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | SByte::SByte(Argument<SByte> argument) |
| 1730 | { |
| 1731 | storeValue(argument.value); |
| 1732 | } |
| 1733 | |
| 1734 | SByte::SByte(RValue<Int> cast) |
| 1735 | { |
| 1736 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1737 | |
| 1738 | storeValue(integer); |
| 1739 | } |
| 1740 | |
| 1741 | SByte::SByte(RValue<Short> cast) |
| 1742 | { |
| 1743 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1744 | |
| 1745 | storeValue(integer); |
| 1746 | } |
| 1747 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1748 | SByte::SByte(signed char x) |
| 1749 | { |
| 1750 | storeValue(Nucleus::createConstantByte(x)); |
| 1751 | } |
| 1752 | |
| 1753 | SByte::SByte(RValue<SByte> rhs) |
| 1754 | { |
| 1755 | storeValue(rhs.value); |
| 1756 | } |
| 1757 | |
| 1758 | SByte::SByte(const SByte &rhs) |
| 1759 | { |
| 1760 | Value *value = rhs.loadValue(); |
| 1761 | storeValue(value); |
| 1762 | } |
| 1763 | |
| 1764 | SByte::SByte(const Reference<SByte> &rhs) |
| 1765 | { |
| 1766 | Value *value = rhs.loadValue(); |
| 1767 | storeValue(value); |
| 1768 | } |
| 1769 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1770 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1771 | { |
| 1772 | storeValue(rhs.value); |
| 1773 | |
| 1774 | return rhs; |
| 1775 | } |
| 1776 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1777 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1778 | { |
| 1779 | Value *value = rhs.loadValue(); |
| 1780 | storeValue(value); |
| 1781 | |
| 1782 | return RValue<SByte>(value); |
| 1783 | } |
| 1784 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1785 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1786 | { |
| 1787 | Value *value = rhs.loadValue(); |
| 1788 | storeValue(value); |
| 1789 | |
| 1790 | return RValue<SByte>(value); |
| 1791 | } |
| 1792 | |
| 1793 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1794 | { |
| 1795 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1796 | } |
| 1797 | |
| 1798 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1799 | { |
| 1800 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1801 | } |
| 1802 | |
| 1803 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1804 | { |
| 1805 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1806 | } |
| 1807 | |
| 1808 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1809 | { |
| 1810 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1811 | } |
| 1812 | |
| 1813 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1814 | { |
| 1815 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1816 | } |
| 1817 | |
| 1818 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1819 | { |
| 1820 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1821 | } |
| 1822 | |
| 1823 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1824 | { |
| 1825 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1826 | } |
| 1827 | |
| 1828 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1829 | { |
| 1830 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1831 | } |
| 1832 | |
| 1833 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1834 | { |
| 1835 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1836 | } |
| 1837 | |
| 1838 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1839 | { |
| 1840 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1841 | } |
| 1842 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1843 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1844 | { |
| 1845 | return lhs = lhs + rhs; |
| 1846 | } |
| 1847 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1848 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1849 | { |
| 1850 | return lhs = lhs - rhs; |
| 1851 | } |
| 1852 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1853 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1854 | { |
| 1855 | return lhs = lhs * rhs; |
| 1856 | } |
| 1857 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1858 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1859 | { |
| 1860 | return lhs = lhs / rhs; |
| 1861 | } |
| 1862 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1863 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1864 | { |
| 1865 | return lhs = lhs % rhs; |
| 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 | |
| 1893 | RValue<SByte> operator+(RValue<SByte> val) |
| 1894 | { |
| 1895 | return val; |
| 1896 | } |
| 1897 | |
| 1898 | RValue<SByte> operator-(RValue<SByte> val) |
| 1899 | { |
| 1900 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 1901 | } |
| 1902 | |
| 1903 | RValue<SByte> operator~(RValue<SByte> val) |
| 1904 | { |
| 1905 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 1906 | } |
| 1907 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1908 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1909 | { |
| 1910 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1911 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1912 | return res; |
| 1913 | } |
| 1914 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1915 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1916 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1917 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1918 | return val; |
| 1919 | } |
| 1920 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1921 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1922 | { |
| 1923 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1924 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1925 | return res; |
| 1926 | } |
| 1927 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1928 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1929 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1930 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1931 | return val; |
| 1932 | } |
| 1933 | |
| 1934 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1935 | { |
| 1936 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 1937 | } |
| 1938 | |
| 1939 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1940 | { |
| 1941 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 1942 | } |
| 1943 | |
| 1944 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1945 | { |
| 1946 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 1947 | } |
| 1948 | |
| 1949 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1950 | { |
| 1951 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 1952 | } |
| 1953 | |
| 1954 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1955 | { |
| 1956 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1957 | } |
| 1958 | |
| 1959 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1960 | { |
| 1961 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1962 | } |
| 1963 | |
| 1964 | Type *SByte::getType() |
| 1965 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1966 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | Short::Short(Argument<Short> argument) |
| 1970 | { |
| 1971 | storeValue(argument.value); |
| 1972 | } |
| 1973 | |
| 1974 | Short::Short(RValue<Int> cast) |
| 1975 | { |
| 1976 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 1977 | |
| 1978 | storeValue(integer); |
| 1979 | } |
| 1980 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1981 | Short::Short(short x) |
| 1982 | { |
| 1983 | storeValue(Nucleus::createConstantShort(x)); |
| 1984 | } |
| 1985 | |
| 1986 | Short::Short(RValue<Short> rhs) |
| 1987 | { |
| 1988 | storeValue(rhs.value); |
| 1989 | } |
| 1990 | |
| 1991 | Short::Short(const Short &rhs) |
| 1992 | { |
| 1993 | Value *value = rhs.loadValue(); |
| 1994 | storeValue(value); |
| 1995 | } |
| 1996 | |
| 1997 | Short::Short(const Reference<Short> &rhs) |
| 1998 | { |
| 1999 | Value *value = rhs.loadValue(); |
| 2000 | storeValue(value); |
| 2001 | } |
| 2002 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2003 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2004 | { |
| 2005 | storeValue(rhs.value); |
| 2006 | |
| 2007 | return rhs; |
| 2008 | } |
| 2009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2010 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2011 | { |
| 2012 | Value *value = rhs.loadValue(); |
| 2013 | storeValue(value); |
| 2014 | |
| 2015 | return RValue<Short>(value); |
| 2016 | } |
| 2017 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2018 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2019 | { |
| 2020 | Value *value = rhs.loadValue(); |
| 2021 | storeValue(value); |
| 2022 | |
| 2023 | return RValue<Short>(value); |
| 2024 | } |
| 2025 | |
| 2026 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 2027 | { |
| 2028 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2029 | } |
| 2030 | |
| 2031 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 2032 | { |
| 2033 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2034 | } |
| 2035 | |
| 2036 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 2037 | { |
| 2038 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2039 | } |
| 2040 | |
| 2041 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 2042 | { |
| 2043 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2044 | } |
| 2045 | |
| 2046 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 2047 | { |
| 2048 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2049 | } |
| 2050 | |
| 2051 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 2052 | { |
| 2053 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2054 | } |
| 2055 | |
| 2056 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 2057 | { |
| 2058 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2059 | } |
| 2060 | |
| 2061 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2062 | { |
| 2063 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2064 | } |
| 2065 | |
| 2066 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2067 | { |
| 2068 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2069 | } |
| 2070 | |
| 2071 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2072 | { |
| 2073 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2074 | } |
| 2075 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2076 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2077 | { |
| 2078 | return lhs = lhs + rhs; |
| 2079 | } |
| 2080 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2081 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2082 | { |
| 2083 | return lhs = lhs - rhs; |
| 2084 | } |
| 2085 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2086 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2087 | { |
| 2088 | return lhs = lhs * rhs; |
| 2089 | } |
| 2090 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2091 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2092 | { |
| 2093 | return lhs = lhs / rhs; |
| 2094 | } |
| 2095 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2096 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2097 | { |
| 2098 | return lhs = lhs % rhs; |
| 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 | |
| 2126 | RValue<Short> operator+(RValue<Short> val) |
| 2127 | { |
| 2128 | return val; |
| 2129 | } |
| 2130 | |
| 2131 | RValue<Short> operator-(RValue<Short> val) |
| 2132 | { |
| 2133 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2134 | } |
| 2135 | |
| 2136 | RValue<Short> operator~(RValue<Short> val) |
| 2137 | { |
| 2138 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2139 | } |
| 2140 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2141 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2142 | { |
| 2143 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2144 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2145 | return res; |
| 2146 | } |
| 2147 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2148 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2149 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2150 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2151 | return val; |
| 2152 | } |
| 2153 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2154 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2155 | { |
| 2156 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2157 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2158 | return res; |
| 2159 | } |
| 2160 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2161 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2162 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2163 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2164 | return val; |
| 2165 | } |
| 2166 | |
| 2167 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2168 | { |
| 2169 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2170 | } |
| 2171 | |
| 2172 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2173 | { |
| 2174 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2175 | } |
| 2176 | |
| 2177 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2178 | { |
| 2179 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2180 | } |
| 2181 | |
| 2182 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2183 | { |
| 2184 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2185 | } |
| 2186 | |
| 2187 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2188 | { |
| 2189 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2190 | } |
| 2191 | |
| 2192 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2193 | { |
| 2194 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2195 | } |
| 2196 | |
| 2197 | Type *Short::getType() |
| 2198 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2199 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | UShort::UShort(Argument<UShort> argument) |
| 2203 | { |
| 2204 | storeValue(argument.value); |
| 2205 | } |
| 2206 | |
| 2207 | UShort::UShort(RValue<UInt> cast) |
| 2208 | { |
| 2209 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2210 | |
| 2211 | storeValue(integer); |
| 2212 | } |
| 2213 | |
| 2214 | UShort::UShort(RValue<Int> cast) |
| 2215 | { |
| 2216 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2217 | |
| 2218 | storeValue(integer); |
| 2219 | } |
| 2220 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2221 | UShort::UShort(unsigned short x) |
| 2222 | { |
| 2223 | storeValue(Nucleus::createConstantShort(x)); |
| 2224 | } |
| 2225 | |
| 2226 | UShort::UShort(RValue<UShort> rhs) |
| 2227 | { |
| 2228 | storeValue(rhs.value); |
| 2229 | } |
| 2230 | |
| 2231 | UShort::UShort(const UShort &rhs) |
| 2232 | { |
| 2233 | Value *value = rhs.loadValue(); |
| 2234 | storeValue(value); |
| 2235 | } |
| 2236 | |
| 2237 | UShort::UShort(const Reference<UShort> &rhs) |
| 2238 | { |
| 2239 | Value *value = rhs.loadValue(); |
| 2240 | storeValue(value); |
| 2241 | } |
| 2242 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2243 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2244 | { |
| 2245 | storeValue(rhs.value); |
| 2246 | |
| 2247 | return rhs; |
| 2248 | } |
| 2249 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2250 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2251 | { |
| 2252 | Value *value = rhs.loadValue(); |
| 2253 | storeValue(value); |
| 2254 | |
| 2255 | return RValue<UShort>(value); |
| 2256 | } |
| 2257 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2258 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2259 | { |
| 2260 | Value *value = rhs.loadValue(); |
| 2261 | storeValue(value); |
| 2262 | |
| 2263 | return RValue<UShort>(value); |
| 2264 | } |
| 2265 | |
| 2266 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2267 | { |
| 2268 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2269 | } |
| 2270 | |
| 2271 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2272 | { |
| 2273 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2274 | } |
| 2275 | |
| 2276 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2277 | { |
| 2278 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2279 | } |
| 2280 | |
| 2281 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2282 | { |
| 2283 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2284 | } |
| 2285 | |
| 2286 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2287 | { |
| 2288 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2289 | } |
| 2290 | |
| 2291 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2292 | { |
| 2293 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2294 | } |
| 2295 | |
| 2296 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2297 | { |
| 2298 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2299 | } |
| 2300 | |
| 2301 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2302 | { |
| 2303 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2304 | } |
| 2305 | |
| 2306 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2307 | { |
| 2308 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2309 | } |
| 2310 | |
| 2311 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2312 | { |
| 2313 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2314 | } |
| 2315 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2316 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2317 | { |
| 2318 | return lhs = lhs + rhs; |
| 2319 | } |
| 2320 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2321 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2322 | { |
| 2323 | return lhs = lhs - rhs; |
| 2324 | } |
| 2325 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2326 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2327 | { |
| 2328 | return lhs = lhs * rhs; |
| 2329 | } |
| 2330 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2331 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2332 | { |
| 2333 | return lhs = lhs / rhs; |
| 2334 | } |
| 2335 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2336 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2337 | { |
| 2338 | return lhs = lhs % rhs; |
| 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 | |
| 2366 | RValue<UShort> operator+(RValue<UShort> val) |
| 2367 | { |
| 2368 | return val; |
| 2369 | } |
| 2370 | |
| 2371 | RValue<UShort> operator-(RValue<UShort> val) |
| 2372 | { |
| 2373 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2374 | } |
| 2375 | |
| 2376 | RValue<UShort> operator~(RValue<UShort> val) |
| 2377 | { |
| 2378 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2379 | } |
| 2380 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2381 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2382 | { |
| 2383 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2384 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2385 | return res; |
| 2386 | } |
| 2387 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2388 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2389 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2390 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2391 | return val; |
| 2392 | } |
| 2393 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2394 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2395 | { |
| 2396 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2397 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2398 | return res; |
| 2399 | } |
| 2400 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2401 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2402 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2403 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2404 | return val; |
| 2405 | } |
| 2406 | |
| 2407 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2408 | { |
| 2409 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2410 | } |
| 2411 | |
| 2412 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2413 | { |
| 2414 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2415 | } |
| 2416 | |
| 2417 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2418 | { |
| 2419 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2420 | } |
| 2421 | |
| 2422 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2423 | { |
| 2424 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2425 | } |
| 2426 | |
| 2427 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2428 | { |
| 2429 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2430 | } |
| 2431 | |
| 2432 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2433 | { |
| 2434 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2435 | } |
| 2436 | |
| 2437 | Type *UShort::getType() |
| 2438 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2439 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2440 | } |
| 2441 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2442 | Byte4::Byte4(RValue<Byte8> cast) |
| 2443 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2444 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2445 | } |
| 2446 | |
| 2447 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2448 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2449 | Value *value = rhs.loadValue(); |
| 2450 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2451 | } |
| 2452 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2453 | Type *Byte4::getType() |
| 2454 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2455 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | Type *SByte4::getType() |
| 2459 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2460 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2461 | } |
| 2462 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2463 | 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) |
| 2464 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2465 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2466 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2470 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2471 | storeValue(rhs.value); |
| 2472 | } |
| 2473 | |
| 2474 | Byte8::Byte8(const Byte8 &rhs) |
| 2475 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2476 | Value *value = rhs.loadValue(); |
| 2477 | storeValue(value); |
| 2478 | } |
| 2479 | |
| 2480 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2481 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2482 | Value *value = rhs.loadValue(); |
| 2483 | storeValue(value); |
| 2484 | } |
| 2485 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2486 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2487 | { |
| 2488 | storeValue(rhs.value); |
| 2489 | |
| 2490 | return rhs; |
| 2491 | } |
| 2492 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2493 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2494 | { |
| 2495 | Value *value = rhs.loadValue(); |
| 2496 | storeValue(value); |
| 2497 | |
| 2498 | return RValue<Byte8>(value); |
| 2499 | } |
| 2500 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2501 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2502 | { |
| 2503 | Value *value = rhs.loadValue(); |
| 2504 | storeValue(value); |
| 2505 | |
| 2506 | return RValue<Byte8>(value); |
| 2507 | } |
| 2508 | |
| 2509 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2510 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2511 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2515 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2516 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2520 | // { |
| 2521 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2522 | // } |
| 2523 | |
| 2524 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2525 | // { |
| 2526 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2527 | // } |
| 2528 | |
| 2529 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2530 | // { |
| 2531 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.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::createAnd(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::createOr(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 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2546 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2550 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2551 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2552 | // } |
| 2553 | |
| 2554 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2555 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2556 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2557 | // } |
| 2558 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2559 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2560 | { |
| 2561 | return lhs = lhs + rhs; |
| 2562 | } |
| 2563 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2564 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2565 | { |
| 2566 | return lhs = lhs - rhs; |
| 2567 | } |
| 2568 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2569 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2570 | // { |
| 2571 | // return lhs = lhs * rhs; |
| 2572 | // } |
| 2573 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2574 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2575 | // { |
| 2576 | // return lhs = lhs / rhs; |
| 2577 | // } |
| 2578 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2579 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2580 | // { |
| 2581 | // return lhs = lhs % rhs; |
| 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 | |
| 2609 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2610 | // { |
| 2611 | // return val; |
| 2612 | // } |
| 2613 | |
| 2614 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2615 | // { |
| 2616 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2617 | // } |
| 2618 | |
| 2619 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2620 | { |
| 2621 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2622 | } |
| 2623 | |
| 2624 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2625 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2626 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2627 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2628 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2629 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2630 | paddusb->addArg(x.value); |
| 2631 | paddusb->addArg(y.value); |
| 2632 | ::basicBlock->appendInst(paddusb); |
| 2633 | |
| 2634 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2638 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2639 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2640 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2641 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2642 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2643 | psubusw->addArg(x.value); |
| 2644 | psubusw->addArg(y.value); |
| 2645 | ::basicBlock->appendInst(psubusw); |
| 2646 | |
| 2647 | return RValue<Byte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2651 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2652 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
| 2653 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2654 | } |
| 2655 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2656 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2657 | { |
| 2658 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| 2659 | } |
| 2660 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2661 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2662 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2663 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2664 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2668 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2669 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2670 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2671 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2675 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2676 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2677 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2678 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2679 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2680 | movmsk->addArg(x.value); |
| 2681 | ::basicBlock->appendInst(movmsk); |
| 2682 | |
| 2683 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2687 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2688 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2689 | // } |
| 2690 | |
| 2691 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2692 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2693 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | Type *Byte8::getType() |
| 2697 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2698 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2699 | } |
| 2700 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2701 | 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) |
| 2702 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2703 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2704 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2705 | |
| 2706 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2707 | } |
| 2708 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2709 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2710 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2711 | storeValue(rhs.value); |
| 2712 | } |
| 2713 | |
| 2714 | SByte8::SByte8(const SByte8 &rhs) |
| 2715 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2716 | Value *value = rhs.loadValue(); |
| 2717 | storeValue(value); |
| 2718 | } |
| 2719 | |
| 2720 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2721 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2722 | Value *value = rhs.loadValue(); |
| 2723 | storeValue(value); |
| 2724 | } |
| 2725 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2726 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2727 | { |
| 2728 | storeValue(rhs.value); |
| 2729 | |
| 2730 | return rhs; |
| 2731 | } |
| 2732 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2733 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2734 | { |
| 2735 | Value *value = rhs.loadValue(); |
| 2736 | storeValue(value); |
| 2737 | |
| 2738 | return RValue<SByte8>(value); |
| 2739 | } |
| 2740 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2741 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2742 | { |
| 2743 | Value *value = rhs.loadValue(); |
| 2744 | storeValue(value); |
| 2745 | |
| 2746 | return RValue<SByte8>(value); |
| 2747 | } |
| 2748 | |
| 2749 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2750 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2751 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2755 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2756 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2760 | // { |
| 2761 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2762 | // } |
| 2763 | |
| 2764 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2765 | // { |
| 2766 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2767 | // } |
| 2768 | |
| 2769 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2770 | // { |
| 2771 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2772 | // } |
| 2773 | |
| 2774 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2775 | { |
| 2776 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2777 | } |
| 2778 | |
| 2779 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2780 | { |
| 2781 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2782 | } |
| 2783 | |
| 2784 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2785 | { |
| 2786 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2787 | } |
| 2788 | |
| 2789 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2790 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2791 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2792 | // } |
| 2793 | |
| 2794 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2795 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2796 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2797 | // } |
| 2798 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2799 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2800 | { |
| 2801 | return lhs = lhs + rhs; |
| 2802 | } |
| 2803 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2804 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2805 | { |
| 2806 | return lhs = lhs - rhs; |
| 2807 | } |
| 2808 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2809 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2810 | // { |
| 2811 | // return lhs = lhs * rhs; |
| 2812 | // } |
| 2813 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2814 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2815 | // { |
| 2816 | // return lhs = lhs / rhs; |
| 2817 | // } |
| 2818 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2819 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2820 | // { |
| 2821 | // return lhs = lhs % rhs; |
| 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 | |
| 2849 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 2850 | // { |
| 2851 | // return val; |
| 2852 | // } |
| 2853 | |
| 2854 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 2855 | // { |
| 2856 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 2857 | // } |
| 2858 | |
| 2859 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 2860 | { |
| 2861 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 2862 | } |
| 2863 | |
| 2864 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2865 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2866 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2867 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2868 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2869 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2870 | paddsb->addArg(x.value); |
| 2871 | paddsb->addArg(y.value); |
| 2872 | ::basicBlock->appendInst(paddsb); |
| 2873 | |
| 2874 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 2878 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2879 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2880 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2881 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2882 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2883 | psubsb->addArg(x.value); |
| 2884 | psubsb->addArg(y.value); |
| 2885 | ::basicBlock->appendInst(psubsb); |
| 2886 | |
| 2887 | return RValue<SByte8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 2891 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2892 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2893 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 2897 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2898 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2899 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2900 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | RValue<Int> SignMask(RValue<SByte8> x) |
| 2904 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 2905 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2906 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2907 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2908 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2909 | movmsk->addArg(x.value); |
| 2910 | ::basicBlock->appendInst(movmsk); |
| 2911 | |
| 2912 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 2916 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2917 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 2921 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2922 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | Type *SByte8::getType() |
| 2926 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2927 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | Byte16::Byte16(RValue<Byte16> rhs) |
| 2931 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2932 | storeValue(rhs.value); |
| 2933 | } |
| 2934 | |
| 2935 | Byte16::Byte16(const Byte16 &rhs) |
| 2936 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2937 | Value *value = rhs.loadValue(); |
| 2938 | storeValue(value); |
| 2939 | } |
| 2940 | |
| 2941 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 2942 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2943 | Value *value = rhs.loadValue(); |
| 2944 | storeValue(value); |
| 2945 | } |
| 2946 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2947 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2948 | { |
| 2949 | storeValue(rhs.value); |
| 2950 | |
| 2951 | return rhs; |
| 2952 | } |
| 2953 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2954 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2955 | { |
| 2956 | Value *value = rhs.loadValue(); |
| 2957 | storeValue(value); |
| 2958 | |
| 2959 | return RValue<Byte16>(value); |
| 2960 | } |
| 2961 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2962 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2963 | { |
| 2964 | Value *value = rhs.loadValue(); |
| 2965 | storeValue(value); |
| 2966 | |
| 2967 | return RValue<Byte16>(value); |
| 2968 | } |
| 2969 | |
| 2970 | Type *Byte16::getType() |
| 2971 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2972 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | Type *SByte16::getType() |
| 2976 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2977 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2978 | } |
| 2979 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2980 | Short2::Short2(RValue<Short4> cast) |
| 2981 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2982 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | Type *Short2::getType() |
| 2986 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2987 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2988 | } |
| 2989 | |
| 2990 | UShort2::UShort2(RValue<UShort4> cast) |
| 2991 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 2992 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | Type *UShort2::getType() |
| 2996 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2997 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2998 | } |
| 2999 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3000 | Short4::Short4(RValue<Int> cast) |
| 3001 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3002 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 3003 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 3004 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3005 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3006 | |
| 3007 | storeValue(swizzle); |
| 3008 | } |
| 3009 | |
| 3010 | Short4::Short4(RValue<Int4> cast) |
| 3011 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 3012 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 3013 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 3014 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3015 | |
| 3016 | Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value; |
| 3017 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 3018 | |
| 3019 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | // Short4::Short4(RValue<Float> cast) |
| 3023 | // { |
| 3024 | // } |
| 3025 | |
| 3026 | Short4::Short4(RValue<Float4> cast) |
| 3027 | { |
| 3028 | assert(false && "UNIMPLEMENTED"); |
| 3029 | } |
| 3030 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3031 | Short4::Short4(short xyzw) |
| 3032 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3033 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3034 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | Short4::Short4(short x, short y, short z, short w) |
| 3038 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3039 | int64_t constantVector[4] = {x, y, z, w}; |
| 3040 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | Short4::Short4(RValue<Short4> rhs) |
| 3044 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3045 | storeValue(rhs.value); |
| 3046 | } |
| 3047 | |
| 3048 | Short4::Short4(const Short4 &rhs) |
| 3049 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3050 | Value *value = rhs.loadValue(); |
| 3051 | storeValue(value); |
| 3052 | } |
| 3053 | |
| 3054 | Short4::Short4(const Reference<Short4> &rhs) |
| 3055 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3056 | Value *value = rhs.loadValue(); |
| 3057 | storeValue(value); |
| 3058 | } |
| 3059 | |
| 3060 | Short4::Short4(RValue<UShort4> rhs) |
| 3061 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3062 | storeValue(rhs.value); |
| 3063 | } |
| 3064 | |
| 3065 | Short4::Short4(const UShort4 &rhs) |
| 3066 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3067 | storeValue(rhs.loadValue()); |
| 3068 | } |
| 3069 | |
| 3070 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3071 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3072 | storeValue(rhs.loadValue()); |
| 3073 | } |
| 3074 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3075 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3076 | { |
| 3077 | storeValue(rhs.value); |
| 3078 | |
| 3079 | return rhs; |
| 3080 | } |
| 3081 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3082 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3083 | { |
| 3084 | Value *value = rhs.loadValue(); |
| 3085 | storeValue(value); |
| 3086 | |
| 3087 | return RValue<Short4>(value); |
| 3088 | } |
| 3089 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3090 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3091 | { |
| 3092 | Value *value = rhs.loadValue(); |
| 3093 | storeValue(value); |
| 3094 | |
| 3095 | return RValue<Short4>(value); |
| 3096 | } |
| 3097 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3098 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3099 | { |
| 3100 | storeValue(rhs.value); |
| 3101 | |
| 3102 | return RValue<Short4>(rhs); |
| 3103 | } |
| 3104 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3105 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3106 | { |
| 3107 | Value *value = rhs.loadValue(); |
| 3108 | storeValue(value); |
| 3109 | |
| 3110 | return RValue<Short4>(value); |
| 3111 | } |
| 3112 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3113 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3114 | { |
| 3115 | Value *value = rhs.loadValue(); |
| 3116 | storeValue(value); |
| 3117 | |
| 3118 | return RValue<Short4>(value); |
| 3119 | } |
| 3120 | |
| 3121 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3122 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3123 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3127 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3128 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3132 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3133 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3137 | // { |
| 3138 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3139 | // } |
| 3140 | |
| 3141 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3142 | // { |
| 3143 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.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::createAnd(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::createOr(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::createXor(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, unsigned char rhs) |
| 3162 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3163 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3167 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3168 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3169 | } |
| 3170 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3171 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3172 | { |
| 3173 | return lhs = lhs + rhs; |
| 3174 | } |
| 3175 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3176 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3177 | { |
| 3178 | return lhs = lhs - rhs; |
| 3179 | } |
| 3180 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3181 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3182 | { |
| 3183 | return lhs = lhs * rhs; |
| 3184 | } |
| 3185 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3186 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3187 | // { |
| 3188 | // return lhs = lhs / rhs; |
| 3189 | // } |
| 3190 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3191 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3192 | // { |
| 3193 | // return lhs = lhs % rhs; |
| 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, unsigned char 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, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3217 | { |
| 3218 | return lhs = lhs >> rhs; |
| 3219 | } |
| 3220 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3221 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3222 | // { |
| 3223 | // return val; |
| 3224 | // } |
| 3225 | |
| 3226 | RValue<Short4> operator-(RValue<Short4> val) |
| 3227 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3228 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | RValue<Short4> operator~(RValue<Short4> val) |
| 3232 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3233 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3237 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3238 | RValue<Int4> int4 = RoundInt(cast); |
| 3239 | return As<Short4>(Pack(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3243 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3244 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3245 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3246 | ::basicBlock->appendInst(cmp); |
| 3247 | |
| 3248 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3249 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3250 | ::basicBlock->appendInst(select); |
| 3251 | |
| 3252 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3256 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3257 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3258 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3259 | ::basicBlock->appendInst(cmp); |
| 3260 | |
| 3261 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3262 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3263 | ::basicBlock->appendInst(select); |
| 3264 | |
| 3265 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3269 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3270 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3271 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3272 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3273 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3274 | paddsw->addArg(x.value); |
| 3275 | paddsw->addArg(y.value); |
| 3276 | ::basicBlock->appendInst(paddsw); |
| 3277 | |
| 3278 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3282 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3283 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3284 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3285 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3286 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3287 | psubsw->addArg(x.value); |
| 3288 | psubsw->addArg(y.value); |
| 3289 | ::basicBlock->appendInst(psubsw); |
| 3290 | |
| 3291 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3295 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3296 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3297 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3298 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3299 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3300 | pmulhw->addArg(x.value); |
| 3301 | pmulhw->addArg(y.value); |
| 3302 | ::basicBlock->appendInst(pmulhw); |
| 3303 | |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3304 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3308 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3309 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3310 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3311 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3312 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3313 | pmaddwd->addArg(x.value); |
| 3314 | pmaddwd->addArg(y.value); |
| 3315 | ::basicBlock->appendInst(pmaddwd); |
| 3316 | |
| 3317 | return RValue<Int2>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y) |
| 3321 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3322 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3323 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3324 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3325 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3326 | pack->addArg(x.value); |
| 3327 | pack->addArg(y.value); |
| 3328 | ::basicBlock->appendInst(pack); |
| 3329 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3330 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3331 | } |
| 3332 | |
| 3333 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3334 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3335 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3336 | return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3340 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3341 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3342 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3343 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3347 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3348 | // Real type is v8i16 |
| 3349 | int shuffle[8] = |
| 3350 | { |
| 3351 | (select >> 0) & 0x03, |
| 3352 | (select >> 2) & 0x03, |
| 3353 | (select >> 4) & 0x03, |
| 3354 | (select >> 6) & 0x03, |
| 3355 | (select >> 0) & 0x03, |
| 3356 | (select >> 2) & 0x03, |
| 3357 | (select >> 4) & 0x03, |
| 3358 | (select >> 6) & 0x03, |
| 3359 | }; |
| 3360 | |
| 3361 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3365 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3366 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3370 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3371 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3375 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3376 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3380 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3381 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | Type *Short4::getType() |
| 3385 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3386 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | UShort4::UShort4(RValue<Int4> cast) |
| 3390 | { |
| 3391 | *this = Short4(cast); |
| 3392 | } |
| 3393 | |
| 3394 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3395 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3396 | if(saturate) |
| 3397 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3398 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3399 | { |
| 3400 | Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation |
| 3401 | *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4))); |
| 3402 | } |
| 3403 | else |
| 3404 | { |
| 3405 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3406 | } |
| 3407 | } |
| 3408 | else |
| 3409 | { |
| 3410 | *this = Short4(Int4(cast)); |
| 3411 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3412 | } |
| 3413 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3414 | UShort4::UShort4(unsigned short xyzw) |
| 3415 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3416 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3417 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3421 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3422 | int64_t constantVector[4] = {x, y, z, w}; |
| 3423 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3427 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3428 | storeValue(rhs.value); |
| 3429 | } |
| 3430 | |
| 3431 | UShort4::UShort4(const UShort4 &rhs) |
| 3432 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3433 | Value *value = rhs.loadValue(); |
| 3434 | storeValue(value); |
| 3435 | } |
| 3436 | |
| 3437 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3438 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3439 | Value *value = rhs.loadValue(); |
| 3440 | storeValue(value); |
| 3441 | } |
| 3442 | |
| 3443 | UShort4::UShort4(RValue<Short4> rhs) |
| 3444 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3445 | storeValue(rhs.value); |
| 3446 | } |
| 3447 | |
| 3448 | UShort4::UShort4(const Short4 &rhs) |
| 3449 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3450 | Value *value = rhs.loadValue(); |
| 3451 | storeValue(value); |
| 3452 | } |
| 3453 | |
| 3454 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3455 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3456 | Value *value = rhs.loadValue(); |
| 3457 | storeValue(value); |
| 3458 | } |
| 3459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3460 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3461 | { |
| 3462 | storeValue(rhs.value); |
| 3463 | |
| 3464 | return rhs; |
| 3465 | } |
| 3466 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3467 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3468 | { |
| 3469 | Value *value = rhs.loadValue(); |
| 3470 | storeValue(value); |
| 3471 | |
| 3472 | return RValue<UShort4>(value); |
| 3473 | } |
| 3474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3475 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3476 | { |
| 3477 | Value *value = rhs.loadValue(); |
| 3478 | storeValue(value); |
| 3479 | |
| 3480 | return RValue<UShort4>(value); |
| 3481 | } |
| 3482 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3483 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3484 | { |
| 3485 | storeValue(rhs.value); |
| 3486 | |
| 3487 | return RValue<UShort4>(rhs); |
| 3488 | } |
| 3489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3490 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3491 | { |
| 3492 | Value *value = rhs.loadValue(); |
| 3493 | storeValue(value); |
| 3494 | |
| 3495 | return RValue<UShort4>(value); |
| 3496 | } |
| 3497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3498 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3499 | { |
| 3500 | Value *value = rhs.loadValue(); |
| 3501 | storeValue(value); |
| 3502 | |
| 3503 | return RValue<UShort4>(value); |
| 3504 | } |
| 3505 | |
| 3506 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3507 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3508 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3512 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3513 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3517 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3518 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3519 | } |
| 3520 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3521 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3522 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3523 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3527 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3528 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3532 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3533 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3534 | } |
| 3535 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3536 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3537 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3538 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3542 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3543 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3544 | } |
| 3545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3546 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3547 | { |
| 3548 | return lhs = lhs << rhs; |
| 3549 | } |
| 3550 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3551 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3552 | { |
| 3553 | return lhs = lhs >> rhs; |
| 3554 | } |
| 3555 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3556 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3557 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3558 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3562 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3563 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3564 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3565 | ::basicBlock->appendInst(cmp); |
| 3566 | |
| 3567 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3568 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3569 | ::basicBlock->appendInst(select); |
| 3570 | |
| 3571 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3575 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3576 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3577 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3578 | ::basicBlock->appendInst(cmp); |
| 3579 | |
| 3580 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3581 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3582 | ::basicBlock->appendInst(select); |
| 3583 | |
| 3584 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3588 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3589 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3590 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3591 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3592 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3593 | paddusw->addArg(x.value); |
| 3594 | paddusw->addArg(y.value); |
| 3595 | ::basicBlock->appendInst(paddusw); |
| 3596 | |
| 3597 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 3601 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3602 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3603 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3604 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3605 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3606 | psubusw->addArg(x.value); |
| 3607 | psubusw->addArg(y.value); |
| 3608 | ::basicBlock->appendInst(psubusw); |
| 3609 | |
| 3610 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3611 | } |
| 3612 | |
| 3613 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 3614 | { |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3615 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3616 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3617 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3618 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3619 | pmulhuw->addArg(x.value); |
| 3620 | pmulhuw->addArg(y.value); |
| 3621 | ::basicBlock->appendInst(pmulhuw); |
| 3622 | |
| 3623 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 3627 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3628 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3629 | } |
| 3630 | |
| 3631 | RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y) |
| 3632 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3633 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3634 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3635 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3636 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3637 | pack->addArg(x.value); |
| 3638 | pack->addArg(y.value); |
| 3639 | ::basicBlock->appendInst(pack); |
| 3640 | |
Nicolas Capens | 70dfff4 | 2016-10-27 10:20:28 -0400 | [diff] [blame] | 3641 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | Type *UShort4::getType() |
| 3645 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3646 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3647 | } |
| 3648 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3649 | Short8::Short8(short c) |
| 3650 | { |
| 3651 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3652 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3653 | } |
| 3654 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3655 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 3656 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3657 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3658 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | Short8::Short8(RValue<Short8> rhs) |
| 3662 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3663 | storeValue(rhs.value); |
| 3664 | } |
| 3665 | |
| 3666 | Short8::Short8(const Reference<Short8> &rhs) |
| 3667 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3668 | Value *value = rhs.loadValue(); |
| 3669 | storeValue(value); |
| 3670 | } |
| 3671 | |
| 3672 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 3673 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3674 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3675 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3676 | |
| 3677 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3681 | { |
| 3682 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3683 | } |
| 3684 | |
| 3685 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 3686 | { |
| 3687 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3688 | } |
| 3689 | |
| 3690 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 3691 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3692 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 3696 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3697 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 3701 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3702 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3703 | } |
| 3704 | |
| 3705 | RValue<Int4> Abs(RValue<Int4> x) |
| 3706 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 3707 | auto negative = x >> 31; |
| 3708 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 3712 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3713 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | Type *Short8::getType() |
| 3717 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3718 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3719 | } |
| 3720 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 3721 | UShort8::UShort8(unsigned short c) |
| 3722 | { |
| 3723 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 3724 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 3725 | } |
| 3726 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3727 | 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) |
| 3728 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3729 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 3730 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | UShort8::UShort8(RValue<UShort8> rhs) |
| 3734 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3735 | storeValue(rhs.value); |
| 3736 | } |
| 3737 | |
| 3738 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 3739 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3740 | Value *value = rhs.loadValue(); |
| 3741 | storeValue(value); |
| 3742 | } |
| 3743 | |
| 3744 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 3745 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3746 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 3747 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 3748 | |
| 3749 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3750 | } |
| 3751 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3752 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3753 | { |
| 3754 | storeValue(rhs.value); |
| 3755 | |
| 3756 | return rhs; |
| 3757 | } |
| 3758 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3759 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3760 | { |
| 3761 | Value *value = rhs.loadValue(); |
| 3762 | storeValue(value); |
| 3763 | |
| 3764 | return RValue<UShort8>(value); |
| 3765 | } |
| 3766 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3767 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3768 | { |
| 3769 | Value *value = rhs.loadValue(); |
| 3770 | storeValue(value); |
| 3771 | |
| 3772 | return RValue<UShort8>(value); |
| 3773 | } |
| 3774 | |
| 3775 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3776 | { |
| 3777 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 3778 | } |
| 3779 | |
| 3780 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 3781 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3782 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 3786 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 3787 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3791 | { |
| 3792 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3793 | } |
| 3794 | |
| 3795 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 3796 | { |
| 3797 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3798 | } |
| 3799 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3800 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3801 | { |
| 3802 | return lhs = lhs + rhs; |
| 3803 | } |
| 3804 | |
| 3805 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 3806 | { |
| 3807 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 3808 | } |
| 3809 | |
| 3810 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 3811 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3812 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 3816 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3817 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 3821 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 3822 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 3823 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3824 | // } |
| 3825 | |
| 3826 | Type *UShort8::getType() |
| 3827 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3828 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3829 | } |
| 3830 | |
| 3831 | Int::Int(Argument<Int> argument) |
| 3832 | { |
| 3833 | storeValue(argument.value); |
| 3834 | } |
| 3835 | |
| 3836 | Int::Int(RValue<Byte> cast) |
| 3837 | { |
| 3838 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3839 | |
| 3840 | storeValue(integer); |
| 3841 | } |
| 3842 | |
| 3843 | Int::Int(RValue<SByte> cast) |
| 3844 | { |
| 3845 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3846 | |
| 3847 | storeValue(integer); |
| 3848 | } |
| 3849 | |
| 3850 | Int::Int(RValue<Short> cast) |
| 3851 | { |
| 3852 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 3853 | |
| 3854 | storeValue(integer); |
| 3855 | } |
| 3856 | |
| 3857 | Int::Int(RValue<UShort> cast) |
| 3858 | { |
| 3859 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 3860 | |
| 3861 | storeValue(integer); |
| 3862 | } |
| 3863 | |
| 3864 | Int::Int(RValue<Int2> cast) |
| 3865 | { |
| 3866 | *this = Extract(cast, 0); |
| 3867 | } |
| 3868 | |
| 3869 | Int::Int(RValue<Long> cast) |
| 3870 | { |
| 3871 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 3872 | |
| 3873 | storeValue(integer); |
| 3874 | } |
| 3875 | |
| 3876 | Int::Int(RValue<Float> cast) |
| 3877 | { |
| 3878 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 3879 | |
| 3880 | storeValue(integer); |
| 3881 | } |
| 3882 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3883 | Int::Int(int x) |
| 3884 | { |
| 3885 | storeValue(Nucleus::createConstantInt(x)); |
| 3886 | } |
| 3887 | |
| 3888 | Int::Int(RValue<Int> rhs) |
| 3889 | { |
| 3890 | storeValue(rhs.value); |
| 3891 | } |
| 3892 | |
| 3893 | Int::Int(RValue<UInt> rhs) |
| 3894 | { |
| 3895 | storeValue(rhs.value); |
| 3896 | } |
| 3897 | |
| 3898 | Int::Int(const Int &rhs) |
| 3899 | { |
| 3900 | Value *value = rhs.loadValue(); |
| 3901 | storeValue(value); |
| 3902 | } |
| 3903 | |
| 3904 | Int::Int(const Reference<Int> &rhs) |
| 3905 | { |
| 3906 | Value *value = rhs.loadValue(); |
| 3907 | storeValue(value); |
| 3908 | } |
| 3909 | |
| 3910 | Int::Int(const UInt &rhs) |
| 3911 | { |
| 3912 | Value *value = rhs.loadValue(); |
| 3913 | storeValue(value); |
| 3914 | } |
| 3915 | |
| 3916 | Int::Int(const Reference<UInt> &rhs) |
| 3917 | { |
| 3918 | Value *value = rhs.loadValue(); |
| 3919 | storeValue(value); |
| 3920 | } |
| 3921 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3922 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3923 | { |
| 3924 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 3925 | } |
| 3926 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3927 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3928 | { |
| 3929 | storeValue(rhs.value); |
| 3930 | |
| 3931 | return rhs; |
| 3932 | } |
| 3933 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3934 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3935 | { |
| 3936 | storeValue(rhs.value); |
| 3937 | |
| 3938 | return RValue<Int>(rhs); |
| 3939 | } |
| 3940 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3941 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3942 | { |
| 3943 | Value *value = rhs.loadValue(); |
| 3944 | storeValue(value); |
| 3945 | |
| 3946 | return RValue<Int>(value); |
| 3947 | } |
| 3948 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3949 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3950 | { |
| 3951 | Value *value = rhs.loadValue(); |
| 3952 | storeValue(value); |
| 3953 | |
| 3954 | return RValue<Int>(value); |
| 3955 | } |
| 3956 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3957 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3958 | { |
| 3959 | Value *value = rhs.loadValue(); |
| 3960 | storeValue(value); |
| 3961 | |
| 3962 | return RValue<Int>(value); |
| 3963 | } |
| 3964 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3965 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3966 | { |
| 3967 | Value *value = rhs.loadValue(); |
| 3968 | storeValue(value); |
| 3969 | |
| 3970 | return RValue<Int>(value); |
| 3971 | } |
| 3972 | |
| 3973 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 3974 | { |
| 3975 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 3976 | } |
| 3977 | |
| 3978 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 3979 | { |
| 3980 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 3981 | } |
| 3982 | |
| 3983 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 3984 | { |
| 3985 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 3986 | } |
| 3987 | |
| 3988 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 3989 | { |
| 3990 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3991 | } |
| 3992 | |
| 3993 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 3994 | { |
| 3995 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3996 | } |
| 3997 | |
| 3998 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 3999 | { |
| 4000 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4001 | } |
| 4002 | |
| 4003 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 4004 | { |
| 4005 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4006 | } |
| 4007 | |
| 4008 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 4009 | { |
| 4010 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4011 | } |
| 4012 | |
| 4013 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 4014 | { |
| 4015 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4016 | } |
| 4017 | |
| 4018 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 4019 | { |
| 4020 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4021 | } |
| 4022 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4023 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4024 | { |
| 4025 | return lhs = lhs + rhs; |
| 4026 | } |
| 4027 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4028 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4029 | { |
| 4030 | return lhs = lhs - rhs; |
| 4031 | } |
| 4032 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4033 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4034 | { |
| 4035 | return lhs = lhs * rhs; |
| 4036 | } |
| 4037 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4038 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4039 | { |
| 4040 | return lhs = lhs / rhs; |
| 4041 | } |
| 4042 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4043 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4044 | { |
| 4045 | return lhs = lhs % rhs; |
| 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 | |
| 4073 | RValue<Int> operator+(RValue<Int> val) |
| 4074 | { |
| 4075 | return val; |
| 4076 | } |
| 4077 | |
| 4078 | RValue<Int> operator-(RValue<Int> val) |
| 4079 | { |
| 4080 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4081 | } |
| 4082 | |
| 4083 | RValue<Int> operator~(RValue<Int> val) |
| 4084 | { |
| 4085 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4086 | } |
| 4087 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4088 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4089 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4090 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4091 | val += 1; |
| 4092 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4093 | } |
| 4094 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4095 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4096 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4097 | val += 1; |
| 4098 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4099 | } |
| 4100 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4101 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4102 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4103 | RValue<Int> res = val; |
| 4104 | val -= 1; |
| 4105 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4106 | } |
| 4107 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4108 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4109 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4110 | val -= 1; |
| 4111 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4112 | } |
| 4113 | |
| 4114 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4115 | { |
| 4116 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4117 | } |
| 4118 | |
| 4119 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4120 | { |
| 4121 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4122 | } |
| 4123 | |
| 4124 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4125 | { |
| 4126 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4127 | } |
| 4128 | |
| 4129 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4130 | { |
| 4131 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4132 | } |
| 4133 | |
| 4134 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4135 | { |
| 4136 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4137 | } |
| 4138 | |
| 4139 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4140 | { |
| 4141 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4142 | } |
| 4143 | |
| 4144 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4145 | { |
| 4146 | return IfThenElse(x > y, x, y); |
| 4147 | } |
| 4148 | |
| 4149 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4150 | { |
| 4151 | return IfThenElse(x < y, x, y); |
| 4152 | } |
| 4153 | |
| 4154 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4155 | { |
| 4156 | return Min(Max(x, min), max); |
| 4157 | } |
| 4158 | |
| 4159 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4160 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4161 | if(emulateIntrinsics) |
| 4162 | { |
| 4163 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 4164 | return Int((cast + Float(0x00C00000)) - Float(0x00C00000)); |
| 4165 | } |
| 4166 | else |
| 4167 | { |
| 4168 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 4169 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4170 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4171 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4172 | nearbyint->addArg(cast.value); |
| 4173 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4174 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4175 | return RValue<Int>(V(result)); |
| 4176 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | Type *Int::getType() |
| 4180 | { |
| 4181 | return T(Ice::IceType_i32); |
| 4182 | } |
| 4183 | |
| 4184 | Long::Long(RValue<Int> cast) |
| 4185 | { |
| 4186 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4187 | |
| 4188 | storeValue(integer); |
| 4189 | } |
| 4190 | |
| 4191 | Long::Long(RValue<UInt> cast) |
| 4192 | { |
| 4193 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4194 | |
| 4195 | storeValue(integer); |
| 4196 | } |
| 4197 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4198 | Long::Long(RValue<Long> rhs) |
| 4199 | { |
| 4200 | storeValue(rhs.value); |
| 4201 | } |
| 4202 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4203 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4204 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4205 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4206 | } |
| 4207 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4208 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4209 | { |
| 4210 | storeValue(rhs.value); |
| 4211 | |
| 4212 | return rhs; |
| 4213 | } |
| 4214 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4215 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4216 | { |
| 4217 | Value *value = rhs.loadValue(); |
| 4218 | storeValue(value); |
| 4219 | |
| 4220 | return RValue<Long>(value); |
| 4221 | } |
| 4222 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4223 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4224 | { |
| 4225 | Value *value = rhs.loadValue(); |
| 4226 | storeValue(value); |
| 4227 | |
| 4228 | return RValue<Long>(value); |
| 4229 | } |
| 4230 | |
| 4231 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4232 | { |
| 4233 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4234 | } |
| 4235 | |
| 4236 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4237 | { |
| 4238 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4239 | } |
| 4240 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4241 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4242 | { |
| 4243 | return lhs = lhs + rhs; |
| 4244 | } |
| 4245 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4246 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4247 | { |
| 4248 | return lhs = lhs - rhs; |
| 4249 | } |
| 4250 | |
| 4251 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4252 | { |
| 4253 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4254 | } |
| 4255 | |
| 4256 | Type *Long::getType() |
| 4257 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4258 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4259 | } |
| 4260 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4261 | UInt::UInt(Argument<UInt> argument) |
| 4262 | { |
| 4263 | storeValue(argument.value); |
| 4264 | } |
| 4265 | |
| 4266 | UInt::UInt(RValue<UShort> cast) |
| 4267 | { |
| 4268 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4269 | |
| 4270 | storeValue(integer); |
| 4271 | } |
| 4272 | |
| 4273 | UInt::UInt(RValue<Long> cast) |
| 4274 | { |
| 4275 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4276 | |
| 4277 | storeValue(integer); |
| 4278 | } |
| 4279 | |
| 4280 | UInt::UInt(RValue<Float> cast) |
| 4281 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4282 | // Smallest positive value representable in UInt, but not in Int |
| 4283 | const unsigned int ustart = 0x80000000u; |
| 4284 | const float ustartf = float(ustart); |
| 4285 | |
| 4286 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4287 | storeValue((~(As<Int>(cast) >> 31) & |
| 4288 | // Check if the value can be represented as an Int |
| 4289 | IfThenElse(cast >= ustartf, |
| 4290 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4291 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4292 | // Otherwise, just convert normally |
| 4293 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4294 | } |
| 4295 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4296 | UInt::UInt(int x) |
| 4297 | { |
| 4298 | storeValue(Nucleus::createConstantInt(x)); |
| 4299 | } |
| 4300 | |
| 4301 | UInt::UInt(unsigned int x) |
| 4302 | { |
| 4303 | storeValue(Nucleus::createConstantInt(x)); |
| 4304 | } |
| 4305 | |
| 4306 | UInt::UInt(RValue<UInt> rhs) |
| 4307 | { |
| 4308 | storeValue(rhs.value); |
| 4309 | } |
| 4310 | |
| 4311 | UInt::UInt(RValue<Int> rhs) |
| 4312 | { |
| 4313 | storeValue(rhs.value); |
| 4314 | } |
| 4315 | |
| 4316 | UInt::UInt(const UInt &rhs) |
| 4317 | { |
| 4318 | Value *value = rhs.loadValue(); |
| 4319 | storeValue(value); |
| 4320 | } |
| 4321 | |
| 4322 | UInt::UInt(const Reference<UInt> &rhs) |
| 4323 | { |
| 4324 | Value *value = rhs.loadValue(); |
| 4325 | storeValue(value); |
| 4326 | } |
| 4327 | |
| 4328 | UInt::UInt(const Int &rhs) |
| 4329 | { |
| 4330 | Value *value = rhs.loadValue(); |
| 4331 | storeValue(value); |
| 4332 | } |
| 4333 | |
| 4334 | UInt::UInt(const Reference<Int> &rhs) |
| 4335 | { |
| 4336 | Value *value = rhs.loadValue(); |
| 4337 | storeValue(value); |
| 4338 | } |
| 4339 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4340 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4341 | { |
| 4342 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4343 | } |
| 4344 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4345 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4346 | { |
| 4347 | storeValue(rhs.value); |
| 4348 | |
| 4349 | return rhs; |
| 4350 | } |
| 4351 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4352 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4353 | { |
| 4354 | storeValue(rhs.value); |
| 4355 | |
| 4356 | return RValue<UInt>(rhs); |
| 4357 | } |
| 4358 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4359 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4360 | { |
| 4361 | Value *value = rhs.loadValue(); |
| 4362 | storeValue(value); |
| 4363 | |
| 4364 | return RValue<UInt>(value); |
| 4365 | } |
| 4366 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4367 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4368 | { |
| 4369 | Value *value = rhs.loadValue(); |
| 4370 | storeValue(value); |
| 4371 | |
| 4372 | return RValue<UInt>(value); |
| 4373 | } |
| 4374 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4375 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4376 | { |
| 4377 | Value *value = rhs.loadValue(); |
| 4378 | storeValue(value); |
| 4379 | |
| 4380 | return RValue<UInt>(value); |
| 4381 | } |
| 4382 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4383 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4384 | { |
| 4385 | Value *value = rhs.loadValue(); |
| 4386 | storeValue(value); |
| 4387 | |
| 4388 | return RValue<UInt>(value); |
| 4389 | } |
| 4390 | |
| 4391 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4392 | { |
| 4393 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4394 | } |
| 4395 | |
| 4396 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4397 | { |
| 4398 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4399 | } |
| 4400 | |
| 4401 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4402 | { |
| 4403 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4404 | } |
| 4405 | |
| 4406 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4407 | { |
| 4408 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4409 | } |
| 4410 | |
| 4411 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4412 | { |
| 4413 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 4414 | } |
| 4415 | |
| 4416 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4417 | { |
| 4418 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4419 | } |
| 4420 | |
| 4421 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4422 | { |
| 4423 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4424 | } |
| 4425 | |
| 4426 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4427 | { |
| 4428 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4429 | } |
| 4430 | |
| 4431 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4432 | { |
| 4433 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4434 | } |
| 4435 | |
| 4436 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4437 | { |
| 4438 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 4439 | } |
| 4440 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4441 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4442 | { |
| 4443 | return lhs = lhs + rhs; |
| 4444 | } |
| 4445 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4446 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4447 | { |
| 4448 | return lhs = lhs - rhs; |
| 4449 | } |
| 4450 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4451 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4452 | { |
| 4453 | return lhs = lhs * rhs; |
| 4454 | } |
| 4455 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4456 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4457 | { |
| 4458 | return lhs = lhs / rhs; |
| 4459 | } |
| 4460 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4461 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4462 | { |
| 4463 | return lhs = lhs % rhs; |
| 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 | |
| 4491 | RValue<UInt> operator+(RValue<UInt> val) |
| 4492 | { |
| 4493 | return val; |
| 4494 | } |
| 4495 | |
| 4496 | RValue<UInt> operator-(RValue<UInt> val) |
| 4497 | { |
| 4498 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 4499 | } |
| 4500 | |
| 4501 | RValue<UInt> operator~(RValue<UInt> val) |
| 4502 | { |
| 4503 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 4504 | } |
| 4505 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4506 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4507 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4508 | RValue<UInt> res = val; |
| 4509 | val += 1; |
| 4510 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4511 | } |
| 4512 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4513 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4514 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4515 | val += 1; |
| 4516 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4517 | } |
| 4518 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4519 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4520 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4521 | RValue<UInt> res = val; |
| 4522 | val -= 1; |
| 4523 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4524 | } |
| 4525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4526 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4527 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4528 | val -= 1; |
| 4529 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 4533 | { |
| 4534 | return IfThenElse(x > y, x, y); |
| 4535 | } |
| 4536 | |
| 4537 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 4538 | { |
| 4539 | return IfThenElse(x < y, x, y); |
| 4540 | } |
| 4541 | |
| 4542 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 4543 | { |
| 4544 | return Min(Max(x, min), max); |
| 4545 | } |
| 4546 | |
| 4547 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4548 | { |
| 4549 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 4550 | } |
| 4551 | |
| 4552 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4553 | { |
| 4554 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 4555 | } |
| 4556 | |
| 4557 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4558 | { |
| 4559 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 4560 | } |
| 4561 | |
| 4562 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4563 | { |
| 4564 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 4565 | } |
| 4566 | |
| 4567 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4568 | { |
| 4569 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4570 | } |
| 4571 | |
| 4572 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4573 | { |
| 4574 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4575 | } |
| 4576 | |
| 4577 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 4578 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4579 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4580 | // } |
| 4581 | |
| 4582 | Type *UInt::getType() |
| 4583 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4584 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | // Int2::Int2(RValue<Int> cast) |
| 4588 | // { |
| 4589 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 4590 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 4591 | // |
| 4592 | // Constant *shuffle[2]; |
| 4593 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 4594 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 4595 | // |
| 4596 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 4597 | // |
| 4598 | // storeValue(replicate); |
| 4599 | // } |
| 4600 | |
| 4601 | Int2::Int2(RValue<Int4> cast) |
| 4602 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 4603 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4604 | } |
| 4605 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4606 | Int2::Int2(int x, int y) |
| 4607 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4608 | int64_t constantVector[2] = {x, y}; |
| 4609 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | Int2::Int2(RValue<Int2> rhs) |
| 4613 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4614 | storeValue(rhs.value); |
| 4615 | } |
| 4616 | |
| 4617 | Int2::Int2(const Int2 &rhs) |
| 4618 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4619 | Value *value = rhs.loadValue(); |
| 4620 | storeValue(value); |
| 4621 | } |
| 4622 | |
| 4623 | Int2::Int2(const Reference<Int2> &rhs) |
| 4624 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4625 | Value *value = rhs.loadValue(); |
| 4626 | storeValue(value); |
| 4627 | } |
| 4628 | |
| 4629 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 4630 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4631 | int shuffle[4] = {0, 4, 1, 5}; |
| 4632 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 4633 | |
| 4634 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4635 | } |
| 4636 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4637 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4638 | { |
| 4639 | storeValue(rhs.value); |
| 4640 | |
| 4641 | return rhs; |
| 4642 | } |
| 4643 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4644 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4645 | { |
| 4646 | Value *value = rhs.loadValue(); |
| 4647 | storeValue(value); |
| 4648 | |
| 4649 | return RValue<Int2>(value); |
| 4650 | } |
| 4651 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4652 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4653 | { |
| 4654 | Value *value = rhs.loadValue(); |
| 4655 | storeValue(value); |
| 4656 | |
| 4657 | return RValue<Int2>(value); |
| 4658 | } |
| 4659 | |
| 4660 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4661 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4662 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4666 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4667 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4671 | // { |
| 4672 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4673 | // } |
| 4674 | |
| 4675 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4676 | // { |
| 4677 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4678 | // } |
| 4679 | |
| 4680 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 4681 | // { |
| 4682 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.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::createAnd(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::createOr(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 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4697 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 4701 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4702 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4703 | } |
| 4704 | |
| 4705 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 4706 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4707 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4708 | } |
| 4709 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4710 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4711 | { |
| 4712 | return lhs = lhs + rhs; |
| 4713 | } |
| 4714 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4715 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4716 | { |
| 4717 | return lhs = lhs - rhs; |
| 4718 | } |
| 4719 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4720 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4721 | // { |
| 4722 | // return lhs = lhs * rhs; |
| 4723 | // } |
| 4724 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4725 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4726 | // { |
| 4727 | // return lhs = lhs / rhs; |
| 4728 | // } |
| 4729 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4730 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4731 | // { |
| 4732 | // return lhs = lhs % rhs; |
| 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, unsigned char 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, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4756 | { |
| 4757 | return lhs = lhs >> rhs; |
| 4758 | } |
| 4759 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4760 | // RValue<Int2> operator+(RValue<Int2> val) |
| 4761 | // { |
| 4762 | // return val; |
| 4763 | // } |
| 4764 | |
| 4765 | // RValue<Int2> operator-(RValue<Int2> val) |
| 4766 | // { |
| 4767 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 4768 | // } |
| 4769 | |
| 4770 | RValue<Int2> operator~(RValue<Int2> val) |
| 4771 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 4772 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4773 | } |
| 4774 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4775 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4776 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4777 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 4778 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4779 | } |
| 4780 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 4781 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4782 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 4783 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4784 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 4785 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 4789 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4790 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 4794 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 4795 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | Type *Int2::getType() |
| 4799 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4800 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4801 | } |
| 4802 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4803 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 4804 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4805 | int64_t constantVector[2] = {x, y}; |
| 4806 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | UInt2::UInt2(RValue<UInt2> rhs) |
| 4810 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4811 | storeValue(rhs.value); |
| 4812 | } |
| 4813 | |
| 4814 | UInt2::UInt2(const UInt2 &rhs) |
| 4815 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4816 | Value *value = rhs.loadValue(); |
| 4817 | storeValue(value); |
| 4818 | } |
| 4819 | |
| 4820 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 4821 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4822 | Value *value = rhs.loadValue(); |
| 4823 | storeValue(value); |
| 4824 | } |
| 4825 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4826 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4827 | { |
| 4828 | storeValue(rhs.value); |
| 4829 | |
| 4830 | return rhs; |
| 4831 | } |
| 4832 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4833 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4834 | { |
| 4835 | Value *value = rhs.loadValue(); |
| 4836 | storeValue(value); |
| 4837 | |
| 4838 | return RValue<UInt2>(value); |
| 4839 | } |
| 4840 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4841 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4842 | { |
| 4843 | Value *value = rhs.loadValue(); |
| 4844 | storeValue(value); |
| 4845 | |
| 4846 | return RValue<UInt2>(value); |
| 4847 | } |
| 4848 | |
| 4849 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4850 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4851 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4855 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4856 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4860 | // { |
| 4861 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4862 | // } |
| 4863 | |
| 4864 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4865 | // { |
| 4866 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 4867 | // } |
| 4868 | |
| 4869 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 4870 | // { |
| 4871 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.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::createAnd(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::createOr(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 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 4886 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 4890 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4891 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 4895 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 4896 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4897 | } |
| 4898 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4899 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4900 | { |
| 4901 | return lhs = lhs + rhs; |
| 4902 | } |
| 4903 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4904 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4905 | { |
| 4906 | return lhs = lhs - rhs; |
| 4907 | } |
| 4908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4909 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4910 | // { |
| 4911 | // return lhs = lhs * rhs; |
| 4912 | // } |
| 4913 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4914 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4915 | // { |
| 4916 | // return lhs = lhs / rhs; |
| 4917 | // } |
| 4918 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4919 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4920 | // { |
| 4921 | // return lhs = lhs % rhs; |
| 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, unsigned char 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, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4945 | { |
| 4946 | return lhs = lhs >> rhs; |
| 4947 | } |
| 4948 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4949 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 4950 | // { |
| 4951 | // return val; |
| 4952 | // } |
| 4953 | |
| 4954 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 4955 | // { |
| 4956 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 4957 | // } |
| 4958 | |
| 4959 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 4960 | { |
| 4961 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 4962 | } |
| 4963 | |
| 4964 | Type *UInt2::getType() |
| 4965 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4966 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4967 | } |
| 4968 | |
| 4969 | Int4::Int4(RValue<Byte4> cast) |
| 4970 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4971 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4972 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4973 | |
| 4974 | Value *e; |
| 4975 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 4976 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4977 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 4978 | |
| 4979 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 4980 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4981 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 4982 | |
| 4983 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 4984 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | Int4::Int4(RValue<SByte4> cast) |
| 4988 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 4989 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 4990 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 4991 | |
| 4992 | Value *e; |
| 4993 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 4994 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 4995 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 4996 | |
| 4997 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 4998 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 4999 | e = Nucleus::createShuffleVector(d, d, swizzle2); |
| 5000 | |
| 5001 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5002 | Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5003 | storeValue(g); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5004 | } |
| 5005 | |
| 5006 | Int4::Int4(RValue<Float4> cast) |
| 5007 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5008 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 5009 | |
| 5010 | storeValue(xyzw); |
| 5011 | } |
| 5012 | |
| 5013 | Int4::Int4(RValue<Short4> cast) |
| 5014 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5015 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5016 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
| 5017 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5018 | Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16))); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5019 | storeValue(e); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | Int4::Int4(RValue<UShort4> cast) |
| 5023 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5024 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5025 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5026 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5027 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5028 | } |
| 5029 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5030 | Int4::Int4(int xyzw) |
| 5031 | { |
| 5032 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5033 | } |
| 5034 | |
| 5035 | Int4::Int4(int x, int yzw) |
| 5036 | { |
| 5037 | constant(x, yzw, yzw, yzw); |
| 5038 | } |
| 5039 | |
| 5040 | Int4::Int4(int x, int y, int zw) |
| 5041 | { |
| 5042 | constant(x, y, zw, zw); |
| 5043 | } |
| 5044 | |
| 5045 | Int4::Int4(int x, int y, int z, int w) |
| 5046 | { |
| 5047 | constant(x, y, z, w); |
| 5048 | } |
| 5049 | |
| 5050 | void Int4::constant(int x, int y, int z, int w) |
| 5051 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5052 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5053 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | Int4::Int4(RValue<Int4> rhs) |
| 5057 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5058 | storeValue(rhs.value); |
| 5059 | } |
| 5060 | |
| 5061 | Int4::Int4(const Int4 &rhs) |
| 5062 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5063 | Value *value = rhs.loadValue(); |
| 5064 | storeValue(value); |
| 5065 | } |
| 5066 | |
| 5067 | Int4::Int4(const Reference<Int4> &rhs) |
| 5068 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5069 | Value *value = rhs.loadValue(); |
| 5070 | storeValue(value); |
| 5071 | } |
| 5072 | |
| 5073 | Int4::Int4(RValue<UInt4> rhs) |
| 5074 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5075 | storeValue(rhs.value); |
| 5076 | } |
| 5077 | |
| 5078 | Int4::Int4(const UInt4 &rhs) |
| 5079 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5080 | Value *value = rhs.loadValue(); |
| 5081 | storeValue(value); |
| 5082 | } |
| 5083 | |
| 5084 | Int4::Int4(const Reference<UInt4> &rhs) |
| 5085 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5086 | Value *value = rhs.loadValue(); |
| 5087 | storeValue(value); |
| 5088 | } |
| 5089 | |
| 5090 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) |
| 5091 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5092 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5093 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5094 | |
| 5095 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | Int4::Int4(RValue<Int> rhs) |
| 5099 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5100 | Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5101 | |
| 5102 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5103 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5104 | |
| 5105 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | Int4::Int4(const Int &rhs) |
| 5109 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5110 | *this = RValue<Int>(rhs.loadValue()); |
| 5111 | } |
| 5112 | |
| 5113 | Int4::Int4(const Reference<Int> &rhs) |
| 5114 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5115 | *this = RValue<Int>(rhs.loadValue()); |
| 5116 | } |
| 5117 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5118 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5119 | { |
| 5120 | storeValue(rhs.value); |
| 5121 | |
| 5122 | return rhs; |
| 5123 | } |
| 5124 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5125 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5126 | { |
| 5127 | Value *value = rhs.loadValue(); |
| 5128 | storeValue(value); |
| 5129 | |
| 5130 | return RValue<Int4>(value); |
| 5131 | } |
| 5132 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5133 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5134 | { |
| 5135 | Value *value = rhs.loadValue(); |
| 5136 | storeValue(value); |
| 5137 | |
| 5138 | return RValue<Int4>(value); |
| 5139 | } |
| 5140 | |
| 5141 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5142 | { |
| 5143 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5144 | } |
| 5145 | |
| 5146 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5147 | { |
| 5148 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5149 | } |
| 5150 | |
| 5151 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5152 | { |
| 5153 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5154 | } |
| 5155 | |
| 5156 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5157 | { |
| 5158 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5159 | } |
| 5160 | |
| 5161 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5162 | { |
| 5163 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5164 | } |
| 5165 | |
| 5166 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5167 | { |
| 5168 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5169 | } |
| 5170 | |
| 5171 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5172 | { |
| 5173 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5174 | } |
| 5175 | |
| 5176 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5177 | { |
| 5178 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5179 | } |
| 5180 | |
| 5181 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5182 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5183 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5187 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5188 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5192 | { |
| 5193 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5194 | } |
| 5195 | |
| 5196 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5197 | { |
| 5198 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5199 | } |
| 5200 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5201 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5202 | { |
| 5203 | return lhs = lhs + rhs; |
| 5204 | } |
| 5205 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5206 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5207 | { |
| 5208 | return lhs = lhs - rhs; |
| 5209 | } |
| 5210 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5211 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5212 | { |
| 5213 | return lhs = lhs * rhs; |
| 5214 | } |
| 5215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5216 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5217 | // { |
| 5218 | // return lhs = lhs / rhs; |
| 5219 | // } |
| 5220 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5221 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5222 | // { |
| 5223 | // return lhs = lhs % rhs; |
| 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, unsigned char 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, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5247 | { |
| 5248 | return lhs = lhs >> rhs; |
| 5249 | } |
| 5250 | |
| 5251 | RValue<Int4> operator+(RValue<Int4> val) |
| 5252 | { |
| 5253 | return val; |
| 5254 | } |
| 5255 | |
| 5256 | RValue<Int4> operator-(RValue<Int4> val) |
| 5257 | { |
| 5258 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5259 | } |
| 5260 | |
| 5261 | RValue<Int4> operator~(RValue<Int4> val) |
| 5262 | { |
| 5263 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5264 | } |
| 5265 | |
| 5266 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5267 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5268 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5272 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5273 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5277 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5278 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5279 | } |
| 5280 | |
| 5281 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5282 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5283 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5287 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5288 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5292 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5293 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5297 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5298 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5299 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5300 | ::basicBlock->appendInst(cmp); |
| 5301 | |
| 5302 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5303 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5304 | ::basicBlock->appendInst(select); |
| 5305 | |
| 5306 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5310 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5311 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5312 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5313 | ::basicBlock->appendInst(cmp); |
| 5314 | |
| 5315 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5316 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5317 | ::basicBlock->appendInst(select); |
| 5318 | |
| 5319 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5323 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5324 | if(emulateIntrinsics) |
| 5325 | { |
| 5326 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 5327 | return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000)); |
| 5328 | } |
| 5329 | else |
| 5330 | { |
| 5331 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5332 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5333 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5334 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5335 | nearbyint->addArg(cast.value); |
| 5336 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5337 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 5338 | return RValue<Int4>(V(result)); |
| 5339 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5340 | } |
| 5341 | |
| 5342 | RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y) |
| 5343 | { |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5344 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5345 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5346 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5347 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5348 | pack->addArg(x.value); |
| 5349 | pack->addArg(y.value); |
| 5350 | ::basicBlock->appendInst(pack); |
| 5351 | |
| 5352 | return RValue<Short8>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 5356 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5357 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 5361 | { |
| 5362 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 5363 | } |
| 5364 | |
| 5365 | RValue<Int> SignMask(RValue<Int4> x) |
| 5366 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 5367 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 5368 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5369 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5370 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5371 | movmsk->addArg(x.value); |
| 5372 | ::basicBlock->appendInst(movmsk); |
| 5373 | |
| 5374 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 5378 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 5379 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5380 | } |
| 5381 | |
| 5382 | Type *Int4::getType() |
| 5383 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 5384 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | UInt4::UInt4(RValue<Float4> cast) |
| 5388 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5389 | // Smallest positive value representable in UInt, but not in Int |
| 5390 | const unsigned int ustart = 0x80000000u; |
| 5391 | const float ustartf = float(ustart); |
| 5392 | |
| 5393 | // Check if the value can be represented as an Int |
| 5394 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 5395 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 5396 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 5397 | // Otherwise, just convert normally |
| 5398 | (~uiValue & Int4(cast)); |
| 5399 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 5400 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5401 | } |
| 5402 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5403 | UInt4::UInt4(int xyzw) |
| 5404 | { |
| 5405 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5406 | } |
| 5407 | |
| 5408 | UInt4::UInt4(int x, int yzw) |
| 5409 | { |
| 5410 | constant(x, yzw, yzw, yzw); |
| 5411 | } |
| 5412 | |
| 5413 | UInt4::UInt4(int x, int y, int zw) |
| 5414 | { |
| 5415 | constant(x, y, zw, zw); |
| 5416 | } |
| 5417 | |
| 5418 | UInt4::UInt4(int x, int y, int z, int w) |
| 5419 | { |
| 5420 | constant(x, y, z, w); |
| 5421 | } |
| 5422 | |
| 5423 | void UInt4::constant(int x, int y, int z, int w) |
| 5424 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5425 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5426 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | UInt4::UInt4(RValue<UInt4> rhs) |
| 5430 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5431 | storeValue(rhs.value); |
| 5432 | } |
| 5433 | |
| 5434 | UInt4::UInt4(const UInt4 &rhs) |
| 5435 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5436 | Value *value = rhs.loadValue(); |
| 5437 | storeValue(value); |
| 5438 | } |
| 5439 | |
| 5440 | UInt4::UInt4(const Reference<UInt4> &rhs) |
| 5441 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5442 | Value *value = rhs.loadValue(); |
| 5443 | storeValue(value); |
| 5444 | } |
| 5445 | |
| 5446 | UInt4::UInt4(RValue<Int4> rhs) |
| 5447 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5448 | storeValue(rhs.value); |
| 5449 | } |
| 5450 | |
| 5451 | UInt4::UInt4(const Int4 &rhs) |
| 5452 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5453 | Value *value = rhs.loadValue(); |
| 5454 | storeValue(value); |
| 5455 | } |
| 5456 | |
| 5457 | UInt4::UInt4(const Reference<Int4> &rhs) |
| 5458 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5459 | Value *value = rhs.loadValue(); |
| 5460 | storeValue(value); |
| 5461 | } |
| 5462 | |
| 5463 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) |
| 5464 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5465 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5466 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5467 | |
| 5468 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5469 | } |
| 5470 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5471 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5472 | { |
| 5473 | storeValue(rhs.value); |
| 5474 | |
| 5475 | return rhs; |
| 5476 | } |
| 5477 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5478 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5479 | { |
| 5480 | Value *value = rhs.loadValue(); |
| 5481 | storeValue(value); |
| 5482 | |
| 5483 | return RValue<UInt4>(value); |
| 5484 | } |
| 5485 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5486 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5487 | { |
| 5488 | Value *value = rhs.loadValue(); |
| 5489 | storeValue(value); |
| 5490 | |
| 5491 | return RValue<UInt4>(value); |
| 5492 | } |
| 5493 | |
| 5494 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5495 | { |
| 5496 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5497 | } |
| 5498 | |
| 5499 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5500 | { |
| 5501 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5502 | } |
| 5503 | |
| 5504 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5505 | { |
| 5506 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5507 | } |
| 5508 | |
| 5509 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5510 | { |
| 5511 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5512 | } |
| 5513 | |
| 5514 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5515 | { |
| 5516 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5517 | } |
| 5518 | |
| 5519 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5520 | { |
| 5521 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5522 | } |
| 5523 | |
| 5524 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5525 | { |
| 5526 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5527 | } |
| 5528 | |
| 5529 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5530 | { |
| 5531 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5532 | } |
| 5533 | |
| 5534 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 5535 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5536 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 5540 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 5541 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5545 | { |
| 5546 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5547 | } |
| 5548 | |
| 5549 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 5550 | { |
| 5551 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5552 | } |
| 5553 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5554 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5555 | { |
| 5556 | return lhs = lhs + rhs; |
| 5557 | } |
| 5558 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5559 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5560 | { |
| 5561 | return lhs = lhs - rhs; |
| 5562 | } |
| 5563 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5564 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5565 | { |
| 5566 | return lhs = lhs * rhs; |
| 5567 | } |
| 5568 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5569 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5570 | // { |
| 5571 | // return lhs = lhs / rhs; |
| 5572 | // } |
| 5573 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5574 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5575 | // { |
| 5576 | // return lhs = lhs % rhs; |
| 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, unsigned char 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, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5600 | { |
| 5601 | return lhs = lhs >> rhs; |
| 5602 | } |
| 5603 | |
| 5604 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 5605 | { |
| 5606 | return val; |
| 5607 | } |
| 5608 | |
| 5609 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 5610 | { |
| 5611 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 5612 | } |
| 5613 | |
| 5614 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 5615 | { |
| 5616 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 5617 | } |
| 5618 | |
| 5619 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5620 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5621 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5622 | } |
| 5623 | |
| 5624 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5625 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5626 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5630 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5631 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5632 | } |
| 5633 | |
| 5634 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 5635 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5636 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5637 | } |
| 5638 | |
| 5639 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 5640 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5641 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 5645 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5646 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5647 | } |
| 5648 | |
| 5649 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 5650 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5651 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5652 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 5653 | ::basicBlock->appendInst(cmp); |
| 5654 | |
| 5655 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5656 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5657 | ::basicBlock->appendInst(select); |
| 5658 | |
| 5659 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 5663 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5664 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5665 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 5666 | ::basicBlock->appendInst(cmp); |
| 5667 | |
| 5668 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5669 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5670 | ::basicBlock->appendInst(select); |
| 5671 | |
| 5672 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5673 | } |
| 5674 | |
| 5675 | RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y) |
| 5676 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5677 | if(CPUID::SSE4_1) |
| 5678 | { |
| 5679 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 5680 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5681 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5682 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 5683 | pack->addArg(x.value); |
| 5684 | pack->addArg(y.value); |
| 5685 | ::basicBlock->appendInst(pack); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 5686 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 5687 | return RValue<UShort8>(V(result)); |
| 5688 | } |
| 5689 | else |
| 5690 | { |
| 5691 | RValue<Int4> sx = As<Int4>(x); |
| 5692 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 5693 | |
| 5694 | RValue<Int4> sy = As<Int4>(y); |
| 5695 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 5696 | |
| 5697 | return As<UShort8>(Pack(bx, by) + Short8(0x8000u)); |
| 5698 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5699 | } |
| 5700 | |
| 5701 | Type *UInt4::getType() |
| 5702 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5703 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5704 | } |
| 5705 | |
| 5706 | Float::Float(RValue<Int> cast) |
| 5707 | { |
| 5708 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 5709 | |
| 5710 | storeValue(integer); |
| 5711 | } |
| 5712 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5713 | Float::Float(float x) |
| 5714 | { |
| 5715 | storeValue(Nucleus::createConstantFloat(x)); |
| 5716 | } |
| 5717 | |
| 5718 | Float::Float(RValue<Float> rhs) |
| 5719 | { |
| 5720 | storeValue(rhs.value); |
| 5721 | } |
| 5722 | |
| 5723 | Float::Float(const Float &rhs) |
| 5724 | { |
| 5725 | Value *value = rhs.loadValue(); |
| 5726 | storeValue(value); |
| 5727 | } |
| 5728 | |
| 5729 | Float::Float(const Reference<Float> &rhs) |
| 5730 | { |
| 5731 | Value *value = rhs.loadValue(); |
| 5732 | storeValue(value); |
| 5733 | } |
| 5734 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5735 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5736 | { |
| 5737 | storeValue(rhs.value); |
| 5738 | |
| 5739 | return rhs; |
| 5740 | } |
| 5741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5742 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5743 | { |
| 5744 | Value *value = rhs.loadValue(); |
| 5745 | storeValue(value); |
| 5746 | |
| 5747 | return RValue<Float>(value); |
| 5748 | } |
| 5749 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5750 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5751 | { |
| 5752 | Value *value = rhs.loadValue(); |
| 5753 | storeValue(value); |
| 5754 | |
| 5755 | return RValue<Float>(value); |
| 5756 | } |
| 5757 | |
| 5758 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 5759 | { |
| 5760 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 5761 | } |
| 5762 | |
| 5763 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 5764 | { |
| 5765 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 5766 | } |
| 5767 | |
| 5768 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 5769 | { |
| 5770 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 5771 | } |
| 5772 | |
| 5773 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 5774 | { |
| 5775 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 5776 | } |
| 5777 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5778 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5779 | { |
| 5780 | return lhs = lhs + rhs; |
| 5781 | } |
| 5782 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5783 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5784 | { |
| 5785 | return lhs = lhs - rhs; |
| 5786 | } |
| 5787 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5788 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5789 | { |
| 5790 | return lhs = lhs * rhs; |
| 5791 | } |
| 5792 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5793 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5794 | { |
| 5795 | return lhs = lhs / rhs; |
| 5796 | } |
| 5797 | |
| 5798 | RValue<Float> operator+(RValue<Float> val) |
| 5799 | { |
| 5800 | return val; |
| 5801 | } |
| 5802 | |
| 5803 | RValue<Float> operator-(RValue<Float> val) |
| 5804 | { |
| 5805 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 5806 | } |
| 5807 | |
| 5808 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 5809 | { |
| 5810 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 5811 | } |
| 5812 | |
| 5813 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 5814 | { |
| 5815 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 5816 | } |
| 5817 | |
| 5818 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 5819 | { |
| 5820 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 5821 | } |
| 5822 | |
| 5823 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 5824 | { |
| 5825 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 5826 | } |
| 5827 | |
| 5828 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 5829 | { |
| 5830 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 5831 | } |
| 5832 | |
| 5833 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 5834 | { |
| 5835 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 5836 | } |
| 5837 | |
| 5838 | RValue<Float> Abs(RValue<Float> x) |
| 5839 | { |
| 5840 | return IfThenElse(x > 0.0f, x, -x); |
| 5841 | } |
| 5842 | |
| 5843 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 5844 | { |
| 5845 | return IfThenElse(x > y, x, y); |
| 5846 | } |
| 5847 | |
| 5848 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 5849 | { |
| 5850 | return IfThenElse(x < y, x, y); |
| 5851 | } |
| 5852 | |
| 5853 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 5854 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5855 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5856 | } |
| 5857 | |
| 5858 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 5859 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5860 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | RValue<Float> Sqrt(RValue<Float> x) |
| 5864 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 5865 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 5866 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 5867 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 5868 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 5869 | sqrt->addArg(x.value); |
| 5870 | ::basicBlock->appendInst(sqrt); |
| 5871 | |
| 5872 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | RValue<Float> Round(RValue<Float> x) |
| 5876 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5877 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | RValue<Float> Trunc(RValue<Float> x) |
| 5881 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5882 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | RValue<Float> Frac(RValue<Float> x) |
| 5886 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5887 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | RValue<Float> Floor(RValue<Float> x) |
| 5891 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5892 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | RValue<Float> Ceil(RValue<Float> x) |
| 5896 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 5897 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | Type *Float::getType() |
| 5901 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 5902 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | Float2::Float2(RValue<Float4> cast) |
| 5906 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5907 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | Type *Float2::getType() |
| 5911 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5912 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5913 | } |
| 5914 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5915 | Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5916 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5917 | Value *a = Int4(cast).loadValue(); |
| 5918 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5919 | |
| 5920 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5921 | } |
| 5922 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5923 | Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5924 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5925 | Value *a = Int4(cast).loadValue(); |
| 5926 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 5927 | |
| 5928 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5929 | } |
| 5930 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5931 | Float4::Float4(RValue<Short4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5932 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5933 | Int4 c(cast); |
| 5934 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5935 | } |
| 5936 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5937 | Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5938 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5939 | Int4 c(cast); |
| 5940 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 5941 | } |
| 5942 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5943 | Float4::Float4(RValue<Int4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5944 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5945 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 5946 | |
| 5947 | storeValue(xyzw); |
| 5948 | } |
| 5949 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5950 | Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5951 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5952 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 5953 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5954 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 5955 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5956 | } |
| 5957 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5958 | Float4::Float4() : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5959 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5960 | } |
| 5961 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5962 | Float4::Float4(float xyzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5963 | { |
| 5964 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5965 | } |
| 5966 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5967 | Float4::Float4(float x, float yzw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5968 | { |
| 5969 | constant(x, yzw, yzw, yzw); |
| 5970 | } |
| 5971 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5972 | Float4::Float4(float x, float y, float zw) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5973 | { |
| 5974 | constant(x, y, zw, zw); |
| 5975 | } |
| 5976 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5977 | Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5978 | { |
| 5979 | constant(x, y, z, w); |
| 5980 | } |
| 5981 | |
| 5982 | void Float4::constant(float x, float y, float z, float w) |
| 5983 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5984 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5985 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5986 | } |
| 5987 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5988 | Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5989 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5990 | storeValue(rhs.value); |
| 5991 | } |
| 5992 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5993 | Float4::Float4(const Float4 &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5994 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5995 | Value *value = rhs.loadValue(); |
| 5996 | storeValue(value); |
| 5997 | } |
| 5998 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 5999 | Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6000 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6001 | Value *value = rhs.loadValue(); |
| 6002 | storeValue(value); |
| 6003 | } |
| 6004 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6005 | Float4::Float4(RValue<Float> rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6006 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6007 | Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6008 | |
| 6009 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6010 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6011 | |
| 6012 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6013 | } |
| 6014 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6015 | Float4::Float4(const Float &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6016 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6017 | *this = RValue<Float>(rhs.loadValue()); |
| 6018 | } |
| 6019 | |
Nicolas Capens | a25311a | 2017-01-16 17:19:00 -0500 | [diff] [blame] | 6020 | Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6021 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6022 | *this = RValue<Float>(rhs.loadValue()); |
| 6023 | } |
| 6024 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6025 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6026 | { |
| 6027 | return *this = Float4(x, x, x, x); |
| 6028 | } |
| 6029 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6030 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6031 | { |
| 6032 | storeValue(rhs.value); |
| 6033 | |
| 6034 | return rhs; |
| 6035 | } |
| 6036 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6037 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6038 | { |
| 6039 | Value *value = rhs.loadValue(); |
| 6040 | storeValue(value); |
| 6041 | |
| 6042 | return RValue<Float4>(value); |
| 6043 | } |
| 6044 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6045 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6046 | { |
| 6047 | Value *value = rhs.loadValue(); |
| 6048 | storeValue(value); |
| 6049 | |
| 6050 | return RValue<Float4>(value); |
| 6051 | } |
| 6052 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6053 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6054 | { |
| 6055 | return *this = Float4(rhs); |
| 6056 | } |
| 6057 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6058 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6059 | { |
| 6060 | return *this = Float4(rhs); |
| 6061 | } |
| 6062 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6063 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6064 | { |
| 6065 | return *this = Float4(rhs); |
| 6066 | } |
| 6067 | |
| 6068 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6069 | { |
| 6070 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6071 | } |
| 6072 | |
| 6073 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6074 | { |
| 6075 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6076 | } |
| 6077 | |
| 6078 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6079 | { |
| 6080 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6081 | } |
| 6082 | |
| 6083 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6084 | { |
| 6085 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6086 | } |
| 6087 | |
| 6088 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6089 | { |
| 6090 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6091 | } |
| 6092 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6093 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6094 | { |
| 6095 | return lhs = lhs + rhs; |
| 6096 | } |
| 6097 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6098 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6099 | { |
| 6100 | return lhs = lhs - rhs; |
| 6101 | } |
| 6102 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6103 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6104 | { |
| 6105 | return lhs = lhs * rhs; |
| 6106 | } |
| 6107 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6108 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6109 | { |
| 6110 | return lhs = lhs / rhs; |
| 6111 | } |
| 6112 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6113 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6114 | { |
| 6115 | return lhs = lhs % rhs; |
| 6116 | } |
| 6117 | |
| 6118 | RValue<Float4> operator+(RValue<Float4> val) |
| 6119 | { |
| 6120 | return val; |
| 6121 | } |
| 6122 | |
| 6123 | RValue<Float4> operator-(RValue<Float4> val) |
| 6124 | { |
| 6125 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6126 | } |
| 6127 | |
| 6128 | RValue<Float4> Abs(RValue<Float4> x) |
| 6129 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6130 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6131 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6132 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6133 | |
| 6134 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6138 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6139 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6140 | 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] | 6141 | ::basicBlock->appendInst(cmp); |
| 6142 | |
| 6143 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6144 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6145 | ::basicBlock->appendInst(select); |
| 6146 | |
| 6147 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6151 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6152 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6153 | 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] | 6154 | ::basicBlock->appendInst(cmp); |
| 6155 | |
| 6156 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6157 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6158 | ::basicBlock->appendInst(select); |
| 6159 | |
| 6160 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6164 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6165 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6169 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6170 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6174 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6175 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6176 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6177 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6178 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6179 | sqrt->addArg(x.value); |
| 6180 | ::basicBlock->appendInst(sqrt); |
| 6181 | |
| 6182 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6183 | } |
| 6184 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6185 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6186 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 6187 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6188 | } |
| 6189 | |
| 6190 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 6191 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6192 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 6196 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6197 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6198 | } |
| 6199 | |
| 6200 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 6201 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6202 | int shuffle[4] = |
| 6203 | { |
| 6204 | ((imm >> 0) & 0x03) + 0, |
| 6205 | ((imm >> 2) & 0x03) + 0, |
| 6206 | ((imm >> 4) & 0x03) + 4, |
| 6207 | ((imm >> 6) & 0x03) + 4, |
| 6208 | }; |
| 6209 | |
| 6210 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 6214 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6215 | int shuffle[4] = {0, 4, 1, 5}; |
| 6216 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 6220 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 6221 | int shuffle[4] = {2, 6, 3, 7}; |
| 6222 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 6226 | { |
| 6227 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6228 | Value *result = createMask4(vector, rhs.value, select); |
| 6229 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6230 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 6231 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6232 | } |
| 6233 | |
| 6234 | RValue<Int> SignMask(RValue<Float4> x) |
| 6235 | { |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6236 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6237 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6238 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6239 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6240 | movmsk->addArg(x.value); |
| 6241 | ::basicBlock->appendInst(movmsk); |
| 6242 | |
| 6243 | return RValue<Int>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6244 | } |
| 6245 | |
| 6246 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 6247 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6248 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 6252 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6253 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6254 | } |
| 6255 | |
| 6256 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 6257 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6258 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6259 | } |
| 6260 | |
| 6261 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 6262 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6263 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6264 | } |
| 6265 | |
| 6266 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 6267 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6268 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6269 | } |
| 6270 | |
| 6271 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 6272 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6273 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | RValue<Float4> Round(RValue<Float4> x) |
| 6277 | { |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 6278 | if(emulateIntrinsics) |
| 6279 | { |
| 6280 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 6281 | return (x + Float4(0x00C00000)) - Float4(0x00C00000); |
| 6282 | } |
| 6283 | else if(CPUID::SSE4_1) |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6284 | { |
| 6285 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6286 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6287 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6288 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6289 | round->addArg(x.value); |
| 6290 | round->addArg(::context->getConstantInt32(0)); |
| 6291 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6292 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6293 | return RValue<Float4>(V(result)); |
| 6294 | } |
| 6295 | else |
| 6296 | { |
| 6297 | return Float4(RoundInt(x)); |
| 6298 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | RValue<Float4> Trunc(RValue<Float4> x) |
| 6302 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6303 | if(CPUID::SSE4_1) |
| 6304 | { |
| 6305 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6306 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6307 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6308 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6309 | round->addArg(x.value); |
| 6310 | round->addArg(::context->getConstantInt32(3)); |
| 6311 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6312 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6313 | return RValue<Float4>(V(result)); |
| 6314 | } |
| 6315 | else |
| 6316 | { |
| 6317 | return Float4(Int4(x)); |
| 6318 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | RValue<Float4> Frac(RValue<Float4> x) |
| 6322 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6323 | if(CPUID::SSE4_1) |
| 6324 | { |
| 6325 | return x - Floor(x); |
| 6326 | } |
| 6327 | else |
| 6328 | { |
| 6329 | Float4 frc = x - Float4(Int4(x)); // Signed fractional part |
| 6330 | |
| 6331 | return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); |
| 6332 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | RValue<Float4> Floor(RValue<Float4> x) |
| 6336 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6337 | if(CPUID::SSE4_1) |
| 6338 | { |
| 6339 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6340 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6341 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6342 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6343 | round->addArg(x.value); |
| 6344 | round->addArg(::context->getConstantInt32(1)); |
| 6345 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6346 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6347 | return RValue<Float4>(V(result)); |
| 6348 | } |
| 6349 | else |
| 6350 | { |
| 6351 | return x - Frac(x); |
| 6352 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | RValue<Float4> Ceil(RValue<Float4> x) |
| 6356 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6357 | if(CPUID::SSE4_1) |
| 6358 | { |
| 6359 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6360 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6361 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6362 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6363 | round->addArg(x.value); |
| 6364 | round->addArg(::context->getConstantInt32(2)); |
| 6365 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6366 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 6367 | return RValue<Float4>(V(result)); |
| 6368 | } |
| 6369 | else |
| 6370 | { |
| 6371 | return -Floor(-x); |
| 6372 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6373 | } |
| 6374 | |
| 6375 | Type *Float4::getType() |
| 6376 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6377 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 6381 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 6382 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6386 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6387 | 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] | 6388 | } |
| 6389 | |
| 6390 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6391 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 6392 | 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] | 6393 | } |
| 6394 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6395 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6396 | { |
| 6397 | return lhs = lhs + offset; |
| 6398 | } |
| 6399 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6400 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6401 | { |
| 6402 | return lhs = lhs + offset; |
| 6403 | } |
| 6404 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6405 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6406 | { |
| 6407 | return lhs = lhs + offset; |
| 6408 | } |
| 6409 | |
| 6410 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 6411 | { |
| 6412 | return lhs + -offset; |
| 6413 | } |
| 6414 | |
| 6415 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 6416 | { |
| 6417 | return lhs + -offset; |
| 6418 | } |
| 6419 | |
| 6420 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 6421 | { |
| 6422 | return lhs + -offset; |
| 6423 | } |
| 6424 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6425 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6426 | { |
| 6427 | return lhs = lhs - offset; |
| 6428 | } |
| 6429 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6430 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6431 | { |
| 6432 | return lhs = lhs - offset; |
| 6433 | } |
| 6434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6435 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6436 | { |
| 6437 | return lhs = lhs - offset; |
| 6438 | } |
| 6439 | |
| 6440 | void Return() |
| 6441 | { |
| 6442 | Nucleus::createRetVoid(); |
| 6443 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6444 | Nucleus::createUnreachable(); |
| 6445 | } |
| 6446 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6447 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6448 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 6449 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 6450 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 6451 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6452 | } |
| 6453 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 6454 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6455 | { |
| 6456 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 6457 | Nucleus::setInsertBlock(bodyBB); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6458 | } |
| 6459 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6460 | RValue<Long> Ticks() |
| 6461 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 6462 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6463 | } |
| 6464 | } |