Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 15 | #include "Reactor.hpp" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 16 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 17 | #include "Optimizer.hpp" |
Nicolas Capens | 1a3ce87 | 2018-10-10 10:42:36 -0400 | [diff] [blame] | 18 | #include "ExecutableMemory.hpp" |
Nicolas Capens | a062f32 | 2018-09-06 15:34:46 -0400 | [diff] [blame] | 19 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 20 | #include "src/IceTypes.h" |
| 21 | #include "src/IceCfg.h" |
| 22 | #include "src/IceELFStreamer.h" |
| 23 | #include "src/IceGlobalContext.h" |
| 24 | #include "src/IceCfgNode.h" |
| 25 | #include "src/IceELFObjectWriter.h" |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 26 | #include "src/IceGlobalInits.h" |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 27 | |
| 28 | #include "llvm/Support/FileSystem.h" |
| 29 | #include "llvm/Support/raw_os_ostream.h" |
Nicolas Capens | 6a990f8 | 2018-07-06 15:54:07 -0400 | [diff] [blame] | 30 | #include "llvm/Support/Compiler.h" |
| 31 | |
| 32 | #if __has_feature(memory_sanitizer) |
| 33 | #include <sanitizer/msan_interface.h> |
| 34 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 35 | |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 36 | #if defined(_WIN32) |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 37 | #ifndef WIN32_LEAN_AND_MEAN |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 38 | #define WIN32_LEAN_AND_MEAN |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 39 | #endif // !WIN32_LEAN_AND_MEAN |
| 40 | #ifndef NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 41 | #define NOMINMAX |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 42 | #endif // !NOMINMAX |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 43 | #include <Windows.h> |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 44 | #else |
| 45 | #include <sys/mman.h> |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 46 | #if !defined(MAP_ANONYMOUS) |
| 47 | #define MAP_ANONYMOUS MAP_ANON |
Nicolas Capens | 8b27574 | 2017-01-20 17:11:41 -0500 | [diff] [blame] | 48 | #endif |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 49 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 50 | |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 51 | #include <mutex> |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 52 | #include <limits> |
| 53 | #include <iostream> |
| 54 | #include <cassert> |
| 55 | |
| 56 | namespace |
| 57 | { |
| 58 | Ice::GlobalContext *context = nullptr; |
| 59 | Ice::Cfg *function = nullptr; |
| 60 | Ice::CfgNode *basicBlock = nullptr; |
| 61 | Ice::CfgLocalAllocatorScope *allocator = nullptr; |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 62 | rr::Routine *routine = nullptr; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 63 | |
| 64 | std::mutex codegenMutex; |
| 65 | |
| 66 | Ice::ELFFileStreamer *elfFile = nullptr; |
| 67 | Ice::Fdstream *out = nullptr; |
| 68 | } |
| 69 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 70 | namespace |
| 71 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 72 | #if !defined(__i386__) && defined(_M_IX86) |
| 73 | #define __i386__ 1 |
| 74 | #endif |
| 75 | |
| 76 | #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64)) |
| 77 | #define __x86_64__ 1 |
| 78 | #endif |
| 79 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 80 | class CPUID |
| 81 | { |
| 82 | public: |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 83 | const static bool ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 84 | const static bool SSE4_1; |
| 85 | |
| 86 | private: |
| 87 | static void cpuid(int registers[4], int info) |
| 88 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 89 | #if defined(__i386__) || defined(__x86_64__) |
| 90 | #if defined(_WIN32) |
| 91 | __cpuid(registers, info); |
| 92 | #else |
| 93 | __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info)); |
| 94 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 95 | #else |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 96 | registers[0] = 0; |
| 97 | registers[1] = 0; |
| 98 | registers[2] = 0; |
| 99 | registers[3] = 0; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 100 | #endif |
| 101 | } |
| 102 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 103 | static bool detectARM() |
| 104 | { |
Stephen Lanham | fe79649 | 2018-09-07 11:59:54 -0700 | [diff] [blame] | 105 | #if defined(__arm__) || defined(__aarch64__) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 106 | return true; |
| 107 | #elif defined(__i386__) || defined(__x86_64__) |
| 108 | return false; |
Gordana Cmiljanovic | 082dfec | 2018-10-19 11:36:15 +0200 | [diff] [blame] | 109 | #elif defined(__mips__) |
| 110 | return false; |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 111 | #else |
| 112 | #error "Unknown architecture" |
| 113 | #endif |
| 114 | } |
| 115 | |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 116 | static bool detectSSE4_1() |
| 117 | { |
Nicolas Capens | 47dc867 | 2017-04-25 12:54:39 -0400 | [diff] [blame] | 118 | #if defined(__i386__) || defined(__x86_64__) |
| 119 | int registers[4]; |
| 120 | cpuid(registers, 1); |
| 121 | return (registers[2] & 0x00080000) != 0; |
| 122 | #else |
| 123 | return false; |
| 124 | #endif |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 125 | } |
| 126 | }; |
| 127 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 128 | const bool CPUID::ARM = CPUID::detectARM(); |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 129 | const bool CPUID::SSE4_1 = CPUID::detectSSE4_1(); |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 130 | const bool emulateIntrinsics = false; |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame] | 131 | const bool emulateMismatchedBitCast = CPUID::ARM; |
Nicolas Capens | ccd5ecb | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 134 | namespace rr |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 135 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 136 | enum EmulatedType |
| 137 | { |
| 138 | EmulatedShift = 16, |
| 139 | EmulatedV2 = 2 << EmulatedShift, |
| 140 | EmulatedV4 = 4 << EmulatedShift, |
| 141 | EmulatedV8 = 8 << EmulatedShift, |
| 142 | EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8, |
| 143 | |
| 144 | Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2, |
| 145 | Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4, |
| 146 | Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2, |
| 147 | Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8, |
| 148 | Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4, |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 149 | Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2, |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 150 | }; |
| 151 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 152 | class Value : public Ice::Operand {}; |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 153 | class SwitchCases : public Ice::InstSwitch {}; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 154 | class BasicBlock : public Ice::CfgNode {}; |
| 155 | |
| 156 | Ice::Type T(Type *t) |
| 157 | { |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 158 | 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] | 159 | return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | Type *T(Ice::Type t) |
| 163 | { |
| 164 | return reinterpret_cast<Type*>(t); |
| 165 | } |
| 166 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 167 | Type *T(EmulatedType t) |
| 168 | { |
| 169 | return reinterpret_cast<Type*>(t); |
| 170 | } |
| 171 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 172 | Value *V(Ice::Operand *v) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 173 | { |
| 174 | return reinterpret_cast<Value*>(v); |
| 175 | } |
| 176 | |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 177 | BasicBlock *B(Ice::CfgNode *b) |
| 178 | { |
| 179 | return reinterpret_cast<BasicBlock*>(b); |
| 180 | } |
| 181 | |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 182 | static size_t typeSize(Type *type) |
| 183 | { |
| 184 | if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits) |
| 185 | { |
| 186 | switch(reinterpret_cast<std::intptr_t>(type)) |
| 187 | { |
| 188 | case Type_v2i32: return 8; |
| 189 | case Type_v4i16: return 8; |
| 190 | case Type_v2i16: return 4; |
| 191 | case Type_v8i8: return 8; |
| 192 | case Type_v4i8: return 4; |
| 193 | case Type_v2f32: return 8; |
| 194 | default: assert(false); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | return Ice::typeWidthInBytes(T(type)); |
| 199 | } |
| 200 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 201 | Optimization optimization[10] = {InstructionCombining, Disabled}; |
| 202 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 203 | using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; |
| 204 | using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type; |
| 205 | |
| 206 | inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader) |
| 207 | { |
| 208 | return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff); |
| 209 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 210 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 211 | inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index) |
| 212 | { |
| 213 | return §ionHeader(elfHeader)[index]; |
| 214 | } |
| 215 | |
| 216 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable) |
| 217 | { |
| 218 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
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 | uint32_t index = relocation.getSymbol(); |
| 221 | int table = relocationTable.sh_link; |
| 222 | void *symbolValue = nullptr; |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 223 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 224 | if(index != SHN_UNDEF) |
| 225 | { |
| 226 | if(table == SHN_UNDEF) return nullptr; |
| 227 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 228 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 229 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 230 | if(index >= symtab_entries) |
| 231 | { |
| 232 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 233 | return nullptr; |
| 234 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 235 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 236 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 237 | Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index]; |
| 238 | uint16_t section = symbol.st_shndx; |
| 239 | |
| 240 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 241 | { |
| 242 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 243 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | return nullptr; |
| 248 | } |
| 249 | } |
| 250 | |
Nicolas Capens | 8d2cf75 | 2018-11-22 11:13:45 -0500 | [diff] [blame] | 251 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 252 | unaligned_ptr<int32_t> patchSite = (int32_t*)(address + relocation.r_offset); |
| 253 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 254 | if(CPUID::ARM) |
| 255 | { |
| 256 | switch(relocation.getType()) |
| 257 | { |
| 258 | case R_ARM_NONE: |
| 259 | // No relocation |
| 260 | break; |
| 261 | case R_ARM_MOVW_ABS_NC: |
| 262 | { |
| 263 | uint32_t thumb = 0; // Calls to Thumb code not supported. |
| 264 | uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb; |
| 265 | *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF); |
| 266 | } |
| 267 | break; |
| 268 | case R_ARM_MOVT_ABS: |
| 269 | { |
| 270 | uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16; |
| 271 | *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF); |
| 272 | } |
| 273 | break; |
| 274 | default: |
| 275 | assert(false && "Unsupported relocation type"); |
| 276 | return nullptr; |
| 277 | } |
| 278 | } |
| 279 | else |
| 280 | { |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 281 | switch(relocation.getType()) |
| 282 | { |
| 283 | case R_386_NONE: |
| 284 | // No relocation |
| 285 | break; |
| 286 | case R_386_32: |
| 287 | *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite); |
| 288 | break; |
| 289 | // case R_386_PC32: |
| 290 | // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite); |
| 291 | // break; |
| 292 | default: |
| 293 | assert(false && "Unsupported relocation type"); |
| 294 | return nullptr; |
| 295 | } |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 296 | } |
| 297 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 298 | return symbolValue; |
| 299 | } |
| 300 | |
| 301 | static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable) |
| 302 | { |
| 303 | const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 304 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 305 | uint32_t index = relocation.getSymbol(); |
| 306 | int table = relocationTable.sh_link; |
| 307 | void *symbolValue = nullptr; |
| 308 | |
| 309 | if(index != SHN_UNDEF) |
| 310 | { |
| 311 | if(table == SHN_UNDEF) return nullptr; |
| 312 | const SectionHeader *symbolTable = elfSection(elfHeader, table); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 313 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 314 | uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize; |
| 315 | if(index >= symtab_entries) |
| 316 | { |
| 317 | assert(index < symtab_entries && "Symbol Index out of range"); |
| 318 | return nullptr; |
| 319 | } |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 320 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 321 | intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset; |
| 322 | Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index]; |
| 323 | uint16_t section = symbol.st_shndx; |
| 324 | |
| 325 | if(section != SHN_UNDEF && section < SHN_LORESERVE) |
| 326 | { |
| 327 | const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx); |
| 328 | symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset); |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | return nullptr; |
| 333 | } |
| 334 | } |
| 335 | |
Nicolas Capens | 8d2cf75 | 2018-11-22 11:13:45 -0500 | [diff] [blame] | 336 | intptr_t address = (intptr_t)elfHeader + target->sh_offset; |
| 337 | unaligned_ptr<int32_t> patchSite32 = (int32_t*)(address + relocation.r_offset); |
| 338 | unaligned_ptr<int64_t> patchSite64 = (int64_t*)(address + relocation.r_offset); |
| 339 | |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 340 | switch(relocation.getType()) |
| 341 | { |
| 342 | case R_X86_64_NONE: |
| 343 | // No relocation |
| 344 | break; |
| 345 | case R_X86_64_64: |
Nicolas Capens | 8d2cf75 | 2018-11-22 11:13:45 -0500 | [diff] [blame] | 346 | *patchSite64 = (int64_t)((intptr_t)symbolValue + *patchSite64 + relocation.r_addend); |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 347 | break; |
| 348 | case R_X86_64_PC32: |
Nicolas Capens | 8d2cf75 | 2018-11-22 11:13:45 -0500 | [diff] [blame] | 349 | *patchSite32 = (int32_t)((intptr_t)symbolValue + *patchSite32 - (intptr_t)patchSite32 + relocation.r_addend); |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 350 | break; |
| 351 | case R_X86_64_32S: |
Nicolas Capens | 8d2cf75 | 2018-11-22 11:13:45 -0500 | [diff] [blame] | 352 | *patchSite32 = (int32_t)((intptr_t)symbolValue + *patchSite32 + relocation.r_addend); |
Nicolas Capens | f110e4d | 2017-05-03 15:33:49 -0400 | [diff] [blame] | 353 | break; |
| 354 | default: |
| 355 | assert(false && "Unsupported relocation type"); |
| 356 | return nullptr; |
| 357 | } |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 358 | |
| 359 | return symbolValue; |
| 360 | } |
| 361 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 362 | void *loadImage(uint8_t *const elfImage, size_t &codeSize) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 363 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 364 | ElfHeader *elfHeader = (ElfHeader*)elfImage; |
| 365 | |
| 366 | if(!elfHeader->checkMagic()) |
| 367 | { |
| 368 | return nullptr; |
| 369 | } |
| 370 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 371 | // Expect ELF bitness to match platform |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 372 | assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 373 | #if defined(__i386__) |
| 374 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386); |
| 375 | #elif defined(__x86_64__) |
| 376 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64); |
| 377 | #elif defined(__arm__) |
| 378 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM); |
Stephen Lanham | fe79649 | 2018-09-07 11:59:54 -0700 | [diff] [blame] | 379 | #elif defined(__aarch64__) |
| 380 | assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_AARCH64); |
Gordana Cmiljanovic | 082dfec | 2018-10-19 11:36:15 +0200 | [diff] [blame] | 381 | #elif defined(__mips__) |
| 382 | assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_MIPS); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 383 | #else |
| 384 | #error "Unsupported platform" |
| 385 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 386 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 387 | SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff); |
| 388 | void *entry = nullptr; |
| 389 | |
| 390 | for(int i = 0; i < elfHeader->e_shnum; i++) |
| 391 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 392 | if(sectionHeader[i].sh_type == SHT_PROGBITS) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 393 | { |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 394 | if(sectionHeader[i].sh_flags & SHF_EXECINSTR) |
| 395 | { |
| 396 | entry = elfImage + sectionHeader[i].sh_offset; |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 397 | codeSize = sectionHeader[i].sh_size; |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | else if(sectionHeader[i].sh_type == SHT_REL) |
| 401 | { |
| 402 | assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code |
| 403 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 404 | 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] | 405 | { |
| 406 | 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] | 407 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | else if(sectionHeader[i].sh_type == SHT_RELA) |
| 411 | { |
| 412 | assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code |
| 413 | |
Alexis Hetu | 113e33a | 2017-01-19 10:49:19 -0500 | [diff] [blame] | 414 | 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] | 415 | { |
| 416 | 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] | 417 | relocateSymbol(elfHeader, relocation, sectionHeader[i]); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 418 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | return entry; |
| 423 | } |
| 424 | |
| 425 | template<typename T> |
| 426 | struct ExecutableAllocator |
| 427 | { |
| 428 | ExecutableAllocator() {}; |
| 429 | template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {}; |
| 430 | |
| 431 | using value_type = T; |
| 432 | using size_type = std::size_t; |
| 433 | |
| 434 | T *allocate(size_type n) |
| 435 | { |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 436 | return (T*)allocateExecutable(sizeof(T) * n); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | void deallocate(T *p, size_type n) |
| 440 | { |
Nicolas Capens | c07dc4b | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 441 | deallocateExecutable(p, sizeof(T) * n); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 442 | } |
| 443 | }; |
| 444 | |
| 445 | class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine |
| 446 | { |
| 447 | ELFMemoryStreamer(const ELFMemoryStreamer &) = delete; |
| 448 | ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete; |
| 449 | |
| 450 | public: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 451 | ELFMemoryStreamer() : Routine(), entry(nullptr) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 452 | { |
| 453 | position = 0; |
| 454 | buffer.reserve(0x1000); |
| 455 | } |
| 456 | |
Nicolas Capens | 81aa97b | 2017-06-27 17:08:08 -0400 | [diff] [blame] | 457 | ~ELFMemoryStreamer() override |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 458 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 459 | #if defined(_WIN32) |
| 460 | if(buffer.size() != 0) |
| 461 | { |
| 462 | DWORD exeProtection; |
| 463 | VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection); |
| 464 | } |
| 465 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void write8(uint8_t Value) override |
| 469 | { |
| 470 | if(position == (uint64_t)buffer.size()) |
| 471 | { |
| 472 | buffer.push_back(Value); |
| 473 | position++; |
| 474 | } |
| 475 | else if(position < (uint64_t)buffer.size()) |
| 476 | { |
| 477 | buffer[position] = Value; |
| 478 | position++; |
| 479 | } |
| 480 | else assert(false && "UNIMPLEMENTED"); |
| 481 | } |
| 482 | |
| 483 | void writeBytes(llvm::StringRef Bytes) override |
| 484 | { |
| 485 | std::size_t oldSize = buffer.size(); |
| 486 | buffer.resize(oldSize + Bytes.size()); |
| 487 | memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size()); |
| 488 | position += Bytes.size(); |
| 489 | } |
| 490 | |
| 491 | uint64_t tell() const override { return position; } |
| 492 | |
| 493 | void seek(uint64_t Off) override { position = Off; } |
| 494 | |
| 495 | const void *getEntry() override |
| 496 | { |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 497 | if(!entry) |
| 498 | { |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 499 | 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] | 500 | |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 501 | size_t codeSize = 0; |
| 502 | entry = loadImage(&buffer[0], codeSize); |
| 503 | |
| 504 | #if defined(_WIN32) |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 505 | VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 506 | FlushInstructionCache(GetCurrentProcess(), NULL, 0); |
| 507 | #else |
Nicolas Capens | e745f5a | 2017-05-29 10:00:32 -0400 | [diff] [blame] | 508 | mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC); |
Nicolas Capens | 1cc4438 | 2017-04-25 10:52:16 -0400 | [diff] [blame] | 509 | __builtin___clear_cache((char*)entry, (char*)entry + codeSize); |
| 510 | #endif |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | return entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | private: |
Nicolas Capens | 58274b5 | 2016-10-19 23:45:19 -0400 | [diff] [blame] | 517 | void *entry; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 518 | std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer; |
| 519 | std::size_t position; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 520 | |
| 521 | #if defined(_WIN32) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 522 | DWORD oldProtection; |
Nicolas Capens | bd65da9 | 2017-01-05 16:31:06 -0500 | [diff] [blame] | 523 | #endif |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 524 | }; |
| 525 | |
| 526 | Nucleus::Nucleus() |
| 527 | { |
| 528 | ::codegenMutex.lock(); // Reactor is currently not thread safe |
| 529 | |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 530 | Ice::ClFlags &Flags = Ice::ClFlags::Flags; |
| 531 | Ice::ClFlags::getParsedClFlags(Flags); |
| 532 | |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 533 | #if defined(__arm__) |
| 534 | Flags.setTargetArch(Ice::Target_ARM32); |
| 535 | Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm); |
Gordana Cmiljanovic | 082dfec | 2018-10-19 11:36:15 +0200 | [diff] [blame] | 536 | #elif defined(__mips__) |
| 537 | Flags.setTargetArch(Ice::Target_MIPS32); |
| 538 | Flags.setTargetInstructionSet(Ice::BaseInstructionSet); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 539 | #else // x86 |
| 540 | Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632); |
| 541 | Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2); |
| 542 | #endif |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 543 | Flags.setOutFileType(Ice::FT_Elf); |
| 544 | Flags.setOptLevel(Ice::Opt_2); |
| 545 | Flags.setApplicationBinaryInterface(Ice::ABI_Platform); |
Nicolas Capens | 30cd7d4 | 2017-04-25 15:17:25 -0400 | [diff] [blame] | 546 | Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None); |
| 547 | Flags.setDisableHybridAssembly(true); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 548 | |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 549 | static llvm::raw_os_ostream cout(std::cout); |
| 550 | static llvm::raw_os_ostream cerr(std::cerr); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 551 | |
| 552 | if(false) // Write out to a file |
| 553 | { |
| 554 | std::error_code errorCode; |
| 555 | ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None); |
| 556 | ::elfFile = new Ice::ELFFileStreamer(*out); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 557 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 558 | } |
| 559 | else |
| 560 | { |
| 561 | ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer(); |
Nicolas Capens | 6504711 | 2016-11-07 13:01:07 -0500 | [diff] [blame] | 562 | ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 563 | ::routine = elfMemory; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | Nucleus::~Nucleus() |
| 568 | { |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 569 | delete ::routine; |
| 570 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 571 | delete ::allocator; |
| 572 | delete ::function; |
| 573 | delete ::context; |
| 574 | |
| 575 | delete ::elfFile; |
| 576 | delete ::out; |
| 577 | |
| 578 | ::codegenMutex.unlock(); |
| 579 | } |
| 580 | |
Chris Forbes | 878d4b0 | 2019-01-21 10:48:35 -0800 | [diff] [blame] | 581 | Routine *Nucleus::acquireRoutine(const char *name, bool runOptimizations) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 582 | { |
| 583 | if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret) |
| 584 | { |
| 585 | createRetVoid(); |
| 586 | } |
| 587 | |
Chris Forbes | 878d4b0 | 2019-01-21 10:48:35 -0800 | [diff] [blame] | 588 | ::function->setFunctionName(Ice::GlobalString::createWithString(::context, name)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 589 | |
Nicolas Capens | 2ae9d74 | 2016-11-24 14:43:05 -0500 | [diff] [blame] | 590 | optimize(); |
| 591 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 592 | ::function->translate(); |
Nicolas Capens | de19f39 | 2016-10-19 10:29:49 -0400 | [diff] [blame] | 593 | assert(!::function->hasError()); |
| 594 | |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 595 | auto globals = ::function->getGlobalInits(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 596 | |
| 597 | if(globals && !globals->empty()) |
| 598 | { |
Nicolas Capens | 83a6bb9 | 2017-07-05 15:04:00 -0400 | [diff] [blame] | 599 | ::context->getGlobals()->merge(globals.get()); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 600 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 601 | |
| 602 | ::context->emitFileHeader(); |
| 603 | ::function->emitIAS(); |
| 604 | auto assembler = ::function->releaseAssembler(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 605 | auto objectWriter = ::context->getObjectWriter(); |
| 606 | assembler->alignFunction(); |
| 607 | objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get()); |
| 608 | ::context->lowerGlobals("last"); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 609 | ::context->lowerConstants(); |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 610 | ::context->lowerJumpTables(); |
Nicolas Capens | 6647836 | 2016-10-13 15:36:36 -0400 | [diff] [blame] | 611 | objectWriter->setUndefinedSyms(::context->getConstantExternSyms()); |
| 612 | objectWriter->writeNonUserSections(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 613 | |
Nicolas Capens | 619a8c5 | 2017-07-05 14:10:46 -0400 | [diff] [blame] | 614 | Routine *handoffRoutine = ::routine; |
| 615 | ::routine = nullptr; |
| 616 | |
| 617 | return handoffRoutine; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void Nucleus::optimize() |
| 621 | { |
Nicolas Capens | 4846150 | 2018-08-06 14:20:45 -0400 | [diff] [blame] | 622 | rr::optimize(::function); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | Value *Nucleus::allocateStackVariable(Type *t, int arraySize) |
| 626 | { |
| 627 | Ice::Type type = T(t); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 628 | int typeSize = Ice::typeWidthInBytes(type); |
| 629 | int totalSize = typeSize * (arraySize ? arraySize : 1); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 630 | |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 631 | auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 632 | auto address = ::function->makeVariable(T(getPointerType(t))); |
Nicolas Capens | a8f9863 | 2016-10-20 11:25:55 -0400 | [diff] [blame] | 633 | auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize); |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 634 | ::function->getEntryNode()->getInsts().push_front(alloca); |
| 635 | |
| 636 | return V(address); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | BasicBlock *Nucleus::createBasicBlock() |
| 640 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 641 | return B(::function->makeNode()); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | BasicBlock *Nucleus::getInsertBlock() |
| 645 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 646 | return B(::basicBlock); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | void Nucleus::setInsertBlock(BasicBlock *basicBlock) |
| 650 | { |
Nicolas Capens | 9ed1a18 | 2016-10-24 09:52:23 -0400 | [diff] [blame] | 651 | // 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] | 652 | ::basicBlock = basicBlock; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 653 | } |
| 654 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 655 | void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params) |
| 656 | { |
| 657 | uint32_t sequenceNumber = 0; |
| 658 | ::function = Ice::Cfg::create(::context, sequenceNumber).release(); |
| 659 | ::allocator = new Ice::CfgLocalAllocatorScope(::function); |
| 660 | |
| 661 | for(Type *type : Params) |
| 662 | { |
| 663 | Ice::Variable *arg = ::function->makeVariable(T(type)); |
| 664 | ::function->addArg(arg); |
| 665 | } |
| 666 | |
| 667 | Ice::CfgNode *node = ::function->makeNode(); |
| 668 | ::function->setEntryNode(node); |
| 669 | ::basicBlock = node; |
| 670 | } |
| 671 | |
| 672 | Value *Nucleus::getArgument(unsigned int index) |
| 673 | { |
| 674 | return V(::function->getArgs()[index]); |
| 675 | } |
| 676 | |
| 677 | void Nucleus::createRetVoid() |
| 678 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 679 | Ice::InstRet *ret = Ice::InstRet::create(::function); |
| 680 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | void Nucleus::createRet(Value *v) |
| 684 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 685 | Ice::InstRet *ret = Ice::InstRet::create(::function, v); |
| 686 | ::basicBlock->appendInst(ret); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | void Nucleus::createBr(BasicBlock *dest) |
| 690 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 691 | auto br = Ice::InstBr::create(::function, dest); |
| 692 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse) |
| 696 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 697 | auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse); |
| 698 | ::basicBlock->appendInst(br); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 699 | } |
| 700 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 701 | static bool isCommutative(Ice::InstArithmetic::OpKind op) |
| 702 | { |
| 703 | switch(op) |
| 704 | { |
| 705 | case Ice::InstArithmetic::Add: |
| 706 | case Ice::InstArithmetic::Fadd: |
| 707 | case Ice::InstArithmetic::Mul: |
| 708 | case Ice::InstArithmetic::Fmul: |
| 709 | case Ice::InstArithmetic::And: |
| 710 | case Ice::InstArithmetic::Or: |
| 711 | case Ice::InstArithmetic::Xor: |
| 712 | return true; |
| 713 | default: |
| 714 | return false; |
| 715 | } |
| 716 | } |
| 717 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 718 | static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs) |
| 719 | { |
Nicolas Capens | b64e0ce | 2018-01-26 01:24:57 +0000 | [diff] [blame] | 720 | assert(lhs->getType() == rhs->getType() || llvm::isa<Ice::Constant>(rhs)); |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 721 | |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 722 | bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op); |
| 723 | |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 724 | Ice::Variable *result = ::function->makeVariable(lhs->getType()); |
Nicolas Capens | f8360ba | 2017-01-25 11:35:00 -0800 | [diff] [blame] | 725 | 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] | 726 | ::basicBlock->appendInst(arithmetic); |
| 727 | |
| 728 | return V(result); |
| 729 | } |
| 730 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 731 | Value *Nucleus::createAdd(Value *lhs, Value *rhs) |
| 732 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 733 | return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | Value *Nucleus::createSub(Value *lhs, Value *rhs) |
| 737 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 738 | return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | Value *Nucleus::createMul(Value *lhs, Value *rhs) |
| 742 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 743 | return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | Value *Nucleus::createUDiv(Value *lhs, Value *rhs) |
| 747 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 748 | return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | Value *Nucleus::createSDiv(Value *lhs, Value *rhs) |
| 752 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 753 | return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | Value *Nucleus::createFAdd(Value *lhs, Value *rhs) |
| 757 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 758 | return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | Value *Nucleus::createFSub(Value *lhs, Value *rhs) |
| 762 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 763 | return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | Value *Nucleus::createFMul(Value *lhs, Value *rhs) |
| 767 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 768 | return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | Value *Nucleus::createFDiv(Value *lhs, Value *rhs) |
| 772 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 773 | return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | Value *Nucleus::createURem(Value *lhs, Value *rhs) |
| 777 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 778 | return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | Value *Nucleus::createSRem(Value *lhs, Value *rhs) |
| 782 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 783 | return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | Value *Nucleus::createFRem(Value *lhs, Value *rhs) |
| 787 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 788 | return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | Value *Nucleus::createShl(Value *lhs, Value *rhs) |
| 792 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 793 | return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | Value *Nucleus::createLShr(Value *lhs, Value *rhs) |
| 797 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 798 | return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | Value *Nucleus::createAShr(Value *lhs, Value *rhs) |
| 802 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 803 | return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | Value *Nucleus::createAnd(Value *lhs, Value *rhs) |
| 807 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 808 | return createArithmetic(Ice::InstArithmetic::And, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | Value *Nucleus::createOr(Value *lhs, Value *rhs) |
| 812 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 813 | return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | Value *Nucleus::createXor(Value *lhs, Value *rhs) |
| 817 | { |
Nicolas Capens | 7d9f76d | 2016-09-29 13:39:44 -0400 | [diff] [blame] | 818 | return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | Value *Nucleus::createNeg(Value *v) |
| 822 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 823 | return createSub(createNullValue(T(v->getType())), v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | Value *Nucleus::createFNeg(Value *v) |
| 827 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 828 | double c[4] = {-0.0, -0.0, -0.0, -0.0}; |
| 829 | Value *negativeZero = Ice::isVectorType(v->getType()) ? |
| 830 | createConstantVector(c, T(v->getType())) : |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 831 | V(::context->getConstantFloat(-0.0f)); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 832 | |
| 833 | return createFSub(negativeZero, v); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | Value *Nucleus::createNot(Value *v) |
| 837 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 838 | if(Ice::isScalarIntegerType(v->getType())) |
| 839 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 840 | return createXor(v, V(::context->getConstantInt(v->getType(), -1))); |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 841 | } |
| 842 | else // Vector |
| 843 | { |
Nicolas Capens | f34d1ac | 2017-05-08 17:06:11 -0400 | [diff] [blame] | 844 | 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] | 845 | return createXor(v, createConstantVector(c, T(v->getType()))); |
| 846 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 847 | } |
| 848 | |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 849 | Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 850 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 851 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 852 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 853 | |
Nicolas Capens | f4c4eca | 2017-10-03 14:26:07 -0400 | [diff] [blame] | 854 | if((valueType & EmulatedBits) && (align != 0)) // Narrow vector not stored on stack. |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 855 | { |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 856 | if(emulateIntrinsics) |
| 857 | { |
| 858 | if(typeSize(type) == 4) |
| 859 | { |
| 860 | auto pointer = RValue<Pointer<Byte>>(ptr); |
Nicolas Capens | 1894cfa | 2017-07-27 14:21:46 -0400 | [diff] [blame] | 861 | Int x = *Pointer<Int>(pointer); |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 862 | |
| 863 | Int4 vector; |
| 864 | vector = Insert(vector, x, 0); |
| 865 | |
| 866 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue()); |
| 867 | ::basicBlock->appendInst(bitcast); |
| 868 | } |
| 869 | else if(typeSize(type) == 8) |
| 870 | { |
| 871 | auto pointer = RValue<Pointer<Byte>>(ptr); |
Nicolas Capens | 1894cfa | 2017-07-27 14:21:46 -0400 | [diff] [blame] | 872 | Int x = *Pointer<Int>(pointer); |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 873 | Int y = *Pointer<Int>(pointer + 4); |
| 874 | |
| 875 | Int4 vector; |
| 876 | vector = Insert(vector, x, 0); |
| 877 | vector = Insert(vector, y, 1); |
| 878 | |
| 879 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue()); |
| 880 | ::basicBlock->appendInst(bitcast); |
| 881 | } |
| 882 | else assert(false); |
| 883 | } |
| 884 | else |
| 885 | { |
| 886 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 887 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 888 | auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 889 | load->addArg(ptr); |
| 890 | load->addArg(::context->getConstantInt32(typeSize(type))); |
| 891 | ::basicBlock->appendInst(load); |
| 892 | } |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 893 | } |
| 894 | else |
| 895 | { |
| 896 | auto load = Ice::InstLoad::create(::function, result, ptr, align); |
| 897 | ::basicBlock->appendInst(load); |
| 898 | } |
| 899 | |
| 900 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 901 | } |
| 902 | |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 903 | 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] | 904 | { |
Nicolas Capens | 6a990f8 | 2018-07-06 15:54:07 -0400 | [diff] [blame] | 905 | #if __has_feature(memory_sanitizer) |
| 906 | // Mark all (non-stack) memory writes as initialized by calling __msan_unpoison |
| 907 | if(align != 0) |
| 908 | { |
| 909 | auto call = Ice::InstCall::create(::function, 2, nullptr, ::context->getConstantInt64(reinterpret_cast<intptr_t>(__msan_unpoison)), false); |
| 910 | call->addArg(ptr); |
| 911 | call->addArg(::context->getConstantInt64(typeSize(type))); |
| 912 | ::basicBlock->appendInst(call); |
| 913 | } |
| 914 | #endif |
| 915 | |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 916 | int valueType = (int)reinterpret_cast<intptr_t>(type); |
| 917 | |
Nicolas Capens | f4c4eca | 2017-10-03 14:26:07 -0400 | [diff] [blame] | 918 | if((valueType & EmulatedBits) && (align != 0)) // Narrow vector not stored on stack. |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 919 | { |
Nicolas Capens | 070d9f4 | 2017-04-26 13:36:33 -0400 | [diff] [blame] | 920 | if(emulateIntrinsics) |
| 921 | { |
| 922 | if(typeSize(type) == 4) |
| 923 | { |
| 924 | Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32); |
| 925 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value); |
| 926 | ::basicBlock->appendInst(bitcast); |
| 927 | |
| 928 | RValue<Int4> v(V(vector)); |
| 929 | |
| 930 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 931 | Int x = Extract(v, 0); |
| 932 | *Pointer<Int>(pointer) = x; |
| 933 | } |
| 934 | else if(typeSize(type) == 8) |
| 935 | { |
| 936 | Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32); |
| 937 | auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value); |
| 938 | ::basicBlock->appendInst(bitcast); |
| 939 | |
| 940 | RValue<Int4> v(V(vector)); |
| 941 | |
| 942 | auto pointer = RValue<Pointer<Byte>>(ptr); |
| 943 | Int x = Extract(v, 0); |
| 944 | *Pointer<Int>(pointer) = x; |
| 945 | Int y = Extract(v, 1); |
| 946 | *Pointer<Int>(pointer + 4) = y; |
| 947 | } |
| 948 | else assert(false); |
| 949 | } |
| 950 | else |
| 951 | { |
| 952 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; |
| 953 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 954 | auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic); |
| 955 | store->addArg(value); |
| 956 | store->addArg(ptr); |
| 957 | store->addArg(::context->getConstantInt32(typeSize(type))); |
| 958 | ::basicBlock->appendInst(store); |
| 959 | } |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 960 | } |
| 961 | else |
| 962 | { |
Nicolas Capens | f4c4eca | 2017-10-03 14:26:07 -0400 | [diff] [blame] | 963 | assert(value->getType() == T(type)); |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 964 | |
| 965 | auto store = Ice::InstStore::create(::function, value, ptr, align); |
| 966 | ::basicBlock->appendInst(store); |
| 967 | } |
| 968 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 969 | return value; |
| 970 | } |
| 971 | |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 972 | Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 973 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 974 | assert(index->getType() == Ice::IceType_i32); |
| 975 | |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 976 | if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) |
| 977 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 978 | int32_t offset = constant->getValue() * (int)typeSize(type); |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 979 | |
| 980 | if(offset == 0) |
| 981 | { |
| 982 | return ptr; |
| 983 | } |
| 984 | |
| 985 | return createAdd(ptr, createConstantInt(offset)); |
| 986 | } |
| 987 | |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 988 | if(!Ice::isByteSizedType(T(type))) |
| 989 | { |
Nicolas Capens | 584088c | 2017-01-26 16:05:18 -0800 | [diff] [blame] | 990 | index = createMul(index, createConstantInt((int)typeSize(type))); |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | if(sizeof(void*) == 8) |
| 994 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 995 | if(unsignedIndex) |
| 996 | { |
| 997 | index = createZExt(index, T(Ice::IceType_i64)); |
| 998 | } |
| 999 | else |
| 1000 | { |
| 1001 | index = createSExt(index, T(Ice::IceType_i64)); |
| 1002 | } |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | return createAdd(ptr, index); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) |
| 1009 | { |
| 1010 | assert(false && "UNIMPLEMENTED"); return nullptr; |
| 1011 | } |
| 1012 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1013 | static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType) |
| 1014 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 1015 | if(v->getType() == T(destType)) |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1016 | { |
| 1017 | return v; |
| 1018 | } |
| 1019 | |
| 1020 | Ice::Variable *result = ::function->makeVariable(T(destType)); |
| 1021 | Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v); |
| 1022 | ::basicBlock->appendInst(cast); |
| 1023 | |
| 1024 | return V(result); |
| 1025 | } |
| 1026 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1027 | Value *Nucleus::createTrunc(Value *v, Type *destType) |
| 1028 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1029 | return createCast(Ice::InstCast::Trunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | Value *Nucleus::createZExt(Value *v, Type *destType) |
| 1033 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1034 | return createCast(Ice::InstCast::Zext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | Value *Nucleus::createSExt(Value *v, Type *destType) |
| 1038 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1039 | return createCast(Ice::InstCast::Sext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | Value *Nucleus::createFPToSI(Value *v, Type *destType) |
| 1043 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1044 | return createCast(Ice::InstCast::Fptosi, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1047 | Value *Nucleus::createSIToFP(Value *v, Type *destType) |
| 1048 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1049 | return createCast(Ice::InstCast::Sitofp, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | Value *Nucleus::createFPTrunc(Value *v, Type *destType) |
| 1053 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1054 | return createCast(Ice::InstCast::Fptrunc, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | Value *Nucleus::createFPExt(Value *v, Type *destType) |
| 1058 | { |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1059 | return createCast(Ice::InstCast::Fpext, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | Value *Nucleus::createBitCast(Value *v, Type *destType) |
| 1063 | { |
Nicolas Capens | 2d8c370 | 2017-07-25 13:56:46 -0400 | [diff] [blame] | 1064 | // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need |
| 1065 | // support for casting between scalars and wide vectors. For platforms where this is not supported, |
| 1066 | // emulate them by writing to the stack and reading back as the destination type. |
| 1067 | if(emulateMismatchedBitCast) |
| 1068 | { |
| 1069 | if(!Ice::isVectorType(v->getType()) && Ice::isVectorType(T(destType))) |
| 1070 | { |
| 1071 | Value *address = allocateStackVariable(destType); |
| 1072 | createStore(v, address, T(v->getType())); |
| 1073 | return createLoad(address, destType); |
| 1074 | } |
| 1075 | else if(Ice::isVectorType(v->getType()) && !Ice::isVectorType(T(destType))) |
| 1076 | { |
| 1077 | Value *address = allocateStackVariable(T(v->getType())); |
| 1078 | createStore(v, address, T(v->getType())); |
| 1079 | return createLoad(address, destType); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Nicolas Capens | a0c2fc5 | 2016-09-30 05:04:21 -0400 | [diff] [blame] | 1083 | return createCast(Ice::InstCast::Bitcast, v, destType); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1086 | static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1087 | { |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1088 | assert(lhs->getType() == rhs->getType()); |
| 1089 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1090 | auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType()); |
| 1091 | auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs); |
Nicolas Capens | 611642a | 2016-09-28 16:45:04 -0400 | [diff] [blame] | 1092 | ::basicBlock->appendInst(cmp); |
| 1093 | |
| 1094 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1097 | Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs) |
| 1098 | { |
| 1099 | return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs); |
| 1100 | } |
| 1101 | |
| 1102 | Value *Nucleus::createICmpNE(Value *lhs, Value *rhs) |
| 1103 | { |
| 1104 | return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs); |
| 1105 | } |
| 1106 | |
| 1107 | Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs) |
| 1108 | { |
| 1109 | return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs); |
| 1110 | } |
| 1111 | |
| 1112 | Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs) |
| 1113 | { |
| 1114 | return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs); |
| 1115 | } |
| 1116 | |
| 1117 | Value *Nucleus::createICmpULT(Value *lhs, Value *rhs) |
| 1118 | { |
| 1119 | return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs); |
| 1120 | } |
| 1121 | |
| 1122 | Value *Nucleus::createICmpULE(Value *lhs, Value *rhs) |
| 1123 | { |
| 1124 | return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs); |
| 1125 | } |
| 1126 | |
| 1127 | Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs) |
| 1128 | { |
| 1129 | return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs); |
| 1130 | } |
| 1131 | |
| 1132 | Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs) |
| 1133 | { |
| 1134 | return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs); |
| 1135 | } |
| 1136 | |
| 1137 | Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs) |
| 1138 | { |
| 1139 | return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs); |
| 1140 | } |
| 1141 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1142 | Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs) |
| 1143 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1144 | return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs); |
| 1145 | } |
| 1146 | |
| 1147 | static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs) |
| 1148 | { |
| 1149 | assert(lhs->getType() == rhs->getType()); |
| 1150 | assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32); |
| 1151 | |
| 1152 | auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32); |
| 1153 | auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs); |
| 1154 | ::basicBlock->appendInst(cmp); |
| 1155 | |
| 1156 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs) |
| 1160 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1161 | return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs) |
| 1165 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1166 | return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs) |
| 1170 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1171 | return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs) |
| 1175 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1176 | return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs) |
| 1180 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1181 | return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs) |
| 1185 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1186 | return createFloatCompare(Ice::InstFcmp::One, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs) |
| 1190 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1191 | return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs) |
| 1195 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1196 | return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs) |
| 1200 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1201 | return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs) |
| 1205 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1206 | return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs) |
| 1210 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1211 | return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs) |
| 1215 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1216 | return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs) |
| 1220 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1221 | return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs) |
| 1225 | { |
Nicolas Capens | 43dc629 | 2016-10-20 00:01:38 -0400 | [diff] [blame] | 1226 | return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1227 | } |
| 1228 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1229 | Value *Nucleus::createExtractElement(Value *vector, Type *type, int index) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1230 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1231 | auto result = ::function->makeVariable(T(type)); |
| 1232 | auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index)); |
| 1233 | ::basicBlock->appendInst(extract); |
| 1234 | |
| 1235 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | Value *Nucleus::createInsertElement(Value *vector, Value *element, int index) |
| 1239 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1240 | auto result = ::function->makeVariable(vector->getType()); |
| 1241 | auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index)); |
| 1242 | ::basicBlock->appendInst(insert); |
| 1243 | |
| 1244 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
Nicolas Capens | e89cd58 | 2016-09-30 14:23:47 -0400 | [diff] [blame] | 1247 | Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1248 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1249 | assert(V1->getType() == V2->getType()); |
| 1250 | |
| 1251 | int size = Ice::typeNumElements(V1->getType()); |
| 1252 | auto result = ::function->makeVariable(V1->getType()); |
| 1253 | auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2); |
| 1254 | |
| 1255 | for(int i = 0; i < size; i++) |
| 1256 | { |
| 1257 | shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i]))); |
| 1258 | } |
| 1259 | |
| 1260 | ::basicBlock->appendInst(shuffle); |
| 1261 | |
| 1262 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse) |
| 1266 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 1267 | assert(ifTrue->getType() == ifFalse->getType()); |
| 1268 | |
| 1269 | auto result = ::function->makeVariable(ifTrue->getType()); |
| 1270 | auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse); |
| 1271 | ::basicBlock->appendInst(select); |
| 1272 | |
| 1273 | return V(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1274 | } |
| 1275 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1276 | SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1277 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1278 | auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch); |
| 1279 | ::basicBlock->appendInst(switchInst); |
| 1280 | |
| 1281 | return reinterpret_cast<SwitchCases*>(switchInst); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1282 | } |
| 1283 | |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1284 | void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1285 | { |
Nicolas Capens | b98fe5c | 2016-11-09 12:24:06 -0500 | [diff] [blame] | 1286 | switchCases->addBranch(label, label, branch); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | void Nucleus::createUnreachable() |
| 1290 | { |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 1291 | Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function); |
| 1292 | ::basicBlock->appendInst(unreachable); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1295 | static Value *createSwizzle4(Value *val, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1296 | { |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1297 | int swizzle[4] = |
| 1298 | { |
| 1299 | (select >> 0) & 0x03, |
| 1300 | (select >> 2) & 0x03, |
| 1301 | (select >> 4) & 0x03, |
| 1302 | (select >> 6) & 0x03, |
| 1303 | }; |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 1304 | |
Nicolas Capens | 619c0ab | 2016-09-30 14:46:24 -0400 | [diff] [blame] | 1305 | return Nucleus::createShuffleVector(val, val, swizzle); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1306 | } |
| 1307 | |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 1308 | static Value *createMask4(Value *lhs, Value *rhs, unsigned char select) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1309 | { |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1310 | int64_t mask[4] = {0, 0, 0, 0}; |
| 1311 | |
| 1312 | mask[(select >> 0) & 0x03] = -1; |
| 1313 | mask[(select >> 2) & 0x03] = -1; |
| 1314 | mask[(select >> 4) & 0x03] = -1; |
| 1315 | mask[(select >> 6) & 0x03] = -1; |
| 1316 | |
| 1317 | Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1)); |
| 1318 | Value *result = Nucleus::createSelect(condition, rhs, lhs); |
| 1319 | |
| 1320 | return result; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1321 | } |
| 1322 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1323 | Type *Nucleus::getPointerType(Type *ElementType) |
| 1324 | { |
Nicolas Capens | e12780d | 2016-09-27 14:18:07 -0400 | [diff] [blame] | 1325 | if(sizeof(void*) == 8) |
| 1326 | { |
| 1327 | return T(Ice::IceType_i64); |
| 1328 | } |
| 1329 | else |
| 1330 | { |
| 1331 | return T(Ice::IceType_i32); |
| 1332 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1333 | } |
| 1334 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1335 | Value *Nucleus::createNullValue(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1336 | { |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1337 | if(Ice::isVectorType(T(Ty))) |
| 1338 | { |
Nicolas Capens | 30385f0 | 2017-04-18 13:03:47 -0400 | [diff] [blame] | 1339 | assert(Ice::typeNumElements(T(Ty)) <= 16); |
| 1340 | 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] | 1341 | return createConstantVector(c, Ty); |
| 1342 | } |
| 1343 | else |
| 1344 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1345 | return V(::context->getConstantZero(T(Ty))); |
Nicolas Capens | 73dd7a2 | 2016-10-20 13:20:34 -0400 | [diff] [blame] | 1346 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1349 | Value *Nucleus::createConstantLong(int64_t i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1350 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1351 | return V(::context->getConstantInt64(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1354 | Value *Nucleus::createConstantInt(int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1355 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1356 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1357 | } |
| 1358 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1359 | Value *Nucleus::createConstantInt(unsigned int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1360 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1361 | return V(::context->getConstantInt32(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1362 | } |
| 1363 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1364 | Value *Nucleus::createConstantBool(bool b) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1365 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1366 | return V(::context->getConstantInt1(b)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1367 | } |
| 1368 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1369 | Value *Nucleus::createConstantByte(signed char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1370 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1371 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1372 | } |
| 1373 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1374 | Value *Nucleus::createConstantByte(unsigned char i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1375 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1376 | return V(::context->getConstantInt8(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1379 | Value *Nucleus::createConstantShort(short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1380 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1381 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1382 | } |
| 1383 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1384 | Value *Nucleus::createConstantShort(unsigned short i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1385 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1386 | return V(::context->getConstantInt16(i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1389 | Value *Nucleus::createConstantFloat(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1390 | { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 1391 | return V(::context->getConstantFloat(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1394 | Value *Nucleus::createNullPointer(Type *Ty) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1395 | { |
Nicolas Capens | a29d653 | 2016-12-05 21:38:09 -0500 | [diff] [blame] | 1396 | return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1397 | } |
| 1398 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1399 | Value *Nucleus::createConstantVector(const int64_t *constants, Type *type) |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1400 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1401 | const int vectorSize = 16; |
| 1402 | assert(Ice::typeWidthInBytes(T(type)) == vectorSize); |
| 1403 | const int alignment = vectorSize; |
| 1404 | auto globalPool = ::function->getGlobalPool(); |
| 1405 | |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1406 | const int64_t *i = constants; |
| 1407 | const double *f = reinterpret_cast<const double*>(constants); |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1408 | Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr; |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1409 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1410 | switch((int)reinterpret_cast<intptr_t>(type)) |
| 1411 | { |
| 1412 | case Ice::IceType_v4i32: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1413 | case Ice::IceType_v4i1: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1414 | { |
| 1415 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]}; |
| 1416 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1417 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1418 | } |
| 1419 | break; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1420 | case Ice::IceType_v4f32: |
| 1421 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1422 | 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] | 1423 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1424 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1425 | } |
| 1426 | break; |
| 1427 | case Ice::IceType_v8i16: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1428 | case Ice::IceType_v8i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1429 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1430 | 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] | 1431 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1432 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1433 | } |
| 1434 | break; |
| 1435 | case Ice::IceType_v16i8: |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 1436 | case Ice::IceType_v16i1: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1437 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1438 | 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] | 1439 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1440 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1441 | } |
| 1442 | break; |
| 1443 | case Type_v2i32: |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1444 | { |
| 1445 | const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]}; |
| 1446 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1447 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1448 | } |
| 1449 | break; |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1450 | case Type_v2f32: |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1451 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1452 | 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] | 1453 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1454 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1455 | } |
| 1456 | break; |
| 1457 | case Type_v4i16: |
| 1458 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1459 | 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] | 1460 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1461 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1462 | } |
| 1463 | break; |
| 1464 | case Type_v8i8: |
| 1465 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1466 | const char initializer[16] = {(char)i[0], (char)i[1], (char)i[2], (char)i[3], (char)i[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] | 1467 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1468 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1469 | } |
| 1470 | break; |
| 1471 | case Type_v4i8: |
| 1472 | { |
Nicolas Capens | 7f3f69c | 2016-10-20 01:29:33 -0400 | [diff] [blame] | 1473 | 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] | 1474 | static_assert(sizeof(initializer) == vectorSize, "!"); |
| 1475 | dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize); |
| 1476 | } |
| 1477 | break; |
| 1478 | default: |
| 1479 | assert(false && "Unknown constant vector type" && type); |
| 1480 | } |
| 1481 | |
| 1482 | auto name = Ice::GlobalString::createWithoutString(::context); |
| 1483 | auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool); |
| 1484 | variableDeclaration->setName(name); |
| 1485 | variableDeclaration->setAlignment(alignment); |
| 1486 | variableDeclaration->setIsConstant(true); |
| 1487 | variableDeclaration->addInitializer(dataInitializer); |
Nicolas Capens | 87852e1 | 2016-11-24 14:45:06 -0500 | [diff] [blame] | 1488 | |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1489 | ::function->addGlobal(variableDeclaration); |
| 1490 | |
| 1491 | constexpr int32_t offset = 0; |
| 1492 | Ice::Operand *ptr = ::context->getConstantSym(offset, name); |
| 1493 | |
| 1494 | Ice::Variable *result = ::function->makeVariable(T(type)); |
| 1495 | auto load = Ice::InstLoad::create(::function, result, ptr, alignment); |
| 1496 | ::basicBlock->appendInst(load); |
| 1497 | |
| 1498 | return V(result); |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | Value *Nucleus::createConstantVector(const double *constants, Type *type) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1502 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 1503 | return createConstantVector((const int64_t*)constants, type); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | Type *Void::getType() |
| 1507 | { |
| 1508 | return T(Ice::IceType_void); |
| 1509 | } |
| 1510 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1511 | Bool::Bool(Argument<Bool> argument) |
| 1512 | { |
| 1513 | storeValue(argument.value); |
| 1514 | } |
| 1515 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1516 | Bool::Bool(bool x) |
| 1517 | { |
| 1518 | storeValue(Nucleus::createConstantBool(x)); |
| 1519 | } |
| 1520 | |
| 1521 | Bool::Bool(RValue<Bool> rhs) |
| 1522 | { |
| 1523 | storeValue(rhs.value); |
| 1524 | } |
| 1525 | |
| 1526 | Bool::Bool(const Bool &rhs) |
| 1527 | { |
| 1528 | Value *value = rhs.loadValue(); |
| 1529 | storeValue(value); |
| 1530 | } |
| 1531 | |
| 1532 | Bool::Bool(const Reference<Bool> &rhs) |
| 1533 | { |
| 1534 | Value *value = rhs.loadValue(); |
| 1535 | storeValue(value); |
| 1536 | } |
| 1537 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1538 | RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1539 | { |
| 1540 | storeValue(rhs.value); |
| 1541 | |
| 1542 | return rhs; |
| 1543 | } |
| 1544 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1545 | RValue<Bool> Bool::operator=(const Bool &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<Bool>(value); |
| 1551 | } |
| 1552 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1553 | RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1554 | { |
| 1555 | Value *value = rhs.loadValue(); |
| 1556 | storeValue(value); |
| 1557 | |
| 1558 | return RValue<Bool>(value); |
| 1559 | } |
| 1560 | |
| 1561 | RValue<Bool> operator!(RValue<Bool> val) |
| 1562 | { |
| 1563 | return RValue<Bool>(Nucleus::createNot(val.value)); |
| 1564 | } |
| 1565 | |
| 1566 | RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1567 | { |
| 1568 | return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1569 | } |
| 1570 | |
| 1571 | RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| 1572 | { |
| 1573 | return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1574 | } |
| 1575 | |
| 1576 | Type *Bool::getType() |
| 1577 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 1578 | return T(Ice::IceType_i1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | Byte::Byte(Argument<Byte> argument) |
| 1582 | { |
| 1583 | storeValue(argument.value); |
| 1584 | } |
| 1585 | |
| 1586 | Byte::Byte(RValue<Int> cast) |
| 1587 | { |
| 1588 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1589 | |
| 1590 | storeValue(integer); |
| 1591 | } |
| 1592 | |
| 1593 | Byte::Byte(RValue<UInt> cast) |
| 1594 | { |
| 1595 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1596 | |
| 1597 | storeValue(integer); |
| 1598 | } |
| 1599 | |
| 1600 | Byte::Byte(RValue<UShort> cast) |
| 1601 | { |
| 1602 | Value *integer = Nucleus::createTrunc(cast.value, Byte::getType()); |
| 1603 | |
| 1604 | storeValue(integer); |
| 1605 | } |
| 1606 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1607 | Byte::Byte(int x) |
| 1608 | { |
| 1609 | storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| 1610 | } |
| 1611 | |
| 1612 | Byte::Byte(unsigned char x) |
| 1613 | { |
| 1614 | storeValue(Nucleus::createConstantByte(x)); |
| 1615 | } |
| 1616 | |
| 1617 | Byte::Byte(RValue<Byte> rhs) |
| 1618 | { |
| 1619 | storeValue(rhs.value); |
| 1620 | } |
| 1621 | |
| 1622 | Byte::Byte(const Byte &rhs) |
| 1623 | { |
| 1624 | Value *value = rhs.loadValue(); |
| 1625 | storeValue(value); |
| 1626 | } |
| 1627 | |
| 1628 | Byte::Byte(const Reference<Byte> &rhs) |
| 1629 | { |
| 1630 | Value *value = rhs.loadValue(); |
| 1631 | storeValue(value); |
| 1632 | } |
| 1633 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1634 | RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1635 | { |
| 1636 | storeValue(rhs.value); |
| 1637 | |
| 1638 | return rhs; |
| 1639 | } |
| 1640 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1641 | RValue<Byte> Byte::operator=(const Byte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1642 | { |
| 1643 | Value *value = rhs.loadValue(); |
| 1644 | storeValue(value); |
| 1645 | |
| 1646 | return RValue<Byte>(value); |
| 1647 | } |
| 1648 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1649 | RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1650 | { |
| 1651 | Value *value = rhs.loadValue(); |
| 1652 | storeValue(value); |
| 1653 | |
| 1654 | return RValue<Byte>(value); |
| 1655 | } |
| 1656 | |
| 1657 | RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1658 | { |
| 1659 | return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1660 | } |
| 1661 | |
| 1662 | RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1663 | { |
| 1664 | return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1665 | } |
| 1666 | |
| 1667 | RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1668 | { |
| 1669 | return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1670 | } |
| 1671 | |
| 1672 | RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1673 | { |
| 1674 | return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 1675 | } |
| 1676 | |
| 1677 | RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1678 | { |
| 1679 | return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value)); |
| 1680 | } |
| 1681 | |
| 1682 | RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1683 | { |
| 1684 | return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1685 | } |
| 1686 | |
| 1687 | RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1688 | { |
| 1689 | return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1690 | } |
| 1691 | |
| 1692 | RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1693 | { |
| 1694 | return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1695 | } |
| 1696 | |
| 1697 | RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1698 | { |
| 1699 | return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1700 | } |
| 1701 | |
| 1702 | RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1703 | { |
| 1704 | return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 1705 | } |
| 1706 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1707 | RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1708 | { |
| 1709 | return lhs = lhs + rhs; |
| 1710 | } |
| 1711 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1712 | RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1713 | { |
| 1714 | return lhs = lhs - rhs; |
| 1715 | } |
| 1716 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1717 | RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1718 | { |
| 1719 | return lhs = lhs * rhs; |
| 1720 | } |
| 1721 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1722 | RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1723 | { |
| 1724 | return lhs = lhs / rhs; |
| 1725 | } |
| 1726 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1727 | RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1728 | { |
| 1729 | return lhs = lhs % rhs; |
| 1730 | } |
| 1731 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1732 | RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1733 | { |
| 1734 | return lhs = lhs & rhs; |
| 1735 | } |
| 1736 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1737 | RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1738 | { |
| 1739 | return lhs = lhs | rhs; |
| 1740 | } |
| 1741 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1742 | RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1743 | { |
| 1744 | return lhs = lhs ^ rhs; |
| 1745 | } |
| 1746 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1747 | RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1748 | { |
| 1749 | return lhs = lhs << rhs; |
| 1750 | } |
| 1751 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1752 | RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1753 | { |
| 1754 | return lhs = lhs >> rhs; |
| 1755 | } |
| 1756 | |
| 1757 | RValue<Byte> operator+(RValue<Byte> val) |
| 1758 | { |
| 1759 | return val; |
| 1760 | } |
| 1761 | |
| 1762 | RValue<Byte> operator-(RValue<Byte> val) |
| 1763 | { |
| 1764 | return RValue<Byte>(Nucleus::createNeg(val.value)); |
| 1765 | } |
| 1766 | |
| 1767 | RValue<Byte> operator~(RValue<Byte> val) |
| 1768 | { |
| 1769 | return RValue<Byte>(Nucleus::createNot(val.value)); |
| 1770 | } |
| 1771 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1772 | RValue<Byte> operator++(Byte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1773 | { |
| 1774 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1775 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1776 | return res; |
| 1777 | } |
| 1778 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1779 | const Byte &operator++(Byte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1780 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1781 | val += Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1782 | return val; |
| 1783 | } |
| 1784 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1785 | RValue<Byte> operator--(Byte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1786 | { |
| 1787 | RValue<Byte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1788 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1789 | return res; |
| 1790 | } |
| 1791 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1792 | const Byte &operator--(Byte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1793 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 1794 | val -= Byte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1795 | return val; |
| 1796 | } |
| 1797 | |
| 1798 | RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1799 | { |
| 1800 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 1801 | } |
| 1802 | |
| 1803 | RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1804 | { |
| 1805 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 1806 | } |
| 1807 | |
| 1808 | RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1809 | { |
| 1810 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 1811 | } |
| 1812 | |
| 1813 | RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1814 | { |
| 1815 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 1816 | } |
| 1817 | |
| 1818 | RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1819 | { |
| 1820 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 1821 | } |
| 1822 | |
| 1823 | RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| 1824 | { |
| 1825 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 1826 | } |
| 1827 | |
| 1828 | Type *Byte::getType() |
| 1829 | { |
Nicolas Capens | 6d73871 | 2016-09-30 04:15:22 -0400 | [diff] [blame] | 1830 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | SByte::SByte(Argument<SByte> argument) |
| 1834 | { |
| 1835 | storeValue(argument.value); |
| 1836 | } |
| 1837 | |
| 1838 | SByte::SByte(RValue<Int> cast) |
| 1839 | { |
| 1840 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1841 | |
| 1842 | storeValue(integer); |
| 1843 | } |
| 1844 | |
| 1845 | SByte::SByte(RValue<Short> cast) |
| 1846 | { |
| 1847 | Value *integer = Nucleus::createTrunc(cast.value, SByte::getType()); |
| 1848 | |
| 1849 | storeValue(integer); |
| 1850 | } |
| 1851 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1852 | SByte::SByte(signed char x) |
| 1853 | { |
| 1854 | storeValue(Nucleus::createConstantByte(x)); |
| 1855 | } |
| 1856 | |
| 1857 | SByte::SByte(RValue<SByte> rhs) |
| 1858 | { |
| 1859 | storeValue(rhs.value); |
| 1860 | } |
| 1861 | |
| 1862 | SByte::SByte(const SByte &rhs) |
| 1863 | { |
| 1864 | Value *value = rhs.loadValue(); |
| 1865 | storeValue(value); |
| 1866 | } |
| 1867 | |
| 1868 | SByte::SByte(const Reference<SByte> &rhs) |
| 1869 | { |
| 1870 | Value *value = rhs.loadValue(); |
| 1871 | storeValue(value); |
| 1872 | } |
| 1873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1874 | RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1875 | { |
| 1876 | storeValue(rhs.value); |
| 1877 | |
| 1878 | return rhs; |
| 1879 | } |
| 1880 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1881 | RValue<SByte> SByte::operator=(const SByte &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1882 | { |
| 1883 | Value *value = rhs.loadValue(); |
| 1884 | storeValue(value); |
| 1885 | |
| 1886 | return RValue<SByte>(value); |
| 1887 | } |
| 1888 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1889 | RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1890 | { |
| 1891 | Value *value = rhs.loadValue(); |
| 1892 | storeValue(value); |
| 1893 | |
| 1894 | return RValue<SByte>(value); |
| 1895 | } |
| 1896 | |
| 1897 | RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1898 | { |
| 1899 | return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 1900 | } |
| 1901 | |
| 1902 | RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1903 | { |
| 1904 | return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value)); |
| 1905 | } |
| 1906 | |
| 1907 | RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1908 | { |
| 1909 | return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value)); |
| 1910 | } |
| 1911 | |
| 1912 | RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1913 | { |
| 1914 | return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 1915 | } |
| 1916 | |
| 1917 | RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1918 | { |
| 1919 | return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 1920 | } |
| 1921 | |
| 1922 | RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1923 | { |
| 1924 | return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 1925 | } |
| 1926 | |
| 1927 | RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1928 | { |
| 1929 | return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value)); |
| 1930 | } |
| 1931 | |
| 1932 | RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1933 | { |
| 1934 | return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value)); |
| 1935 | } |
| 1936 | |
| 1937 | RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1938 | { |
| 1939 | return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value)); |
| 1940 | } |
| 1941 | |
| 1942 | RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 1943 | { |
| 1944 | return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 1945 | } |
| 1946 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1947 | RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1948 | { |
| 1949 | return lhs = lhs + rhs; |
| 1950 | } |
| 1951 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1952 | RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1953 | { |
| 1954 | return lhs = lhs - rhs; |
| 1955 | } |
| 1956 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1957 | RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1958 | { |
| 1959 | return lhs = lhs * rhs; |
| 1960 | } |
| 1961 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1962 | RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1963 | { |
| 1964 | return lhs = lhs / rhs; |
| 1965 | } |
| 1966 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1967 | RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1968 | { |
| 1969 | return lhs = lhs % rhs; |
| 1970 | } |
| 1971 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1972 | RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1973 | { |
| 1974 | return lhs = lhs & rhs; |
| 1975 | } |
| 1976 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1977 | RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1978 | { |
| 1979 | return lhs = lhs | rhs; |
| 1980 | } |
| 1981 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1982 | RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1983 | { |
| 1984 | return lhs = lhs ^ rhs; |
| 1985 | } |
| 1986 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1987 | RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1988 | { |
| 1989 | return lhs = lhs << rhs; |
| 1990 | } |
| 1991 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 1992 | RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 1993 | { |
| 1994 | return lhs = lhs >> rhs; |
| 1995 | } |
| 1996 | |
| 1997 | RValue<SByte> operator+(RValue<SByte> val) |
| 1998 | { |
| 1999 | return val; |
| 2000 | } |
| 2001 | |
| 2002 | RValue<SByte> operator-(RValue<SByte> val) |
| 2003 | { |
| 2004 | return RValue<SByte>(Nucleus::createNeg(val.value)); |
| 2005 | } |
| 2006 | |
| 2007 | RValue<SByte> operator~(RValue<SByte> val) |
| 2008 | { |
| 2009 | return RValue<SByte>(Nucleus::createNot(val.value)); |
| 2010 | } |
| 2011 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2012 | RValue<SByte> operator++(SByte &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2013 | { |
| 2014 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2015 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2016 | return res; |
| 2017 | } |
| 2018 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2019 | const SByte &operator++(SByte &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2020 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2021 | val += SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2022 | return val; |
| 2023 | } |
| 2024 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2025 | RValue<SByte> operator--(SByte &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2026 | { |
| 2027 | RValue<SByte> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2028 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2029 | return res; |
| 2030 | } |
| 2031 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2032 | const SByte &operator--(SByte &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2033 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2034 | val -= SByte(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2035 | return val; |
| 2036 | } |
| 2037 | |
| 2038 | RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2039 | { |
| 2040 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2041 | } |
| 2042 | |
| 2043 | RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2044 | { |
| 2045 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2046 | } |
| 2047 | |
| 2048 | RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2049 | { |
| 2050 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2051 | } |
| 2052 | |
| 2053 | RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2054 | { |
| 2055 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2056 | } |
| 2057 | |
| 2058 | RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2059 | { |
| 2060 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2061 | } |
| 2062 | |
| 2063 | RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| 2064 | { |
| 2065 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2066 | } |
| 2067 | |
| 2068 | Type *SByte::getType() |
| 2069 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2070 | return T(Ice::IceType_i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | Short::Short(Argument<Short> argument) |
| 2074 | { |
| 2075 | storeValue(argument.value); |
| 2076 | } |
| 2077 | |
| 2078 | Short::Short(RValue<Int> cast) |
| 2079 | { |
| 2080 | Value *integer = Nucleus::createTrunc(cast.value, Short::getType()); |
| 2081 | |
| 2082 | storeValue(integer); |
| 2083 | } |
| 2084 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2085 | Short::Short(short x) |
| 2086 | { |
| 2087 | storeValue(Nucleus::createConstantShort(x)); |
| 2088 | } |
| 2089 | |
| 2090 | Short::Short(RValue<Short> rhs) |
| 2091 | { |
| 2092 | storeValue(rhs.value); |
| 2093 | } |
| 2094 | |
| 2095 | Short::Short(const Short &rhs) |
| 2096 | { |
| 2097 | Value *value = rhs.loadValue(); |
| 2098 | storeValue(value); |
| 2099 | } |
| 2100 | |
| 2101 | Short::Short(const Reference<Short> &rhs) |
| 2102 | { |
| 2103 | Value *value = rhs.loadValue(); |
| 2104 | storeValue(value); |
| 2105 | } |
| 2106 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2107 | RValue<Short> Short::operator=(RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2108 | { |
| 2109 | storeValue(rhs.value); |
| 2110 | |
| 2111 | return rhs; |
| 2112 | } |
| 2113 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2114 | RValue<Short> Short::operator=(const Short &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2115 | { |
| 2116 | Value *value = rhs.loadValue(); |
| 2117 | storeValue(value); |
| 2118 | |
| 2119 | return RValue<Short>(value); |
| 2120 | } |
| 2121 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2122 | RValue<Short> Short::operator=(const Reference<Short> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2123 | { |
| 2124 | Value *value = rhs.loadValue(); |
| 2125 | storeValue(value); |
| 2126 | |
| 2127 | return RValue<Short>(value); |
| 2128 | } |
| 2129 | |
| 2130 | RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| 2131 | { |
| 2132 | return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2133 | } |
| 2134 | |
| 2135 | RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| 2136 | { |
| 2137 | return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2138 | } |
| 2139 | |
| 2140 | RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| 2141 | { |
| 2142 | return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2143 | } |
| 2144 | |
| 2145 | RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| 2146 | { |
| 2147 | return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2148 | } |
| 2149 | |
| 2150 | RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| 2151 | { |
| 2152 | return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2153 | } |
| 2154 | |
| 2155 | RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| 2156 | { |
| 2157 | return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2158 | } |
| 2159 | |
| 2160 | RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| 2161 | { |
| 2162 | return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2163 | } |
| 2164 | |
| 2165 | RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| 2166 | { |
| 2167 | return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2168 | } |
| 2169 | |
| 2170 | RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| 2171 | { |
| 2172 | return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2173 | } |
| 2174 | |
| 2175 | RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| 2176 | { |
| 2177 | return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 2178 | } |
| 2179 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2180 | RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2181 | { |
| 2182 | return lhs = lhs + rhs; |
| 2183 | } |
| 2184 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2185 | RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2186 | { |
| 2187 | return lhs = lhs - rhs; |
| 2188 | } |
| 2189 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2190 | RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2191 | { |
| 2192 | return lhs = lhs * rhs; |
| 2193 | } |
| 2194 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2195 | RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2196 | { |
| 2197 | return lhs = lhs / rhs; |
| 2198 | } |
| 2199 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2200 | RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2201 | { |
| 2202 | return lhs = lhs % rhs; |
| 2203 | } |
| 2204 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2205 | RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2206 | { |
| 2207 | return lhs = lhs & rhs; |
| 2208 | } |
| 2209 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2210 | RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2211 | { |
| 2212 | return lhs = lhs | rhs; |
| 2213 | } |
| 2214 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2215 | RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2216 | { |
| 2217 | return lhs = lhs ^ rhs; |
| 2218 | } |
| 2219 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2220 | RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2221 | { |
| 2222 | return lhs = lhs << rhs; |
| 2223 | } |
| 2224 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2225 | RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2226 | { |
| 2227 | return lhs = lhs >> rhs; |
| 2228 | } |
| 2229 | |
| 2230 | RValue<Short> operator+(RValue<Short> val) |
| 2231 | { |
| 2232 | return val; |
| 2233 | } |
| 2234 | |
| 2235 | RValue<Short> operator-(RValue<Short> val) |
| 2236 | { |
| 2237 | return RValue<Short>(Nucleus::createNeg(val.value)); |
| 2238 | } |
| 2239 | |
| 2240 | RValue<Short> operator~(RValue<Short> val) |
| 2241 | { |
| 2242 | return RValue<Short>(Nucleus::createNot(val.value)); |
| 2243 | } |
| 2244 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2245 | RValue<Short> operator++(Short &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2246 | { |
| 2247 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2248 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2249 | return res; |
| 2250 | } |
| 2251 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2252 | const Short &operator++(Short &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2253 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2254 | val += Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2255 | return val; |
| 2256 | } |
| 2257 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2258 | RValue<Short> operator--(Short &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2259 | { |
| 2260 | RValue<Short> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2261 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2262 | return res; |
| 2263 | } |
| 2264 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2265 | const Short &operator--(Short &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2266 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2267 | val -= Short(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2268 | return val; |
| 2269 | } |
| 2270 | |
| 2271 | RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| 2272 | { |
| 2273 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 2274 | } |
| 2275 | |
| 2276 | RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| 2277 | { |
| 2278 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 2279 | } |
| 2280 | |
| 2281 | RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| 2282 | { |
| 2283 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 2284 | } |
| 2285 | |
| 2286 | RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| 2287 | { |
| 2288 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 2289 | } |
| 2290 | |
| 2291 | RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| 2292 | { |
| 2293 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2294 | } |
| 2295 | |
| 2296 | RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| 2297 | { |
| 2298 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2299 | } |
| 2300 | |
| 2301 | Type *Short::getType() |
| 2302 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2303 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | UShort::UShort(Argument<UShort> argument) |
| 2307 | { |
| 2308 | storeValue(argument.value); |
| 2309 | } |
| 2310 | |
| 2311 | UShort::UShort(RValue<UInt> cast) |
| 2312 | { |
| 2313 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2314 | |
| 2315 | storeValue(integer); |
| 2316 | } |
| 2317 | |
| 2318 | UShort::UShort(RValue<Int> cast) |
| 2319 | { |
| 2320 | Value *integer = Nucleus::createTrunc(cast.value, UShort::getType()); |
| 2321 | |
| 2322 | storeValue(integer); |
| 2323 | } |
| 2324 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2325 | UShort::UShort(unsigned short x) |
| 2326 | { |
| 2327 | storeValue(Nucleus::createConstantShort(x)); |
| 2328 | } |
| 2329 | |
| 2330 | UShort::UShort(RValue<UShort> rhs) |
| 2331 | { |
| 2332 | storeValue(rhs.value); |
| 2333 | } |
| 2334 | |
| 2335 | UShort::UShort(const UShort &rhs) |
| 2336 | { |
| 2337 | Value *value = rhs.loadValue(); |
| 2338 | storeValue(value); |
| 2339 | } |
| 2340 | |
| 2341 | UShort::UShort(const Reference<UShort> &rhs) |
| 2342 | { |
| 2343 | Value *value = rhs.loadValue(); |
| 2344 | storeValue(value); |
| 2345 | } |
| 2346 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2347 | RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2348 | { |
| 2349 | storeValue(rhs.value); |
| 2350 | |
| 2351 | return rhs; |
| 2352 | } |
| 2353 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2354 | RValue<UShort> UShort::operator=(const UShort &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2355 | { |
| 2356 | Value *value = rhs.loadValue(); |
| 2357 | storeValue(value); |
| 2358 | |
| 2359 | return RValue<UShort>(value); |
| 2360 | } |
| 2361 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2362 | RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2363 | { |
| 2364 | Value *value = rhs.loadValue(); |
| 2365 | storeValue(value); |
| 2366 | |
| 2367 | return RValue<UShort>(value); |
| 2368 | } |
| 2369 | |
| 2370 | RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2371 | { |
| 2372 | return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 2373 | } |
| 2374 | |
| 2375 | RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2376 | { |
| 2377 | return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value)); |
| 2378 | } |
| 2379 | |
| 2380 | RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2381 | { |
| 2382 | return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2383 | } |
| 2384 | |
| 2385 | RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2386 | { |
| 2387 | return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2388 | } |
| 2389 | |
| 2390 | RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2391 | { |
| 2392 | return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2393 | } |
| 2394 | |
| 2395 | RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2396 | { |
| 2397 | return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2398 | } |
| 2399 | |
| 2400 | RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2401 | { |
| 2402 | return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2403 | } |
| 2404 | |
| 2405 | RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2406 | { |
| 2407 | return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2408 | } |
| 2409 | |
| 2410 | RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2411 | { |
| 2412 | return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value)); |
| 2413 | } |
| 2414 | |
| 2415 | RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2416 | { |
| 2417 | return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 2418 | } |
| 2419 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2420 | RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2421 | { |
| 2422 | return lhs = lhs + rhs; |
| 2423 | } |
| 2424 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2425 | RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2426 | { |
| 2427 | return lhs = lhs - rhs; |
| 2428 | } |
| 2429 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2430 | RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2431 | { |
| 2432 | return lhs = lhs * rhs; |
| 2433 | } |
| 2434 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2435 | RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2436 | { |
| 2437 | return lhs = lhs / rhs; |
| 2438 | } |
| 2439 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2440 | RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2441 | { |
| 2442 | return lhs = lhs % rhs; |
| 2443 | } |
| 2444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2445 | RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2446 | { |
| 2447 | return lhs = lhs & rhs; |
| 2448 | } |
| 2449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2450 | RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2451 | { |
| 2452 | return lhs = lhs | rhs; |
| 2453 | } |
| 2454 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2455 | RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2456 | { |
| 2457 | return lhs = lhs ^ rhs; |
| 2458 | } |
| 2459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2460 | RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2461 | { |
| 2462 | return lhs = lhs << rhs; |
| 2463 | } |
| 2464 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2465 | RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2466 | { |
| 2467 | return lhs = lhs >> rhs; |
| 2468 | } |
| 2469 | |
| 2470 | RValue<UShort> operator+(RValue<UShort> val) |
| 2471 | { |
| 2472 | return val; |
| 2473 | } |
| 2474 | |
| 2475 | RValue<UShort> operator-(RValue<UShort> val) |
| 2476 | { |
| 2477 | return RValue<UShort>(Nucleus::createNeg(val.value)); |
| 2478 | } |
| 2479 | |
| 2480 | RValue<UShort> operator~(RValue<UShort> val) |
| 2481 | { |
| 2482 | return RValue<UShort>(Nucleus::createNot(val.value)); |
| 2483 | } |
| 2484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2485 | RValue<UShort> operator++(UShort &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2486 | { |
| 2487 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2488 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2489 | return res; |
| 2490 | } |
| 2491 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2492 | const UShort &operator++(UShort &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2493 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2494 | val += UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2495 | return val; |
| 2496 | } |
| 2497 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2498 | RValue<UShort> operator--(UShort &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2499 | { |
| 2500 | RValue<UShort> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2501 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2502 | return res; |
| 2503 | } |
| 2504 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2505 | const UShort &operator--(UShort &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2506 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2507 | val -= UShort(1); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2508 | return val; |
| 2509 | } |
| 2510 | |
| 2511 | RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2512 | { |
| 2513 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 2514 | } |
| 2515 | |
| 2516 | RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2517 | { |
| 2518 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 2519 | } |
| 2520 | |
| 2521 | RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2522 | { |
| 2523 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 2524 | } |
| 2525 | |
| 2526 | RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2527 | { |
| 2528 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 2529 | } |
| 2530 | |
| 2531 | RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2532 | { |
| 2533 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 2534 | } |
| 2535 | |
| 2536 | RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| 2537 | { |
| 2538 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 2539 | } |
| 2540 | |
| 2541 | Type *UShort::getType() |
| 2542 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2543 | return T(Ice::IceType_i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2544 | } |
| 2545 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2546 | Byte4::Byte4(RValue<Byte8> cast) |
| 2547 | { |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2548 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
| 2549 | } |
| 2550 | |
| 2551 | Byte4::Byte4(const Reference<Byte4> &rhs) |
| 2552 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 2553 | Value *value = rhs.loadValue(); |
| 2554 | storeValue(value); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2557 | Type *Byte4::getType() |
| 2558 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2559 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | Type *SByte4::getType() |
| 2563 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 2564 | return T(Type_v4i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2565 | } |
| 2566 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2567 | 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) |
| 2568 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2569 | int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7}; |
| 2570 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | Byte8::Byte8(RValue<Byte8> rhs) |
| 2574 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2575 | storeValue(rhs.value); |
| 2576 | } |
| 2577 | |
| 2578 | Byte8::Byte8(const Byte8 &rhs) |
| 2579 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2580 | Value *value = rhs.loadValue(); |
| 2581 | storeValue(value); |
| 2582 | } |
| 2583 | |
| 2584 | Byte8::Byte8(const Reference<Byte8> &rhs) |
| 2585 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2586 | Value *value = rhs.loadValue(); |
| 2587 | storeValue(value); |
| 2588 | } |
| 2589 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2590 | RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2591 | { |
| 2592 | storeValue(rhs.value); |
| 2593 | |
| 2594 | return rhs; |
| 2595 | } |
| 2596 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2597 | RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2598 | { |
| 2599 | Value *value = rhs.loadValue(); |
| 2600 | storeValue(value); |
| 2601 | |
| 2602 | return RValue<Byte8>(value); |
| 2603 | } |
| 2604 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2605 | RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2606 | { |
| 2607 | Value *value = rhs.loadValue(); |
| 2608 | storeValue(value); |
| 2609 | |
| 2610 | return RValue<Byte8>(value); |
| 2611 | } |
| 2612 | |
| 2613 | RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2614 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2615 | return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2619 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2620 | return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2624 | // { |
| 2625 | // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2626 | // } |
| 2627 | |
| 2628 | // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2629 | // { |
| 2630 | // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 2631 | // } |
| 2632 | |
| 2633 | // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2634 | // { |
| 2635 | // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value)); |
| 2636 | // } |
| 2637 | |
| 2638 | RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2639 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2640 | return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2644 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2645 | return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| 2649 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2650 | return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| 2654 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2655 | // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2656 | // } |
| 2657 | |
| 2658 | // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| 2659 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2660 | // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2661 | // } |
| 2662 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2663 | RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2664 | { |
| 2665 | return lhs = lhs + rhs; |
| 2666 | } |
| 2667 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2668 | RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2669 | { |
| 2670 | return lhs = lhs - rhs; |
| 2671 | } |
| 2672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2673 | // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2674 | // { |
| 2675 | // return lhs = lhs * rhs; |
| 2676 | // } |
| 2677 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2678 | // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2679 | // { |
| 2680 | // return lhs = lhs / rhs; |
| 2681 | // } |
| 2682 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2683 | // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2684 | // { |
| 2685 | // return lhs = lhs % rhs; |
| 2686 | // } |
| 2687 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2688 | RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2689 | { |
| 2690 | return lhs = lhs & rhs; |
| 2691 | } |
| 2692 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2693 | RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2694 | { |
| 2695 | return lhs = lhs | rhs; |
| 2696 | } |
| 2697 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2698 | RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2699 | { |
| 2700 | return lhs = lhs ^ rhs; |
| 2701 | } |
| 2702 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2703 | // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2704 | // { |
| 2705 | // return lhs = lhs << rhs; |
| 2706 | // } |
| 2707 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2708 | // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2709 | // { |
| 2710 | // return lhs = lhs >> rhs; |
| 2711 | // } |
| 2712 | |
| 2713 | // RValue<Byte8> operator+(RValue<Byte8> val) |
| 2714 | // { |
| 2715 | // return val; |
| 2716 | // } |
| 2717 | |
| 2718 | // RValue<Byte8> operator-(RValue<Byte8> val) |
| 2719 | // { |
| 2720 | // return RValue<Byte8>(Nucleus::createNeg(val.value)); |
| 2721 | // } |
| 2722 | |
| 2723 | RValue<Byte8> operator~(RValue<Byte8> val) |
| 2724 | { |
| 2725 | return RValue<Byte8>(Nucleus::createNot(val.value)); |
| 2726 | } |
| 2727 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2728 | RValue<Byte> Extract(RValue<Byte8> val, int i) |
| 2729 | { |
| 2730 | return RValue<Byte>(Nucleus::createExtractElement(val.value, Byte::getType(), i)); |
| 2731 | } |
| 2732 | |
| 2733 | RValue<Byte8> Insert(RValue<Byte8> val, RValue<Byte> element, int i) |
| 2734 | { |
| 2735 | return RValue<Byte8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2736 | } |
| 2737 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2738 | RValue<Byte> SaturateUnsigned(RValue<Short> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2739 | { |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 2740 | return Byte(IfThenElse(Int(x) > 0xFF, Int(0xFF), IfThenElse(Int(x) < 0, Int(0), Int(x)))); |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2741 | } |
| 2742 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2743 | RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2744 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2745 | if(emulateIntrinsics) |
| 2746 | { |
| 2747 | Byte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2748 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0); |
| 2749 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1); |
| 2750 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2); |
| 2751 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3); |
| 2752 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4); |
| 2753 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5); |
| 2754 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6); |
| 2755 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2756 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2757 | return result; |
| 2758 | } |
| 2759 | else |
| 2760 | { |
| 2761 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2762 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2763 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2764 | auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2765 | paddusb->addArg(x.value); |
| 2766 | paddusb->addArg(y.value); |
| 2767 | ::basicBlock->appendInst(paddusb); |
| 2768 | |
| 2769 | return RValue<Byte8>(V(result)); |
| 2770 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y) |
| 2774 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2775 | if(emulateIntrinsics) |
| 2776 | { |
| 2777 | Byte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 2778 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0); |
| 2779 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1); |
| 2780 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2); |
| 2781 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3); |
| 2782 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4); |
| 2783 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5); |
| 2784 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6); |
| 2785 | result = Insert(result, SaturateUnsigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2786 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2787 | return result; |
| 2788 | } |
| 2789 | else |
| 2790 | { |
| 2791 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 2792 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2793 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2794 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 2795 | psubusw->addArg(x.value); |
| 2796 | psubusw->addArg(y.value); |
| 2797 | ::basicBlock->appendInst(psubusw); |
| 2798 | |
| 2799 | return RValue<Byte8>(V(result)); |
| 2800 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | RValue<Short4> Unpack(RValue<Byte4> x) |
| 2804 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2805 | int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 2806 | return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2807 | } |
| 2808 | |
Nicolas Capens | 411273e | 2017-01-26 15:13:36 -0800 | [diff] [blame] | 2809 | RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| 2810 | { |
| 2811 | return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| 2812 | } |
| 2813 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2814 | RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| 2815 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 2816 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 2817 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| 2821 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 2822 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 2823 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 2824 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2825 | } |
| 2826 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2827 | RValue<SByte> Extract(RValue<SByte8> val, int i) |
| 2828 | { |
| 2829 | return RValue<SByte>(Nucleus::createExtractElement(val.value, SByte::getType(), i)); |
| 2830 | } |
| 2831 | |
| 2832 | RValue<SByte8> Insert(RValue<SByte8> val, RValue<SByte> element, int i) |
| 2833 | { |
| 2834 | return RValue<SByte8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 2835 | } |
| 2836 | |
| 2837 | RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2838 | { |
| 2839 | if(emulateIntrinsics) |
| 2840 | { |
| 2841 | SByte8 result; |
| 2842 | result = Insert(result, Extract(lhs, 0) >> SByte(rhs), 0); |
| 2843 | result = Insert(result, Extract(lhs, 1) >> SByte(rhs), 1); |
| 2844 | result = Insert(result, Extract(lhs, 2) >> SByte(rhs), 2); |
| 2845 | result = Insert(result, Extract(lhs, 3) >> SByte(rhs), 3); |
| 2846 | result = Insert(result, Extract(lhs, 4) >> SByte(rhs), 4); |
| 2847 | result = Insert(result, Extract(lhs, 5) >> SByte(rhs), 5); |
| 2848 | result = Insert(result, Extract(lhs, 6) >> SByte(rhs), 6); |
| 2849 | result = Insert(result, Extract(lhs, 7) >> SByte(rhs), 7); |
| 2850 | |
| 2851 | return result; |
| 2852 | } |
| 2853 | else |
| 2854 | { |
| 2855 | #if defined(__i386__) || defined(__x86_64__) |
| 2856 | // SSE2 doesn't support byte vector shifts, so shift as shorts and recombine. |
Alexis Hetu | e18c530 | 2017-08-04 11:48:17 -0400 | [diff] [blame] | 2857 | RValue<Short4> hi = (As<Short4>(lhs) >> rhs) & Short4(0xFF00u); |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2858 | RValue<Short4> lo = As<Short4>(As<UShort4>((As<Short4>(lhs) << 8) >> rhs) >> 8); |
| 2859 | |
| 2860 | return As<SByte8>(hi | lo); |
| 2861 | #else |
| 2862 | return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 2863 | #endif |
| 2864 | } |
| 2865 | } |
| 2866 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2867 | RValue<Int> SignMask(RValue<Byte8> x) |
| 2868 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 2869 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2870 | { |
| 2871 | Byte8 xx = As<Byte8>(As<SByte8>(x) >> 7) & Byte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80); |
| 2872 | return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7)); |
| 2873 | } |
| 2874 | else |
| 2875 | { |
| 2876 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 2877 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 2878 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 2879 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 2880 | movmsk->addArg(x.value); |
| 2881 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 2882 | |
Nicolas Capens | 0f70a7f | 2017-07-26 13:50:04 -0400 | [diff] [blame] | 2883 | return RValue<Int>(V(result)) & 0xFF; |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 2884 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y) |
| 2888 | // { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 2889 | // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2890 | // } |
| 2891 | |
| 2892 | RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y) |
| 2893 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 2894 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | Type *Byte8::getType() |
| 2898 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 2899 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2900 | } |
| 2901 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2902 | 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) |
| 2903 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 2904 | int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| 2905 | Value *vector = V(Nucleus::createConstantVector(constantVector, getType())); |
| 2906 | |
| 2907 | storeValue(Nucleus::createBitCast(vector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2908 | } |
| 2909 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2910 | SByte8::SByte8(RValue<SByte8> rhs) |
| 2911 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2912 | storeValue(rhs.value); |
| 2913 | } |
| 2914 | |
| 2915 | SByte8::SByte8(const SByte8 &rhs) |
| 2916 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2917 | Value *value = rhs.loadValue(); |
| 2918 | storeValue(value); |
| 2919 | } |
| 2920 | |
| 2921 | SByte8::SByte8(const Reference<SByte8> &rhs) |
| 2922 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2923 | Value *value = rhs.loadValue(); |
| 2924 | storeValue(value); |
| 2925 | } |
| 2926 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2927 | RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2928 | { |
| 2929 | storeValue(rhs.value); |
| 2930 | |
| 2931 | return rhs; |
| 2932 | } |
| 2933 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2934 | RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2935 | { |
| 2936 | Value *value = rhs.loadValue(); |
| 2937 | storeValue(value); |
| 2938 | |
| 2939 | return RValue<SByte8>(value); |
| 2940 | } |
| 2941 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 2942 | RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2943 | { |
| 2944 | Value *value = rhs.loadValue(); |
| 2945 | storeValue(value); |
| 2946 | |
| 2947 | return RValue<SByte8>(value); |
| 2948 | } |
| 2949 | |
| 2950 | RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2951 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2952 | return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2956 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 2957 | return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2961 | // { |
| 2962 | // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 2963 | // } |
| 2964 | |
| 2965 | // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2966 | // { |
| 2967 | // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 2968 | // } |
| 2969 | |
| 2970 | // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2971 | // { |
| 2972 | // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 2973 | // } |
| 2974 | |
| 2975 | RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2976 | { |
| 2977 | return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 2978 | } |
| 2979 | |
| 2980 | RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2981 | { |
| 2982 | return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value)); |
| 2983 | } |
| 2984 | |
| 2985 | RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| 2986 | { |
| 2987 | return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value)); |
| 2988 | } |
| 2989 | |
| 2990 | // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| 2991 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2992 | // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2993 | // } |
| 2994 | |
| 2995 | // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| 2996 | // { |
Nicolas Capens | 15060bb | 2016-12-05 22:17:19 -0500 | [diff] [blame] | 2997 | // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 2998 | // } |
| 2999 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3000 | RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3001 | { |
| 3002 | return lhs = lhs + rhs; |
| 3003 | } |
| 3004 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3005 | RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3006 | { |
| 3007 | return lhs = lhs - rhs; |
| 3008 | } |
| 3009 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3010 | // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3011 | // { |
| 3012 | // return lhs = lhs * rhs; |
| 3013 | // } |
| 3014 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3015 | // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3016 | // { |
| 3017 | // return lhs = lhs / rhs; |
| 3018 | // } |
| 3019 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3020 | // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3021 | // { |
| 3022 | // return lhs = lhs % rhs; |
| 3023 | // } |
| 3024 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3025 | RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3026 | { |
| 3027 | return lhs = lhs & rhs; |
| 3028 | } |
| 3029 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3030 | RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3031 | { |
| 3032 | return lhs = lhs | rhs; |
| 3033 | } |
| 3034 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3035 | RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3036 | { |
| 3037 | return lhs = lhs ^ rhs; |
| 3038 | } |
| 3039 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3040 | // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3041 | // { |
| 3042 | // return lhs = lhs << rhs; |
| 3043 | // } |
| 3044 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3045 | // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3046 | // { |
| 3047 | // return lhs = lhs >> rhs; |
| 3048 | // } |
| 3049 | |
| 3050 | // RValue<SByte8> operator+(RValue<SByte8> val) |
| 3051 | // { |
| 3052 | // return val; |
| 3053 | // } |
| 3054 | |
| 3055 | // RValue<SByte8> operator-(RValue<SByte8> val) |
| 3056 | // { |
| 3057 | // return RValue<SByte8>(Nucleus::createNeg(val.value)); |
| 3058 | // } |
| 3059 | |
| 3060 | RValue<SByte8> operator~(RValue<SByte8> val) |
| 3061 | { |
| 3062 | return RValue<SByte8>(Nucleus::createNot(val.value)); |
| 3063 | } |
| 3064 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3065 | RValue<SByte> SaturateSigned(RValue<Short> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3066 | { |
| 3067 | return SByte(IfThenElse(Int(x) > 0x7F, Int(0x7F), IfThenElse(Int(x) < -0x80, Int(0x80), Int(x)))); |
| 3068 | } |
| 3069 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3070 | RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y) |
| 3071 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3072 | if(emulateIntrinsics) |
| 3073 | { |
| 3074 | SByte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3075 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) + Int(Extract(y, 0)))), 0); |
| 3076 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) + Int(Extract(y, 1)))), 1); |
| 3077 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) + Int(Extract(y, 2)))), 2); |
| 3078 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) + Int(Extract(y, 3)))), 3); |
| 3079 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) + Int(Extract(y, 4)))), 4); |
| 3080 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) + Int(Extract(y, 5)))), 5); |
| 3081 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) + Int(Extract(y, 6)))), 6); |
| 3082 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) + Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3083 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3084 | return result; |
| 3085 | } |
| 3086 | else |
| 3087 | { |
| 3088 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3089 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3090 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3091 | auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3092 | paddsb->addArg(x.value); |
| 3093 | paddsb->addArg(y.value); |
| 3094 | ::basicBlock->appendInst(paddsb); |
| 3095 | |
| 3096 | return RValue<SByte8>(V(result)); |
| 3097 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y) |
| 3101 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3102 | if(emulateIntrinsics) |
| 3103 | { |
| 3104 | SByte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3105 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 0)) - Int(Extract(y, 0)))), 0); |
| 3106 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 1)) - Int(Extract(y, 1)))), 1); |
| 3107 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 2)) - Int(Extract(y, 2)))), 2); |
| 3108 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 3)) - Int(Extract(y, 3)))), 3); |
| 3109 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 4)) - Int(Extract(y, 4)))), 4); |
| 3110 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 5)) - Int(Extract(y, 5)))), 5); |
| 3111 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 6)) - Int(Extract(y, 6)))), 6); |
| 3112 | result = Insert(result, SaturateSigned(Short(Int(Extract(x, 7)) - Int(Extract(y, 7)))), 7); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3113 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3114 | return result; |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| 3118 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3119 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3120 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3121 | auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3122 | psubsb->addArg(x.value); |
| 3123 | psubsb->addArg(y.value); |
| 3124 | ::basicBlock->appendInst(psubsb); |
| 3125 | |
| 3126 | return RValue<SByte8>(V(result)); |
| 3127 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3128 | } |
| 3129 | |
| 3130 | RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| 3131 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3132 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3133 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| 3137 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3138 | int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8 |
| 3139 | auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3140 | return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | RValue<Int> SignMask(RValue<SByte8> x) |
| 3144 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 3145 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3146 | { |
| 3147 | SByte8 xx = (x >> 7) & SByte8(0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80); |
| 3148 | return Int(Extract(xx, 0)) | Int(Extract(xx, 1)) | Int(Extract(xx, 2)) | Int(Extract(xx, 3)) | Int(Extract(xx, 4)) | Int(Extract(xx, 5)) | Int(Extract(xx, 6)) | Int(Extract(xx, 7)); |
| 3149 | } |
| 3150 | else |
| 3151 | { |
| 3152 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 3153 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3154 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3155 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 3156 | movmsk->addArg(x.value); |
| 3157 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 3158 | |
Nicolas Capens | 0f70a7f | 2017-07-26 13:50:04 -0400 | [diff] [blame] | 3159 | return RValue<Int>(V(result)) & 0xFF; |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3160 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y) |
| 3164 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3165 | return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y) |
| 3169 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3170 | return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | Type *SByte8::getType() |
| 3174 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 3175 | return T(Type_v8i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | Byte16::Byte16(RValue<Byte16> rhs) |
| 3179 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3180 | storeValue(rhs.value); |
| 3181 | } |
| 3182 | |
| 3183 | Byte16::Byte16(const Byte16 &rhs) |
| 3184 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3185 | Value *value = rhs.loadValue(); |
| 3186 | storeValue(value); |
| 3187 | } |
| 3188 | |
| 3189 | Byte16::Byte16(const Reference<Byte16> &rhs) |
| 3190 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3191 | Value *value = rhs.loadValue(); |
| 3192 | storeValue(value); |
| 3193 | } |
| 3194 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3195 | RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3196 | { |
| 3197 | storeValue(rhs.value); |
| 3198 | |
| 3199 | return rhs; |
| 3200 | } |
| 3201 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3202 | RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3203 | { |
| 3204 | Value *value = rhs.loadValue(); |
| 3205 | storeValue(value); |
| 3206 | |
| 3207 | return RValue<Byte16>(value); |
| 3208 | } |
| 3209 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3210 | RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3211 | { |
| 3212 | Value *value = rhs.loadValue(); |
| 3213 | storeValue(value); |
| 3214 | |
| 3215 | return RValue<Byte16>(value); |
| 3216 | } |
| 3217 | |
| 3218 | Type *Byte16::getType() |
| 3219 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3220 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | Type *SByte16::getType() |
| 3224 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3225 | return T(Ice::IceType_v16i8); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3226 | } |
| 3227 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3228 | Short2::Short2(RValue<Short4> cast) |
| 3229 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3230 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | Type *Short2::getType() |
| 3234 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3235 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | UShort2::UShort2(RValue<UShort4> cast) |
| 3239 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 3240 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3241 | } |
| 3242 | |
| 3243 | Type *UShort2::getType() |
| 3244 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3245 | return T(Type_v2i16); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3246 | } |
| 3247 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3248 | Short4::Short4(RValue<Int> cast) |
| 3249 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3250 | Value *vector = loadValue(); |
Nicolas Capens | bf22bbf | 2017-01-13 17:37:45 -0500 | [diff] [blame] | 3251 | Value *element = Nucleus::createTrunc(cast.value, Short::getType()); |
| 3252 | Value *insert = Nucleus::createInsertElement(vector, element, 0); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3253 | Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3254 | |
| 3255 | storeValue(swizzle); |
| 3256 | } |
| 3257 | |
| 3258 | Short4::Short4(RValue<Int4> cast) |
| 3259 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 3260 | int select[8] = {0, 2, 4, 6, 0, 2, 4, 6}; |
| 3261 | Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType()); |
| 3262 | Value *packed = Nucleus::createShuffleVector(short8, short8, select); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3263 | |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3264 | Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value; |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3265 | Value *short4 = Nucleus::createBitCast(int2, Short4::getType()); |
| 3266 | |
| 3267 | storeValue(short4); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | // Short4::Short4(RValue<Float> cast) |
| 3271 | // { |
| 3272 | // } |
| 3273 | |
| 3274 | Short4::Short4(RValue<Float4> cast) |
| 3275 | { |
| 3276 | assert(false && "UNIMPLEMENTED"); |
| 3277 | } |
| 3278 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3279 | Short4::Short4(short xyzw) |
| 3280 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3281 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3282 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | Short4::Short4(short x, short y, short z, short w) |
| 3286 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3287 | int64_t constantVector[4] = {x, y, z, w}; |
| 3288 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | Short4::Short4(RValue<Short4> rhs) |
| 3292 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3293 | storeValue(rhs.value); |
| 3294 | } |
| 3295 | |
| 3296 | Short4::Short4(const Short4 &rhs) |
| 3297 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3298 | Value *value = rhs.loadValue(); |
| 3299 | storeValue(value); |
| 3300 | } |
| 3301 | |
| 3302 | Short4::Short4(const Reference<Short4> &rhs) |
| 3303 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3304 | Value *value = rhs.loadValue(); |
| 3305 | storeValue(value); |
| 3306 | } |
| 3307 | |
| 3308 | Short4::Short4(RValue<UShort4> rhs) |
| 3309 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3310 | storeValue(rhs.value); |
| 3311 | } |
| 3312 | |
| 3313 | Short4::Short4(const UShort4 &rhs) |
| 3314 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3315 | storeValue(rhs.loadValue()); |
| 3316 | } |
| 3317 | |
| 3318 | Short4::Short4(const Reference<UShort4> &rhs) |
| 3319 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3320 | storeValue(rhs.loadValue()); |
| 3321 | } |
| 3322 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3323 | RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3324 | { |
| 3325 | storeValue(rhs.value); |
| 3326 | |
| 3327 | return rhs; |
| 3328 | } |
| 3329 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3330 | RValue<Short4> Short4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3331 | { |
| 3332 | Value *value = rhs.loadValue(); |
| 3333 | storeValue(value); |
| 3334 | |
| 3335 | return RValue<Short4>(value); |
| 3336 | } |
| 3337 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3338 | RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3339 | { |
| 3340 | Value *value = rhs.loadValue(); |
| 3341 | storeValue(value); |
| 3342 | |
| 3343 | return RValue<Short4>(value); |
| 3344 | } |
| 3345 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3346 | RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3347 | { |
| 3348 | storeValue(rhs.value); |
| 3349 | |
| 3350 | return RValue<Short4>(rhs); |
| 3351 | } |
| 3352 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3353 | RValue<Short4> Short4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3354 | { |
| 3355 | Value *value = rhs.loadValue(); |
| 3356 | storeValue(value); |
| 3357 | |
| 3358 | return RValue<Short4>(value); |
| 3359 | } |
| 3360 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3361 | RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3362 | { |
| 3363 | Value *value = rhs.loadValue(); |
| 3364 | storeValue(value); |
| 3365 | |
| 3366 | return RValue<Short4>(value); |
| 3367 | } |
| 3368 | |
| 3369 | RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3370 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3371 | return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3375 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3376 | return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3380 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3381 | return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3385 | // { |
| 3386 | // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 3387 | // } |
| 3388 | |
| 3389 | // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3390 | // { |
| 3391 | // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 3392 | // } |
| 3393 | |
| 3394 | RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3395 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3396 | return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3400 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3401 | return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| 3405 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3406 | return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs) |
| 3410 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3411 | if(emulateIntrinsics) |
| 3412 | { |
| 3413 | Short4 result; |
| 3414 | result = Insert(result, Extract(lhs, 0) << Short(rhs), 0); |
| 3415 | result = Insert(result, Extract(lhs, 1) << Short(rhs), 1); |
| 3416 | result = Insert(result, Extract(lhs, 2) << Short(rhs), 2); |
| 3417 | result = Insert(result, Extract(lhs, 3) << Short(rhs), 3); |
| 3418 | |
| 3419 | return result; |
| 3420 | } |
| 3421 | else |
| 3422 | { |
| 3423 | return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3424 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs) |
| 3428 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3429 | if(emulateIntrinsics) |
| 3430 | { |
| 3431 | Short4 result; |
| 3432 | result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0); |
| 3433 | result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1); |
| 3434 | result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2); |
| 3435 | result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3); |
| 3436 | |
| 3437 | return result; |
| 3438 | } |
| 3439 | else |
| 3440 | { |
| 3441 | return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3442 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3443 | } |
| 3444 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3445 | RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3446 | { |
| 3447 | return lhs = lhs + rhs; |
| 3448 | } |
| 3449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3450 | RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3451 | { |
| 3452 | return lhs = lhs - rhs; |
| 3453 | } |
| 3454 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3455 | RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3456 | { |
| 3457 | return lhs = lhs * rhs; |
| 3458 | } |
| 3459 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3460 | // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3461 | // { |
| 3462 | // return lhs = lhs / rhs; |
| 3463 | // } |
| 3464 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3465 | // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3466 | // { |
| 3467 | // return lhs = lhs % rhs; |
| 3468 | // } |
| 3469 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3470 | RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3471 | { |
| 3472 | return lhs = lhs & rhs; |
| 3473 | } |
| 3474 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3475 | RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3476 | { |
| 3477 | return lhs = lhs | rhs; |
| 3478 | } |
| 3479 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3480 | RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3481 | { |
| 3482 | return lhs = lhs ^ rhs; |
| 3483 | } |
| 3484 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3485 | RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3486 | { |
| 3487 | return lhs = lhs << rhs; |
| 3488 | } |
| 3489 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3490 | RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3491 | { |
| 3492 | return lhs = lhs >> rhs; |
| 3493 | } |
| 3494 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3495 | // RValue<Short4> operator+(RValue<Short4> val) |
| 3496 | // { |
| 3497 | // return val; |
| 3498 | // } |
| 3499 | |
| 3500 | RValue<Short4> operator-(RValue<Short4> val) |
| 3501 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3502 | return RValue<Short4>(Nucleus::createNeg(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | RValue<Short4> operator~(RValue<Short4> val) |
| 3506 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3507 | return RValue<Short4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | RValue<Short4> RoundShort4(RValue<Float4> cast) |
| 3511 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3512 | RValue<Int4> int4 = RoundInt(cast); |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3513 | return As<Short4>(PackSigned(int4, int4)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y) |
| 3517 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3518 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3519 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 3520 | ::basicBlock->appendInst(cmp); |
| 3521 | |
| 3522 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3523 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3524 | ::basicBlock->appendInst(select); |
| 3525 | |
| 3526 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y) |
| 3530 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3531 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3532 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 3533 | ::basicBlock->appendInst(cmp); |
| 3534 | |
| 3535 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3536 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3537 | ::basicBlock->appendInst(select); |
| 3538 | |
| 3539 | return RValue<Short4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3540 | } |
| 3541 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3542 | RValue<Short> SaturateSigned(RValue<Int> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3543 | { |
| 3544 | return Short(IfThenElse(x > 0x7FFF, Int(0x7FFF), IfThenElse(x < -0x8000, Int(0x8000), x))); |
| 3545 | } |
| 3546 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3547 | RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y) |
| 3548 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3549 | if(emulateIntrinsics) |
| 3550 | { |
| 3551 | Short4 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3552 | result = Insert(result, SaturateSigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0); |
| 3553 | result = Insert(result, SaturateSigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1); |
| 3554 | result = Insert(result, SaturateSigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2); |
| 3555 | result = Insert(result, SaturateSigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3556 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3557 | return result; |
| 3558 | } |
| 3559 | else |
| 3560 | { |
| 3561 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3562 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3563 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3564 | auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3565 | paddsw->addArg(x.value); |
| 3566 | paddsw->addArg(y.value); |
| 3567 | ::basicBlock->appendInst(paddsw); |
| 3568 | |
| 3569 | return RValue<Short4>(V(result)); |
| 3570 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y) |
| 3574 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3575 | if(emulateIntrinsics) |
| 3576 | { |
| 3577 | Short4 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3578 | result = Insert(result, SaturateSigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0); |
| 3579 | result = Insert(result, SaturateSigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1); |
| 3580 | result = Insert(result, SaturateSigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2); |
| 3581 | result = Insert(result, SaturateSigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3582 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3583 | return result; |
| 3584 | } |
| 3585 | else |
| 3586 | { |
| 3587 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3588 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3589 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3590 | auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3591 | psubsw->addArg(x.value); |
| 3592 | psubsw->addArg(y.value); |
| 3593 | ::basicBlock->appendInst(psubsw); |
| 3594 | |
| 3595 | return RValue<Short4>(V(result)); |
| 3596 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y) |
| 3600 | { |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3601 | if(emulateIntrinsics) |
| 3602 | { |
| 3603 | Short4 result; |
| 3604 | result = Insert(result, Short((Int(Extract(x, 0)) * Int(Extract(y, 0))) >> 16), 0); |
| 3605 | result = Insert(result, Short((Int(Extract(x, 1)) * Int(Extract(y, 1))) >> 16), 1); |
| 3606 | result = Insert(result, Short((Int(Extract(x, 2)) * Int(Extract(y, 2))) >> 16), 2); |
| 3607 | result = Insert(result, Short((Int(Extract(x, 3)) * Int(Extract(y, 3))) >> 16), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3608 | |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3609 | return result; |
| 3610 | } |
| 3611 | else |
| 3612 | { |
| 3613 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3614 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3615 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3616 | auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3617 | pmulhw->addArg(x.value); |
| 3618 | pmulhw->addArg(y.value); |
| 3619 | ::basicBlock->appendInst(pmulhw); |
| 3620 | |
| 3621 | return RValue<Short4>(V(result)); |
| 3622 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y) |
| 3626 | { |
Nicolas Capens | afe27e9 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3627 | if(emulateIntrinsics) |
| 3628 | { |
| 3629 | Int2 result; |
| 3630 | result = Insert(result, Int(Extract(x, 0)) * Int(Extract(y, 0)) + Int(Extract(x, 1)) * Int(Extract(y, 1)), 0); |
| 3631 | result = Insert(result, Int(Extract(x, 2)) * Int(Extract(y, 2)) + Int(Extract(x, 3)) * Int(Extract(y, 3)), 1); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 3632 | |
Nicolas Capens | afe27e9 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3633 | return result; |
| 3634 | } |
| 3635 | else |
| 3636 | { |
| 3637 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3638 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3639 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3640 | auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3641 | pmaddwd->addArg(x.value); |
| 3642 | pmaddwd->addArg(y.value); |
| 3643 | ::basicBlock->appendInst(pmaddwd); |
| 3644 | |
| 3645 | return As<Int2>(V(result)); |
| 3646 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3647 | } |
| 3648 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3649 | RValue<SByte8> PackSigned(RValue<Short4> x, RValue<Short4> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3650 | { |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3651 | if(emulateIntrinsics) |
| 3652 | { |
| 3653 | SByte8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3654 | result = Insert(result, SaturateSigned(Extract(x, 0)), 0); |
| 3655 | result = Insert(result, SaturateSigned(Extract(x, 1)), 1); |
| 3656 | result = Insert(result, SaturateSigned(Extract(x, 2)), 2); |
| 3657 | result = Insert(result, SaturateSigned(Extract(x, 3)), 3); |
| 3658 | result = Insert(result, SaturateSigned(Extract(y, 0)), 4); |
| 3659 | result = Insert(result, SaturateSigned(Extract(y, 1)), 5); |
| 3660 | result = Insert(result, SaturateSigned(Extract(y, 2)), 6); |
| 3661 | result = Insert(result, SaturateSigned(Extract(y, 3)), 7); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3662 | |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3663 | return result; |
| 3664 | } |
| 3665 | else |
| 3666 | { |
| 3667 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3668 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3669 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3670 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3671 | pack->addArg(x.value); |
| 3672 | pack->addArg(y.value); |
| 3673 | ::basicBlock->appendInst(pack); |
| 3674 | |
| 3675 | return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
| 3676 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3677 | } |
| 3678 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3679 | RValue<Byte8> PackUnsigned(RValue<Short4> x, RValue<Short4> y) |
| 3680 | { |
| 3681 | if(emulateIntrinsics) |
| 3682 | { |
| 3683 | Byte8 result; |
| 3684 | result = Insert(result, SaturateUnsigned(Extract(x, 0)), 0); |
| 3685 | result = Insert(result, SaturateUnsigned(Extract(x, 1)), 1); |
| 3686 | result = Insert(result, SaturateUnsigned(Extract(x, 2)), 2); |
| 3687 | result = Insert(result, SaturateUnsigned(Extract(x, 3)), 3); |
| 3688 | result = Insert(result, SaturateUnsigned(Extract(y, 0)), 4); |
| 3689 | result = Insert(result, SaturateUnsigned(Extract(y, 1)), 5); |
| 3690 | result = Insert(result, SaturateUnsigned(Extract(y, 2)), 6); |
| 3691 | result = Insert(result, SaturateUnsigned(Extract(y, 3)), 7); |
| 3692 | |
| 3693 | return result; |
| 3694 | } |
| 3695 | else |
| 3696 | { |
| 3697 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8); |
| 3698 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 3699 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 3700 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 3701 | pack->addArg(x.value); |
| 3702 | pack->addArg(y.value); |
| 3703 | ::basicBlock->appendInst(pack); |
| 3704 | |
| 3705 | return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88)); |
| 3706 | } |
| 3707 | } |
| 3708 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3709 | RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| 3710 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3711 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
Nicolas Capens | bea4dce | 2017-07-24 16:54:44 -0400 | [diff] [blame] | 3712 | return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| 3716 | { |
Nicolas Capens | 20e22c4 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 3717 | int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16 |
| 3718 | auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 3719 | return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select) |
| 3723 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 3724 | // Real type is v8i16 |
| 3725 | int shuffle[8] = |
| 3726 | { |
| 3727 | (select >> 0) & 0x03, |
| 3728 | (select >> 2) & 0x03, |
| 3729 | (select >> 4) & 0x03, |
| 3730 | (select >> 6) & 0x03, |
| 3731 | (select >> 0) & 0x03, |
| 3732 | (select >> 2) & 0x03, |
| 3733 | (select >> 4) & 0x03, |
| 3734 | (select >> 6) & 0x03, |
| 3735 | }; |
| 3736 | |
| 3737 | return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| 3741 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 3742 | return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | RValue<Short> Extract(RValue<Short4> val, int i) |
| 3746 | { |
Nicolas Capens | 0133d0f | 2017-01-16 16:25:08 -0500 | [diff] [blame] | 3747 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y) |
| 3751 | { |
Nicolas Capens | 2f970b6 | 2016-11-08 14:28:59 -0500 | [diff] [blame] | 3752 | return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y) |
| 3756 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 3757 | return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | Type *Short4::getType() |
| 3761 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 3762 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | UShort4::UShort4(RValue<Int4> cast) |
| 3766 | { |
| 3767 | *this = Short4(cast); |
| 3768 | } |
| 3769 | |
| 3770 | UShort4::UShort4(RValue<Float4> cast, bool saturate) |
| 3771 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3772 | if(saturate) |
| 3773 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 3774 | if(CPUID::SSE4_1) |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3775 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 3776 | // x86 produces 0x80000000 on 32-bit integer overflow/underflow. |
| 3777 | // PackUnsigned takes care of 0x0000 saturation. |
| 3778 | Int4 int4(Min(cast, Float4(0xFFFF))); |
| 3779 | *this = As<UShort4>(PackUnsigned(int4, int4)); |
| 3780 | } |
| 3781 | else if(CPUID::ARM) |
| 3782 | { |
| 3783 | // ARM saturates the 32-bit integer result on overflow/undeflow. |
| 3784 | Int4 int4(cast); |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 3785 | *this = As<UShort4>(PackUnsigned(int4, int4)); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 3786 | } |
| 3787 | else |
| 3788 | { |
| 3789 | *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000)))); |
| 3790 | } |
| 3791 | } |
| 3792 | else |
| 3793 | { |
| 3794 | *this = Short4(Int4(cast)); |
| 3795 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3796 | } |
| 3797 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3798 | UShort4::UShort4(unsigned short xyzw) |
| 3799 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3800 | int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw}; |
| 3801 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3802 | } |
| 3803 | |
| 3804 | UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| 3805 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 3806 | int64_t constantVector[4] = {x, y, z, w}; |
| 3807 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | UShort4::UShort4(RValue<UShort4> rhs) |
| 3811 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3812 | storeValue(rhs.value); |
| 3813 | } |
| 3814 | |
| 3815 | UShort4::UShort4(const UShort4 &rhs) |
| 3816 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3817 | Value *value = rhs.loadValue(); |
| 3818 | storeValue(value); |
| 3819 | } |
| 3820 | |
| 3821 | UShort4::UShort4(const Reference<UShort4> &rhs) |
| 3822 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3823 | Value *value = rhs.loadValue(); |
| 3824 | storeValue(value); |
| 3825 | } |
| 3826 | |
| 3827 | UShort4::UShort4(RValue<Short4> rhs) |
| 3828 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3829 | storeValue(rhs.value); |
| 3830 | } |
| 3831 | |
| 3832 | UShort4::UShort4(const Short4 &rhs) |
| 3833 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3834 | Value *value = rhs.loadValue(); |
| 3835 | storeValue(value); |
| 3836 | } |
| 3837 | |
| 3838 | UShort4::UShort4(const Reference<Short4> &rhs) |
| 3839 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3840 | Value *value = rhs.loadValue(); |
| 3841 | storeValue(value); |
| 3842 | } |
| 3843 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3844 | RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3845 | { |
| 3846 | storeValue(rhs.value); |
| 3847 | |
| 3848 | return rhs; |
| 3849 | } |
| 3850 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3851 | RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3852 | { |
| 3853 | Value *value = rhs.loadValue(); |
| 3854 | storeValue(value); |
| 3855 | |
| 3856 | return RValue<UShort4>(value); |
| 3857 | } |
| 3858 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3859 | RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3860 | { |
| 3861 | Value *value = rhs.loadValue(); |
| 3862 | storeValue(value); |
| 3863 | |
| 3864 | return RValue<UShort4>(value); |
| 3865 | } |
| 3866 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3867 | RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3868 | { |
| 3869 | storeValue(rhs.value); |
| 3870 | |
| 3871 | return RValue<UShort4>(rhs); |
| 3872 | } |
| 3873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3874 | RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3875 | { |
| 3876 | Value *value = rhs.loadValue(); |
| 3877 | storeValue(value); |
| 3878 | |
| 3879 | return RValue<UShort4>(value); |
| 3880 | } |
| 3881 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3882 | RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3883 | { |
| 3884 | Value *value = rhs.loadValue(); |
| 3885 | storeValue(value); |
| 3886 | |
| 3887 | return RValue<UShort4>(value); |
| 3888 | } |
| 3889 | |
| 3890 | RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3891 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 3892 | return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3893 | } |
| 3894 | |
| 3895 | RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3896 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3897 | return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3898 | } |
| 3899 | |
| 3900 | RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3901 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3902 | return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3903 | } |
| 3904 | |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3905 | RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3906 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3907 | return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3911 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3912 | return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| 3916 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 3917 | return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 16b5f15 | 2016-10-13 13:39:01 -0400 | [diff] [blame] | 3918 | } |
| 3919 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3920 | RValue<UShort> Extract(RValue<UShort4> val, int i) |
| 3921 | { |
| 3922 | return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i)); |
| 3923 | } |
| 3924 | |
| 3925 | RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i) |
| 3926 | { |
| 3927 | return RValue<UShort4>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 3928 | } |
| 3929 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3930 | RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs) |
| 3931 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3932 | if(emulateIntrinsics) |
| 3933 | { |
| 3934 | UShort4 result; |
| 3935 | result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0); |
| 3936 | result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1); |
| 3937 | result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2); |
| 3938 | result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3); |
| 3939 | |
| 3940 | return result; |
| 3941 | } |
| 3942 | else |
| 3943 | { |
| 3944 | return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3945 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3946 | } |
| 3947 | |
| 3948 | RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs) |
| 3949 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 3950 | if(emulateIntrinsics) |
| 3951 | { |
| 3952 | UShort4 result; |
| 3953 | result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0); |
| 3954 | result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1); |
| 3955 | result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2); |
| 3956 | result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3); |
| 3957 | |
| 3958 | return result; |
| 3959 | } |
| 3960 | else |
| 3961 | { |
| 3962 | return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 3963 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3964 | } |
| 3965 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3966 | RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3967 | { |
| 3968 | return lhs = lhs << rhs; |
| 3969 | } |
| 3970 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 3971 | RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3972 | { |
| 3973 | return lhs = lhs >> rhs; |
| 3974 | } |
| 3975 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3976 | RValue<UShort4> operator~(RValue<UShort4> val) |
| 3977 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 3978 | return RValue<UShort4>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y) |
| 3982 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3983 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3984 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 3985 | ::basicBlock->appendInst(cmp); |
| 3986 | |
| 3987 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 3988 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 3989 | ::basicBlock->appendInst(select); |
| 3990 | |
| 3991 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y) |
| 3995 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 3996 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1); |
| 3997 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 3998 | ::basicBlock->appendInst(cmp); |
| 3999 | |
| 4000 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4001 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 4002 | ::basicBlock->appendInst(select); |
| 4003 | |
| 4004 | return RValue<UShort4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4005 | } |
| 4006 | |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 4007 | RValue<UShort> SaturateUnsigned(RValue<Int> x) |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4008 | { |
| 4009 | return UShort(IfThenElse(x > 0xFFFF, Int(0xFFFF), IfThenElse(x < 0, Int(0), x))); |
| 4010 | } |
| 4011 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4012 | RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y) |
| 4013 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4014 | if(emulateIntrinsics) |
| 4015 | { |
| 4016 | UShort4 result; |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 4017 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) + Int(Extract(y, 0))), 0); |
| 4018 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) + Int(Extract(y, 1))), 1); |
| 4019 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) + Int(Extract(y, 2))), 2); |
| 4020 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) + Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 4021 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4022 | return result; |
| 4023 | } |
| 4024 | else |
| 4025 | { |
| 4026 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4027 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4028 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4029 | auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 4030 | paddusw->addArg(x.value); |
| 4031 | paddusw->addArg(y.value); |
| 4032 | ::basicBlock->appendInst(paddusw); |
| 4033 | |
| 4034 | return RValue<UShort4>(V(result)); |
| 4035 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y) |
| 4039 | { |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4040 | if(emulateIntrinsics) |
| 4041 | { |
| 4042 | UShort4 result; |
Nicolas Capens | 7f30181 | 2017-10-02 17:32:34 -0400 | [diff] [blame] | 4043 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 0)) - Int(Extract(y, 0))), 0); |
| 4044 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 1)) - Int(Extract(y, 1))), 1); |
| 4045 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 2)) - Int(Extract(y, 2))), 2); |
| 4046 | result = Insert(result, SaturateUnsigned(Int(Extract(x, 3)) - Int(Extract(y, 3))), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 4047 | |
Nicolas Capens | 9843673 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4048 | return result; |
| 4049 | } |
| 4050 | else |
| 4051 | { |
| 4052 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4053 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4054 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4055 | auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 4056 | psubusw->addArg(x.value); |
| 4057 | psubusw->addArg(y.value); |
| 4058 | ::basicBlock->appendInst(psubusw); |
| 4059 | |
| 4060 | return RValue<UShort4>(V(result)); |
| 4061 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y) |
| 4065 | { |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4066 | if(emulateIntrinsics) |
| 4067 | { |
| 4068 | UShort4 result; |
| 4069 | result = Insert(result, UShort((UInt(Extract(x, 0)) * UInt(Extract(y, 0))) >> 16), 0); |
| 4070 | result = Insert(result, UShort((UInt(Extract(x, 1)) * UInt(Extract(y, 1))) >> 16), 1); |
| 4071 | result = Insert(result, UShort((UInt(Extract(x, 2)) * UInt(Extract(y, 2))) >> 16), 2); |
| 4072 | result = Insert(result, UShort((UInt(Extract(x, 3)) * UInt(Extract(y, 3))) >> 16), 3); |
Nicolas Capens | c71bed2 | 2016-11-07 22:25:14 -0500 | [diff] [blame] | 4073 | |
Nicolas Capens | 6c15744 | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4074 | return result; |
| 4075 | } |
| 4076 | else |
| 4077 | { |
| 4078 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 4079 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4080 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4081 | auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 4082 | pmulhuw->addArg(x.value); |
| 4083 | pmulhuw->addArg(y.value); |
| 4084 | ::basicBlock->appendInst(pmulhuw); |
| 4085 | |
| 4086 | return RValue<UShort4>(V(result)); |
| 4087 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4088 | } |
| 4089 | |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame^] | 4090 | RValue<Int4> MulHigh(RValue<Int4> x, RValue<Int4> y) |
| 4091 | { |
| 4092 | // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq. |
| 4093 | |
| 4094 | // Scalarized implementation. |
| 4095 | Int4 result; |
| 4096 | result = Insert(result, Int((Long(Extract(x, 0)) * Long(Extract(y, 0))) >> Long(Int(32))), 0); |
| 4097 | result = Insert(result, Int((Long(Extract(x, 1)) * Long(Extract(y, 1))) >> Long(Int(32))), 1); |
| 4098 | result = Insert(result, Int((Long(Extract(x, 2)) * Long(Extract(y, 2))) >> Long(Int(32))), 2); |
| 4099 | result = Insert(result, Int((Long(Extract(x, 3)) * Long(Extract(y, 3))) >> Long(Int(32))), 3); |
| 4100 | |
| 4101 | return result; |
| 4102 | } |
| 4103 | |
| 4104 | RValue<UInt4> MulHigh(RValue<UInt4> x, RValue<UInt4> y) |
| 4105 | { |
| 4106 | // TODO: For x86, build an intrinsics version of this which uses shuffles + pmuludq. |
| 4107 | |
| 4108 | if(false) // Partial product based implementation. |
| 4109 | { |
| 4110 | auto xh = x >> 16; |
| 4111 | auto yh = y >> 16; |
| 4112 | auto xl = x & UInt4(0x0000FFFF); |
| 4113 | auto yl = y & UInt4(0x0000FFFF); |
| 4114 | auto xlyh = xl * yh; |
| 4115 | auto xhyl = xh * yl; |
| 4116 | auto xlyhh = xlyh >> 16; |
| 4117 | auto xhylh = xhyl >> 16; |
| 4118 | auto xlyhl = xlyh & UInt4(0x0000FFFF); |
| 4119 | auto xhyll = xhyl & UInt4(0x0000FFFF); |
| 4120 | auto xlylh = (xl * yl) >> 16; |
| 4121 | auto oflow = (xlyhl + xhyll + xlylh) >> 16; |
| 4122 | |
| 4123 | return (xh * yh) + (xlyhh + xhylh) + oflow; |
| 4124 | } |
| 4125 | |
| 4126 | // Scalarized implementation. |
| 4127 | Int4 result; |
| 4128 | result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 0))) * Long(UInt(Extract(As<Int4>(y), 0)))) >> Long(Int(32))), 0); |
| 4129 | result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 1))) * Long(UInt(Extract(As<Int4>(y), 1)))) >> Long(Int(32))), 1); |
| 4130 | result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 2))) * Long(UInt(Extract(As<Int4>(y), 2)))) >> Long(Int(32))), 2); |
| 4131 | result = Insert(result, Int((Long(UInt(Extract(As<Int4>(x), 3))) * Long(UInt(Extract(As<Int4>(y), 3)))) >> Long(Int(32))), 3); |
| 4132 | |
| 4133 | return As<UInt4>(result); |
| 4134 | } |
| 4135 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4136 | RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y) |
| 4137 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4138 | assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4139 | } |
| 4140 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4141 | Type *UShort4::getType() |
| 4142 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 4143 | return T(Type_v4i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4144 | } |
| 4145 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 4146 | Short8::Short8(short c) |
| 4147 | { |
| 4148 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 4149 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 4150 | } |
| 4151 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4152 | Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| 4153 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4154 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 4155 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | Short8::Short8(RValue<Short8> rhs) |
| 4159 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4160 | storeValue(rhs.value); |
| 4161 | } |
| 4162 | |
| 4163 | Short8::Short8(const Reference<Short8> &rhs) |
| 4164 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4165 | Value *value = rhs.loadValue(); |
| 4166 | storeValue(value); |
| 4167 | } |
| 4168 | |
| 4169 | Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| 4170 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4171 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 4172 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 4173 | |
| 4174 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| 4178 | { |
| 4179 | return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4180 | } |
| 4181 | |
| 4182 | RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| 4183 | { |
| 4184 | return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4185 | } |
| 4186 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4187 | RValue<Short> Extract(RValue<Short8> val, int i) |
| 4188 | { |
| 4189 | return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i)); |
| 4190 | } |
| 4191 | |
| 4192 | RValue<Short8> Insert(RValue<Short8> val, RValue<Short> element, int i) |
| 4193 | { |
| 4194 | return RValue<Short8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 4195 | } |
| 4196 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4197 | RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs) |
| 4198 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4199 | if(emulateIntrinsics) |
| 4200 | { |
| 4201 | Short8 result; |
| 4202 | result = Insert(result, Extract(lhs, 0) << Short(rhs), 0); |
| 4203 | result = Insert(result, Extract(lhs, 1) << Short(rhs), 1); |
| 4204 | result = Insert(result, Extract(lhs, 2) << Short(rhs), 2); |
| 4205 | result = Insert(result, Extract(lhs, 3) << Short(rhs), 3); |
| 4206 | result = Insert(result, Extract(lhs, 4) << Short(rhs), 4); |
| 4207 | result = Insert(result, Extract(lhs, 5) << Short(rhs), 5); |
| 4208 | result = Insert(result, Extract(lhs, 6) << Short(rhs), 6); |
| 4209 | result = Insert(result, Extract(lhs, 7) << Short(rhs), 7); |
| 4210 | |
| 4211 | return result; |
| 4212 | } |
| 4213 | else |
| 4214 | { |
| 4215 | return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4216 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs) |
| 4220 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4221 | if(emulateIntrinsics) |
| 4222 | { |
| 4223 | Short8 result; |
| 4224 | result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0); |
| 4225 | result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1); |
| 4226 | result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2); |
| 4227 | result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3); |
| 4228 | result = Insert(result, Extract(lhs, 4) >> Short(rhs), 4); |
| 4229 | result = Insert(result, Extract(lhs, 5) >> Short(rhs), 5); |
| 4230 | result = Insert(result, Extract(lhs, 6) >> Short(rhs), 6); |
| 4231 | result = Insert(result, Extract(lhs, 7) >> Short(rhs), 7); |
| 4232 | |
| 4233 | return result; |
| 4234 | } |
| 4235 | else |
| 4236 | { |
| 4237 | return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4238 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y) |
| 4242 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4243 | assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | RValue<Int4> Abs(RValue<Int4> x) |
| 4247 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 4248 | auto negative = x >> 31; |
| 4249 | return (x ^ negative) - negative; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y) |
| 4253 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4254 | assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | Type *Short8::getType() |
| 4258 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4259 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4260 | } |
| 4261 | |
Nicolas Capens | 3e7062b | 2017-01-17 14:01:33 -0500 | [diff] [blame] | 4262 | UShort8::UShort8(unsigned short c) |
| 4263 | { |
| 4264 | int64_t constantVector[8] = {c, c, c, c, c, c, c, c}; |
| 4265 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
| 4266 | } |
| 4267 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4268 | 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) |
| 4269 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 4270 | int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7}; |
| 4271 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | UShort8::UShort8(RValue<UShort8> rhs) |
| 4275 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4276 | storeValue(rhs.value); |
| 4277 | } |
| 4278 | |
| 4279 | UShort8::UShort8(const Reference<UShort8> &rhs) |
| 4280 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4281 | Value *value = rhs.loadValue(); |
| 4282 | storeValue(value); |
| 4283 | } |
| 4284 | |
| 4285 | UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| 4286 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4287 | int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16 |
| 4288 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 4289 | |
| 4290 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4291 | } |
| 4292 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4293 | RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4294 | { |
| 4295 | storeValue(rhs.value); |
| 4296 | |
| 4297 | return rhs; |
| 4298 | } |
| 4299 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4300 | RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4301 | { |
| 4302 | Value *value = rhs.loadValue(); |
| 4303 | storeValue(value); |
| 4304 | |
| 4305 | return RValue<UShort8>(value); |
| 4306 | } |
| 4307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4308 | RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4309 | { |
| 4310 | Value *value = rhs.loadValue(); |
| 4311 | storeValue(value); |
| 4312 | |
| 4313 | return RValue<UShort8>(value); |
| 4314 | } |
| 4315 | |
| 4316 | RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4317 | { |
| 4318 | return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4319 | } |
| 4320 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4321 | RValue<UShort> Extract(RValue<UShort8> val, int i) |
| 4322 | { |
| 4323 | return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i)); |
| 4324 | } |
| 4325 | |
| 4326 | RValue<UShort8> Insert(RValue<UShort8> val, RValue<UShort> element, int i) |
| 4327 | { |
| 4328 | return RValue<UShort8>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 4329 | } |
| 4330 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4331 | RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs) |
| 4332 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4333 | if(emulateIntrinsics) |
| 4334 | { |
| 4335 | UShort8 result; |
| 4336 | result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0); |
| 4337 | result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1); |
| 4338 | result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2); |
| 4339 | result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3); |
| 4340 | result = Insert(result, Extract(lhs, 4) << UShort(rhs), 4); |
| 4341 | result = Insert(result, Extract(lhs, 5) << UShort(rhs), 5); |
| 4342 | result = Insert(result, Extract(lhs, 6) << UShort(rhs), 6); |
| 4343 | result = Insert(result, Extract(lhs, 7) << UShort(rhs), 7); |
| 4344 | |
| 4345 | return result; |
| 4346 | } |
| 4347 | else |
| 4348 | { |
| 4349 | return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4350 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs) |
| 4354 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 4355 | if(emulateIntrinsics) |
| 4356 | { |
| 4357 | UShort8 result; |
| 4358 | result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0); |
| 4359 | result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1); |
| 4360 | result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2); |
| 4361 | result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3); |
| 4362 | result = Insert(result, Extract(lhs, 4) >> UShort(rhs), 4); |
| 4363 | result = Insert(result, Extract(lhs, 5) >> UShort(rhs), 5); |
| 4364 | result = Insert(result, Extract(lhs, 6) >> UShort(rhs), 6); |
| 4365 | result = Insert(result, Extract(lhs, 7) >> UShort(rhs), 7); |
| 4366 | |
| 4367 | return result; |
| 4368 | } |
| 4369 | else |
| 4370 | { |
| 4371 | return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 4372 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4376 | { |
| 4377 | return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4378 | } |
| 4379 | |
| 4380 | RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| 4381 | { |
| 4382 | return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4383 | } |
| 4384 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4385 | RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4386 | { |
| 4387 | return lhs = lhs + rhs; |
| 4388 | } |
| 4389 | |
| 4390 | RValue<UShort8> operator~(RValue<UShort8> val) |
| 4391 | { |
| 4392 | return RValue<UShort8>(Nucleus::createNot(val.value)); |
| 4393 | } |
| 4394 | |
| 4395 | RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7) |
| 4396 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4397 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y) |
| 4401 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4402 | assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element)) |
| 4406 | // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element) |
| 4407 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 4408 | // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4409 | // } |
| 4410 | |
| 4411 | Type *UShort8::getType() |
| 4412 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4413 | return T(Ice::IceType_v8i16); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | Int::Int(Argument<Int> argument) |
| 4417 | { |
| 4418 | storeValue(argument.value); |
| 4419 | } |
| 4420 | |
| 4421 | Int::Int(RValue<Byte> cast) |
| 4422 | { |
| 4423 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 4424 | |
| 4425 | storeValue(integer); |
| 4426 | } |
| 4427 | |
| 4428 | Int::Int(RValue<SByte> cast) |
| 4429 | { |
| 4430 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 4431 | |
| 4432 | storeValue(integer); |
| 4433 | } |
| 4434 | |
| 4435 | Int::Int(RValue<Short> cast) |
| 4436 | { |
| 4437 | Value *integer = Nucleus::createSExt(cast.value, Int::getType()); |
| 4438 | |
| 4439 | storeValue(integer); |
| 4440 | } |
| 4441 | |
| 4442 | Int::Int(RValue<UShort> cast) |
| 4443 | { |
| 4444 | Value *integer = Nucleus::createZExt(cast.value, Int::getType()); |
| 4445 | |
| 4446 | storeValue(integer); |
| 4447 | } |
| 4448 | |
| 4449 | Int::Int(RValue<Int2> cast) |
| 4450 | { |
| 4451 | *this = Extract(cast, 0); |
| 4452 | } |
| 4453 | |
| 4454 | Int::Int(RValue<Long> cast) |
| 4455 | { |
| 4456 | Value *integer = Nucleus::createTrunc(cast.value, Int::getType()); |
| 4457 | |
| 4458 | storeValue(integer); |
| 4459 | } |
| 4460 | |
| 4461 | Int::Int(RValue<Float> cast) |
| 4462 | { |
| 4463 | Value *integer = Nucleus::createFPToSI(cast.value, Int::getType()); |
| 4464 | |
| 4465 | storeValue(integer); |
| 4466 | } |
| 4467 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4468 | Int::Int(int x) |
| 4469 | { |
| 4470 | storeValue(Nucleus::createConstantInt(x)); |
| 4471 | } |
| 4472 | |
| 4473 | Int::Int(RValue<Int> rhs) |
| 4474 | { |
| 4475 | storeValue(rhs.value); |
| 4476 | } |
| 4477 | |
| 4478 | Int::Int(RValue<UInt> rhs) |
| 4479 | { |
| 4480 | storeValue(rhs.value); |
| 4481 | } |
| 4482 | |
| 4483 | Int::Int(const Int &rhs) |
| 4484 | { |
| 4485 | Value *value = rhs.loadValue(); |
| 4486 | storeValue(value); |
| 4487 | } |
| 4488 | |
| 4489 | Int::Int(const Reference<Int> &rhs) |
| 4490 | { |
| 4491 | Value *value = rhs.loadValue(); |
| 4492 | storeValue(value); |
| 4493 | } |
| 4494 | |
| 4495 | Int::Int(const UInt &rhs) |
| 4496 | { |
| 4497 | Value *value = rhs.loadValue(); |
| 4498 | storeValue(value); |
| 4499 | } |
| 4500 | |
| 4501 | Int::Int(const Reference<UInt> &rhs) |
| 4502 | { |
| 4503 | Value *value = rhs.loadValue(); |
| 4504 | storeValue(value); |
| 4505 | } |
| 4506 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4507 | RValue<Int> Int::operator=(int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4508 | { |
| 4509 | return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4510 | } |
| 4511 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4512 | RValue<Int> Int::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4513 | { |
| 4514 | storeValue(rhs.value); |
| 4515 | |
| 4516 | return rhs; |
| 4517 | } |
| 4518 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4519 | RValue<Int> Int::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4520 | { |
| 4521 | storeValue(rhs.value); |
| 4522 | |
| 4523 | return RValue<Int>(rhs); |
| 4524 | } |
| 4525 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4526 | RValue<Int> Int::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4527 | { |
| 4528 | Value *value = rhs.loadValue(); |
| 4529 | storeValue(value); |
| 4530 | |
| 4531 | return RValue<Int>(value); |
| 4532 | } |
| 4533 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4534 | RValue<Int> Int::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4535 | { |
| 4536 | Value *value = rhs.loadValue(); |
| 4537 | storeValue(value); |
| 4538 | |
| 4539 | return RValue<Int>(value); |
| 4540 | } |
| 4541 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4542 | RValue<Int> Int::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4543 | { |
| 4544 | Value *value = rhs.loadValue(); |
| 4545 | storeValue(value); |
| 4546 | |
| 4547 | return RValue<Int>(value); |
| 4548 | } |
| 4549 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4550 | RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4551 | { |
| 4552 | Value *value = rhs.loadValue(); |
| 4553 | storeValue(value); |
| 4554 | |
| 4555 | return RValue<Int>(value); |
| 4556 | } |
| 4557 | |
| 4558 | RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| 4559 | { |
| 4560 | return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4561 | } |
| 4562 | |
| 4563 | RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| 4564 | { |
| 4565 | return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4566 | } |
| 4567 | |
| 4568 | RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| 4569 | { |
| 4570 | return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4571 | } |
| 4572 | |
| 4573 | RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| 4574 | { |
| 4575 | return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 4576 | } |
| 4577 | |
| 4578 | RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| 4579 | { |
| 4580 | return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 4581 | } |
| 4582 | |
| 4583 | RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| 4584 | { |
| 4585 | return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 4586 | } |
| 4587 | |
| 4588 | RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| 4589 | { |
| 4590 | return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value)); |
| 4591 | } |
| 4592 | |
| 4593 | RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| 4594 | { |
| 4595 | return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value)); |
| 4596 | } |
| 4597 | |
| 4598 | RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| 4599 | { |
| 4600 | return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value)); |
| 4601 | } |
| 4602 | |
| 4603 | RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| 4604 | { |
| 4605 | return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4606 | } |
| 4607 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4608 | RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4609 | { |
| 4610 | return lhs = lhs + rhs; |
| 4611 | } |
| 4612 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4613 | RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4614 | { |
| 4615 | return lhs = lhs - rhs; |
| 4616 | } |
| 4617 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4618 | RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4619 | { |
| 4620 | return lhs = lhs * rhs; |
| 4621 | } |
| 4622 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4623 | RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4624 | { |
| 4625 | return lhs = lhs / rhs; |
| 4626 | } |
| 4627 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4628 | RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4629 | { |
| 4630 | return lhs = lhs % rhs; |
| 4631 | } |
| 4632 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4633 | RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4634 | { |
| 4635 | return lhs = lhs & rhs; |
| 4636 | } |
| 4637 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4638 | RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4639 | { |
| 4640 | return lhs = lhs | rhs; |
| 4641 | } |
| 4642 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4643 | RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4644 | { |
| 4645 | return lhs = lhs ^ rhs; |
| 4646 | } |
| 4647 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4648 | RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4649 | { |
| 4650 | return lhs = lhs << rhs; |
| 4651 | } |
| 4652 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4653 | RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4654 | { |
| 4655 | return lhs = lhs >> rhs; |
| 4656 | } |
| 4657 | |
| 4658 | RValue<Int> operator+(RValue<Int> val) |
| 4659 | { |
| 4660 | return val; |
| 4661 | } |
| 4662 | |
| 4663 | RValue<Int> operator-(RValue<Int> val) |
| 4664 | { |
| 4665 | return RValue<Int>(Nucleus::createNeg(val.value)); |
| 4666 | } |
| 4667 | |
| 4668 | RValue<Int> operator~(RValue<Int> val) |
| 4669 | { |
| 4670 | return RValue<Int>(Nucleus::createNot(val.value)); |
| 4671 | } |
| 4672 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4673 | RValue<Int> operator++(Int &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4674 | { |
Nicolas Capens | 5b41ba3 | 2016-12-08 14:34:00 -0500 | [diff] [blame] | 4675 | RValue<Int> res = val; |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4676 | val += 1; |
| 4677 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4678 | } |
| 4679 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4680 | const Int &operator++(Int &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4681 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4682 | val += 1; |
| 4683 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4684 | } |
| 4685 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4686 | RValue<Int> operator--(Int &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4687 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4688 | RValue<Int> res = val; |
| 4689 | val -= 1; |
| 4690 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4691 | } |
| 4692 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4693 | const Int &operator--(Int &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4694 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 4695 | val -= 1; |
| 4696 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| 4700 | { |
| 4701 | return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value)); |
| 4702 | } |
| 4703 | |
| 4704 | RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| 4705 | { |
| 4706 | return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value)); |
| 4707 | } |
| 4708 | |
| 4709 | RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| 4710 | { |
| 4711 | return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value)); |
| 4712 | } |
| 4713 | |
| 4714 | RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| 4715 | { |
| 4716 | return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value)); |
| 4717 | } |
| 4718 | |
| 4719 | RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| 4720 | { |
| 4721 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 4722 | } |
| 4723 | |
| 4724 | RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| 4725 | { |
| 4726 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 4727 | } |
| 4728 | |
| 4729 | RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| 4730 | { |
| 4731 | return IfThenElse(x > y, x, y); |
| 4732 | } |
| 4733 | |
| 4734 | RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| 4735 | { |
| 4736 | return IfThenElse(x < y, x, y); |
| 4737 | } |
| 4738 | |
| 4739 | RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| 4740 | { |
| 4741 | return Min(Max(x, min), max); |
| 4742 | } |
| 4743 | |
| 4744 | RValue<Int> RoundInt(RValue<Float> cast) |
| 4745 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 4746 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4747 | { |
| 4748 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 4749 | return Int((cast + Float(0x00C00000)) - Float(0x00C00000)); |
| 4750 | } |
| 4751 | else |
| 4752 | { |
| 4753 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 4754 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 4755 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 4756 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 4757 | nearbyint->addArg(cast.value); |
| 4758 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 4759 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 4760 | return RValue<Int>(V(result)); |
| 4761 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | Type *Int::getType() |
| 4765 | { |
| 4766 | return T(Ice::IceType_i32); |
| 4767 | } |
| 4768 | |
| 4769 | Long::Long(RValue<Int> cast) |
| 4770 | { |
| 4771 | Value *integer = Nucleus::createSExt(cast.value, Long::getType()); |
| 4772 | |
| 4773 | storeValue(integer); |
| 4774 | } |
| 4775 | |
| 4776 | Long::Long(RValue<UInt> cast) |
| 4777 | { |
| 4778 | Value *integer = Nucleus::createZExt(cast.value, Long::getType()); |
| 4779 | |
| 4780 | storeValue(integer); |
| 4781 | } |
| 4782 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4783 | Long::Long(RValue<Long> rhs) |
| 4784 | { |
| 4785 | storeValue(rhs.value); |
| 4786 | } |
| 4787 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4788 | RValue<Long> Long::operator=(int64_t rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4789 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 4790 | return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4791 | } |
| 4792 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4793 | RValue<Long> Long::operator=(RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4794 | { |
| 4795 | storeValue(rhs.value); |
| 4796 | |
| 4797 | return rhs; |
| 4798 | } |
| 4799 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4800 | RValue<Long> Long::operator=(const Long &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4801 | { |
| 4802 | Value *value = rhs.loadValue(); |
| 4803 | storeValue(value); |
| 4804 | |
| 4805 | return RValue<Long>(value); |
| 4806 | } |
| 4807 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4808 | RValue<Long> Long::operator=(const Reference<Long> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4809 | { |
| 4810 | Value *value = rhs.loadValue(); |
| 4811 | storeValue(value); |
| 4812 | |
| 4813 | return RValue<Long>(value); |
| 4814 | } |
| 4815 | |
| 4816 | RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| 4817 | { |
| 4818 | return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4819 | } |
| 4820 | |
| 4821 | RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| 4822 | { |
| 4823 | return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4824 | } |
| 4825 | |
Chris Forbes | aa8f699 | 2019-03-01 14:18:30 -0800 | [diff] [blame^] | 4826 | RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs) |
| 4827 | { |
| 4828 | return RValue<Long>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4829 | } |
| 4830 | |
| 4831 | RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs) |
| 4832 | { |
| 4833 | return RValue<Long>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 4834 | } |
| 4835 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4836 | RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4837 | { |
| 4838 | return lhs = lhs + rhs; |
| 4839 | } |
| 4840 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4841 | RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4842 | { |
| 4843 | return lhs = lhs - rhs; |
| 4844 | } |
| 4845 | |
| 4846 | RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y) |
| 4847 | { |
| 4848 | return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value)); |
| 4849 | } |
| 4850 | |
| 4851 | Type *Long::getType() |
| 4852 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 4853 | return T(Ice::IceType_i64); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4854 | } |
| 4855 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4856 | UInt::UInt(Argument<UInt> argument) |
| 4857 | { |
| 4858 | storeValue(argument.value); |
| 4859 | } |
| 4860 | |
| 4861 | UInt::UInt(RValue<UShort> cast) |
| 4862 | { |
| 4863 | Value *integer = Nucleus::createZExt(cast.value, UInt::getType()); |
| 4864 | |
| 4865 | storeValue(integer); |
| 4866 | } |
| 4867 | |
| 4868 | UInt::UInt(RValue<Long> cast) |
| 4869 | { |
| 4870 | Value *integer = Nucleus::createTrunc(cast.value, UInt::getType()); |
| 4871 | |
| 4872 | storeValue(integer); |
| 4873 | } |
| 4874 | |
| 4875 | UInt::UInt(RValue<Float> cast) |
| 4876 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 4877 | // Smallest positive value representable in UInt, but not in Int |
| 4878 | const unsigned int ustart = 0x80000000u; |
| 4879 | const float ustartf = float(ustart); |
| 4880 | |
| 4881 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 4882 | storeValue((~(As<Int>(cast) >> 31) & |
| 4883 | // Check if the value can be represented as an Int |
| 4884 | IfThenElse(cast >= ustartf, |
| 4885 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 4886 | As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)), |
| 4887 | // Otherwise, just convert normally |
| 4888 | Int(cast))).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4889 | } |
| 4890 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4891 | UInt::UInt(int x) |
| 4892 | { |
| 4893 | storeValue(Nucleus::createConstantInt(x)); |
| 4894 | } |
| 4895 | |
| 4896 | UInt::UInt(unsigned int x) |
| 4897 | { |
| 4898 | storeValue(Nucleus::createConstantInt(x)); |
| 4899 | } |
| 4900 | |
| 4901 | UInt::UInt(RValue<UInt> rhs) |
| 4902 | { |
| 4903 | storeValue(rhs.value); |
| 4904 | } |
| 4905 | |
| 4906 | UInt::UInt(RValue<Int> rhs) |
| 4907 | { |
| 4908 | storeValue(rhs.value); |
| 4909 | } |
| 4910 | |
| 4911 | UInt::UInt(const UInt &rhs) |
| 4912 | { |
| 4913 | Value *value = rhs.loadValue(); |
| 4914 | storeValue(value); |
| 4915 | } |
| 4916 | |
| 4917 | UInt::UInt(const Reference<UInt> &rhs) |
| 4918 | { |
| 4919 | Value *value = rhs.loadValue(); |
| 4920 | storeValue(value); |
| 4921 | } |
| 4922 | |
| 4923 | UInt::UInt(const Int &rhs) |
| 4924 | { |
| 4925 | Value *value = rhs.loadValue(); |
| 4926 | storeValue(value); |
| 4927 | } |
| 4928 | |
| 4929 | UInt::UInt(const Reference<Int> &rhs) |
| 4930 | { |
| 4931 | Value *value = rhs.loadValue(); |
| 4932 | storeValue(value); |
| 4933 | } |
| 4934 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4935 | RValue<UInt> UInt::operator=(unsigned int rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4936 | { |
| 4937 | return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| 4938 | } |
| 4939 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4940 | RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4941 | { |
| 4942 | storeValue(rhs.value); |
| 4943 | |
| 4944 | return rhs; |
| 4945 | } |
| 4946 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4947 | RValue<UInt> UInt::operator=(RValue<Int> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4948 | { |
| 4949 | storeValue(rhs.value); |
| 4950 | |
| 4951 | return RValue<UInt>(rhs); |
| 4952 | } |
| 4953 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4954 | RValue<UInt> UInt::operator=(const UInt &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4955 | { |
| 4956 | Value *value = rhs.loadValue(); |
| 4957 | storeValue(value); |
| 4958 | |
| 4959 | return RValue<UInt>(value); |
| 4960 | } |
| 4961 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4962 | RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4963 | { |
| 4964 | Value *value = rhs.loadValue(); |
| 4965 | storeValue(value); |
| 4966 | |
| 4967 | return RValue<UInt>(value); |
| 4968 | } |
| 4969 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4970 | RValue<UInt> UInt::operator=(const Int &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4971 | { |
| 4972 | Value *value = rhs.loadValue(); |
| 4973 | storeValue(value); |
| 4974 | |
| 4975 | return RValue<UInt>(value); |
| 4976 | } |
| 4977 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 4978 | RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 4979 | { |
| 4980 | Value *value = rhs.loadValue(); |
| 4981 | storeValue(value); |
| 4982 | |
| 4983 | return RValue<UInt>(value); |
| 4984 | } |
| 4985 | |
| 4986 | RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4987 | { |
| 4988 | return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 4989 | } |
| 4990 | |
| 4991 | RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4992 | { |
| 4993 | return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value)); |
| 4994 | } |
| 4995 | |
| 4996 | RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| 4997 | { |
| 4998 | return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value)); |
| 4999 | } |
| 5000 | |
| 5001 | RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5002 | { |
| 5003 | return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5004 | } |
| 5005 | |
| 5006 | RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5007 | { |
| 5008 | return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5009 | } |
| 5010 | |
| 5011 | RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5012 | { |
| 5013 | return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5014 | } |
| 5015 | |
| 5016 | RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5017 | { |
| 5018 | return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5019 | } |
| 5020 | |
| 5021 | RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5022 | { |
| 5023 | return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5024 | } |
| 5025 | |
| 5026 | RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5027 | { |
| 5028 | return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5029 | } |
| 5030 | |
| 5031 | RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5032 | { |
| 5033 | return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 5034 | } |
| 5035 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5036 | RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5037 | { |
| 5038 | return lhs = lhs + rhs; |
| 5039 | } |
| 5040 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5041 | RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5042 | { |
| 5043 | return lhs = lhs - rhs; |
| 5044 | } |
| 5045 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5046 | RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5047 | { |
| 5048 | return lhs = lhs * rhs; |
| 5049 | } |
| 5050 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5051 | RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5052 | { |
| 5053 | return lhs = lhs / rhs; |
| 5054 | } |
| 5055 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5056 | RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5057 | { |
| 5058 | return lhs = lhs % rhs; |
| 5059 | } |
| 5060 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5061 | RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5062 | { |
| 5063 | return lhs = lhs & rhs; |
| 5064 | } |
| 5065 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5066 | RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5067 | { |
| 5068 | return lhs = lhs | rhs; |
| 5069 | } |
| 5070 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5071 | RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5072 | { |
| 5073 | return lhs = lhs ^ rhs; |
| 5074 | } |
| 5075 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5076 | RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5077 | { |
| 5078 | return lhs = lhs << rhs; |
| 5079 | } |
| 5080 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5081 | RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5082 | { |
| 5083 | return lhs = lhs >> rhs; |
| 5084 | } |
| 5085 | |
| 5086 | RValue<UInt> operator+(RValue<UInt> val) |
| 5087 | { |
| 5088 | return val; |
| 5089 | } |
| 5090 | |
| 5091 | RValue<UInt> operator-(RValue<UInt> val) |
| 5092 | { |
| 5093 | return RValue<UInt>(Nucleus::createNeg(val.value)); |
| 5094 | } |
| 5095 | |
| 5096 | RValue<UInt> operator~(RValue<UInt> val) |
| 5097 | { |
| 5098 | return RValue<UInt>(Nucleus::createNot(val.value)); |
| 5099 | } |
| 5100 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5101 | RValue<UInt> operator++(UInt &val, int) // Post-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5102 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5103 | RValue<UInt> res = val; |
| 5104 | val += 1; |
| 5105 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5106 | } |
| 5107 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5108 | const UInt &operator++(UInt &val) // Pre-increment |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5109 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5110 | val += 1; |
| 5111 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5112 | } |
| 5113 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5114 | RValue<UInt> operator--(UInt &val, int) // Post-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5115 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5116 | RValue<UInt> res = val; |
| 5117 | val -= 1; |
| 5118 | return res; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5119 | } |
| 5120 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5121 | const UInt &operator--(UInt &val) // Pre-decrement |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5122 | { |
Nicolas Capens | d122940 | 2016-11-07 16:05:22 -0500 | [diff] [blame] | 5123 | val -= 1; |
| 5124 | return val; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y) |
| 5128 | { |
| 5129 | return IfThenElse(x > y, x, y); |
| 5130 | } |
| 5131 | |
| 5132 | RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y) |
| 5133 | { |
| 5134 | return IfThenElse(x < y, x, y); |
| 5135 | } |
| 5136 | |
| 5137 | RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max) |
| 5138 | { |
| 5139 | return Min(Max(x, min), max); |
| 5140 | } |
| 5141 | |
| 5142 | RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5143 | { |
| 5144 | return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value)); |
| 5145 | } |
| 5146 | |
| 5147 | RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5148 | { |
| 5149 | return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value)); |
| 5150 | } |
| 5151 | |
| 5152 | RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5153 | { |
| 5154 | return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value)); |
| 5155 | } |
| 5156 | |
| 5157 | RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5158 | { |
| 5159 | return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value)); |
| 5160 | } |
| 5161 | |
| 5162 | RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5163 | { |
| 5164 | return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value)); |
| 5165 | } |
| 5166 | |
| 5167 | RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs) |
| 5168 | { |
| 5169 | return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value)); |
| 5170 | } |
| 5171 | |
| 5172 | // RValue<UInt> RoundUInt(RValue<Float> cast) |
| 5173 | // { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 5174 | // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5175 | // } |
| 5176 | |
| 5177 | Type *UInt::getType() |
| 5178 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5179 | return T(Ice::IceType_i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | // Int2::Int2(RValue<Int> cast) |
| 5183 | // { |
| 5184 | // Value *extend = Nucleus::createZExt(cast.value, Long::getType()); |
| 5185 | // Value *vector = Nucleus::createBitCast(extend, Int2::getType()); |
| 5186 | // |
| 5187 | // Constant *shuffle[2]; |
| 5188 | // shuffle[0] = Nucleus::createConstantInt(0); |
| 5189 | // shuffle[1] = Nucleus::createConstantInt(0); |
| 5190 | // |
| 5191 | // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2)); |
| 5192 | // |
| 5193 | // storeValue(replicate); |
| 5194 | // } |
| 5195 | |
| 5196 | Int2::Int2(RValue<Int4> cast) |
| 5197 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 5198 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5199 | } |
| 5200 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5201 | Int2::Int2(int x, int y) |
| 5202 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5203 | int64_t constantVector[2] = {x, y}; |
| 5204 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | Int2::Int2(RValue<Int2> rhs) |
| 5208 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5209 | storeValue(rhs.value); |
| 5210 | } |
| 5211 | |
| 5212 | Int2::Int2(const Int2 &rhs) |
| 5213 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5214 | Value *value = rhs.loadValue(); |
| 5215 | storeValue(value); |
| 5216 | } |
| 5217 | |
| 5218 | Int2::Int2(const Reference<Int2> &rhs) |
| 5219 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5220 | Value *value = rhs.loadValue(); |
| 5221 | storeValue(value); |
| 5222 | } |
| 5223 | |
| 5224 | Int2::Int2(RValue<Int> lo, RValue<Int> hi) |
| 5225 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5226 | int shuffle[4] = {0, 4, 1, 5}; |
| 5227 | Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle); |
| 5228 | |
| 5229 | storeValue(Nucleus::createBitCast(packed, Int2::getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5230 | } |
| 5231 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5232 | RValue<Int2> Int2::operator=(RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5233 | { |
| 5234 | storeValue(rhs.value); |
| 5235 | |
| 5236 | return rhs; |
| 5237 | } |
| 5238 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5239 | RValue<Int2> Int2::operator=(const Int2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5240 | { |
| 5241 | Value *value = rhs.loadValue(); |
| 5242 | storeValue(value); |
| 5243 | |
| 5244 | return RValue<Int2>(value); |
| 5245 | } |
| 5246 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5247 | RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5248 | { |
| 5249 | Value *value = rhs.loadValue(); |
| 5250 | storeValue(value); |
| 5251 | |
| 5252 | return RValue<Int2>(value); |
| 5253 | } |
| 5254 | |
| 5255 | RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5256 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5257 | return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5261 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5262 | return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5266 | // { |
| 5267 | // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5268 | // } |
| 5269 | |
| 5270 | // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5271 | // { |
| 5272 | // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5273 | // } |
| 5274 | |
| 5275 | // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5276 | // { |
| 5277 | // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5278 | // } |
| 5279 | |
| 5280 | RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5281 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5282 | return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5283 | } |
| 5284 | |
| 5285 | RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5286 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5287 | return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs) |
| 5291 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5292 | return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs) |
| 5296 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5297 | if(emulateIntrinsics) |
| 5298 | { |
| 5299 | Int2 result; |
| 5300 | result = Insert(result, Extract(lhs, 0) << Int(rhs), 0); |
| 5301 | result = Insert(result, Extract(lhs, 1) << Int(rhs), 1); |
| 5302 | |
| 5303 | return result; |
| 5304 | } |
| 5305 | else |
| 5306 | { |
| 5307 | return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5308 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs) |
| 5312 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5313 | if(emulateIntrinsics) |
| 5314 | { |
| 5315 | Int2 result; |
| 5316 | result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0); |
| 5317 | result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1); |
| 5318 | |
| 5319 | return result; |
| 5320 | } |
| 5321 | else |
| 5322 | { |
| 5323 | return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5324 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5325 | } |
| 5326 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5327 | RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5328 | { |
| 5329 | return lhs = lhs + rhs; |
| 5330 | } |
| 5331 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5332 | RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5333 | { |
| 5334 | return lhs = lhs - rhs; |
| 5335 | } |
| 5336 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5337 | // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5338 | // { |
| 5339 | // return lhs = lhs * rhs; |
| 5340 | // } |
| 5341 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5342 | // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5343 | // { |
| 5344 | // return lhs = lhs / rhs; |
| 5345 | // } |
| 5346 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5347 | // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5348 | // { |
| 5349 | // return lhs = lhs % rhs; |
| 5350 | // } |
| 5351 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5352 | RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5353 | { |
| 5354 | return lhs = lhs & rhs; |
| 5355 | } |
| 5356 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5357 | RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5358 | { |
| 5359 | return lhs = lhs | rhs; |
| 5360 | } |
| 5361 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5362 | RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5363 | { |
| 5364 | return lhs = lhs ^ rhs; |
| 5365 | } |
| 5366 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5367 | RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5368 | { |
| 5369 | return lhs = lhs << rhs; |
| 5370 | } |
| 5371 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5372 | RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5373 | { |
| 5374 | return lhs = lhs >> rhs; |
| 5375 | } |
| 5376 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5377 | // RValue<Int2> operator+(RValue<Int2> val) |
| 5378 | // { |
| 5379 | // return val; |
| 5380 | // } |
| 5381 | |
| 5382 | // RValue<Int2> operator-(RValue<Int2> val) |
| 5383 | // { |
| 5384 | // return RValue<Int2>(Nucleus::createNeg(val.value)); |
| 5385 | // } |
| 5386 | |
| 5387 | RValue<Int2> operator~(RValue<Int2> val) |
| 5388 | { |
Nicolas Capens | c5c0c33 | 2016-11-08 11:37:01 -0500 | [diff] [blame] | 5389 | return RValue<Int2>(Nucleus::createNot(val.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5390 | } |
| 5391 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 5392 | RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5393 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5394 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
| 5395 | return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5396 | } |
| 5397 | |
Nicolas Capens | 45f187a | 2016-12-02 15:30:56 -0500 | [diff] [blame] | 5398 | RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5399 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5400 | int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32 |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5401 | auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
| 5402 | return As<Short4>(Swizzle(lowHigh, 0xEE)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | RValue<Int> Extract(RValue<Int2> val, int i) |
| 5406 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 5407 | return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i) |
| 5411 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 5412 | return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | Type *Int2::getType() |
| 5416 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5417 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5418 | } |
| 5419 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5420 | UInt2::UInt2(unsigned int x, unsigned int y) |
| 5421 | { |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5422 | int64_t constantVector[2] = {x, y}; |
| 5423 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | UInt2::UInt2(RValue<UInt2> rhs) |
| 5427 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5428 | storeValue(rhs.value); |
| 5429 | } |
| 5430 | |
| 5431 | UInt2::UInt2(const UInt2 &rhs) |
| 5432 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5433 | Value *value = rhs.loadValue(); |
| 5434 | storeValue(value); |
| 5435 | } |
| 5436 | |
| 5437 | UInt2::UInt2(const Reference<UInt2> &rhs) |
| 5438 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5439 | Value *value = rhs.loadValue(); |
| 5440 | storeValue(value); |
| 5441 | } |
| 5442 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5443 | RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5444 | { |
| 5445 | storeValue(rhs.value); |
| 5446 | |
| 5447 | return rhs; |
| 5448 | } |
| 5449 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5450 | RValue<UInt2> UInt2::operator=(const UInt2 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5451 | { |
| 5452 | Value *value = rhs.loadValue(); |
| 5453 | storeValue(value); |
| 5454 | |
| 5455 | return RValue<UInt2>(value); |
| 5456 | } |
| 5457 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5458 | RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5459 | { |
| 5460 | Value *value = rhs.loadValue(); |
| 5461 | storeValue(value); |
| 5462 | |
| 5463 | return RValue<UInt2>(value); |
| 5464 | } |
| 5465 | |
| 5466 | RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5467 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5468 | return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5472 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5473 | return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5477 | // { |
| 5478 | // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5479 | // } |
| 5480 | |
| 5481 | // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5482 | // { |
| 5483 | // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 5484 | // } |
| 5485 | |
| 5486 | // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5487 | // { |
| 5488 | // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value)); |
| 5489 | // } |
| 5490 | |
| 5491 | RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5492 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5493 | return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5497 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5498 | return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs) |
| 5502 | { |
Nicolas Capens | c4c431d | 2016-10-21 15:30:29 -0400 | [diff] [blame] | 5503 | return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5504 | } |
| 5505 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5506 | RValue<UInt> Extract(RValue<UInt2> val, int i) |
| 5507 | { |
| 5508 | return RValue<UInt>(Nucleus::createExtractElement(val.value, UInt::getType(), i)); |
| 5509 | } |
| 5510 | |
| 5511 | RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i) |
| 5512 | { |
| 5513 | return RValue<UInt2>(Nucleus::createInsertElement(val.value, element.value, i)); |
| 5514 | } |
| 5515 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5516 | RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs) |
| 5517 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5518 | if(emulateIntrinsics) |
| 5519 | { |
| 5520 | UInt2 result; |
| 5521 | result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0); |
| 5522 | result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1); |
| 5523 | |
| 5524 | return result; |
| 5525 | } |
| 5526 | else |
| 5527 | { |
| 5528 | return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5529 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs) |
| 5533 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5534 | if(emulateIntrinsics) |
| 5535 | { |
| 5536 | UInt2 result; |
| 5537 | result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0); |
| 5538 | result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1); |
| 5539 | |
| 5540 | return result; |
| 5541 | } |
| 5542 | else |
| 5543 | { |
| 5544 | return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5545 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5546 | } |
| 5547 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5548 | RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5549 | { |
| 5550 | return lhs = lhs + rhs; |
| 5551 | } |
| 5552 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5553 | RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5554 | { |
| 5555 | return lhs = lhs - rhs; |
| 5556 | } |
| 5557 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5558 | // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5559 | // { |
| 5560 | // return lhs = lhs * rhs; |
| 5561 | // } |
| 5562 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5563 | // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5564 | // { |
| 5565 | // return lhs = lhs / rhs; |
| 5566 | // } |
| 5567 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5568 | // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5569 | // { |
| 5570 | // return lhs = lhs % rhs; |
| 5571 | // } |
| 5572 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5573 | RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5574 | { |
| 5575 | return lhs = lhs & rhs; |
| 5576 | } |
| 5577 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5578 | RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5579 | { |
| 5580 | return lhs = lhs | rhs; |
| 5581 | } |
| 5582 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5583 | RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5584 | { |
| 5585 | return lhs = lhs ^ rhs; |
| 5586 | } |
| 5587 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5588 | RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5589 | { |
| 5590 | return lhs = lhs << rhs; |
| 5591 | } |
| 5592 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5593 | RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5594 | { |
| 5595 | return lhs = lhs >> rhs; |
| 5596 | } |
| 5597 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5598 | // RValue<UInt2> operator+(RValue<UInt2> val) |
| 5599 | // { |
| 5600 | // return val; |
| 5601 | // } |
| 5602 | |
| 5603 | // RValue<UInt2> operator-(RValue<UInt2> val) |
| 5604 | // { |
| 5605 | // return RValue<UInt2>(Nucleus::createNeg(val.value)); |
| 5606 | // } |
| 5607 | |
| 5608 | RValue<UInt2> operator~(RValue<UInt2> val) |
| 5609 | { |
| 5610 | return RValue<UInt2>(Nucleus::createNot(val.value)); |
| 5611 | } |
| 5612 | |
| 5613 | Type *UInt2::getType() |
| 5614 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 5615 | return T(Type_v2i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5616 | } |
| 5617 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5618 | Int4::Int4() : XYZW(this) |
| 5619 | { |
| 5620 | } |
| 5621 | |
| 5622 | Int4::Int4(RValue<Byte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5623 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5624 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5625 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5626 | |
| 5627 | Value *e; |
| 5628 | int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; |
| 5629 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5630 | Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle); |
| 5631 | |
| 5632 | int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5633 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
| 5634 | e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2); |
| 5635 | |
| 5636 | Value *f = Nucleus::createBitCast(e, Int4::getType()); |
| 5637 | storeValue(f); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5638 | } |
| 5639 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5640 | Int4::Int4(RValue<SByte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5641 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5642 | Value *x = Nucleus::createBitCast(cast.value, Int::getType()); |
| 5643 | Value *a = Nucleus::createInsertElement(loadValue(), x, 0); |
| 5644 | |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5645 | int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; |
| 5646 | Value *b = Nucleus::createBitCast(a, Byte16::getType()); |
| 5647 | Value *c = Nucleus::createShuffleVector(b, b, swizzle); |
| 5648 | |
| 5649 | int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5650 | Value *d = Nucleus::createBitCast(c, Short8::getType()); |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5651 | Value *e = Nucleus::createShuffleVector(d, d, swizzle2); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5652 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5653 | *this = As<Int4>(e) >> 24; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5654 | } |
| 5655 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5656 | Int4::Int4(RValue<Float4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5657 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5658 | Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType()); |
| 5659 | |
| 5660 | storeValue(xyzw); |
| 5661 | } |
| 5662 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5663 | Int4::Int4(RValue<Short4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5664 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5665 | int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3}; |
| 5666 | Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle); |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5667 | |
| 5668 | *this = As<Int4>(c) >> 16; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5669 | } |
| 5670 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5671 | Int4::Int4(RValue<UShort4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5672 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5673 | int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; |
| 5674 | Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle); |
| 5675 | Value *d = Nucleus::createBitCast(c, Int4::getType()); |
| 5676 | storeValue(d); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5677 | } |
| 5678 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5679 | Int4::Int4(int xyzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5680 | { |
| 5681 | constant(xyzw, xyzw, xyzw, xyzw); |
| 5682 | } |
| 5683 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5684 | Int4::Int4(int x, int yzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5685 | { |
| 5686 | constant(x, yzw, yzw, yzw); |
| 5687 | } |
| 5688 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5689 | Int4::Int4(int x, int y, int zw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5690 | { |
| 5691 | constant(x, y, zw, zw); |
| 5692 | } |
| 5693 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5694 | Int4::Int4(int x, int y, int z, int w) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5695 | { |
| 5696 | constant(x, y, z, w); |
| 5697 | } |
| 5698 | |
| 5699 | void Int4::constant(int x, int y, int z, int w) |
| 5700 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 5701 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 5702 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5703 | } |
| 5704 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5705 | Int4::Int4(RValue<Int4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5706 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5707 | storeValue(rhs.value); |
| 5708 | } |
| 5709 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5710 | Int4::Int4(const Int4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5711 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5712 | Value *value = rhs.loadValue(); |
| 5713 | storeValue(value); |
| 5714 | } |
| 5715 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5716 | Int4::Int4(const Reference<Int4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5717 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5718 | Value *value = rhs.loadValue(); |
| 5719 | storeValue(value); |
| 5720 | } |
| 5721 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5722 | Int4::Int4(RValue<UInt4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5723 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5724 | storeValue(rhs.value); |
| 5725 | } |
| 5726 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5727 | Int4::Int4(const UInt4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5728 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5729 | Value *value = rhs.loadValue(); |
| 5730 | storeValue(value); |
| 5731 | } |
| 5732 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5733 | Int4::Int4(const Reference<UInt4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5734 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5735 | Value *value = rhs.loadValue(); |
| 5736 | storeValue(value); |
| 5737 | } |
| 5738 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5739 | Int4::Int4(RValue<Int2> lo, RValue<Int2> hi) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5740 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 5741 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 5742 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 5743 | |
| 5744 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5745 | } |
| 5746 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5747 | Int4::Int4(RValue<Int> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5748 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5749 | Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5750 | |
| 5751 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 5752 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 5753 | |
| 5754 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5755 | } |
| 5756 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5757 | Int4::Int4(const Int &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5758 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5759 | *this = RValue<Int>(rhs.loadValue()); |
| 5760 | } |
| 5761 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 5762 | Int4::Int4(const Reference<Int> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5763 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5764 | *this = RValue<Int>(rhs.loadValue()); |
| 5765 | } |
| 5766 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5767 | RValue<Int4> Int4::operator=(RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5768 | { |
| 5769 | storeValue(rhs.value); |
| 5770 | |
| 5771 | return rhs; |
| 5772 | } |
| 5773 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5774 | RValue<Int4> Int4::operator=(const Int4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5775 | { |
| 5776 | Value *value = rhs.loadValue(); |
| 5777 | storeValue(value); |
| 5778 | |
| 5779 | return RValue<Int4>(value); |
| 5780 | } |
| 5781 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5782 | RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5783 | { |
| 5784 | Value *value = rhs.loadValue(); |
| 5785 | storeValue(value); |
| 5786 | |
| 5787 | return RValue<Int4>(value); |
| 5788 | } |
| 5789 | |
| 5790 | RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5791 | { |
| 5792 | return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 5793 | } |
| 5794 | |
| 5795 | RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5796 | { |
| 5797 | return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 5798 | } |
| 5799 | |
| 5800 | RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5801 | { |
| 5802 | return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 5803 | } |
| 5804 | |
| 5805 | RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5806 | { |
| 5807 | return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value)); |
| 5808 | } |
| 5809 | |
| 5810 | RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5811 | { |
| 5812 | return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value)); |
| 5813 | } |
| 5814 | |
| 5815 | RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5816 | { |
| 5817 | return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 5818 | } |
| 5819 | |
| 5820 | RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5821 | { |
| 5822 | return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 5823 | } |
| 5824 | |
| 5825 | RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5826 | { |
| 5827 | return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 5828 | } |
| 5829 | |
| 5830 | RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs) |
| 5831 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5832 | if(emulateIntrinsics) |
| 5833 | { |
| 5834 | Int4 result; |
| 5835 | result = Insert(result, Extract(lhs, 0) << Int(rhs), 0); |
| 5836 | result = Insert(result, Extract(lhs, 1) << Int(rhs), 1); |
| 5837 | result = Insert(result, Extract(lhs, 2) << Int(rhs), 2); |
| 5838 | result = Insert(result, Extract(lhs, 3) << Int(rhs), 3); |
| 5839 | |
| 5840 | return result; |
| 5841 | } |
| 5842 | else |
| 5843 | { |
| 5844 | return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5845 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs) |
| 5849 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 5850 | if(emulateIntrinsics) |
| 5851 | { |
| 5852 | Int4 result; |
| 5853 | result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0); |
| 5854 | result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1); |
| 5855 | result = Insert(result, Extract(lhs, 2) >> Int(rhs), 2); |
| 5856 | result = Insert(result, Extract(lhs, 3) >> Int(rhs), 3); |
| 5857 | |
| 5858 | return result; |
| 5859 | } |
| 5860 | else |
| 5861 | { |
| 5862 | return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 5863 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5867 | { |
| 5868 | return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 5869 | } |
| 5870 | |
| 5871 | RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs) |
| 5872 | { |
| 5873 | return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value)); |
| 5874 | } |
| 5875 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5876 | RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5877 | { |
| 5878 | return lhs = lhs + rhs; |
| 5879 | } |
| 5880 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5881 | RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5882 | { |
| 5883 | return lhs = lhs - rhs; |
| 5884 | } |
| 5885 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5886 | RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5887 | { |
| 5888 | return lhs = lhs * rhs; |
| 5889 | } |
| 5890 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5891 | // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5892 | // { |
| 5893 | // return lhs = lhs / rhs; |
| 5894 | // } |
| 5895 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5896 | // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5897 | // { |
| 5898 | // return lhs = lhs % rhs; |
| 5899 | // } |
| 5900 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5901 | RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5902 | { |
| 5903 | return lhs = lhs & rhs; |
| 5904 | } |
| 5905 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5906 | RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5907 | { |
| 5908 | return lhs = lhs | rhs; |
| 5909 | } |
| 5910 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5911 | RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5912 | { |
| 5913 | return lhs = lhs ^ rhs; |
| 5914 | } |
| 5915 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5916 | RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5917 | { |
| 5918 | return lhs = lhs << rhs; |
| 5919 | } |
| 5920 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 5921 | RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5922 | { |
| 5923 | return lhs = lhs >> rhs; |
| 5924 | } |
| 5925 | |
| 5926 | RValue<Int4> operator+(RValue<Int4> val) |
| 5927 | { |
| 5928 | return val; |
| 5929 | } |
| 5930 | |
| 5931 | RValue<Int4> operator-(RValue<Int4> val) |
| 5932 | { |
| 5933 | return RValue<Int4>(Nucleus::createNeg(val.value)); |
| 5934 | } |
| 5935 | |
| 5936 | RValue<Int4> operator~(RValue<Int4> val) |
| 5937 | { |
| 5938 | return RValue<Int4>(Nucleus::createNot(val.value)); |
| 5939 | } |
| 5940 | |
| 5941 | RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y) |
| 5942 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5943 | return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5944 | } |
| 5945 | |
| 5946 | RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y) |
| 5947 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5948 | return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5949 | } |
| 5950 | |
| 5951 | RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y) |
| 5952 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5953 | return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y) |
| 5957 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5958 | return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y) |
| 5962 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5963 | return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5964 | } |
| 5965 | |
| 5966 | RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y) |
| 5967 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 5968 | return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y) |
| 5972 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5973 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5974 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value); |
| 5975 | ::basicBlock->appendInst(cmp); |
| 5976 | |
| 5977 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5978 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5979 | ::basicBlock->appendInst(select); |
| 5980 | |
| 5981 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y) |
| 5985 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 5986 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 5987 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value); |
| 5988 | ::basicBlock->appendInst(cmp); |
| 5989 | |
| 5990 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 5991 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 5992 | ::basicBlock->appendInst(select); |
| 5993 | |
| 5994 | return RValue<Int4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | RValue<Int4> RoundInt(RValue<Float4> cast) |
| 5998 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 5999 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 6000 | { |
| 6001 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 6002 | return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000)); |
| 6003 | } |
| 6004 | else |
| 6005 | { |
| 6006 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6007 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6008 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6009 | auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6010 | nearbyint->addArg(cast.value); |
| 6011 | ::basicBlock->appendInst(nearbyint); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6012 | |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 6013 | return RValue<Int4>(V(result)); |
| 6014 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6015 | } |
| 6016 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6017 | RValue<Short8> PackSigned(RValue<Int4> x, RValue<Int4> y) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6018 | { |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6019 | if(emulateIntrinsics) |
| 6020 | { |
| 6021 | Short8 result; |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6022 | result = Insert(result, SaturateSigned(Extract(x, 0)), 0); |
| 6023 | result = Insert(result, SaturateSigned(Extract(x, 1)), 1); |
| 6024 | result = Insert(result, SaturateSigned(Extract(x, 2)), 2); |
| 6025 | result = Insert(result, SaturateSigned(Extract(x, 3)), 3); |
| 6026 | result = Insert(result, SaturateSigned(Extract(y, 0)), 4); |
| 6027 | result = Insert(result, SaturateSigned(Extract(y, 1)), 5); |
| 6028 | result = Insert(result, SaturateSigned(Extract(y, 2)), 6); |
| 6029 | result = Insert(result, SaturateSigned(Extract(y, 3)), 7); |
Nicolas Capens | ec54a17 | 2016-10-25 17:32:37 -0400 | [diff] [blame] | 6030 | |
Nicolas Capens | 8960fbf | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6031 | return result; |
| 6032 | } |
| 6033 | else |
| 6034 | { |
| 6035 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 6036 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6037 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6038 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6039 | pack->addArg(x.value); |
| 6040 | pack->addArg(y.value); |
| 6041 | ::basicBlock->appendInst(pack); |
| 6042 | |
| 6043 | return RValue<Short8>(V(result)); |
| 6044 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6045 | } |
| 6046 | |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6047 | RValue<UShort8> PackUnsigned(RValue<Int4> x, RValue<Int4> y) |
| 6048 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6049 | if(emulateIntrinsics || !(CPUID::SSE4_1 || CPUID::ARM)) |
| 6050 | { |
| 6051 | RValue<Int4> sx = As<Int4>(x); |
| 6052 | RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000); |
| 6053 | |
| 6054 | RValue<Int4> sy = As<Int4>(y); |
| 6055 | RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000); |
| 6056 | |
| 6057 | return As<UShort8>(PackSigned(bx, by) + Short8(0x8000u)); |
| 6058 | } |
| 6059 | else |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6060 | { |
| 6061 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16); |
| 6062 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6063 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6064 | auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 6065 | pack->addArg(x.value); |
| 6066 | pack->addArg(y.value); |
| 6067 | ::basicBlock->appendInst(pack); |
| 6068 | |
| 6069 | return RValue<UShort8>(V(result)); |
| 6070 | } |
Nicolas Capens | 33438a6 | 2017-09-27 11:47:35 -0400 | [diff] [blame] | 6071 | } |
| 6072 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6073 | RValue<Int> Extract(RValue<Int4> x, int i) |
| 6074 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6075 | return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) |
| 6079 | { |
| 6080 | return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 6081 | } |
| 6082 | |
| 6083 | RValue<Int> SignMask(RValue<Int4> x) |
| 6084 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6085 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6086 | { |
| 6087 | Int4 xx = (x >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008); |
| 6088 | return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3); |
| 6089 | } |
| 6090 | else |
| 6091 | { |
| 6092 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 6093 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6094 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6095 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6096 | movmsk->addArg(x.value); |
| 6097 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 6098 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6099 | return RValue<Int>(V(result)); |
| 6100 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) |
| 6104 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 6105 | return RValue<Int4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | Type *Int4::getType() |
| 6109 | { |
Nicolas Capens | 23d99a4 | 2016-09-30 14:57:16 -0400 | [diff] [blame] | 6110 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6111 | } |
| 6112 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6113 | UInt4::UInt4() : XYZW(this) |
| 6114 | { |
| 6115 | } |
| 6116 | |
| 6117 | UInt4::UInt4(RValue<Float4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6118 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 6119 | // Smallest positive value representable in UInt, but not in Int |
| 6120 | const unsigned int ustart = 0x80000000u; |
| 6121 | const float ustartf = float(ustart); |
| 6122 | |
| 6123 | // Check if the value can be represented as an Int |
| 6124 | Int4 uiValue = CmpNLT(cast, Float4(ustartf)); |
| 6125 | // If the value is too large, subtract ustart and re-add it after conversion. |
| 6126 | uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) | |
| 6127 | // Otherwise, just convert normally |
| 6128 | (~uiValue & Int4(cast)); |
| 6129 | // If the value is negative, store 0, otherwise store the result of the conversion |
| 6130 | storeValue((~(As<Int4>(cast) >> 31) & uiValue).value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6131 | } |
| 6132 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6133 | UInt4::UInt4(int xyzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6134 | { |
| 6135 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6136 | } |
| 6137 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6138 | UInt4::UInt4(int x, int yzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6139 | { |
| 6140 | constant(x, yzw, yzw, yzw); |
| 6141 | } |
| 6142 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6143 | UInt4::UInt4(int x, int y, int zw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6144 | { |
| 6145 | constant(x, y, zw, zw); |
| 6146 | } |
| 6147 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6148 | UInt4::UInt4(int x, int y, int z, int w) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6149 | { |
| 6150 | constant(x, y, z, w); |
| 6151 | } |
| 6152 | |
| 6153 | void UInt4::constant(int x, int y, int z, int w) |
| 6154 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6155 | int64_t constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6156 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6157 | } |
| 6158 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6159 | UInt4::UInt4(RValue<UInt4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6160 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6161 | storeValue(rhs.value); |
| 6162 | } |
| 6163 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6164 | UInt4::UInt4(const UInt4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6165 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6166 | Value *value = rhs.loadValue(); |
| 6167 | storeValue(value); |
| 6168 | } |
| 6169 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6170 | UInt4::UInt4(const Reference<UInt4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6171 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6172 | Value *value = rhs.loadValue(); |
| 6173 | storeValue(value); |
| 6174 | } |
| 6175 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6176 | UInt4::UInt4(RValue<Int4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6177 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6178 | storeValue(rhs.value); |
| 6179 | } |
| 6180 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6181 | UInt4::UInt4(const Int4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6182 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6183 | Value *value = rhs.loadValue(); |
| 6184 | storeValue(value); |
| 6185 | } |
| 6186 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6187 | UInt4::UInt4(const Reference<Int4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6188 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6189 | Value *value = rhs.loadValue(); |
| 6190 | storeValue(value); |
| 6191 | } |
| 6192 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6193 | UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6194 | { |
Nicolas Capens | c70a116 | 2016-12-03 00:16:14 -0500 | [diff] [blame] | 6195 | int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32 |
| 6196 | Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle); |
| 6197 | |
| 6198 | storeValue(packed); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6199 | } |
| 6200 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6201 | RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6202 | { |
| 6203 | storeValue(rhs.value); |
| 6204 | |
| 6205 | return rhs; |
| 6206 | } |
| 6207 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6208 | RValue<UInt4> UInt4::operator=(const UInt4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6209 | { |
| 6210 | Value *value = rhs.loadValue(); |
| 6211 | storeValue(value); |
| 6212 | |
| 6213 | return RValue<UInt4>(value); |
| 6214 | } |
| 6215 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6216 | RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6217 | { |
| 6218 | Value *value = rhs.loadValue(); |
| 6219 | storeValue(value); |
| 6220 | |
| 6221 | return RValue<UInt4>(value); |
| 6222 | } |
| 6223 | |
| 6224 | RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6225 | { |
| 6226 | return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value)); |
| 6227 | } |
| 6228 | |
| 6229 | RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6230 | { |
| 6231 | return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value)); |
| 6232 | } |
| 6233 | |
| 6234 | RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6235 | { |
| 6236 | return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value)); |
| 6237 | } |
| 6238 | |
| 6239 | RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6240 | { |
| 6241 | return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value)); |
| 6242 | } |
| 6243 | |
| 6244 | RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6245 | { |
| 6246 | return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value)); |
| 6247 | } |
| 6248 | |
| 6249 | RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6250 | { |
| 6251 | return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value)); |
| 6252 | } |
| 6253 | |
| 6254 | RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6255 | { |
| 6256 | return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value)); |
| 6257 | } |
| 6258 | |
| 6259 | RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6260 | { |
| 6261 | return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value)); |
| 6262 | } |
| 6263 | |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6264 | RValue<UInt> Extract(RValue<UInt4> x, int i) |
| 6265 | { |
| 6266 | return RValue<UInt>(Nucleus::createExtractElement(x.value, UInt::getType(), i)); |
| 6267 | } |
| 6268 | |
| 6269 | RValue<UInt4> Insert(RValue<UInt4> x, RValue<UInt> element, int i) |
| 6270 | { |
| 6271 | return RValue<UInt4>(Nucleus::createInsertElement(x.value, element.value, i)); |
| 6272 | } |
| 6273 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6274 | RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs) |
| 6275 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6276 | if(emulateIntrinsics) |
| 6277 | { |
| 6278 | UInt4 result; |
| 6279 | result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0); |
| 6280 | result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1); |
| 6281 | result = Insert(result, Extract(lhs, 2) << UInt(rhs), 2); |
| 6282 | result = Insert(result, Extract(lhs, 3) << UInt(rhs), 3); |
| 6283 | |
| 6284 | return result; |
| 6285 | } |
| 6286 | else |
| 6287 | { |
| 6288 | return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 6289 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs) |
| 6293 | { |
Nicolas Capens | 8be6c7b | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 6294 | if(emulateIntrinsics) |
| 6295 | { |
| 6296 | UInt4 result; |
| 6297 | result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0); |
| 6298 | result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1); |
| 6299 | result = Insert(result, Extract(lhs, 2) >> UInt(rhs), 2); |
| 6300 | result = Insert(result, Extract(lhs, 3) >> UInt(rhs), 3); |
| 6301 | |
| 6302 | return result; |
| 6303 | } |
| 6304 | else |
| 6305 | { |
| 6306 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs)))); |
| 6307 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6308 | } |
| 6309 | |
| 6310 | RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6311 | { |
| 6312 | return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value)); |
| 6313 | } |
| 6314 | |
| 6315 | RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs) |
| 6316 | { |
| 6317 | return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value)); |
| 6318 | } |
| 6319 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6320 | RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6321 | { |
| 6322 | return lhs = lhs + rhs; |
| 6323 | } |
| 6324 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6325 | RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6326 | { |
| 6327 | return lhs = lhs - rhs; |
| 6328 | } |
| 6329 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6330 | RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6331 | { |
| 6332 | return lhs = lhs * rhs; |
| 6333 | } |
| 6334 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6335 | // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6336 | // { |
| 6337 | // return lhs = lhs / rhs; |
| 6338 | // } |
| 6339 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6340 | // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6341 | // { |
| 6342 | // return lhs = lhs % rhs; |
| 6343 | // } |
| 6344 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6345 | RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6346 | { |
| 6347 | return lhs = lhs & rhs; |
| 6348 | } |
| 6349 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6350 | RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6351 | { |
| 6352 | return lhs = lhs | rhs; |
| 6353 | } |
| 6354 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6355 | RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6356 | { |
| 6357 | return lhs = lhs ^ rhs; |
| 6358 | } |
| 6359 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6360 | RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6361 | { |
| 6362 | return lhs = lhs << rhs; |
| 6363 | } |
| 6364 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6365 | RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6366 | { |
| 6367 | return lhs = lhs >> rhs; |
| 6368 | } |
| 6369 | |
| 6370 | RValue<UInt4> operator+(RValue<UInt4> val) |
| 6371 | { |
| 6372 | return val; |
| 6373 | } |
| 6374 | |
| 6375 | RValue<UInt4> operator-(RValue<UInt4> val) |
| 6376 | { |
| 6377 | return RValue<UInt4>(Nucleus::createNeg(val.value)); |
| 6378 | } |
| 6379 | |
| 6380 | RValue<UInt4> operator~(RValue<UInt4> val) |
| 6381 | { |
| 6382 | return RValue<UInt4>(Nucleus::createNot(val.value)); |
| 6383 | } |
| 6384 | |
| 6385 | RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6386 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6387 | return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6391 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6392 | return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6396 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6397 | return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y) |
| 6401 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6402 | return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6403 | } |
| 6404 | |
| 6405 | RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y) |
| 6406 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6407 | return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y) |
| 6411 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 6412 | return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6413 | } |
| 6414 | |
| 6415 | RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y) |
| 6416 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6417 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6418 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value); |
| 6419 | ::basicBlock->appendInst(cmp); |
| 6420 | |
| 6421 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6422 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6423 | ::basicBlock->appendInst(select); |
| 6424 | |
| 6425 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6426 | } |
| 6427 | |
| 6428 | RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y) |
| 6429 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6430 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
| 6431 | auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value); |
| 6432 | ::basicBlock->appendInst(cmp); |
| 6433 | |
| 6434 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32); |
| 6435 | auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value); |
| 6436 | ::basicBlock->appendInst(select); |
| 6437 | |
| 6438 | return RValue<UInt4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6439 | } |
| 6440 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6441 | Type *UInt4::getType() |
| 6442 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 6443 | return T(Ice::IceType_v4i32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6444 | } |
| 6445 | |
Ben Clayton | ec1aeb8 | 2019-03-04 19:33:27 +0000 | [diff] [blame] | 6446 | Half::Half(RValue<Float> cast) |
| 6447 | { |
| 6448 | UInt fp32i = As<UInt>(cast); |
| 6449 | UInt abs = fp32i & 0x7FFFFFFF; |
| 6450 | UShort fp16i((fp32i & 0x80000000) >> 16); // sign |
| 6451 | |
| 6452 | If(abs > 0x47FFEFFF) // Infinity |
| 6453 | { |
| 6454 | fp16i |= UShort(0x7FFF); |
| 6455 | } |
| 6456 | Else |
| 6457 | { |
| 6458 | If(abs < 0x38800000) // Denormal |
| 6459 | { |
| 6460 | Int mantissa = (abs & 0x007FFFFF) | 0x00800000; |
| 6461 | Int e = 113 - (abs >> 23); |
| 6462 | abs = IfThenElse(e < 24, mantissa >> e, Int(0)); |
| 6463 | fp16i |= UShort((abs + 0x00000FFF + ((abs >> 13) & 1)) >> 13); |
| 6464 | } |
| 6465 | Else |
| 6466 | { |
| 6467 | fp16i |= UShort((abs + 0xC8000000 + 0x00000FFF + ((abs >> 13) & 1)) >> 13); |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | storeValue(fp16i.loadValue()); |
| 6472 | } |
| 6473 | |
| 6474 | Type *Half::getType() |
| 6475 | { |
| 6476 | return T(Ice::IceType_i16); |
| 6477 | } |
Alexis Hetu | 734e257 | 2018-12-20 14:00:49 -0500 | [diff] [blame] | 6478 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6479 | Float::Float(RValue<Int> cast) |
| 6480 | { |
| 6481 | Value *integer = Nucleus::createSIToFP(cast.value, Float::getType()); |
| 6482 | |
| 6483 | storeValue(integer); |
| 6484 | } |
| 6485 | |
Alexis Hetu | cfd9632 | 2017-07-24 14:44:33 -0400 | [diff] [blame] | 6486 | Float::Float(RValue<UInt> cast) |
| 6487 | { |
| 6488 | RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) + |
| 6489 | As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u))); |
| 6490 | |
| 6491 | storeValue(result.value); |
| 6492 | } |
| 6493 | |
Ben Clayton | ec1aeb8 | 2019-03-04 19:33:27 +0000 | [diff] [blame] | 6494 | Float::Float(RValue<Half> cast) |
| 6495 | { |
| 6496 | Int fp16i(As<UShort>(cast)); |
| 6497 | |
| 6498 | Int s = (fp16i >> 15) & 0x00000001; |
| 6499 | Int e = (fp16i >> 10) & 0x0000001F; |
| 6500 | Int m = fp16i & 0x000003FF; |
| 6501 | |
| 6502 | UInt fp32i(s << 31); |
| 6503 | If(e == 0) |
| 6504 | { |
| 6505 | If(m != 0) |
| 6506 | { |
| 6507 | While((m & 0x00000400) == 0) |
| 6508 | { |
| 6509 | m <<= 1; |
| 6510 | e -= 1; |
| 6511 | } |
| 6512 | |
| 6513 | fp32i |= As<UInt>(((e + (127 - 15) + 1) << 23) | ((m & ~0x00000400) << 13)); |
| 6514 | } |
| 6515 | } |
| 6516 | Else |
| 6517 | { |
| 6518 | fp32i |= As<UInt>(((e + (127 - 15)) << 23) | (m << 13)); |
| 6519 | } |
| 6520 | |
| 6521 | storeValue(As<Float>(fp32i).value); |
Alexis Hetu | 734e257 | 2018-12-20 14:00:49 -0500 | [diff] [blame] | 6522 | } |
| 6523 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6524 | Float::Float(float x) |
| 6525 | { |
| 6526 | storeValue(Nucleus::createConstantFloat(x)); |
| 6527 | } |
| 6528 | |
| 6529 | Float::Float(RValue<Float> rhs) |
| 6530 | { |
| 6531 | storeValue(rhs.value); |
| 6532 | } |
| 6533 | |
| 6534 | Float::Float(const Float &rhs) |
| 6535 | { |
| 6536 | Value *value = rhs.loadValue(); |
| 6537 | storeValue(value); |
| 6538 | } |
| 6539 | |
| 6540 | Float::Float(const Reference<Float> &rhs) |
| 6541 | { |
| 6542 | Value *value = rhs.loadValue(); |
| 6543 | storeValue(value); |
| 6544 | } |
| 6545 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6546 | RValue<Float> Float::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6547 | { |
| 6548 | storeValue(rhs.value); |
| 6549 | |
| 6550 | return rhs; |
| 6551 | } |
| 6552 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6553 | RValue<Float> Float::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6554 | { |
| 6555 | Value *value = rhs.loadValue(); |
| 6556 | storeValue(value); |
| 6557 | |
| 6558 | return RValue<Float>(value); |
| 6559 | } |
| 6560 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6561 | RValue<Float> Float::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6562 | { |
| 6563 | Value *value = rhs.loadValue(); |
| 6564 | storeValue(value); |
| 6565 | |
| 6566 | return RValue<Float>(value); |
| 6567 | } |
| 6568 | |
| 6569 | RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs) |
| 6570 | { |
| 6571 | return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6572 | } |
| 6573 | |
| 6574 | RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs) |
| 6575 | { |
| 6576 | return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6577 | } |
| 6578 | |
| 6579 | RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs) |
| 6580 | { |
| 6581 | return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6582 | } |
| 6583 | |
| 6584 | RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs) |
| 6585 | { |
| 6586 | return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6587 | } |
| 6588 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6589 | RValue<Float> operator+=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6590 | { |
| 6591 | return lhs = lhs + rhs; |
| 6592 | } |
| 6593 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6594 | RValue<Float> operator-=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6595 | { |
| 6596 | return lhs = lhs - rhs; |
| 6597 | } |
| 6598 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6599 | RValue<Float> operator*=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6600 | { |
| 6601 | return lhs = lhs * rhs; |
| 6602 | } |
| 6603 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6604 | RValue<Float> operator/=(Float &lhs, RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6605 | { |
| 6606 | return lhs = lhs / rhs; |
| 6607 | } |
| 6608 | |
| 6609 | RValue<Float> operator+(RValue<Float> val) |
| 6610 | { |
| 6611 | return val; |
| 6612 | } |
| 6613 | |
| 6614 | RValue<Float> operator-(RValue<Float> val) |
| 6615 | { |
| 6616 | return RValue<Float>(Nucleus::createFNeg(val.value)); |
| 6617 | } |
| 6618 | |
| 6619 | RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs) |
| 6620 | { |
| 6621 | return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value)); |
| 6622 | } |
| 6623 | |
| 6624 | RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs) |
| 6625 | { |
| 6626 | return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value)); |
| 6627 | } |
| 6628 | |
| 6629 | RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs) |
| 6630 | { |
| 6631 | return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value)); |
| 6632 | } |
| 6633 | |
| 6634 | RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs) |
| 6635 | { |
| 6636 | return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value)); |
| 6637 | } |
| 6638 | |
| 6639 | RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs) |
| 6640 | { |
| 6641 | return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value)); |
| 6642 | } |
| 6643 | |
| 6644 | RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs) |
| 6645 | { |
| 6646 | return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value)); |
| 6647 | } |
| 6648 | |
| 6649 | RValue<Float> Abs(RValue<Float> x) |
| 6650 | { |
| 6651 | return IfThenElse(x > 0.0f, x, -x); |
| 6652 | } |
| 6653 | |
| 6654 | RValue<Float> Max(RValue<Float> x, RValue<Float> y) |
| 6655 | { |
| 6656 | return IfThenElse(x > y, x, y); |
| 6657 | } |
| 6658 | |
| 6659 | RValue<Float> Min(RValue<Float> x, RValue<Float> y) |
| 6660 | { |
| 6661 | return IfThenElse(x < y, x, y); |
| 6662 | } |
| 6663 | |
| 6664 | RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2) |
| 6665 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6666 | return 1.0f / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | RValue<Float> RcpSqrt_pp(RValue<Float> x) |
| 6670 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6671 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | RValue<Float> Sqrt(RValue<Float> x) |
| 6675 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6676 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32); |
| 6677 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 6678 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 6679 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 6680 | sqrt->addArg(x.value); |
| 6681 | ::basicBlock->appendInst(sqrt); |
| 6682 | |
| 6683 | return RValue<Float>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6684 | } |
| 6685 | |
| 6686 | RValue<Float> Round(RValue<Float> x) |
| 6687 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6688 | return Float4(Round(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6689 | } |
| 6690 | |
| 6691 | RValue<Float> Trunc(RValue<Float> x) |
| 6692 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6693 | return Float4(Trunc(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6694 | } |
| 6695 | |
| 6696 | RValue<Float> Frac(RValue<Float> x) |
| 6697 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6698 | return Float4(Frac(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6699 | } |
| 6700 | |
| 6701 | RValue<Float> Floor(RValue<Float> x) |
| 6702 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6703 | return Float4(Floor(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | RValue<Float> Ceil(RValue<Float> x) |
| 6707 | { |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 6708 | return Float4(Ceil(Float4(x))).x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6709 | } |
| 6710 | |
| 6711 | Type *Float::getType() |
| 6712 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 6713 | return T(Ice::IceType_f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6714 | } |
| 6715 | |
| 6716 | Float2::Float2(RValue<Float4> cast) |
| 6717 | { |
Nicolas Capens | 2200878 | 2016-10-20 01:11:47 -0400 | [diff] [blame] | 6718 | storeValue(Nucleus::createBitCast(cast.value, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | Type *Float2::getType() |
| 6722 | { |
Nicolas Capens | 4cfd457 | 2016-10-20 01:00:19 -0400 | [diff] [blame] | 6723 | return T(Type_v2f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6724 | } |
| 6725 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6726 | Float4::Float4(RValue<Byte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6727 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6728 | Value *a = Int4(cast).loadValue(); |
| 6729 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 6730 | |
| 6731 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6732 | } |
| 6733 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6734 | Float4::Float4(RValue<SByte4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6735 | { |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6736 | Value *a = Int4(cast).loadValue(); |
| 6737 | Value *xyzw = Nucleus::createSIToFP(a, Float4::getType()); |
| 6738 | |
| 6739 | storeValue(xyzw); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6740 | } |
| 6741 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6742 | Float4::Float4(RValue<Short4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6743 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6744 | Int4 c(cast); |
| 6745 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 6746 | } |
| 6747 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6748 | Float4::Float4(RValue<UShort4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6749 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6750 | Int4 c(cast); |
| 6751 | storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType())); |
| 6752 | } |
| 6753 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6754 | Float4::Float4(RValue<Int4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6755 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6756 | Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType()); |
| 6757 | |
| 6758 | storeValue(xyzw); |
| 6759 | } |
| 6760 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6761 | Float4::Float4(RValue<UInt4> cast) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6762 | { |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 6763 | RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) + |
| 6764 | As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6765 | |
Nicolas Capens | 96445fe | 2016-12-15 14:45:13 -0500 | [diff] [blame] | 6766 | storeValue(result.value); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6767 | } |
| 6768 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6769 | Float4::Float4() : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6770 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6771 | } |
| 6772 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6773 | Float4::Float4(float xyzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6774 | { |
| 6775 | constant(xyzw, xyzw, xyzw, xyzw); |
| 6776 | } |
| 6777 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6778 | Float4::Float4(float x, float yzw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6779 | { |
| 6780 | constant(x, yzw, yzw, yzw); |
| 6781 | } |
| 6782 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6783 | Float4::Float4(float x, float y, float zw) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6784 | { |
| 6785 | constant(x, y, zw, zw); |
| 6786 | } |
| 6787 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6788 | Float4::Float4(float x, float y, float z, float w) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6789 | { |
| 6790 | constant(x, y, z, w); |
| 6791 | } |
| 6792 | |
| 6793 | void Float4::constant(float x, float y, float z, float w) |
| 6794 | { |
Nicolas Capens | 13ac232 | 2016-10-13 14:52:12 -0400 | [diff] [blame] | 6795 | double constantVector[4] = {x, y, z, w}; |
Nicolas Capens | 8dfd9a7 | 2016-10-13 17:44:51 -0400 | [diff] [blame] | 6796 | storeValue(Nucleus::createConstantVector(constantVector, getType())); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6797 | } |
| 6798 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6799 | Float4::Float4(RValue<Float4> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6800 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6801 | storeValue(rhs.value); |
| 6802 | } |
| 6803 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6804 | Float4::Float4(const Float4 &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6805 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6806 | Value *value = rhs.loadValue(); |
| 6807 | storeValue(value); |
| 6808 | } |
| 6809 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6810 | Float4::Float4(const Reference<Float4> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6811 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6812 | Value *value = rhs.loadValue(); |
| 6813 | storeValue(value); |
| 6814 | } |
| 6815 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6816 | Float4::Float4(RValue<Float> rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6817 | { |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6818 | Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType()); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6819 | |
| 6820 | int swizzle[4] = {0, 0, 0, 0}; |
Nicolas Capens | f8beb4b | 2017-01-27 02:55:44 -0800 | [diff] [blame] | 6821 | Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle); |
Nicolas Capens | d422796 | 2016-11-09 14:24:25 -0500 | [diff] [blame] | 6822 | |
| 6823 | storeValue(replicate); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6824 | } |
| 6825 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6826 | Float4::Float4(const Float &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6827 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6828 | *this = RValue<Float>(rhs.loadValue()); |
| 6829 | } |
| 6830 | |
Nicolas Capens | cb98676 | 2017-01-20 11:34:37 -0500 | [diff] [blame] | 6831 | Float4::Float4(const Reference<Float> &rhs) : XYZW(this) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6832 | { |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6833 | *this = RValue<Float>(rhs.loadValue()); |
| 6834 | } |
| 6835 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6836 | RValue<Float4> Float4::operator=(float x) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6837 | { |
| 6838 | return *this = Float4(x, x, x, x); |
| 6839 | } |
| 6840 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6841 | RValue<Float4> Float4::operator=(RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6842 | { |
| 6843 | storeValue(rhs.value); |
| 6844 | |
| 6845 | return rhs; |
| 6846 | } |
| 6847 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6848 | RValue<Float4> Float4::operator=(const Float4 &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6849 | { |
| 6850 | Value *value = rhs.loadValue(); |
| 6851 | storeValue(value); |
| 6852 | |
| 6853 | return RValue<Float4>(value); |
| 6854 | } |
| 6855 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6856 | RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6857 | { |
| 6858 | Value *value = rhs.loadValue(); |
| 6859 | storeValue(value); |
| 6860 | |
| 6861 | return RValue<Float4>(value); |
| 6862 | } |
| 6863 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6864 | RValue<Float4> Float4::operator=(RValue<Float> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6865 | { |
| 6866 | return *this = Float4(rhs); |
| 6867 | } |
| 6868 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6869 | RValue<Float4> Float4::operator=(const Float &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6870 | { |
| 6871 | return *this = Float4(rhs); |
| 6872 | } |
| 6873 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6874 | RValue<Float4> Float4::operator=(const Reference<Float> &rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6875 | { |
| 6876 | return *this = Float4(rhs); |
| 6877 | } |
| 6878 | |
| 6879 | RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6880 | { |
| 6881 | return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value)); |
| 6882 | } |
| 6883 | |
| 6884 | RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6885 | { |
| 6886 | return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value)); |
| 6887 | } |
| 6888 | |
| 6889 | RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6890 | { |
| 6891 | return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value)); |
| 6892 | } |
| 6893 | |
| 6894 | RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6895 | { |
| 6896 | return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value)); |
| 6897 | } |
| 6898 | |
| 6899 | RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs) |
| 6900 | { |
| 6901 | return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value)); |
| 6902 | } |
| 6903 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6904 | RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6905 | { |
| 6906 | return lhs = lhs + rhs; |
| 6907 | } |
| 6908 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6909 | RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6910 | { |
| 6911 | return lhs = lhs - rhs; |
| 6912 | } |
| 6913 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6914 | RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6915 | { |
| 6916 | return lhs = lhs * rhs; |
| 6917 | } |
| 6918 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6919 | RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6920 | { |
| 6921 | return lhs = lhs / rhs; |
| 6922 | } |
| 6923 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 6924 | RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6925 | { |
| 6926 | return lhs = lhs % rhs; |
| 6927 | } |
| 6928 | |
| 6929 | RValue<Float4> operator+(RValue<Float4> val) |
| 6930 | { |
| 6931 | return val; |
| 6932 | } |
| 6933 | |
| 6934 | RValue<Float4> operator-(RValue<Float4> val) |
| 6935 | { |
| 6936 | return RValue<Float4>(Nucleus::createFNeg(val.value)); |
| 6937 | } |
| 6938 | |
| 6939 | RValue<Float4> Abs(RValue<Float4> x) |
| 6940 | { |
Nicolas Capens | 8427224 | 2016-11-09 13:31:06 -0500 | [diff] [blame] | 6941 | Value *vector = Nucleus::createBitCast(x.value, Int4::getType()); |
| 6942 | int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF}; |
| 6943 | Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType()))); |
| 6944 | |
| 6945 | return As<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y) |
| 6949 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6950 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6951 | 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] | 6952 | ::basicBlock->appendInst(cmp); |
| 6953 | |
| 6954 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6955 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6956 | ::basicBlock->appendInst(select); |
| 6957 | |
| 6958 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y) |
| 6962 | { |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6963 | Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6964 | 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] | 6965 | ::basicBlock->appendInst(cmp); |
| 6966 | |
| 6967 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
Nicolas Capens | 5cdb91a | 2017-02-13 12:39:18 -0500 | [diff] [blame] | 6968 | auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value); |
Nicolas Capens | 53a8a3f | 2016-10-26 00:23:12 -0400 | [diff] [blame] | 6969 | ::basicBlock->appendInst(select); |
| 6970 | |
| 6971 | return RValue<Float4>(V(result)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2) |
| 6975 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6976 | return Float4(1.0f) / x; |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | RValue<Float4> RcpSqrt_pp(RValue<Float4> x) |
| 6980 | { |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6981 | return Rcp_pp(Sqrt(x)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 6982 | } |
| 6983 | |
| 6984 | RValue<Float4> Sqrt(RValue<Float4> x) |
| 6985 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 6986 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | 9f737d3 | 2017-07-25 17:26:14 -0400 | [diff] [blame] | 6987 | { |
| 6988 | Float4 result; |
| 6989 | result.x = Sqrt(Float(Float4(x).x)); |
| 6990 | result.y = Sqrt(Float(Float4(x).y)); |
| 6991 | result.z = Sqrt(Float(Float4(x).z)); |
| 6992 | result.w = Sqrt(Float(Float4(x).w)); |
Nicolas Capens | d52e936 | 2016-10-31 23:23:15 -0400 | [diff] [blame] | 6993 | |
Nicolas Capens | 9f737d3 | 2017-07-25 17:26:14 -0400 | [diff] [blame] | 6994 | return result; |
| 6995 | } |
| 6996 | else |
| 6997 | { |
| 6998 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 6999 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7000 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7001 | auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 7002 | sqrt->addArg(x.value); |
| 7003 | ::basicBlock->appendInst(sqrt); |
| 7004 | |
| 7005 | return RValue<Float4>(V(result)); |
| 7006 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7007 | } |
| 7008 | |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 7009 | RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7010 | { |
Nicolas Capens | c94ab74 | 2016-11-08 15:15:31 -0500 | [diff] [blame] | 7011 | return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | RValue<Float> Extract(RValue<Float4> x, int i) |
| 7015 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 7016 | return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) |
| 7020 | { |
Nicolas Capens | e95d534 | 2016-09-30 11:37:28 -0400 | [diff] [blame] | 7021 | return RValue<Float4>(createSwizzle4(x.value, select)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) |
| 7025 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 7026 | int shuffle[4] = |
| 7027 | { |
| 7028 | ((imm >> 0) & 0x03) + 0, |
| 7029 | ((imm >> 2) & 0x03) + 0, |
| 7030 | ((imm >> 4) & 0x03) + 4, |
| 7031 | ((imm >> 6) & 0x03) + 4, |
| 7032 | }; |
| 7033 | |
| 7034 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y) |
| 7038 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 7039 | int shuffle[4] = {0, 4, 1, 5}; |
| 7040 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7041 | } |
| 7042 | |
| 7043 | RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y) |
| 7044 | { |
Nicolas Capens | 37fbece | 2016-10-21 15:08:56 -0400 | [diff] [blame] | 7045 | int shuffle[4] = {2, 6, 3, 7}; |
| 7046 | return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7047 | } |
| 7048 | |
| 7049 | RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) |
| 7050 | { |
| 7051 | Value *vector = lhs.loadValue(); |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 7052 | Value *result = createMask4(vector, rhs.value, select); |
| 7053 | lhs.storeValue(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7054 | |
Nicolas Capens | a4c30b0 | 2016-11-08 15:43:17 -0500 | [diff] [blame] | 7055 | return RValue<Float4>(result); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7056 | } |
| 7057 | |
| 7058 | RValue<Int> SignMask(RValue<Float4> x) |
| 7059 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 7060 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 7061 | { |
| 7062 | Int4 xx = (As<Int4>(x) >> 31) & Int4(0x00000001, 0x00000002, 0x00000004, 0x00000008); |
| 7063 | return Extract(xx, 0) | Extract(xx, 1) | Extract(xx, 2) | Extract(xx, 3); |
| 7064 | } |
| 7065 | else |
| 7066 | { |
| 7067 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32); |
| 7068 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7069 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7070 | auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic); |
| 7071 | movmsk->addArg(x.value); |
| 7072 | ::basicBlock->appendInst(movmsk); |
Nicolas Capens | f2cb9df | 2016-10-21 17:26:13 -0400 | [diff] [blame] | 7073 | |
Nicolas Capens | d6cacad | 2017-07-25 15:32:12 -0400 | [diff] [blame] | 7074 | return RValue<Int>(V(result)); |
| 7075 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y) |
| 7079 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 7080 | return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7081 | } |
| 7082 | |
| 7083 | RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y) |
| 7084 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 7085 | return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y) |
| 7089 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 7090 | return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y) |
| 7094 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 7095 | return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7096 | } |
| 7097 | |
| 7098 | RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y) |
| 7099 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 7100 | return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7101 | } |
| 7102 | |
| 7103 | RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y) |
| 7104 | { |
Nicolas Capens | 5e6ca09 | 2017-01-13 15:09:21 -0500 | [diff] [blame] | 7105 | return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7106 | } |
| 7107 | |
Ben Clayton | ec1aeb8 | 2019-03-04 19:33:27 +0000 | [diff] [blame] | 7108 | RValue<Int4> CmpUEQ(RValue<Float4> x, RValue<Float4> y) |
| 7109 | { |
| 7110 | return RValue<Int4>(Nucleus::createFCmpUEQ(x.value, y.value)); |
| 7111 | } |
| 7112 | |
| 7113 | RValue<Int4> CmpULT(RValue<Float4> x, RValue<Float4> y) |
| 7114 | { |
| 7115 | return RValue<Int4>(Nucleus::createFCmpULT(x.value, y.value)); |
| 7116 | } |
| 7117 | |
| 7118 | RValue<Int4> CmpULE(RValue<Float4> x, RValue<Float4> y) |
| 7119 | { |
| 7120 | return RValue<Int4>(Nucleus::createFCmpULE(x.value, y.value)); |
| 7121 | } |
| 7122 | |
| 7123 | RValue<Int4> CmpUNEQ(RValue<Float4> x, RValue<Float4> y) |
| 7124 | { |
| 7125 | return RValue<Int4>(Nucleus::createFCmpUNE(x.value, y.value)); |
| 7126 | } |
| 7127 | |
| 7128 | RValue<Int4> CmpUNLT(RValue<Float4> x, RValue<Float4> y) |
| 7129 | { |
| 7130 | return RValue<Int4>(Nucleus::createFCmpUGE(x.value, y.value)); |
| 7131 | } |
| 7132 | |
| 7133 | RValue<Int4> CmpUNLE(RValue<Float4> x, RValue<Float4> y) |
| 7134 | { |
| 7135 | return RValue<Int4>(Nucleus::createFCmpUGT(x.value, y.value)); |
| 7136 | } |
| 7137 | |
Alexis Hetu | 8ef6d10 | 2017-11-09 15:49:09 -0500 | [diff] [blame] | 7138 | RValue<Int4> IsInf(RValue<Float4> x) |
| 7139 | { |
| 7140 | return CmpEQ(As<Int4>(x) & Int4(0x7FFFFFFF), Int4(0x7F800000)); |
| 7141 | } |
| 7142 | |
| 7143 | RValue<Int4> IsNan(RValue<Float4> x) |
| 7144 | { |
| 7145 | return ~CmpEQ(x, x); |
| 7146 | } |
| 7147 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7148 | RValue<Float4> Round(RValue<Float4> x) |
| 7149 | { |
Nicolas Capens | 091f350 | 2017-10-03 14:56:49 -0400 | [diff] [blame] | 7150 | if(emulateIntrinsics || CPUID::ARM) |
Nicolas Capens | f7b7588 | 2017-04-26 09:30:47 -0400 | [diff] [blame] | 7151 | { |
| 7152 | // Push the fractional part off the mantissa. Accurate up to +/-2^22. |
| 7153 | return (x + Float4(0x00C00000)) - Float4(0x00C00000); |
| 7154 | } |
| 7155 | else if(CPUID::SSE4_1) |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7156 | { |
| 7157 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7158 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7159 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7160 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7161 | round->addArg(x.value); |
| 7162 | round->addArg(::context->getConstantInt32(0)); |
| 7163 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7164 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7165 | return RValue<Float4>(V(result)); |
| 7166 | } |
| 7167 | else |
| 7168 | { |
| 7169 | return Float4(RoundInt(x)); |
| 7170 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7171 | } |
| 7172 | |
| 7173 | RValue<Float4> Trunc(RValue<Float4> x) |
| 7174 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7175 | if(CPUID::SSE4_1) |
| 7176 | { |
| 7177 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7178 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7179 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7180 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7181 | round->addArg(x.value); |
| 7182 | round->addArg(::context->getConstantInt32(3)); |
| 7183 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7184 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7185 | return RValue<Float4>(V(result)); |
| 7186 | } |
| 7187 | else |
| 7188 | { |
| 7189 | return Float4(Int4(x)); |
| 7190 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | RValue<Float4> Frac(RValue<Float4> x) |
| 7194 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7195 | Float4 frc; |
| 7196 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7197 | if(CPUID::SSE4_1) |
| 7198 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7199 | frc = x - Floor(x); |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7200 | } |
| 7201 | else |
| 7202 | { |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7203 | frc = x - Float4(Int4(x)); // Signed fractional part. |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7204 | |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7205 | frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); // Add 1.0 if negative. |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7206 | } |
Nicolas Capens | b923042 | 2017-07-17 10:27:33 -0400 | [diff] [blame] | 7207 | |
| 7208 | // x - floor(x) can be 1.0 for very small negative x. |
| 7209 | // Clamp against the value just below 1.0. |
| 7210 | return Min(frc, As<Float4>(Int4(0x3F7FFFFF))); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | RValue<Float4> Floor(RValue<Float4> x) |
| 7214 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7215 | if(CPUID::SSE4_1) |
| 7216 | { |
| 7217 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7218 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7219 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7220 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7221 | round->addArg(x.value); |
| 7222 | round->addArg(::context->getConstantInt32(1)); |
| 7223 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7224 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7225 | return RValue<Float4>(V(result)); |
| 7226 | } |
| 7227 | else |
| 7228 | { |
| 7229 | return x - Frac(x); |
| 7230 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7231 | } |
| 7232 | |
| 7233 | RValue<Float4> Ceil(RValue<Float4> x) |
| 7234 | { |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7235 | if(CPUID::SSE4_1) |
| 7236 | { |
| 7237 | Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32); |
| 7238 | const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; |
| 7239 | auto target = ::context->getConstantUndef(Ice::IceType_i32); |
| 7240 | auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic); |
| 7241 | round->addArg(x.value); |
| 7242 | round->addArg(::context->getConstantInt32(2)); |
| 7243 | ::basicBlock->appendInst(round); |
Nicolas Capens | a808651 | 2016-11-07 17:32:17 -0500 | [diff] [blame] | 7244 | |
Nicolas Capens | 9ca48d5 | 2017-01-14 12:52:55 -0500 | [diff] [blame] | 7245 | return RValue<Float4>(V(result)); |
| 7246 | } |
| 7247 | else |
| 7248 | { |
| 7249 | return -Floor(-x); |
| 7250 | } |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7251 | } |
| 7252 | |
| 7253 | Type *Float4::getType() |
| 7254 | { |
Nicolas Capens | 9709d4f | 2016-09-30 11:44:14 -0400 | [diff] [blame] | 7255 | return T(Ice::IceType_v4f32); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7256 | } |
| 7257 | |
| 7258 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) |
| 7259 | { |
Nicolas Capens | 8820f64 | 2016-09-30 04:42:43 -0400 | [diff] [blame] | 7260 | return lhs + RValue<Int>(Nucleus::createConstantInt(offset)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7261 | } |
| 7262 | |
| 7263 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 7264 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 7265 | 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] | 7266 | } |
| 7267 | |
| 7268 | RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 7269 | { |
Nicolas Capens | d294def | 2017-01-26 17:44:37 -0800 | [diff] [blame] | 7270 | 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] | 7271 | } |
| 7272 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7273 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7274 | { |
| 7275 | return lhs = lhs + offset; |
| 7276 | } |
| 7277 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7278 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7279 | { |
| 7280 | return lhs = lhs + offset; |
| 7281 | } |
| 7282 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7283 | RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7284 | { |
| 7285 | return lhs = lhs + offset; |
| 7286 | } |
| 7287 | |
| 7288 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset) |
| 7289 | { |
| 7290 | return lhs + -offset; |
| 7291 | } |
| 7292 | |
| 7293 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset) |
| 7294 | { |
| 7295 | return lhs + -offset; |
| 7296 | } |
| 7297 | |
| 7298 | RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset) |
| 7299 | { |
| 7300 | return lhs + -offset; |
| 7301 | } |
| 7302 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7303 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7304 | { |
| 7305 | return lhs = lhs - offset; |
| 7306 | } |
| 7307 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7308 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7309 | { |
| 7310 | return lhs = lhs - offset; |
| 7311 | } |
| 7312 | |
Nicolas Capens | 96d4e09 | 2016-11-18 14:22:38 -0500 | [diff] [blame] | 7313 | RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7314 | { |
| 7315 | return lhs = lhs - offset; |
| 7316 | } |
| 7317 | |
| 7318 | void Return() |
| 7319 | { |
| 7320 | Nucleus::createRetVoid(); |
| 7321 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 7322 | Nucleus::createUnreachable(); |
| 7323 | } |
| 7324 | |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 7325 | void Return(RValue<Int> ret) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7326 | { |
Nicolas Capens | eb253d0 | 2016-11-18 14:40:40 -0500 | [diff] [blame] | 7327 | Nucleus::createRet(ret.value); |
Nicolas Capens | fdcca2d | 2016-10-20 11:31:36 -0400 | [diff] [blame] | 7328 | Nucleus::setInsertBlock(Nucleus::createBasicBlock()); |
| 7329 | Nucleus::createUnreachable(); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7330 | } |
| 7331 | |
Nicolas Capens | f4eec2f | 2017-05-24 15:46:48 -0400 | [diff] [blame] | 7332 | void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB) |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7333 | { |
| 7334 | Nucleus::createCondBr(cmp.value, bodyBB, endBB); |
| 7335 | Nucleus::setInsertBlock(bodyBB); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7336 | } |
| 7337 | |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7338 | RValue<Long> Ticks() |
| 7339 | { |
Nicolas Capens | c37252c | 2016-09-28 16:11:54 -0400 | [diff] [blame] | 7340 | assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr)); |
Nicolas Capens | 598f8d8 | 2016-09-26 15:09:10 -0400 | [diff] [blame] | 7341 | } |
| 7342 | } |