blob: 0f65a372891981b83fd7fedb01035b7c019ecbdb [file] [log] [blame]
Nicolas Capens598f8d82016-09-26 15:09:10 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "Nucleus.hpp"
16
17#include "Reactor.hpp"
18#include "Routine.hpp"
19
Nicolas Capens2ae9d742016-11-24 14:43:05 -050020#include "Optimizer.hpp"
21
Nicolas Capens598f8d82016-09-26 15:09:10 -040022#include "src/IceTypes.h"
23#include "src/IceCfg.h"
24#include "src/IceELFStreamer.h"
25#include "src/IceGlobalContext.h"
26#include "src/IceCfgNode.h"
27#include "src/IceELFObjectWriter.h"
Nicolas Capens8dfd9a72016-10-13 17:44:51 -040028#include "src/IceGlobalInits.h"
Nicolas Capens598f8d82016-09-26 15:09:10 -040029
30#include "llvm/Support/FileSystem.h"
31#include "llvm/Support/raw_os_ostream.h"
32
Nicolas Capensbd65da92017-01-05 16:31:06 -050033#if defined(_WIN32)
Alexis Hetu113e33a2017-01-19 10:49:19 -050034#ifndef WIN32_LEAN_AND_MEAN
Nicolas Capens598f8d82016-09-26 15:09:10 -040035#define WIN32_LEAN_AND_MEAN
Alexis Hetu113e33a2017-01-19 10:49:19 -050036#endif // !WIN32_LEAN_AND_MEAN
37#ifndef NOMINMAX
Nicolas Capens598f8d82016-09-26 15:09:10 -040038#define NOMINMAX
Alexis Hetu113e33a2017-01-19 10:49:19 -050039#endif // !NOMINMAX
Nicolas Capens598f8d82016-09-26 15:09:10 -040040#include <Windows.h>
Nicolas Capensbd65da92017-01-05 16:31:06 -050041#else
42#include <sys/mman.h>
Nicolas Capens411273e2017-01-26 15:13:36 -080043#if !defined(MAP_ANONYMOUS)
44#define MAP_ANONYMOUS MAP_ANON
Nicolas Capens8b275742017-01-20 17:11:41 -050045#endif
Nicolas Capensbd65da92017-01-05 16:31:06 -050046#endif
Nicolas Capens598f8d82016-09-26 15:09:10 -040047
48#include <mutex>
49#include <limits>
50#include <iostream>
51#include <cassert>
52
53namespace
54{
55 Ice::GlobalContext *context = nullptr;
56 Ice::Cfg *function = nullptr;
57 Ice::CfgNode *basicBlock = nullptr;
58 Ice::CfgLocalAllocatorScope *allocator = nullptr;
59 sw::Routine *routine = nullptr;
60
61 std::mutex codegenMutex;
62
63 Ice::ELFFileStreamer *elfFile = nullptr;
64 Ice::Fdstream *out = nullptr;
65}
66
Nicolas Capensccd5ecb2017-01-14 12:52:55 -050067namespace
68{
Nicolas Capens47dc8672017-04-25 12:54:39 -040069 #if !defined(__i386__) && defined(_M_IX86)
70 #define __i386__ 1
71 #endif
72
73 #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
74 #define __x86_64__ 1
75 #endif
76
Nicolas Capensccd5ecb2017-01-14 12:52:55 -050077 class CPUID
78 {
79 public:
Nicolas Capensf7b75882017-04-26 09:30:47 -040080 const static bool ARM;
Nicolas Capensccd5ecb2017-01-14 12:52:55 -050081 const static bool SSE4_1;
82
83 private:
84 static void cpuid(int registers[4], int info)
85 {
Nicolas Capens47dc8672017-04-25 12:54:39 -040086 #if defined(__i386__) || defined(__x86_64__)
87 #if defined(_WIN32)
88 __cpuid(registers, info);
89 #else
90 __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
91 #endif
Nicolas Capensccd5ecb2017-01-14 12:52:55 -050092 #else
Nicolas Capens47dc8672017-04-25 12:54:39 -040093 registers[0] = 0;
94 registers[1] = 0;
95 registers[2] = 0;
96 registers[3] = 0;
Nicolas Capensccd5ecb2017-01-14 12:52:55 -050097 #endif
98 }
99
Nicolas Capensf7b75882017-04-26 09:30:47 -0400100 static bool detectARM()
101 {
102 #if defined(__arm__)
103 return true;
104 #elif defined(__i386__) || defined(__x86_64__)
105 return false;
106 #else
107 #error "Unknown architecture"
108 #endif
109 }
110
Nicolas Capensccd5ecb2017-01-14 12:52:55 -0500111 static bool detectSSE4_1()
112 {
Nicolas Capens47dc8672017-04-25 12:54:39 -0400113 #if defined(__i386__) || defined(__x86_64__)
114 int registers[4];
115 cpuid(registers, 1);
116 return (registers[2] & 0x00080000) != 0;
117 #else
118 return false;
119 #endif
Nicolas Capensccd5ecb2017-01-14 12:52:55 -0500120 }
121 };
122
Nicolas Capensf7b75882017-04-26 09:30:47 -0400123 const bool CPUID::ARM = CPUID::detectARM();
Nicolas Capensccd5ecb2017-01-14 12:52:55 -0500124 const bool CPUID::SSE4_1 = CPUID::detectSSE4_1();
Nicolas Capensf7b75882017-04-26 09:30:47 -0400125 const bool emulateIntrinsics = CPUID::ARM;
Nicolas Capensccd5ecb2017-01-14 12:52:55 -0500126}
127
Nicolas Capens598f8d82016-09-26 15:09:10 -0400128namespace sw
129{
Nicolas Capens23d99a42016-09-30 14:57:16 -0400130 enum EmulatedType
131 {
132 EmulatedShift = 16,
133 EmulatedV2 = 2 << EmulatedShift,
134 EmulatedV4 = 4 << EmulatedShift,
135 EmulatedV8 = 8 << EmulatedShift,
136 EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8,
137
138 Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2,
139 Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4,
140 Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2,
141 Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8,
142 Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4,
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400143 Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2,
Nicolas Capens23d99a42016-09-30 14:57:16 -0400144 };
145
Nicolas Capens15060bb2016-12-05 22:17:19 -0500146 class Value : public Ice::Operand {};
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500147 class SwitchCases : public Ice::InstSwitch {};
Nicolas Capens598f8d82016-09-26 15:09:10 -0400148 class BasicBlock : public Ice::CfgNode {};
149
150 Ice::Type T(Type *t)
151 {
Alexis Hetu113e33a2017-01-19 10:49:19 -0500152 static_assert(static_cast<unsigned int>(Ice::IceType_NUM) < static_cast<unsigned int>(EmulatedBits), "Ice::Type overlaps with our emulated types!");
Nicolas Capens23d99a42016-09-30 14:57:16 -0400153 return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400154 }
155
156 Type *T(Ice::Type t)
157 {
158 return reinterpret_cast<Type*>(t);
159 }
160
Nicolas Capens23d99a42016-09-30 14:57:16 -0400161 Type *T(EmulatedType t)
162 {
163 return reinterpret_cast<Type*>(t);
164 }
165
Nicolas Capens15060bb2016-12-05 22:17:19 -0500166 Value *V(Ice::Operand *v)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400167 {
168 return reinterpret_cast<Value*>(v);
169 }
170
Nicolas Capens611642a2016-09-28 16:45:04 -0400171 BasicBlock *B(Ice::CfgNode *b)
172 {
173 return reinterpret_cast<BasicBlock*>(b);
174 }
175
Nicolas Capens584088c2017-01-26 16:05:18 -0800176 static size_t typeSize(Type *type)
177 {
178 if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits)
179 {
180 switch(reinterpret_cast<std::intptr_t>(type))
181 {
182 case Type_v2i32: return 8;
183 case Type_v4i16: return 8;
184 case Type_v2i16: return 4;
185 case Type_v8i8: return 8;
186 case Type_v4i8: return 4;
187 case Type_v2f32: return 8;
188 default: assert(false);
189 }
190 }
191
192 return Ice::typeWidthInBytes(T(type));
193 }
194
Nicolas Capens598f8d82016-09-26 15:09:10 -0400195 Optimization optimization[10] = {InstructionCombining, Disabled};
196
Nicolas Capens66478362016-10-13 15:36:36 -0400197 using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type;
198 using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type;
199
200 inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader)
201 {
202 return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff);
203 }
Nicolas Capens87852e12016-11-24 14:45:06 -0500204
Nicolas Capens66478362016-10-13 15:36:36 -0400205 inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index)
206 {
207 return &sectionHeader(elfHeader)[index];
208 }
209
210 static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable)
211 {
212 const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info);
Nicolas Capens87852e12016-11-24 14:45:06 -0500213
Nicolas Capens66478362016-10-13 15:36:36 -0400214 intptr_t address = (intptr_t)elfHeader + target->sh_offset;
215 int32_t *patchSite = (int*)(address + relocation.r_offset);
216 uint32_t index = relocation.getSymbol();
217 int table = relocationTable.sh_link;
218 void *symbolValue = nullptr;
Nicolas Capens87852e12016-11-24 14:45:06 -0500219
Nicolas Capens66478362016-10-13 15:36:36 -0400220 if(index != SHN_UNDEF)
221 {
222 if(table == SHN_UNDEF) return nullptr;
223 const SectionHeader *symbolTable = elfSection(elfHeader, table);
Nicolas Capens87852e12016-11-24 14:45:06 -0500224
Nicolas Capens66478362016-10-13 15:36:36 -0400225 uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize;
226 if(index >= symtab_entries)
227 {
228 assert(index < symtab_entries && "Symbol Index out of range");
229 return nullptr;
230 }
Nicolas Capens87852e12016-11-24 14:45:06 -0500231
Nicolas Capens66478362016-10-13 15:36:36 -0400232 intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset;
233 Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index];
234 uint16_t section = symbol.st_shndx;
235
236 if(section != SHN_UNDEF && section < SHN_LORESERVE)
237 {
238 const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx);
239 symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset);
240 }
241 else
242 {
243 return nullptr;
244 }
245 }
246
Nicolas Capensf110e4d2017-05-03 15:33:49 -0400247 if(CPUID::ARM)
248 {
249 switch(relocation.getType())
250 {
251 case R_ARM_NONE:
252 // No relocation
253 break;
254 case R_ARM_MOVW_ABS_NC:
255 {
256 uint32_t thumb = 0; // Calls to Thumb code not supported.
257 uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb;
258 *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF);
259 }
260 break;
261 case R_ARM_MOVT_ABS:
262 {
263 uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16;
264 *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF);
265 }
266 break;
267 default:
268 assert(false && "Unsupported relocation type");
269 return nullptr;
270 }
271 }
272 else
273 {
Nicolas Capens30cd7d42017-04-25 15:17:25 -0400274 switch(relocation.getType())
275 {
276 case R_386_NONE:
277 // No relocation
278 break;
279 case R_386_32:
280 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite);
281 break;
282 // case R_386_PC32:
283 // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite);
284 // break;
285 default:
286 assert(false && "Unsupported relocation type");
287 return nullptr;
288 }
Nicolas Capensf110e4d2017-05-03 15:33:49 -0400289 }
290
Nicolas Capens66478362016-10-13 15:36:36 -0400291
292 return symbolValue;
293 }
294
295 static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable)
296 {
297 const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info);
Nicolas Capens87852e12016-11-24 14:45:06 -0500298
Nicolas Capens66478362016-10-13 15:36:36 -0400299 intptr_t address = (intptr_t)elfHeader + target->sh_offset;
300 int32_t *patchSite = (int*)(address + relocation.r_offset);
301 uint32_t index = relocation.getSymbol();
302 int table = relocationTable.sh_link;
303 void *symbolValue = nullptr;
304
305 if(index != SHN_UNDEF)
306 {
307 if(table == SHN_UNDEF) return nullptr;
308 const SectionHeader *symbolTable = elfSection(elfHeader, table);
Nicolas Capens87852e12016-11-24 14:45:06 -0500309
Nicolas Capens66478362016-10-13 15:36:36 -0400310 uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize;
311 if(index >= symtab_entries)
312 {
313 assert(index < symtab_entries && "Symbol Index out of range");
314 return nullptr;
315 }
Nicolas Capens87852e12016-11-24 14:45:06 -0500316
Nicolas Capens66478362016-10-13 15:36:36 -0400317 intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset;
318 Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index];
319 uint16_t section = symbol.st_shndx;
320
321 if(section != SHN_UNDEF && section < SHN_LORESERVE)
322 {
323 const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx);
324 symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset);
325 }
326 else
327 {
328 return nullptr;
329 }
330 }
331
Nicolas Capensf110e4d2017-05-03 15:33:49 -0400332 switch(relocation.getType())
333 {
334 case R_X86_64_NONE:
335 // No relocation
336 break;
337 case R_X86_64_64:
338 *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend;
339 break;
340 case R_X86_64_PC32:
341 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend;
342 break;
343 case R_X86_64_32S:
344 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend;
345 break;
346 default:
347 assert(false && "Unsupported relocation type");
348 return nullptr;
349 }
Nicolas Capens66478362016-10-13 15:36:36 -0400350
351 return symbolValue;
352 }
353
Nicolas Capens1cc44382017-04-25 10:52:16 -0400354 void *loadImage(uint8_t *const elfImage, size_t &codeSize)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400355 {
Nicolas Capens598f8d82016-09-26 15:09:10 -0400356 ElfHeader *elfHeader = (ElfHeader*)elfImage;
357
358 if(!elfHeader->checkMagic())
359 {
360 return nullptr;
361 }
362
Nicolas Capens66478362016-10-13 15:36:36 -0400363 // Expect ELF bitness to match platform
Nicolas Capens65047112016-11-07 13:01:07 -0500364 assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32);
Nicolas Capens30cd7d42017-04-25 15:17:25 -0400365 #if defined(__i386__)
366 assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386);
367 #elif defined(__x86_64__)
368 assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64);
369 #elif defined(__arm__)
370 assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM);
371 #else
372 #error "Unsupported platform"
373 #endif
Nicolas Capens66478362016-10-13 15:36:36 -0400374
Nicolas Capens598f8d82016-09-26 15:09:10 -0400375 SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff);
376 void *entry = nullptr;
377
378 for(int i = 0; i < elfHeader->e_shnum; i++)
379 {
Nicolas Capens66478362016-10-13 15:36:36 -0400380 if(sectionHeader[i].sh_type == SHT_PROGBITS)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400381 {
Nicolas Capens66478362016-10-13 15:36:36 -0400382 if(sectionHeader[i].sh_flags & SHF_EXECINSTR)
383 {
384 entry = elfImage + sectionHeader[i].sh_offset;
Nicolas Capens1cc44382017-04-25 10:52:16 -0400385 codeSize = sectionHeader[i].sh_size;
Nicolas Capens66478362016-10-13 15:36:36 -0400386 }
387 }
388 else if(sectionHeader[i].sh_type == SHT_REL)
389 {
390 assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code
391
Alexis Hetu113e33a2017-01-19 10:49:19 -0500392 for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
Nicolas Capens66478362016-10-13 15:36:36 -0400393 {
394 const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index];
Alexis Hetu113e33a2017-01-19 10:49:19 -0500395 relocateSymbol(elfHeader, relocation, sectionHeader[i]);
Nicolas Capens66478362016-10-13 15:36:36 -0400396 }
397 }
398 else if(sectionHeader[i].sh_type == SHT_RELA)
399 {
400 assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code
401
Alexis Hetu113e33a2017-01-19 10:49:19 -0500402 for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
Nicolas Capens66478362016-10-13 15:36:36 -0400403 {
404 const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index];
Alexis Hetu113e33a2017-01-19 10:49:19 -0500405 relocateSymbol(elfHeader, relocation, sectionHeader[i]);
Nicolas Capens66478362016-10-13 15:36:36 -0400406 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400407 }
408 }
409
410 return entry;
411 }
412
413 template<typename T>
414 struct ExecutableAllocator
415 {
416 ExecutableAllocator() {};
417 template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {};
418
419 using value_type = T;
420 using size_type = std::size_t;
421
422 T *allocate(size_type n)
423 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500424 #if defined(_WIN32)
425 return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
426 #else
427 return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
428 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400429 }
430
431 void deallocate(T *p, size_type n)
432 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500433 #if defined(_WIN32)
434 VirtualFree(p, 0, MEM_RELEASE);
435 #else
436 munmap(p, sizeof(T) * n);
437 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400438 }
439 };
440
441 class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine
442 {
443 ELFMemoryStreamer(const ELFMemoryStreamer &) = delete;
444 ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete;
445
446 public:
Nicolas Capens58274b52016-10-19 23:45:19 -0400447 ELFMemoryStreamer() : Routine(), entry(nullptr)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400448 {
449 position = 0;
450 buffer.reserve(0x1000);
451 }
452
Nicolas Capens81aa97b2017-06-27 17:08:08 -0400453 ~ELFMemoryStreamer() override
Nicolas Capens598f8d82016-09-26 15:09:10 -0400454 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500455 #if defined(_WIN32)
456 if(buffer.size() != 0)
457 {
458 DWORD exeProtection;
459 VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection);
460 }
461 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400462 }
463
464 void write8(uint8_t Value) override
465 {
466 if(position == (uint64_t)buffer.size())
467 {
468 buffer.push_back(Value);
469 position++;
470 }
471 else if(position < (uint64_t)buffer.size())
472 {
473 buffer[position] = Value;
474 position++;
475 }
476 else assert(false && "UNIMPLEMENTED");
477 }
478
479 void writeBytes(llvm::StringRef Bytes) override
480 {
481 std::size_t oldSize = buffer.size();
482 buffer.resize(oldSize + Bytes.size());
483 memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size());
484 position += Bytes.size();
485 }
486
487 uint64_t tell() const override { return position; }
488
489 void seek(uint64_t Off) override { position = Off; }
490
491 const void *getEntry() override
492 {
Nicolas Capens58274b52016-10-19 23:45:19 -0400493 if(!entry)
494 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500495 position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this
Nicolas Capens598f8d82016-09-26 15:09:10 -0400496
Nicolas Capens1cc44382017-04-25 10:52:16 -0400497 size_t codeSize = 0;
498 entry = loadImage(&buffer[0], codeSize);
499
500 #if defined(_WIN32)
Nicolas Capense745f5a2017-05-29 10:00:32 -0400501 VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection);
Nicolas Capens1cc44382017-04-25 10:52:16 -0400502 FlushInstructionCache(GetCurrentProcess(), NULL, 0);
503 #else
Nicolas Capense745f5a2017-05-29 10:00:32 -0400504 mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC);
Nicolas Capens1cc44382017-04-25 10:52:16 -0400505 __builtin___clear_cache((char*)entry, (char*)entry + codeSize);
506 #endif
Nicolas Capens58274b52016-10-19 23:45:19 -0400507 }
508
509 return entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400510 }
511
512 private:
Nicolas Capens58274b52016-10-19 23:45:19 -0400513 void *entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400514 std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer;
515 std::size_t position;
Nicolas Capensbd65da92017-01-05 16:31:06 -0500516
517 #if defined(_WIN32)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400518 DWORD oldProtection;
Nicolas Capensbd65da92017-01-05 16:31:06 -0500519 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400520 };
521
522 Nucleus::Nucleus()
523 {
524 ::codegenMutex.lock(); // Reactor is currently not thread safe
525
Nicolas Capens66478362016-10-13 15:36:36 -0400526 Ice::ClFlags &Flags = Ice::ClFlags::Flags;
527 Ice::ClFlags::getParsedClFlags(Flags);
528
Nicolas Capens30cd7d42017-04-25 15:17:25 -0400529 #if defined(__arm__)
530 Flags.setTargetArch(Ice::Target_ARM32);
531 Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm);
532 #else // x86
533 Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632);
534 Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2);
535 #endif
Nicolas Capens66478362016-10-13 15:36:36 -0400536 Flags.setOutFileType(Ice::FT_Elf);
537 Flags.setOptLevel(Ice::Opt_2);
538 Flags.setApplicationBinaryInterface(Ice::ABI_Platform);
Nicolas Capens30cd7d42017-04-25 15:17:25 -0400539 Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None);
540 Flags.setDisableHybridAssembly(true);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400541
Nicolas Capens65047112016-11-07 13:01:07 -0500542 static llvm::raw_os_ostream cout(std::cout);
543 static llvm::raw_os_ostream cerr(std::cerr);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400544
545 if(false) // Write out to a file
546 {
547 std::error_code errorCode;
548 ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None);
549 ::elfFile = new Ice::ELFFileStreamer(*out);
Nicolas Capens65047112016-11-07 13:01:07 -0500550 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400551 }
552 else
553 {
554 ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer();
Nicolas Capens65047112016-11-07 13:01:07 -0500555 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400556 ::routine = elfMemory;
557 }
558 }
559
560 Nucleus::~Nucleus()
561 {
562 delete ::allocator;
563 delete ::function;
564 delete ::context;
565
566 delete ::elfFile;
567 delete ::out;
568
569 ::codegenMutex.unlock();
570 }
571
572 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
573 {
574 if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
575 {
576 createRetVoid();
577 }
578
579 std::wstring wideName(name);
580 std::string asciiName(wideName.begin(), wideName.end());
581 ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
582
Nicolas Capens2ae9d742016-11-24 14:43:05 -0500583 optimize();
584
Nicolas Capens598f8d82016-09-26 15:09:10 -0400585 ::function->translate();
Nicolas Capensde19f392016-10-19 10:29:49 -0400586 assert(!::function->hasError());
587
Nicolas Capens66478362016-10-13 15:36:36 -0400588 auto *globals = ::function->getGlobalInits().release();
589
590 if(globals && !globals->empty())
591 {
592 ::context->getGlobals()->merge(globals);
593 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400594
595 ::context->emitFileHeader();
596 ::function->emitIAS();
597 auto assembler = ::function->releaseAssembler();
Nicolas Capens66478362016-10-13 15:36:36 -0400598 auto objectWriter = ::context->getObjectWriter();
599 assembler->alignFunction();
600 objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
601 ::context->lowerGlobals("last");
Nicolas Capens73dd7a22016-10-20 13:20:34 -0400602 ::context->lowerConstants();
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500603 ::context->lowerJumpTables();
Nicolas Capens66478362016-10-13 15:36:36 -0400604 objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
605 objectWriter->writeNonUserSections();
Nicolas Capens598f8d82016-09-26 15:09:10 -0400606
607 return ::routine;
608 }
609
610 void Nucleus::optimize()
611 {
Nicolas Capens2ae9d742016-11-24 14:43:05 -0500612 sw::optimize(::function);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400613 }
614
615 Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
616 {
617 Ice::Type type = T(t);
Nicolas Capensa8f98632016-10-20 11:25:55 -0400618 int typeSize = Ice::typeWidthInBytes(type);
619 int totalSize = typeSize * (arraySize ? arraySize : 1);
Nicolas Capense12780d2016-09-27 14:18:07 -0400620
Nicolas Capensa8f98632016-10-20 11:25:55 -0400621 auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400622 auto address = ::function->makeVariable(T(getPointerType(t)));
Nicolas Capensa8f98632016-10-20 11:25:55 -0400623 auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400624 ::function->getEntryNode()->getInsts().push_front(alloca);
625
626 return V(address);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400627 }
628
629 BasicBlock *Nucleus::createBasicBlock()
630 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400631 return B(::function->makeNode());
Nicolas Capens598f8d82016-09-26 15:09:10 -0400632 }
633
634 BasicBlock *Nucleus::getInsertBlock()
635 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400636 return B(::basicBlock);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400637 }
638
639 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
640 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -0400641 // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator");
Nicolas Capens611642a2016-09-28 16:45:04 -0400642 ::basicBlock = basicBlock;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400643 }
644
Nicolas Capens598f8d82016-09-26 15:09:10 -0400645 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
646 {
647 uint32_t sequenceNumber = 0;
648 ::function = Ice::Cfg::create(::context, sequenceNumber).release();
649 ::allocator = new Ice::CfgLocalAllocatorScope(::function);
650
651 for(Type *type : Params)
652 {
653 Ice::Variable *arg = ::function->makeVariable(T(type));
654 ::function->addArg(arg);
655 }
656
657 Ice::CfgNode *node = ::function->makeNode();
658 ::function->setEntryNode(node);
659 ::basicBlock = node;
660 }
661
662 Value *Nucleus::getArgument(unsigned int index)
663 {
664 return V(::function->getArgs()[index]);
665 }
666
667 void Nucleus::createRetVoid()
668 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400669 Ice::InstRet *ret = Ice::InstRet::create(::function);
670 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400671 }
672
673 void Nucleus::createRet(Value *v)
674 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400675 Ice::InstRet *ret = Ice::InstRet::create(::function, v);
676 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400677 }
678
679 void Nucleus::createBr(BasicBlock *dest)
680 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400681 auto br = Ice::InstBr::create(::function, dest);
682 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400683 }
684
685 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
686 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400687 auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse);
688 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400689 }
690
Nicolas Capensf8360ba2017-01-25 11:35:00 -0800691 static bool isCommutative(Ice::InstArithmetic::OpKind op)
692 {
693 switch(op)
694 {
695 case Ice::InstArithmetic::Add:
696 case Ice::InstArithmetic::Fadd:
697 case Ice::InstArithmetic::Mul:
698 case Ice::InstArithmetic::Fmul:
699 case Ice::InstArithmetic::And:
700 case Ice::InstArithmetic::Or:
701 case Ice::InstArithmetic::Xor:
702 return true;
703 default:
704 return false;
705 }
706 }
707
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400708 static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
709 {
Nicolas Capens327f1df2016-10-21 14:26:34 -0400710 assert(lhs->getType() == rhs->getType() || (llvm::isa<Ice::Constant>(rhs) && (op == Ice::InstArithmetic::Shl || Ice::InstArithmetic::Lshr || Ice::InstArithmetic::Ashr)));
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400711
Nicolas Capensf8360ba2017-01-25 11:35:00 -0800712 bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op);
713
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400714 Ice::Variable *result = ::function->makeVariable(lhs->getType());
Nicolas Capensf8360ba2017-01-25 11:35:00 -0800715 Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, swapOperands ? rhs : lhs, swapOperands ? lhs : rhs);
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400716 ::basicBlock->appendInst(arithmetic);
717
718 return V(result);
719 }
720
Nicolas Capens598f8d82016-09-26 15:09:10 -0400721 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
722 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400723 return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400724 }
725
726 Value *Nucleus::createSub(Value *lhs, Value *rhs)
727 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400728 return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400729 }
730
731 Value *Nucleus::createMul(Value *lhs, Value *rhs)
732 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400733 return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400734 }
735
736 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
737 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400738 return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400739 }
740
741 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
742 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400743 return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400744 }
745
746 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
747 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400748 return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400749 }
750
751 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
752 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400753 return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400754 }
755
756 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
757 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400758 return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400759 }
760
761 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
762 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400763 return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400764 }
765
766 Value *Nucleus::createURem(Value *lhs, Value *rhs)
767 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400768 return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400769 }
770
771 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
772 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400773 return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400774 }
775
776 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
777 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400778 return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400779 }
780
781 Value *Nucleus::createShl(Value *lhs, Value *rhs)
782 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400783 return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400784 }
785
786 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
787 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400788 return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400789 }
790
791 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
792 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400793 return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400794 }
795
796 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
797 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400798 return createArithmetic(Ice::InstArithmetic::And, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400799 }
800
801 Value *Nucleus::createOr(Value *lhs, Value *rhs)
802 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400803 return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400804 }
805
806 Value *Nucleus::createXor(Value *lhs, Value *rhs)
807 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400808 return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400809 }
810
811 Value *Nucleus::createNeg(Value *v)
812 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500813 return createSub(createNullValue(T(v->getType())), v);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400814 }
815
816 Value *Nucleus::createFNeg(Value *v)
817 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500818 double c[4] = {-0.0, -0.0, -0.0, -0.0};
819 Value *negativeZero = Ice::isVectorType(v->getType()) ?
820 createConstantVector(c, T(v->getType())) :
Nicolas Capens15060bb2016-12-05 22:17:19 -0500821 V(::context->getConstantFloat(-0.0f));
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500822
823 return createFSub(negativeZero, v);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400824 }
825
826 Value *Nucleus::createNot(Value *v)
827 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500828 if(Ice::isScalarIntegerType(v->getType()))
829 {
Nicolas Capens15060bb2016-12-05 22:17:19 -0500830 return createXor(v, V(::context->getConstantInt(v->getType(), -1)));
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500831 }
832 else // Vector
833 {
Nicolas Capensf34d1ac2017-05-08 17:06:11 -0400834 int64_t c[16] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500835 return createXor(v, createConstantVector(c, T(v->getType())));
836 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400837 }
838
Nicolas Capense12780d2016-09-27 14:18:07 -0400839 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400840 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400841 int valueType = (int)reinterpret_cast<intptr_t>(type);
842 Ice::Variable *result = ::function->makeVariable(T(type));
843
844 if(valueType & EmulatedBits)
845 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800846 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
847 auto target = ::context->getConstantUndef(Ice::IceType_i32);
848 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
849 load->addArg(ptr);
850 load->addArg(::context->getConstantInt32(typeSize(type)));
851 ::basicBlock->appendInst(load);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400852 }
853 else
854 {
855 auto load = Ice::InstLoad::create(::function, result, ptr, align);
856 ::basicBlock->appendInst(load);
857 }
858
859 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400860 }
861
Nicolas Capens6d738712016-09-30 04:15:22 -0400862 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400863 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400864 int valueType = (int)reinterpret_cast<intptr_t>(type);
865
866 if(valueType & EmulatedBits)
867 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800868 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
869 auto target = ::context->getConstantUndef(Ice::IceType_i32);
870 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
871 store->addArg(value);
872 store->addArg(ptr);
873 store->addArg(::context->getConstantInt32(typeSize(type)));
874 ::basicBlock->appendInst(store);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400875 }
876 else
877 {
878 assert(T(value->getType()) == type);
879
880 auto store = Ice::InstStore::create(::function, value, ptr, align);
881 ::basicBlock->appendInst(store);
882 }
883
Nicolas Capens598f8d82016-09-26 15:09:10 -0400884 return value;
885 }
886
Nicolas Capensd294def2017-01-26 17:44:37 -0800887 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400888 {
Nicolas Capens8820f642016-09-30 04:42:43 -0400889 assert(index->getType() == Ice::IceType_i32);
890
Nicolas Capens15060bb2016-12-05 22:17:19 -0500891 if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index))
892 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800893 int32_t offset = constant->getValue() * (int)typeSize(type);
Nicolas Capens15060bb2016-12-05 22:17:19 -0500894
895 if(offset == 0)
896 {
897 return ptr;
898 }
899
900 return createAdd(ptr, createConstantInt(offset));
901 }
902
Nicolas Capens8820f642016-09-30 04:42:43 -0400903 if(!Ice::isByteSizedType(T(type)))
904 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800905 index = createMul(index, createConstantInt((int)typeSize(type)));
Nicolas Capens8820f642016-09-30 04:42:43 -0400906 }
907
908 if(sizeof(void*) == 8)
909 {
Nicolas Capensd294def2017-01-26 17:44:37 -0800910 if(unsignedIndex)
911 {
912 index = createZExt(index, T(Ice::IceType_i64));
913 }
914 else
915 {
916 index = createSExt(index, T(Ice::IceType_i64));
917 }
Nicolas Capens8820f642016-09-30 04:42:43 -0400918 }
919
920 return createAdd(ptr, index);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400921 }
922
923 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
924 {
925 assert(false && "UNIMPLEMENTED"); return nullptr;
926 }
927
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400928 static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType)
929 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400930 if(v->getType() == T(destType))
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400931 {
932 return v;
933 }
934
935 Ice::Variable *result = ::function->makeVariable(T(destType));
936 Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v);
937 ::basicBlock->appendInst(cast);
938
939 return V(result);
940 }
941
Nicolas Capens598f8d82016-09-26 15:09:10 -0400942 Value *Nucleus::createTrunc(Value *v, Type *destType)
943 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400944 return createCast(Ice::InstCast::Trunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400945 }
946
947 Value *Nucleus::createZExt(Value *v, Type *destType)
948 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400949 return createCast(Ice::InstCast::Zext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400950 }
951
952 Value *Nucleus::createSExt(Value *v, Type *destType)
953 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400954 return createCast(Ice::InstCast::Sext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400955 }
956
957 Value *Nucleus::createFPToSI(Value *v, Type *destType)
958 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400959 return createCast(Ice::InstCast::Fptosi, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400960 }
961
Nicolas Capens598f8d82016-09-26 15:09:10 -0400962 Value *Nucleus::createSIToFP(Value *v, Type *destType)
963 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400964 return createCast(Ice::InstCast::Sitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400965 }
966
967 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
968 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400969 return createCast(Ice::InstCast::Fptrunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400970 }
971
972 Value *Nucleus::createFPExt(Value *v, Type *destType)
973 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400974 return createCast(Ice::InstCast::Fpext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400975 }
976
977 Value *Nucleus::createBitCast(Value *v, Type *destType)
978 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400979 return createCast(Ice::InstCast::Bitcast, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400980 }
981
Nicolas Capens43dc6292016-10-20 00:01:38 -0400982 static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400983 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400984 assert(lhs->getType() == rhs->getType());
985
Nicolas Capens43dc6292016-10-20 00:01:38 -0400986 auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType());
987 auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs);
Nicolas Capens611642a2016-09-28 16:45:04 -0400988 ::basicBlock->appendInst(cmp);
989
990 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400991 }
992
Nicolas Capens43dc6292016-10-20 00:01:38 -0400993 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
994 {
995 return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs);
996 }
997
998 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
999 {
1000 return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs);
1001 }
1002
1003 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
1004 {
1005 return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs);
1006 }
1007
1008 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
1009 {
1010 return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs);
1011 }
1012
1013 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
1014 {
1015 return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs);
1016 }
1017
1018 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
1019 {
1020 return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs);
1021 }
1022
1023 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
1024 {
1025 return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs);
1026 }
1027
1028 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
1029 {
1030 return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs);
1031 }
1032
1033 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
1034 {
1035 return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs);
1036 }
1037
Nicolas Capens598f8d82016-09-26 15:09:10 -04001038 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
1039 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001040 return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs);
1041 }
1042
1043 static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs)
1044 {
1045 assert(lhs->getType() == rhs->getType());
1046 assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32);
1047
1048 auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32);
1049 auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs);
1050 ::basicBlock->appendInst(cmp);
1051
1052 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001053 }
1054
1055 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
1056 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001057 return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001058 }
1059
1060 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
1061 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001062 return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001063 }
1064
1065 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
1066 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001067 return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001068 }
1069
1070 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
1071 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001072 return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001073 }
1074
1075 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
1076 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001077 return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001078 }
1079
1080 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
1081 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001082 return createFloatCompare(Ice::InstFcmp::One, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001083 }
1084
1085 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
1086 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001087 return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001088 }
1089
1090 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
1091 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001092 return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001093 }
1094
1095 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
1096 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001097 return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001098 }
1099
1100 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
1101 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001102 return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001103 }
1104
1105 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
1106 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001107 return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001108 }
1109
1110 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
1111 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001112 return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001113 }
1114
1115 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
1116 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001117 return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001118 }
1119
1120 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
1121 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001122 return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001123 }
1124
Nicolas Capense95d5342016-09-30 11:37:28 -04001125 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001126 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001127 auto result = ::function->makeVariable(T(type));
1128 auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index));
1129 ::basicBlock->appendInst(extract);
1130
1131 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001132 }
1133
1134 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
1135 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001136 auto result = ::function->makeVariable(vector->getType());
1137 auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index));
1138 ::basicBlock->appendInst(insert);
1139
1140 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001141 }
1142
Nicolas Capense89cd582016-09-30 14:23:47 -04001143 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001144 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001145 assert(V1->getType() == V2->getType());
1146
1147 int size = Ice::typeNumElements(V1->getType());
1148 auto result = ::function->makeVariable(V1->getType());
1149 auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2);
1150
1151 for(int i = 0; i < size; i++)
1152 {
1153 shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i])));
1154 }
1155
1156 ::basicBlock->appendInst(shuffle);
1157
1158 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001159 }
1160
1161 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
1162 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04001163 assert(ifTrue->getType() == ifFalse->getType());
1164
1165 auto result = ::function->makeVariable(ifTrue->getType());
1166 auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse);
1167 ::basicBlock->appendInst(select);
1168
1169 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001170 }
1171
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001172 SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001173 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001174 auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch);
1175 ::basicBlock->appendInst(switchInst);
1176
1177 return reinterpret_cast<SwitchCases*>(switchInst);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001178 }
1179
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001180 void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001181 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001182 switchCases->addBranch(label, label, branch);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001183 }
1184
1185 void Nucleus::createUnreachable()
1186 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04001187 Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function);
1188 ::basicBlock->appendInst(unreachable);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001189 }
1190
Nicolas Capense95d5342016-09-30 11:37:28 -04001191 static Value *createSwizzle4(Value *val, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001192 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001193 int swizzle[4] =
1194 {
1195 (select >> 0) & 0x03,
1196 (select >> 2) & 0x03,
1197 (select >> 4) & 0x03,
1198 (select >> 6) & 0x03,
1199 };
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001200
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001201 return Nucleus::createShuffleVector(val, val, swizzle);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001202 }
1203
Nicolas Capense95d5342016-09-30 11:37:28 -04001204 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001205 {
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001206 int64_t mask[4] = {0, 0, 0, 0};
1207
1208 mask[(select >> 0) & 0x03] = -1;
1209 mask[(select >> 2) & 0x03] = -1;
1210 mask[(select >> 4) & 0x03] = -1;
1211 mask[(select >> 6) & 0x03] = -1;
1212
1213 Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1));
1214 Value *result = Nucleus::createSelect(condition, rhs, lhs);
1215
1216 return result;
Nicolas Capens598f8d82016-09-26 15:09:10 -04001217 }
1218
Nicolas Capens598f8d82016-09-26 15:09:10 -04001219 Type *Nucleus::getPointerType(Type *ElementType)
1220 {
Nicolas Capense12780d2016-09-27 14:18:07 -04001221 if(sizeof(void*) == 8)
1222 {
1223 return T(Ice::IceType_i64);
1224 }
1225 else
1226 {
1227 return T(Ice::IceType_i32);
1228 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001229 }
1230
Nicolas Capens13ac2322016-10-13 14:52:12 -04001231 Value *Nucleus::createNullValue(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001232 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001233 if(Ice::isVectorType(T(Ty)))
1234 {
Nicolas Capens30385f02017-04-18 13:03:47 -04001235 assert(Ice::typeNumElements(T(Ty)) <= 16);
1236 int64_t c[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001237 return createConstantVector(c, Ty);
1238 }
1239 else
1240 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001241 return V(::context->getConstantZero(T(Ty)));
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001242 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001243 }
1244
Nicolas Capens13ac2322016-10-13 14:52:12 -04001245 Value *Nucleus::createConstantLong(int64_t i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001246 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001247 return V(::context->getConstantInt64(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001248 }
1249
Nicolas Capens13ac2322016-10-13 14:52:12 -04001250 Value *Nucleus::createConstantInt(int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001251 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001252 return V(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001253 }
1254
Nicolas Capens13ac2322016-10-13 14:52:12 -04001255 Value *Nucleus::createConstantInt(unsigned int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001256 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001257 return V(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001258 }
1259
Nicolas Capens13ac2322016-10-13 14:52:12 -04001260 Value *Nucleus::createConstantBool(bool b)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001261 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001262 return V(::context->getConstantInt1(b));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001263 }
1264
Nicolas Capens13ac2322016-10-13 14:52:12 -04001265 Value *Nucleus::createConstantByte(signed char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001266 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001267 return V(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001268 }
1269
Nicolas Capens13ac2322016-10-13 14:52:12 -04001270 Value *Nucleus::createConstantByte(unsigned char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001271 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001272 return V(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001273 }
1274
Nicolas Capens13ac2322016-10-13 14:52:12 -04001275 Value *Nucleus::createConstantShort(short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001276 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001277 return V(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001278 }
1279
Nicolas Capens13ac2322016-10-13 14:52:12 -04001280 Value *Nucleus::createConstantShort(unsigned short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001281 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001282 return V(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001283 }
1284
Nicolas Capens13ac2322016-10-13 14:52:12 -04001285 Value *Nucleus::createConstantFloat(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001286 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001287 return V(::context->getConstantFloat(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001288 }
1289
Nicolas Capens13ac2322016-10-13 14:52:12 -04001290 Value *Nucleus::createNullPointer(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001291 {
Nicolas Capensa29d6532016-12-05 21:38:09 -05001292 return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001293 }
1294
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001295 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
Nicolas Capens13ac2322016-10-13 14:52:12 -04001296 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001297 const int vectorSize = 16;
1298 assert(Ice::typeWidthInBytes(T(type)) == vectorSize);
1299 const int alignment = vectorSize;
1300 auto globalPool = ::function->getGlobalPool();
1301
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001302 const int64_t *i = constants;
1303 const double *f = reinterpret_cast<const double*>(constants);
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001304 Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr;
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001305
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001306 switch((int)reinterpret_cast<intptr_t>(type))
1307 {
1308 case Ice::IceType_v4i32:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001309 case Ice::IceType_v4i1:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001310 {
1311 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]};
1312 static_assert(sizeof(initializer) == vectorSize, "!");
1313 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1314 }
1315 break;
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001316 case Ice::IceType_v4f32:
1317 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001318 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001319 static_assert(sizeof(initializer) == vectorSize, "!");
1320 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1321 }
1322 break;
1323 case Ice::IceType_v8i16:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001324 case Ice::IceType_v8i1:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001325 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001326 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 Capens8dfd9a72016-10-13 17:44:51 -04001327 static_assert(sizeof(initializer) == vectorSize, "!");
1328 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1329 }
1330 break;
1331 case Ice::IceType_v16i8:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001332 case Ice::IceType_v16i1:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001333 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001334 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 Capens8dfd9a72016-10-13 17:44:51 -04001335 static_assert(sizeof(initializer) == vectorSize, "!");
1336 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1337 }
1338 break;
1339 case Type_v2i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001340 {
1341 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]};
1342 static_assert(sizeof(initializer) == vectorSize, "!");
1343 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1344 }
1345 break;
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001346 case Type_v2f32:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001347 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001348 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001349 static_assert(sizeof(initializer) == vectorSize, "!");
1350 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1351 }
1352 break;
1353 case Type_v4i16:
1354 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001355 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 Capens8dfd9a72016-10-13 17:44:51 -04001356 static_assert(sizeof(initializer) == vectorSize, "!");
1357 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1358 }
1359 break;
1360 case Type_v8i8:
1361 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001362 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 Capens8dfd9a72016-10-13 17:44:51 -04001363 static_assert(sizeof(initializer) == vectorSize, "!");
1364 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1365 }
1366 break;
1367 case Type_v4i8:
1368 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001369 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 Capens8dfd9a72016-10-13 17:44:51 -04001370 static_assert(sizeof(initializer) == vectorSize, "!");
1371 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1372 }
1373 break;
1374 default:
1375 assert(false && "Unknown constant vector type" && type);
1376 }
1377
1378 auto name = Ice::GlobalString::createWithoutString(::context);
1379 auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool);
1380 variableDeclaration->setName(name);
1381 variableDeclaration->setAlignment(alignment);
1382 variableDeclaration->setIsConstant(true);
1383 variableDeclaration->addInitializer(dataInitializer);
Nicolas Capens87852e12016-11-24 14:45:06 -05001384
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001385 ::function->addGlobal(variableDeclaration);
1386
1387 constexpr int32_t offset = 0;
1388 Ice::Operand *ptr = ::context->getConstantSym(offset, name);
1389
1390 Ice::Variable *result = ::function->makeVariable(T(type));
1391 auto load = Ice::InstLoad::create(::function, result, ptr, alignment);
1392 ::basicBlock->appendInst(load);
1393
1394 return V(result);
Nicolas Capens13ac2322016-10-13 14:52:12 -04001395 }
1396
1397 Value *Nucleus::createConstantVector(const double *constants, Type *type)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001398 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001399 return createConstantVector((const int64_t*)constants, type);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001400 }
1401
1402 Type *Void::getType()
1403 {
1404 return T(Ice::IceType_void);
1405 }
1406
Nicolas Capens598f8d82016-09-26 15:09:10 -04001407 Bool::Bool(Argument<Bool> argument)
1408 {
1409 storeValue(argument.value);
1410 }
1411
Nicolas Capens598f8d82016-09-26 15:09:10 -04001412 Bool::Bool(bool x)
1413 {
1414 storeValue(Nucleus::createConstantBool(x));
1415 }
1416
1417 Bool::Bool(RValue<Bool> rhs)
1418 {
1419 storeValue(rhs.value);
1420 }
1421
1422 Bool::Bool(const Bool &rhs)
1423 {
1424 Value *value = rhs.loadValue();
1425 storeValue(value);
1426 }
1427
1428 Bool::Bool(const Reference<Bool> &rhs)
1429 {
1430 Value *value = rhs.loadValue();
1431 storeValue(value);
1432 }
1433
Nicolas Capens96d4e092016-11-18 14:22:38 -05001434 RValue<Bool> Bool::operator=(RValue<Bool> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001435 {
1436 storeValue(rhs.value);
1437
1438 return rhs;
1439 }
1440
Nicolas Capens96d4e092016-11-18 14:22:38 -05001441 RValue<Bool> Bool::operator=(const Bool &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001442 {
1443 Value *value = rhs.loadValue();
1444 storeValue(value);
1445
1446 return RValue<Bool>(value);
1447 }
1448
Nicolas Capens96d4e092016-11-18 14:22:38 -05001449 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001450 {
1451 Value *value = rhs.loadValue();
1452 storeValue(value);
1453
1454 return RValue<Bool>(value);
1455 }
1456
1457 RValue<Bool> operator!(RValue<Bool> val)
1458 {
1459 return RValue<Bool>(Nucleus::createNot(val.value));
1460 }
1461
1462 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
1463 {
1464 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1465 }
1466
1467 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
1468 {
1469 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1470 }
1471
1472 Type *Bool::getType()
1473 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001474 return T(Ice::IceType_i1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001475 }
1476
1477 Byte::Byte(Argument<Byte> argument)
1478 {
1479 storeValue(argument.value);
1480 }
1481
1482 Byte::Byte(RValue<Int> cast)
1483 {
1484 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1485
1486 storeValue(integer);
1487 }
1488
1489 Byte::Byte(RValue<UInt> cast)
1490 {
1491 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1492
1493 storeValue(integer);
1494 }
1495
1496 Byte::Byte(RValue<UShort> cast)
1497 {
1498 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1499
1500 storeValue(integer);
1501 }
1502
Nicolas Capens598f8d82016-09-26 15:09:10 -04001503 Byte::Byte(int x)
1504 {
1505 storeValue(Nucleus::createConstantByte((unsigned char)x));
1506 }
1507
1508 Byte::Byte(unsigned char x)
1509 {
1510 storeValue(Nucleus::createConstantByte(x));
1511 }
1512
1513 Byte::Byte(RValue<Byte> rhs)
1514 {
1515 storeValue(rhs.value);
1516 }
1517
1518 Byte::Byte(const Byte &rhs)
1519 {
1520 Value *value = rhs.loadValue();
1521 storeValue(value);
1522 }
1523
1524 Byte::Byte(const Reference<Byte> &rhs)
1525 {
1526 Value *value = rhs.loadValue();
1527 storeValue(value);
1528 }
1529
Nicolas Capens96d4e092016-11-18 14:22:38 -05001530 RValue<Byte> Byte::operator=(RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001531 {
1532 storeValue(rhs.value);
1533
1534 return rhs;
1535 }
1536
Nicolas Capens96d4e092016-11-18 14:22:38 -05001537 RValue<Byte> Byte::operator=(const Byte &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001538 {
1539 Value *value = rhs.loadValue();
1540 storeValue(value);
1541
1542 return RValue<Byte>(value);
1543 }
1544
Nicolas Capens96d4e092016-11-18 14:22:38 -05001545 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001546 {
1547 Value *value = rhs.loadValue();
1548 storeValue(value);
1549
1550 return RValue<Byte>(value);
1551 }
1552
1553 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
1554 {
1555 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1556 }
1557
1558 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
1559 {
1560 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1561 }
1562
1563 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
1564 {
1565 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1566 }
1567
1568 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
1569 {
1570 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1571 }
1572
1573 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
1574 {
1575 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1576 }
1577
1578 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
1579 {
1580 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1581 }
1582
1583 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
1584 {
1585 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1586 }
1587
1588 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
1589 {
1590 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1591 }
1592
1593 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
1594 {
1595 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1596 }
1597
1598 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
1599 {
1600 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1601 }
1602
Nicolas Capens96d4e092016-11-18 14:22:38 -05001603 RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001604 {
1605 return lhs = lhs + rhs;
1606 }
1607
Nicolas Capens96d4e092016-11-18 14:22:38 -05001608 RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001609 {
1610 return lhs = lhs - rhs;
1611 }
1612
Nicolas Capens96d4e092016-11-18 14:22:38 -05001613 RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001614 {
1615 return lhs = lhs * rhs;
1616 }
1617
Nicolas Capens96d4e092016-11-18 14:22:38 -05001618 RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001619 {
1620 return lhs = lhs / rhs;
1621 }
1622
Nicolas Capens96d4e092016-11-18 14:22:38 -05001623 RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001624 {
1625 return lhs = lhs % rhs;
1626 }
1627
Nicolas Capens96d4e092016-11-18 14:22:38 -05001628 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001629 {
1630 return lhs = lhs & rhs;
1631 }
1632
Nicolas Capens96d4e092016-11-18 14:22:38 -05001633 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001634 {
1635 return lhs = lhs | rhs;
1636 }
1637
Nicolas Capens96d4e092016-11-18 14:22:38 -05001638 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001639 {
1640 return lhs = lhs ^ rhs;
1641 }
1642
Nicolas Capens96d4e092016-11-18 14:22:38 -05001643 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001644 {
1645 return lhs = lhs << rhs;
1646 }
1647
Nicolas Capens96d4e092016-11-18 14:22:38 -05001648 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001649 {
1650 return lhs = lhs >> rhs;
1651 }
1652
1653 RValue<Byte> operator+(RValue<Byte> val)
1654 {
1655 return val;
1656 }
1657
1658 RValue<Byte> operator-(RValue<Byte> val)
1659 {
1660 return RValue<Byte>(Nucleus::createNeg(val.value));
1661 }
1662
1663 RValue<Byte> operator~(RValue<Byte> val)
1664 {
1665 return RValue<Byte>(Nucleus::createNot(val.value));
1666 }
1667
Nicolas Capens96d4e092016-11-18 14:22:38 -05001668 RValue<Byte> operator++(Byte &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001669 {
1670 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001671 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001672 return res;
1673 }
1674
Nicolas Capens96d4e092016-11-18 14:22:38 -05001675 const Byte &operator++(Byte &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001676 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001677 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001678 return val;
1679 }
1680
Nicolas Capens96d4e092016-11-18 14:22:38 -05001681 RValue<Byte> operator--(Byte &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001682 {
1683 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001684 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001685 return res;
1686 }
1687
Nicolas Capens96d4e092016-11-18 14:22:38 -05001688 const Byte &operator--(Byte &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001689 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001690 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001691 return val;
1692 }
1693
1694 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
1695 {
1696 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1697 }
1698
1699 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
1700 {
1701 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1702 }
1703
1704 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
1705 {
1706 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1707 }
1708
1709 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
1710 {
1711 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1712 }
1713
1714 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
1715 {
1716 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1717 }
1718
1719 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
1720 {
1721 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1722 }
1723
1724 Type *Byte::getType()
1725 {
Nicolas Capens6d738712016-09-30 04:15:22 -04001726 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001727 }
1728
1729 SByte::SByte(Argument<SByte> argument)
1730 {
1731 storeValue(argument.value);
1732 }
1733
1734 SByte::SByte(RValue<Int> cast)
1735 {
1736 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1737
1738 storeValue(integer);
1739 }
1740
1741 SByte::SByte(RValue<Short> cast)
1742 {
1743 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1744
1745 storeValue(integer);
1746 }
1747
Nicolas Capens598f8d82016-09-26 15:09:10 -04001748 SByte::SByte(signed char x)
1749 {
1750 storeValue(Nucleus::createConstantByte(x));
1751 }
1752
1753 SByte::SByte(RValue<SByte> rhs)
1754 {
1755 storeValue(rhs.value);
1756 }
1757
1758 SByte::SByte(const SByte &rhs)
1759 {
1760 Value *value = rhs.loadValue();
1761 storeValue(value);
1762 }
1763
1764 SByte::SByte(const Reference<SByte> &rhs)
1765 {
1766 Value *value = rhs.loadValue();
1767 storeValue(value);
1768 }
1769
Nicolas Capens96d4e092016-11-18 14:22:38 -05001770 RValue<SByte> SByte::operator=(RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001771 {
1772 storeValue(rhs.value);
1773
1774 return rhs;
1775 }
1776
Nicolas Capens96d4e092016-11-18 14:22:38 -05001777 RValue<SByte> SByte::operator=(const SByte &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001778 {
1779 Value *value = rhs.loadValue();
1780 storeValue(value);
1781
1782 return RValue<SByte>(value);
1783 }
1784
Nicolas Capens96d4e092016-11-18 14:22:38 -05001785 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001786 {
1787 Value *value = rhs.loadValue();
1788 storeValue(value);
1789
1790 return RValue<SByte>(value);
1791 }
1792
1793 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
1794 {
1795 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1796 }
1797
1798 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
1799 {
1800 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1801 }
1802
1803 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
1804 {
1805 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1806 }
1807
1808 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
1809 {
1810 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1811 }
1812
1813 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
1814 {
1815 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1816 }
1817
1818 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
1819 {
1820 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1821 }
1822
1823 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
1824 {
1825 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1826 }
1827
1828 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
1829 {
1830 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1831 }
1832
1833 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
1834 {
1835 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1836 }
1837
1838 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
1839 {
1840 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1841 }
1842
Nicolas Capens96d4e092016-11-18 14:22:38 -05001843 RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001844 {
1845 return lhs = lhs + rhs;
1846 }
1847
Nicolas Capens96d4e092016-11-18 14:22:38 -05001848 RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001849 {
1850 return lhs = lhs - rhs;
1851 }
1852
Nicolas Capens96d4e092016-11-18 14:22:38 -05001853 RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001854 {
1855 return lhs = lhs * rhs;
1856 }
1857
Nicolas Capens96d4e092016-11-18 14:22:38 -05001858 RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001859 {
1860 return lhs = lhs / rhs;
1861 }
1862
Nicolas Capens96d4e092016-11-18 14:22:38 -05001863 RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001864 {
1865 return lhs = lhs % rhs;
1866 }
1867
Nicolas Capens96d4e092016-11-18 14:22:38 -05001868 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001869 {
1870 return lhs = lhs & rhs;
1871 }
1872
Nicolas Capens96d4e092016-11-18 14:22:38 -05001873 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001874 {
1875 return lhs = lhs | rhs;
1876 }
1877
Nicolas Capens96d4e092016-11-18 14:22:38 -05001878 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001879 {
1880 return lhs = lhs ^ rhs;
1881 }
1882
Nicolas Capens96d4e092016-11-18 14:22:38 -05001883 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001884 {
1885 return lhs = lhs << rhs;
1886 }
1887
Nicolas Capens96d4e092016-11-18 14:22:38 -05001888 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001889 {
1890 return lhs = lhs >> rhs;
1891 }
1892
1893 RValue<SByte> operator+(RValue<SByte> val)
1894 {
1895 return val;
1896 }
1897
1898 RValue<SByte> operator-(RValue<SByte> val)
1899 {
1900 return RValue<SByte>(Nucleus::createNeg(val.value));
1901 }
1902
1903 RValue<SByte> operator~(RValue<SByte> val)
1904 {
1905 return RValue<SByte>(Nucleus::createNot(val.value));
1906 }
1907
Nicolas Capens96d4e092016-11-18 14:22:38 -05001908 RValue<SByte> operator++(SByte &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001909 {
1910 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001911 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001912 return res;
1913 }
1914
Nicolas Capens96d4e092016-11-18 14:22:38 -05001915 const SByte &operator++(SByte &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001916 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001917 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001918 return val;
1919 }
1920
Nicolas Capens96d4e092016-11-18 14:22:38 -05001921 RValue<SByte> operator--(SByte &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001922 {
1923 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001924 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001925 return res;
1926 }
1927
Nicolas Capens96d4e092016-11-18 14:22:38 -05001928 const SByte &operator--(SByte &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001929 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001930 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001931 return val;
1932 }
1933
1934 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
1935 {
1936 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1937 }
1938
1939 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
1940 {
1941 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1942 }
1943
1944 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
1945 {
1946 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1947 }
1948
1949 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
1950 {
1951 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1952 }
1953
1954 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
1955 {
1956 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1957 }
1958
1959 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
1960 {
1961 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1962 }
1963
1964 Type *SByte::getType()
1965 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001966 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001967 }
1968
1969 Short::Short(Argument<Short> argument)
1970 {
1971 storeValue(argument.value);
1972 }
1973
1974 Short::Short(RValue<Int> cast)
1975 {
1976 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1977
1978 storeValue(integer);
1979 }
1980
Nicolas Capens598f8d82016-09-26 15:09:10 -04001981 Short::Short(short x)
1982 {
1983 storeValue(Nucleus::createConstantShort(x));
1984 }
1985
1986 Short::Short(RValue<Short> rhs)
1987 {
1988 storeValue(rhs.value);
1989 }
1990
1991 Short::Short(const Short &rhs)
1992 {
1993 Value *value = rhs.loadValue();
1994 storeValue(value);
1995 }
1996
1997 Short::Short(const Reference<Short> &rhs)
1998 {
1999 Value *value = rhs.loadValue();
2000 storeValue(value);
2001 }
2002
Nicolas Capens96d4e092016-11-18 14:22:38 -05002003 RValue<Short> Short::operator=(RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002004 {
2005 storeValue(rhs.value);
2006
2007 return rhs;
2008 }
2009
Nicolas Capens96d4e092016-11-18 14:22:38 -05002010 RValue<Short> Short::operator=(const Short &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002011 {
2012 Value *value = rhs.loadValue();
2013 storeValue(value);
2014
2015 return RValue<Short>(value);
2016 }
2017
Nicolas Capens96d4e092016-11-18 14:22:38 -05002018 RValue<Short> Short::operator=(const Reference<Short> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002019 {
2020 Value *value = rhs.loadValue();
2021 storeValue(value);
2022
2023 return RValue<Short>(value);
2024 }
2025
2026 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
2027 {
2028 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
2029 }
2030
2031 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
2032 {
2033 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
2034 }
2035
2036 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
2037 {
2038 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
2039 }
2040
2041 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
2042 {
2043 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
2044 }
2045
2046 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
2047 {
2048 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
2049 }
2050
2051 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
2052 {
2053 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
2054 }
2055
2056 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
2057 {
2058 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
2059 }
2060
2061 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
2062 {
2063 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
2064 }
2065
2066 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
2067 {
2068 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
2069 }
2070
2071 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
2072 {
2073 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
2074 }
2075
Nicolas Capens96d4e092016-11-18 14:22:38 -05002076 RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002077 {
2078 return lhs = lhs + rhs;
2079 }
2080
Nicolas Capens96d4e092016-11-18 14:22:38 -05002081 RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002082 {
2083 return lhs = lhs - rhs;
2084 }
2085
Nicolas Capens96d4e092016-11-18 14:22:38 -05002086 RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002087 {
2088 return lhs = lhs * rhs;
2089 }
2090
Nicolas Capens96d4e092016-11-18 14:22:38 -05002091 RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002092 {
2093 return lhs = lhs / rhs;
2094 }
2095
Nicolas Capens96d4e092016-11-18 14:22:38 -05002096 RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002097 {
2098 return lhs = lhs % rhs;
2099 }
2100
Nicolas Capens96d4e092016-11-18 14:22:38 -05002101 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002102 {
2103 return lhs = lhs & rhs;
2104 }
2105
Nicolas Capens96d4e092016-11-18 14:22:38 -05002106 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002107 {
2108 return lhs = lhs | rhs;
2109 }
2110
Nicolas Capens96d4e092016-11-18 14:22:38 -05002111 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002112 {
2113 return lhs = lhs ^ rhs;
2114 }
2115
Nicolas Capens96d4e092016-11-18 14:22:38 -05002116 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002117 {
2118 return lhs = lhs << rhs;
2119 }
2120
Nicolas Capens96d4e092016-11-18 14:22:38 -05002121 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002122 {
2123 return lhs = lhs >> rhs;
2124 }
2125
2126 RValue<Short> operator+(RValue<Short> val)
2127 {
2128 return val;
2129 }
2130
2131 RValue<Short> operator-(RValue<Short> val)
2132 {
2133 return RValue<Short>(Nucleus::createNeg(val.value));
2134 }
2135
2136 RValue<Short> operator~(RValue<Short> val)
2137 {
2138 return RValue<Short>(Nucleus::createNot(val.value));
2139 }
2140
Nicolas Capens96d4e092016-11-18 14:22:38 -05002141 RValue<Short> operator++(Short &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002142 {
2143 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002144 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002145 return res;
2146 }
2147
Nicolas Capens96d4e092016-11-18 14:22:38 -05002148 const Short &operator++(Short &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002149 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002150 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002151 return val;
2152 }
2153
Nicolas Capens96d4e092016-11-18 14:22:38 -05002154 RValue<Short> operator--(Short &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002155 {
2156 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002157 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002158 return res;
2159 }
2160
Nicolas Capens96d4e092016-11-18 14:22:38 -05002161 const Short &operator--(Short &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002162 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002163 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002164 return val;
2165 }
2166
2167 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
2168 {
2169 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2170 }
2171
2172 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
2173 {
2174 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2175 }
2176
2177 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
2178 {
2179 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2180 }
2181
2182 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
2183 {
2184 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2185 }
2186
2187 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
2188 {
2189 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2190 }
2191
2192 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
2193 {
2194 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2195 }
2196
2197 Type *Short::getType()
2198 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002199 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002200 }
2201
2202 UShort::UShort(Argument<UShort> argument)
2203 {
2204 storeValue(argument.value);
2205 }
2206
2207 UShort::UShort(RValue<UInt> cast)
2208 {
2209 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2210
2211 storeValue(integer);
2212 }
2213
2214 UShort::UShort(RValue<Int> cast)
2215 {
2216 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2217
2218 storeValue(integer);
2219 }
2220
Nicolas Capens598f8d82016-09-26 15:09:10 -04002221 UShort::UShort(unsigned short x)
2222 {
2223 storeValue(Nucleus::createConstantShort(x));
2224 }
2225
2226 UShort::UShort(RValue<UShort> rhs)
2227 {
2228 storeValue(rhs.value);
2229 }
2230
2231 UShort::UShort(const UShort &rhs)
2232 {
2233 Value *value = rhs.loadValue();
2234 storeValue(value);
2235 }
2236
2237 UShort::UShort(const Reference<UShort> &rhs)
2238 {
2239 Value *value = rhs.loadValue();
2240 storeValue(value);
2241 }
2242
Nicolas Capens96d4e092016-11-18 14:22:38 -05002243 RValue<UShort> UShort::operator=(RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002244 {
2245 storeValue(rhs.value);
2246
2247 return rhs;
2248 }
2249
Nicolas Capens96d4e092016-11-18 14:22:38 -05002250 RValue<UShort> UShort::operator=(const UShort &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002251 {
2252 Value *value = rhs.loadValue();
2253 storeValue(value);
2254
2255 return RValue<UShort>(value);
2256 }
2257
Nicolas Capens96d4e092016-11-18 14:22:38 -05002258 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002259 {
2260 Value *value = rhs.loadValue();
2261 storeValue(value);
2262
2263 return RValue<UShort>(value);
2264 }
2265
2266 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
2267 {
2268 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
2269 }
2270
2271 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
2272 {
2273 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
2274 }
2275
2276 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
2277 {
2278 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
2279 }
2280
2281 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
2282 {
2283 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
2284 }
2285
2286 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
2287 {
2288 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
2289 }
2290
2291 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
2292 {
2293 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
2294 }
2295
2296 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
2297 {
2298 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
2299 }
2300
2301 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
2302 {
2303 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
2304 }
2305
2306 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
2307 {
2308 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
2309 }
2310
2311 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
2312 {
2313 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
2314 }
2315
Nicolas Capens96d4e092016-11-18 14:22:38 -05002316 RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002317 {
2318 return lhs = lhs + rhs;
2319 }
2320
Nicolas Capens96d4e092016-11-18 14:22:38 -05002321 RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002322 {
2323 return lhs = lhs - rhs;
2324 }
2325
Nicolas Capens96d4e092016-11-18 14:22:38 -05002326 RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002327 {
2328 return lhs = lhs * rhs;
2329 }
2330
Nicolas Capens96d4e092016-11-18 14:22:38 -05002331 RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002332 {
2333 return lhs = lhs / rhs;
2334 }
2335
Nicolas Capens96d4e092016-11-18 14:22:38 -05002336 RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002337 {
2338 return lhs = lhs % rhs;
2339 }
2340
Nicolas Capens96d4e092016-11-18 14:22:38 -05002341 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002342 {
2343 return lhs = lhs & rhs;
2344 }
2345
Nicolas Capens96d4e092016-11-18 14:22:38 -05002346 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002347 {
2348 return lhs = lhs | rhs;
2349 }
2350
Nicolas Capens96d4e092016-11-18 14:22:38 -05002351 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002352 {
2353 return lhs = lhs ^ rhs;
2354 }
2355
Nicolas Capens96d4e092016-11-18 14:22:38 -05002356 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002357 {
2358 return lhs = lhs << rhs;
2359 }
2360
Nicolas Capens96d4e092016-11-18 14:22:38 -05002361 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002362 {
2363 return lhs = lhs >> rhs;
2364 }
2365
2366 RValue<UShort> operator+(RValue<UShort> val)
2367 {
2368 return val;
2369 }
2370
2371 RValue<UShort> operator-(RValue<UShort> val)
2372 {
2373 return RValue<UShort>(Nucleus::createNeg(val.value));
2374 }
2375
2376 RValue<UShort> operator~(RValue<UShort> val)
2377 {
2378 return RValue<UShort>(Nucleus::createNot(val.value));
2379 }
2380
Nicolas Capens96d4e092016-11-18 14:22:38 -05002381 RValue<UShort> operator++(UShort &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002382 {
2383 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002384 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002385 return res;
2386 }
2387
Nicolas Capens96d4e092016-11-18 14:22:38 -05002388 const UShort &operator++(UShort &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002389 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002390 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002391 return val;
2392 }
2393
Nicolas Capens96d4e092016-11-18 14:22:38 -05002394 RValue<UShort> operator--(UShort &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002395 {
2396 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002397 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002398 return res;
2399 }
2400
Nicolas Capens96d4e092016-11-18 14:22:38 -05002401 const UShort &operator--(UShort &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002402 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002403 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002404 return val;
2405 }
2406
2407 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
2408 {
2409 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2410 }
2411
2412 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
2413 {
2414 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2415 }
2416
2417 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
2418 {
2419 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2420 }
2421
2422 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
2423 {
2424 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2425 }
2426
2427 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
2428 {
2429 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2430 }
2431
2432 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
2433 {
2434 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2435 }
2436
2437 Type *UShort::getType()
2438 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002439 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002440 }
2441
Nicolas Capens16b5f152016-10-13 13:39:01 -04002442 Byte4::Byte4(RValue<Byte8> cast)
2443 {
Nicolas Capens16b5f152016-10-13 13:39:01 -04002444 storeValue(Nucleus::createBitCast(cast.value, getType()));
2445 }
2446
2447 Byte4::Byte4(const Reference<Byte4> &rhs)
2448 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002449 Value *value = rhs.loadValue();
2450 storeValue(value);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002451 }
2452
Nicolas Capens598f8d82016-09-26 15:09:10 -04002453 Type *Byte4::getType()
2454 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002455 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002456 }
2457
2458 Type *SByte4::getType()
2459 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002460 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002461 }
2462
Nicolas Capens598f8d82016-09-26 15:09:10 -04002463 Byte8::Byte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
2464 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002465 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
2466 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002467 }
2468
2469 Byte8::Byte8(RValue<Byte8> rhs)
2470 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002471 storeValue(rhs.value);
2472 }
2473
2474 Byte8::Byte8(const Byte8 &rhs)
2475 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002476 Value *value = rhs.loadValue();
2477 storeValue(value);
2478 }
2479
2480 Byte8::Byte8(const Reference<Byte8> &rhs)
2481 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002482 Value *value = rhs.loadValue();
2483 storeValue(value);
2484 }
2485
Nicolas Capens96d4e092016-11-18 14:22:38 -05002486 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002487 {
2488 storeValue(rhs.value);
2489
2490 return rhs;
2491 }
2492
Nicolas Capens96d4e092016-11-18 14:22:38 -05002493 RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002494 {
2495 Value *value = rhs.loadValue();
2496 storeValue(value);
2497
2498 return RValue<Byte8>(value);
2499 }
2500
Nicolas Capens96d4e092016-11-18 14:22:38 -05002501 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002502 {
2503 Value *value = rhs.loadValue();
2504 storeValue(value);
2505
2506 return RValue<Byte8>(value);
2507 }
2508
2509 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
2510 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002511 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002512 }
2513
2514 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
2515 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002516 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002517 }
2518
2519// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2520// {
2521// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2522// }
2523
2524// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2525// {
2526// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2527// }
2528
2529// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2530// {
2531// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2532// }
2533
2534 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
2535 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002536 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002537 }
2538
2539 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
2540 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002541 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002542 }
2543
2544 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
2545 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002546 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002547 }
2548
2549// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
2550// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002551// return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002552// }
2553
2554// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
2555// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002556// return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002557// }
2558
Nicolas Capens96d4e092016-11-18 14:22:38 -05002559 RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002560 {
2561 return lhs = lhs + rhs;
2562 }
2563
Nicolas Capens96d4e092016-11-18 14:22:38 -05002564 RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002565 {
2566 return lhs = lhs - rhs;
2567 }
2568
Nicolas Capens96d4e092016-11-18 14:22:38 -05002569// RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002570// {
2571// return lhs = lhs * rhs;
2572// }
2573
Nicolas Capens96d4e092016-11-18 14:22:38 -05002574// RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002575// {
2576// return lhs = lhs / rhs;
2577// }
2578
Nicolas Capens96d4e092016-11-18 14:22:38 -05002579// RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002580// {
2581// return lhs = lhs % rhs;
2582// }
2583
Nicolas Capens96d4e092016-11-18 14:22:38 -05002584 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002585 {
2586 return lhs = lhs & rhs;
2587 }
2588
Nicolas Capens96d4e092016-11-18 14:22:38 -05002589 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002590 {
2591 return lhs = lhs | rhs;
2592 }
2593
Nicolas Capens96d4e092016-11-18 14:22:38 -05002594 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002595 {
2596 return lhs = lhs ^ rhs;
2597 }
2598
Nicolas Capens96d4e092016-11-18 14:22:38 -05002599// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002600// {
2601// return lhs = lhs << rhs;
2602// }
2603
Nicolas Capens96d4e092016-11-18 14:22:38 -05002604// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002605// {
2606// return lhs = lhs >> rhs;
2607// }
2608
2609// RValue<Byte8> operator+(RValue<Byte8> val)
2610// {
2611// return val;
2612// }
2613
2614// RValue<Byte8> operator-(RValue<Byte8> val)
2615// {
2616// return RValue<Byte8>(Nucleus::createNeg(val.value));
2617// }
2618
2619 RValue<Byte8> operator~(RValue<Byte8> val)
2620 {
2621 return RValue<Byte8>(Nucleus::createNot(val.value));
2622 }
2623
2624 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
2625 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002626 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2627 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2628 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2629 auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2630 paddusb->addArg(x.value);
2631 paddusb->addArg(y.value);
2632 ::basicBlock->appendInst(paddusb);
2633
2634 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002635 }
2636
2637 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
2638 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002639 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2640 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2641 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2642 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2643 psubusw->addArg(x.value);
2644 psubusw->addArg(y.value);
2645 ::basicBlock->appendInst(psubusw);
2646
2647 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002648 }
2649
2650 RValue<Short4> Unpack(RValue<Byte4> x)
2651 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002652 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2653 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002654 }
2655
Nicolas Capens411273e2017-01-26 15:13:36 -08002656 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
2657 {
2658 return UnpackLow(As<Byte8>(x), As<Byte8>(y));
2659 }
2660
Nicolas Capens598f8d82016-09-26 15:09:10 -04002661 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2662 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002663 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2664 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002665 }
2666
2667 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
2668 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002669 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2670 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2671 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002672 }
2673
2674 RValue<Int> SignMask(RValue<Byte8> x)
2675 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002676 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2677 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2678 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2679 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2680 movmsk->addArg(x.value);
2681 ::basicBlock->appendInst(movmsk);
2682
2683 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002684 }
2685
2686// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
2687// {
Nicolas Capens2f970b62016-11-08 14:28:59 -05002688// return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002689// }
2690
2691 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
2692 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05002693 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002694 }
2695
2696 Type *Byte8::getType()
2697 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002698 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002699 }
2700
Nicolas Capens598f8d82016-09-26 15:09:10 -04002701 SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
2702 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002703 int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
2704 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
2705
2706 storeValue(Nucleus::createBitCast(vector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002707 }
2708
Nicolas Capens598f8d82016-09-26 15:09:10 -04002709 SByte8::SByte8(RValue<SByte8> rhs)
2710 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002711 storeValue(rhs.value);
2712 }
2713
2714 SByte8::SByte8(const SByte8 &rhs)
2715 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002716 Value *value = rhs.loadValue();
2717 storeValue(value);
2718 }
2719
2720 SByte8::SByte8(const Reference<SByte8> &rhs)
2721 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002722 Value *value = rhs.loadValue();
2723 storeValue(value);
2724 }
2725
Nicolas Capens96d4e092016-11-18 14:22:38 -05002726 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002727 {
2728 storeValue(rhs.value);
2729
2730 return rhs;
2731 }
2732
Nicolas Capens96d4e092016-11-18 14:22:38 -05002733 RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002734 {
2735 Value *value = rhs.loadValue();
2736 storeValue(value);
2737
2738 return RValue<SByte8>(value);
2739 }
2740
Nicolas Capens96d4e092016-11-18 14:22:38 -05002741 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002742 {
2743 Value *value = rhs.loadValue();
2744 storeValue(value);
2745
2746 return RValue<SByte8>(value);
2747 }
2748
2749 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
2750 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002751 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002752 }
2753
2754 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
2755 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002756 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002757 }
2758
2759// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2760// {
2761// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2762// }
2763
2764// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2765// {
2766// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2767// }
2768
2769// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2770// {
2771// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2772// }
2773
2774 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
2775 {
2776 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2777 }
2778
2779 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
2780 {
2781 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2782 }
2783
2784 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
2785 {
2786 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2787 }
2788
2789// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
2790// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002791// return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002792// }
2793
2794// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
2795// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002796// return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002797// }
2798
Nicolas Capens96d4e092016-11-18 14:22:38 -05002799 RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002800 {
2801 return lhs = lhs + rhs;
2802 }
2803
Nicolas Capens96d4e092016-11-18 14:22:38 -05002804 RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002805 {
2806 return lhs = lhs - rhs;
2807 }
2808
Nicolas Capens96d4e092016-11-18 14:22:38 -05002809// RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002810// {
2811// return lhs = lhs * rhs;
2812// }
2813
Nicolas Capens96d4e092016-11-18 14:22:38 -05002814// RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002815// {
2816// return lhs = lhs / rhs;
2817// }
2818
Nicolas Capens96d4e092016-11-18 14:22:38 -05002819// RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002820// {
2821// return lhs = lhs % rhs;
2822// }
2823
Nicolas Capens96d4e092016-11-18 14:22:38 -05002824 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002825 {
2826 return lhs = lhs & rhs;
2827 }
2828
Nicolas Capens96d4e092016-11-18 14:22:38 -05002829 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002830 {
2831 return lhs = lhs | rhs;
2832 }
2833
Nicolas Capens96d4e092016-11-18 14:22:38 -05002834 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002835 {
2836 return lhs = lhs ^ rhs;
2837 }
2838
Nicolas Capens96d4e092016-11-18 14:22:38 -05002839// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002840// {
2841// return lhs = lhs << rhs;
2842// }
2843
Nicolas Capens96d4e092016-11-18 14:22:38 -05002844// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002845// {
2846// return lhs = lhs >> rhs;
2847// }
2848
2849// RValue<SByte8> operator+(RValue<SByte8> val)
2850// {
2851// return val;
2852// }
2853
2854// RValue<SByte8> operator-(RValue<SByte8> val)
2855// {
2856// return RValue<SByte8>(Nucleus::createNeg(val.value));
2857// }
2858
2859 RValue<SByte8> operator~(RValue<SByte8> val)
2860 {
2861 return RValue<SByte8>(Nucleus::createNot(val.value));
2862 }
2863
2864 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
2865 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002866 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2867 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2868 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2869 auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2870 paddsb->addArg(x.value);
2871 paddsb->addArg(y.value);
2872 ::basicBlock->appendInst(paddsb);
2873
2874 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002875 }
2876
2877 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
2878 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002879 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2880 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2881 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2882 auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2883 psubsb->addArg(x.value);
2884 psubsb->addArg(y.value);
2885 ::basicBlock->appendInst(psubsb);
2886
2887 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002888 }
2889
2890 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
2891 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002892 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2893 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002894 }
2895
2896 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
2897 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002898 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2899 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2900 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002901 }
2902
2903 RValue<Int> SignMask(RValue<SByte8> x)
2904 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04002905 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2906 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2907 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2908 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2909 movmsk->addArg(x.value);
2910 ::basicBlock->appendInst(movmsk);
2911
2912 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002913 }
2914
2915 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
2916 {
Nicolas Capens2f970b62016-11-08 14:28:59 -05002917 return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002918 }
2919
2920 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
2921 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05002922 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002923 }
2924
2925 Type *SByte8::getType()
2926 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002927 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002928 }
2929
2930 Byte16::Byte16(RValue<Byte16> rhs)
2931 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002932 storeValue(rhs.value);
2933 }
2934
2935 Byte16::Byte16(const Byte16 &rhs)
2936 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002937 Value *value = rhs.loadValue();
2938 storeValue(value);
2939 }
2940
2941 Byte16::Byte16(const Reference<Byte16> &rhs)
2942 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002943 Value *value = rhs.loadValue();
2944 storeValue(value);
2945 }
2946
Nicolas Capens96d4e092016-11-18 14:22:38 -05002947 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002948 {
2949 storeValue(rhs.value);
2950
2951 return rhs;
2952 }
2953
Nicolas Capens96d4e092016-11-18 14:22:38 -05002954 RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002955 {
2956 Value *value = rhs.loadValue();
2957 storeValue(value);
2958
2959 return RValue<Byte16>(value);
2960 }
2961
Nicolas Capens96d4e092016-11-18 14:22:38 -05002962 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002963 {
2964 Value *value = rhs.loadValue();
2965 storeValue(value);
2966
2967 return RValue<Byte16>(value);
2968 }
2969
2970 Type *Byte16::getType()
2971 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002972 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002973 }
2974
2975 Type *SByte16::getType()
2976 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002977 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002978 }
2979
Nicolas Capens16b5f152016-10-13 13:39:01 -04002980 Short2::Short2(RValue<Short4> cast)
2981 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05002982 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002983 }
2984
2985 Type *Short2::getType()
2986 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002987 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002988 }
2989
2990 UShort2::UShort2(RValue<UShort4> cast)
2991 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05002992 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002993 }
2994
2995 Type *UShort2::getType()
2996 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002997 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002998 }
2999
Nicolas Capens598f8d82016-09-26 15:09:10 -04003000 Short4::Short4(RValue<Int> cast)
3001 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003002 Value *vector = loadValue();
Nicolas Capensbf22bbf2017-01-13 17:37:45 -05003003 Value *element = Nucleus::createTrunc(cast.value, Short::getType());
3004 Value *insert = Nucleus::createInsertElement(vector, element, 0);
Nicolas Capensd4227962016-11-09 14:24:25 -05003005 Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003006
3007 storeValue(swizzle);
3008 }
3009
3010 Short4::Short4(RValue<Int4> cast)
3011 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08003012 int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
3013 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
3014 Value *packed = Nucleus::createShuffleVector(short8, short8, select);
Nicolas Capensd4227962016-11-09 14:24:25 -05003015
3016 Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
3017 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
3018
3019 storeValue(short4);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003020 }
3021
3022// Short4::Short4(RValue<Float> cast)
3023// {
3024// }
3025
3026 Short4::Short4(RValue<Float4> cast)
3027 {
3028 assert(false && "UNIMPLEMENTED");
3029 }
3030
Nicolas Capens598f8d82016-09-26 15:09:10 -04003031 Short4::Short4(short xyzw)
3032 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003033 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3034 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003035 }
3036
3037 Short4::Short4(short x, short y, short z, short w)
3038 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003039 int64_t constantVector[4] = {x, y, z, w};
3040 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003041 }
3042
3043 Short4::Short4(RValue<Short4> rhs)
3044 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003045 storeValue(rhs.value);
3046 }
3047
3048 Short4::Short4(const Short4 &rhs)
3049 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003050 Value *value = rhs.loadValue();
3051 storeValue(value);
3052 }
3053
3054 Short4::Short4(const Reference<Short4> &rhs)
3055 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003056 Value *value = rhs.loadValue();
3057 storeValue(value);
3058 }
3059
3060 Short4::Short4(RValue<UShort4> rhs)
3061 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003062 storeValue(rhs.value);
3063 }
3064
3065 Short4::Short4(const UShort4 &rhs)
3066 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003067 storeValue(rhs.loadValue());
3068 }
3069
3070 Short4::Short4(const Reference<UShort4> &rhs)
3071 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003072 storeValue(rhs.loadValue());
3073 }
3074
Nicolas Capens96d4e092016-11-18 14:22:38 -05003075 RValue<Short4> Short4::operator=(RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003076 {
3077 storeValue(rhs.value);
3078
3079 return rhs;
3080 }
3081
Nicolas Capens96d4e092016-11-18 14:22:38 -05003082 RValue<Short4> Short4::operator=(const Short4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003083 {
3084 Value *value = rhs.loadValue();
3085 storeValue(value);
3086
3087 return RValue<Short4>(value);
3088 }
3089
Nicolas Capens96d4e092016-11-18 14:22:38 -05003090 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003091 {
3092 Value *value = rhs.loadValue();
3093 storeValue(value);
3094
3095 return RValue<Short4>(value);
3096 }
3097
Nicolas Capens96d4e092016-11-18 14:22:38 -05003098 RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003099 {
3100 storeValue(rhs.value);
3101
3102 return RValue<Short4>(rhs);
3103 }
3104
Nicolas Capens96d4e092016-11-18 14:22:38 -05003105 RValue<Short4> Short4::operator=(const UShort4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003106 {
3107 Value *value = rhs.loadValue();
3108 storeValue(value);
3109
3110 return RValue<Short4>(value);
3111 }
3112
Nicolas Capens96d4e092016-11-18 14:22:38 -05003113 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003114 {
3115 Value *value = rhs.loadValue();
3116 storeValue(value);
3117
3118 return RValue<Short4>(value);
3119 }
3120
3121 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
3122 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003123 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003124 }
3125
3126 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
3127 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003128 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003129 }
3130
3131 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
3132 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003133 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003134 }
3135
3136// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
3137// {
3138// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
3139// }
3140
3141// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
3142// {
3143// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
3144// }
3145
3146 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
3147 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003148 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003149 }
3150
3151 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
3152 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003153 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003154 }
3155
3156 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
3157 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003158 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003159 }
3160
3161 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
3162 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003163 return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003164 }
3165
3166 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
3167 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003168 return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003169 }
3170
Nicolas Capens96d4e092016-11-18 14:22:38 -05003171 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003172 {
3173 return lhs = lhs + rhs;
3174 }
3175
Nicolas Capens96d4e092016-11-18 14:22:38 -05003176 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003177 {
3178 return lhs = lhs - rhs;
3179 }
3180
Nicolas Capens96d4e092016-11-18 14:22:38 -05003181 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003182 {
3183 return lhs = lhs * rhs;
3184 }
3185
Nicolas Capens96d4e092016-11-18 14:22:38 -05003186// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003187// {
3188// return lhs = lhs / rhs;
3189// }
3190
Nicolas Capens96d4e092016-11-18 14:22:38 -05003191// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003192// {
3193// return lhs = lhs % rhs;
3194// }
3195
Nicolas Capens96d4e092016-11-18 14:22:38 -05003196 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003197 {
3198 return lhs = lhs & rhs;
3199 }
3200
Nicolas Capens96d4e092016-11-18 14:22:38 -05003201 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003202 {
3203 return lhs = lhs | rhs;
3204 }
3205
Nicolas Capens96d4e092016-11-18 14:22:38 -05003206 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003207 {
3208 return lhs = lhs ^ rhs;
3209 }
3210
Nicolas Capens96d4e092016-11-18 14:22:38 -05003211 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003212 {
3213 return lhs = lhs << rhs;
3214 }
3215
Nicolas Capens96d4e092016-11-18 14:22:38 -05003216 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003217 {
3218 return lhs = lhs >> rhs;
3219 }
3220
Nicolas Capens598f8d82016-09-26 15:09:10 -04003221// RValue<Short4> operator+(RValue<Short4> val)
3222// {
3223// return val;
3224// }
3225
3226 RValue<Short4> operator-(RValue<Short4> val)
3227 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003228 return RValue<Short4>(Nucleus::createNeg(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003229 }
3230
3231 RValue<Short4> operator~(RValue<Short4> val)
3232 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003233 return RValue<Short4>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003234 }
3235
3236 RValue<Short4> RoundShort4(RValue<Float4> cast)
3237 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003238 RValue<Int4> int4 = RoundInt(cast);
3239 return As<Short4>(Pack(int4, int4));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003240 }
3241
3242 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
3243 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003244 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3245 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
3246 ::basicBlock->appendInst(cmp);
3247
3248 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3249 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3250 ::basicBlock->appendInst(select);
3251
3252 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003253 }
3254
3255 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
3256 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003257 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3258 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
3259 ::basicBlock->appendInst(cmp);
3260
3261 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3262 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3263 ::basicBlock->appendInst(select);
3264
3265 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003266 }
3267
3268 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
3269 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003270 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3271 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3272 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3273 auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3274 paddsw->addArg(x.value);
3275 paddsw->addArg(y.value);
3276 ::basicBlock->appendInst(paddsw);
3277
3278 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003279 }
3280
3281 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
3282 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003283 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3284 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3285 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3286 auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3287 psubsw->addArg(x.value);
3288 psubsw->addArg(y.value);
3289 ::basicBlock->appendInst(psubsw);
3290
3291 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003292 }
3293
3294 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
3295 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003296 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3297 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3298 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3299 auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3300 pmulhw->addArg(x.value);
3301 pmulhw->addArg(y.value);
3302 ::basicBlock->appendInst(pmulhw);
3303
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003304 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003305 }
3306
3307 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
3308 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003309 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3310 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3311 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3312 auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3313 pmaddwd->addArg(x.value);
3314 pmaddwd->addArg(y.value);
3315 ::basicBlock->appendInst(pmaddwd);
3316
3317 return RValue<Int2>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003318 }
3319
3320 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
3321 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003322 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3323 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3324 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3325 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3326 pack->addArg(x.value);
3327 pack->addArg(y.value);
3328 ::basicBlock->appendInst(pack);
3329
Nicolas Capens70dfff42016-10-27 10:20:28 -04003330 return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003331 }
3332
3333 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
3334 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003335 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3336 return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003337 }
3338
3339 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
3340 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04003341 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3342 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3343 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003344 }
3345
3346 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
3347 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003348 // Real type is v8i16
3349 int shuffle[8] =
3350 {
3351 (select >> 0) & 0x03,
3352 (select >> 2) & 0x03,
3353 (select >> 4) & 0x03,
3354 (select >> 6) & 0x03,
3355 (select >> 0) & 0x03,
3356 (select >> 2) & 0x03,
3357 (select >> 4) & 0x03,
3358 (select >> 6) & 0x03,
3359 };
3360
3361 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003362 }
3363
3364 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
3365 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05003366 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003367 }
3368
3369 RValue<Short> Extract(RValue<Short4> val, int i)
3370 {
Nicolas Capens0133d0f2017-01-16 16:25:08 -05003371 return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003372 }
3373
3374 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
3375 {
Nicolas Capens2f970b62016-11-08 14:28:59 -05003376 return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003377 }
3378
3379 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
3380 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05003381 return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003382 }
3383
3384 Type *Short4::getType()
3385 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003386 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003387 }
3388
3389 UShort4::UShort4(RValue<Int4> cast)
3390 {
3391 *this = Short4(cast);
3392 }
3393
3394 UShort4::UShort4(RValue<Float4> cast, bool saturate)
3395 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003396 if(saturate)
3397 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05003398 if(CPUID::SSE4_1)
Nicolas Capensd4227962016-11-09 14:24:25 -05003399 {
3400 Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
3401 *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4)));
3402 }
3403 else
3404 {
3405 *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
3406 }
3407 }
3408 else
3409 {
3410 *this = Short4(Int4(cast));
3411 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04003412 }
3413
Nicolas Capens598f8d82016-09-26 15:09:10 -04003414 UShort4::UShort4(unsigned short xyzw)
3415 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003416 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3417 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003418 }
3419
3420 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3421 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003422 int64_t constantVector[4] = {x, y, z, w};
3423 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003424 }
3425
3426 UShort4::UShort4(RValue<UShort4> rhs)
3427 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003428 storeValue(rhs.value);
3429 }
3430
3431 UShort4::UShort4(const UShort4 &rhs)
3432 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003433 Value *value = rhs.loadValue();
3434 storeValue(value);
3435 }
3436
3437 UShort4::UShort4(const Reference<UShort4> &rhs)
3438 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003439 Value *value = rhs.loadValue();
3440 storeValue(value);
3441 }
3442
3443 UShort4::UShort4(RValue<Short4> rhs)
3444 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003445 storeValue(rhs.value);
3446 }
3447
3448 UShort4::UShort4(const Short4 &rhs)
3449 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003450 Value *value = rhs.loadValue();
3451 storeValue(value);
3452 }
3453
3454 UShort4::UShort4(const Reference<Short4> &rhs)
3455 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003456 Value *value = rhs.loadValue();
3457 storeValue(value);
3458 }
3459
Nicolas Capens96d4e092016-11-18 14:22:38 -05003460 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003461 {
3462 storeValue(rhs.value);
3463
3464 return rhs;
3465 }
3466
Nicolas Capens96d4e092016-11-18 14:22:38 -05003467 RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003468 {
3469 Value *value = rhs.loadValue();
3470 storeValue(value);
3471
3472 return RValue<UShort4>(value);
3473 }
3474
Nicolas Capens96d4e092016-11-18 14:22:38 -05003475 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003476 {
3477 Value *value = rhs.loadValue();
3478 storeValue(value);
3479
3480 return RValue<UShort4>(value);
3481 }
3482
Nicolas Capens96d4e092016-11-18 14:22:38 -05003483 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003484 {
3485 storeValue(rhs.value);
3486
3487 return RValue<UShort4>(rhs);
3488 }
3489
Nicolas Capens96d4e092016-11-18 14:22:38 -05003490 RValue<UShort4> UShort4::operator=(const Short4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003491 {
3492 Value *value = rhs.loadValue();
3493 storeValue(value);
3494
3495 return RValue<UShort4>(value);
3496 }
3497
Nicolas Capens96d4e092016-11-18 14:22:38 -05003498 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003499 {
3500 Value *value = rhs.loadValue();
3501 storeValue(value);
3502
3503 return RValue<UShort4>(value);
3504 }
3505
3506 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
3507 {
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003508 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003509 }
3510
3511 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
3512 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003513 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003514 }
3515
3516 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
3517 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003518 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003519 }
3520
Nicolas Capens16b5f152016-10-13 13:39:01 -04003521 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3522 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003523 return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003524 }
3525
3526 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
3527 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003528 return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003529 }
3530
3531 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3532 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003533 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003534 }
3535
Nicolas Capens598f8d82016-09-26 15:09:10 -04003536 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
3537 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003538 return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003539 }
3540
3541 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
3542 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003543 return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003544 }
3545
Nicolas Capens96d4e092016-11-18 14:22:38 -05003546 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003547 {
3548 return lhs = lhs << rhs;
3549 }
3550
Nicolas Capens96d4e092016-11-18 14:22:38 -05003551 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003552 {
3553 return lhs = lhs >> rhs;
3554 }
3555
Nicolas Capens598f8d82016-09-26 15:09:10 -04003556 RValue<UShort4> operator~(RValue<UShort4> val)
3557 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003558 return RValue<UShort4>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003559 }
3560
3561 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
3562 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003563 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3564 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
3565 ::basicBlock->appendInst(cmp);
3566
3567 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3568 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3569 ::basicBlock->appendInst(select);
3570
3571 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003572 }
3573
3574 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
3575 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003576 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3577 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
3578 ::basicBlock->appendInst(cmp);
3579
3580 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3581 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3582 ::basicBlock->appendInst(select);
3583
3584 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003585 }
3586
3587 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
3588 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003589 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3590 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3591 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3592 auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3593 paddusw->addArg(x.value);
3594 paddusw->addArg(y.value);
3595 ::basicBlock->appendInst(paddusw);
3596
3597 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003598 }
3599
3600 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
3601 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003602 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3603 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3604 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3605 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3606 psubusw->addArg(x.value);
3607 psubusw->addArg(y.value);
3608 ::basicBlock->appendInst(psubusw);
3609
3610 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003611 }
3612
3613 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
3614 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003615 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3616 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3617 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3618 auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3619 pmulhuw->addArg(x.value);
3620 pmulhuw->addArg(y.value);
3621 ::basicBlock->appendInst(pmulhuw);
3622
3623 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003624 }
3625
3626 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
3627 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003628 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003629 }
3630
3631 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
3632 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003633 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3634 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3635 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3636 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3637 pack->addArg(x.value);
3638 pack->addArg(y.value);
3639 ::basicBlock->appendInst(pack);
3640
Nicolas Capens70dfff42016-10-27 10:20:28 -04003641 return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003642 }
3643
3644 Type *UShort4::getType()
3645 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003646 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003647 }
3648
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003649 Short8::Short8(short c)
3650 {
3651 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3652 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3653 }
3654
Nicolas Capens598f8d82016-09-26 15:09:10 -04003655 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3656 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003657 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3658 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003659 }
3660
3661 Short8::Short8(RValue<Short8> rhs)
3662 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003663 storeValue(rhs.value);
3664 }
3665
3666 Short8::Short8(const Reference<Short8> &rhs)
3667 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003668 Value *value = rhs.loadValue();
3669 storeValue(value);
3670 }
3671
3672 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3673 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05003674 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3675 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3676
3677 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003678 }
3679
3680 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
3681 {
3682 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3683 }
3684
3685 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
3686 {
3687 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3688 }
3689
3690 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
3691 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003692 return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003693 }
3694
3695 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
3696 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003697 return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003698 }
3699
3700 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
3701 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003702 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003703 }
3704
3705 RValue<Int4> Abs(RValue<Int4> x)
3706 {
Nicolas Capens84272242016-11-09 13:31:06 -05003707 auto negative = x >> 31;
3708 return (x ^ negative) - negative;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003709 }
3710
3711 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
3712 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003713 assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003714 }
3715
3716 Type *Short8::getType()
3717 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003718 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003719 }
3720
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003721 UShort8::UShort8(unsigned short c)
3722 {
3723 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3724 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3725 }
3726
Nicolas Capens598f8d82016-09-26 15:09:10 -04003727 UShort8::UShort8(unsigned short c0, unsigned short c1, unsigned short c2, unsigned short c3, unsigned short c4, unsigned short c5, unsigned short c6, unsigned short c7)
3728 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003729 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3730 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003731 }
3732
3733 UShort8::UShort8(RValue<UShort8> rhs)
3734 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003735 storeValue(rhs.value);
3736 }
3737
3738 UShort8::UShort8(const Reference<UShort8> &rhs)
3739 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003740 Value *value = rhs.loadValue();
3741 storeValue(value);
3742 }
3743
3744 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3745 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05003746 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3747 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3748
3749 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003750 }
3751
Nicolas Capens96d4e092016-11-18 14:22:38 -05003752 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003753 {
3754 storeValue(rhs.value);
3755
3756 return rhs;
3757 }
3758
Nicolas Capens96d4e092016-11-18 14:22:38 -05003759 RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003760 {
3761 Value *value = rhs.loadValue();
3762 storeValue(value);
3763
3764 return RValue<UShort8>(value);
3765 }
3766
Nicolas Capens96d4e092016-11-18 14:22:38 -05003767 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003768 {
3769 Value *value = rhs.loadValue();
3770 storeValue(value);
3771
3772 return RValue<UShort8>(value);
3773 }
3774
3775 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
3776 {
3777 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3778 }
3779
3780 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
3781 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003782 return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003783 }
3784
3785 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
3786 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003787 return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003788 }
3789
3790 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
3791 {
3792 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3793 }
3794
3795 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
3796 {
3797 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3798 }
3799
Nicolas Capens96d4e092016-11-18 14:22:38 -05003800 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003801 {
3802 return lhs = lhs + rhs;
3803 }
3804
3805 RValue<UShort8> operator~(RValue<UShort8> val)
3806 {
3807 return RValue<UShort8>(Nucleus::createNot(val.value));
3808 }
3809
3810 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
3811 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003812 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003813 }
3814
3815 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
3816 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003817 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003818 }
3819
3820 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
3821// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
3822// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003823// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003824// }
3825
3826 Type *UShort8::getType()
3827 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003828 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003829 }
3830
3831 Int::Int(Argument<Int> argument)
3832 {
3833 storeValue(argument.value);
3834 }
3835
3836 Int::Int(RValue<Byte> cast)
3837 {
3838 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3839
3840 storeValue(integer);
3841 }
3842
3843 Int::Int(RValue<SByte> cast)
3844 {
3845 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3846
3847 storeValue(integer);
3848 }
3849
3850 Int::Int(RValue<Short> cast)
3851 {
3852 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3853
3854 storeValue(integer);
3855 }
3856
3857 Int::Int(RValue<UShort> cast)
3858 {
3859 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3860
3861 storeValue(integer);
3862 }
3863
3864 Int::Int(RValue<Int2> cast)
3865 {
3866 *this = Extract(cast, 0);
3867 }
3868
3869 Int::Int(RValue<Long> cast)
3870 {
3871 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3872
3873 storeValue(integer);
3874 }
3875
3876 Int::Int(RValue<Float> cast)
3877 {
3878 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3879
3880 storeValue(integer);
3881 }
3882
Nicolas Capens598f8d82016-09-26 15:09:10 -04003883 Int::Int(int x)
3884 {
3885 storeValue(Nucleus::createConstantInt(x));
3886 }
3887
3888 Int::Int(RValue<Int> rhs)
3889 {
3890 storeValue(rhs.value);
3891 }
3892
3893 Int::Int(RValue<UInt> rhs)
3894 {
3895 storeValue(rhs.value);
3896 }
3897
3898 Int::Int(const Int &rhs)
3899 {
3900 Value *value = rhs.loadValue();
3901 storeValue(value);
3902 }
3903
3904 Int::Int(const Reference<Int> &rhs)
3905 {
3906 Value *value = rhs.loadValue();
3907 storeValue(value);
3908 }
3909
3910 Int::Int(const UInt &rhs)
3911 {
3912 Value *value = rhs.loadValue();
3913 storeValue(value);
3914 }
3915
3916 Int::Int(const Reference<UInt> &rhs)
3917 {
3918 Value *value = rhs.loadValue();
3919 storeValue(value);
3920 }
3921
Nicolas Capens96d4e092016-11-18 14:22:38 -05003922 RValue<Int> Int::operator=(int rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003923 {
3924 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
3925 }
3926
Nicolas Capens96d4e092016-11-18 14:22:38 -05003927 RValue<Int> Int::operator=(RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003928 {
3929 storeValue(rhs.value);
3930
3931 return rhs;
3932 }
3933
Nicolas Capens96d4e092016-11-18 14:22:38 -05003934 RValue<Int> Int::operator=(RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003935 {
3936 storeValue(rhs.value);
3937
3938 return RValue<Int>(rhs);
3939 }
3940
Nicolas Capens96d4e092016-11-18 14:22:38 -05003941 RValue<Int> Int::operator=(const Int &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003942 {
3943 Value *value = rhs.loadValue();
3944 storeValue(value);
3945
3946 return RValue<Int>(value);
3947 }
3948
Nicolas Capens96d4e092016-11-18 14:22:38 -05003949 RValue<Int> Int::operator=(const Reference<Int> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003950 {
3951 Value *value = rhs.loadValue();
3952 storeValue(value);
3953
3954 return RValue<Int>(value);
3955 }
3956
Nicolas Capens96d4e092016-11-18 14:22:38 -05003957 RValue<Int> Int::operator=(const UInt &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003958 {
3959 Value *value = rhs.loadValue();
3960 storeValue(value);
3961
3962 return RValue<Int>(value);
3963 }
3964
Nicolas Capens96d4e092016-11-18 14:22:38 -05003965 RValue<Int> Int::operator=(const Reference<UInt> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003966 {
3967 Value *value = rhs.loadValue();
3968 storeValue(value);
3969
3970 return RValue<Int>(value);
3971 }
3972
3973 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
3974 {
3975 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3976 }
3977
3978 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
3979 {
3980 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3981 }
3982
3983 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
3984 {
3985 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3986 }
3987
3988 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
3989 {
3990 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3991 }
3992
3993 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
3994 {
3995 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3996 }
3997
3998 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
3999 {
4000 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
4001 }
4002
4003 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
4004 {
4005 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
4006 }
4007
4008 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
4009 {
4010 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
4011 }
4012
4013 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
4014 {
4015 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
4016 }
4017
4018 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
4019 {
4020 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
4021 }
4022
Nicolas Capens96d4e092016-11-18 14:22:38 -05004023 RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004024 {
4025 return lhs = lhs + rhs;
4026 }
4027
Nicolas Capens96d4e092016-11-18 14:22:38 -05004028 RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004029 {
4030 return lhs = lhs - rhs;
4031 }
4032
Nicolas Capens96d4e092016-11-18 14:22:38 -05004033 RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004034 {
4035 return lhs = lhs * rhs;
4036 }
4037
Nicolas Capens96d4e092016-11-18 14:22:38 -05004038 RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004039 {
4040 return lhs = lhs / rhs;
4041 }
4042
Nicolas Capens96d4e092016-11-18 14:22:38 -05004043 RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004044 {
4045 return lhs = lhs % rhs;
4046 }
4047
Nicolas Capens96d4e092016-11-18 14:22:38 -05004048 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004049 {
4050 return lhs = lhs & rhs;
4051 }
4052
Nicolas Capens96d4e092016-11-18 14:22:38 -05004053 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004054 {
4055 return lhs = lhs | rhs;
4056 }
4057
Nicolas Capens96d4e092016-11-18 14:22:38 -05004058 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004059 {
4060 return lhs = lhs ^ rhs;
4061 }
4062
Nicolas Capens96d4e092016-11-18 14:22:38 -05004063 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004064 {
4065 return lhs = lhs << rhs;
4066 }
4067
Nicolas Capens96d4e092016-11-18 14:22:38 -05004068 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004069 {
4070 return lhs = lhs >> rhs;
4071 }
4072
4073 RValue<Int> operator+(RValue<Int> val)
4074 {
4075 return val;
4076 }
4077
4078 RValue<Int> operator-(RValue<Int> val)
4079 {
4080 return RValue<Int>(Nucleus::createNeg(val.value));
4081 }
4082
4083 RValue<Int> operator~(RValue<Int> val)
4084 {
4085 return RValue<Int>(Nucleus::createNot(val.value));
4086 }
4087
Nicolas Capens96d4e092016-11-18 14:22:38 -05004088 RValue<Int> operator++(Int &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004089 {
Nicolas Capens5b41ba32016-12-08 14:34:00 -05004090 RValue<Int> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05004091 val += 1;
4092 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004093 }
4094
Nicolas Capens96d4e092016-11-18 14:22:38 -05004095 const Int &operator++(Int &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004096 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004097 val += 1;
4098 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004099 }
4100
Nicolas Capens96d4e092016-11-18 14:22:38 -05004101 RValue<Int> operator--(Int &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004102 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004103 RValue<Int> res = val;
4104 val -= 1;
4105 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004106 }
4107
Nicolas Capens96d4e092016-11-18 14:22:38 -05004108 const Int &operator--(Int &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004109 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004110 val -= 1;
4111 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004112 }
4113
4114 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
4115 {
4116 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4117 }
4118
4119 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
4120 {
4121 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4122 }
4123
4124 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
4125 {
4126 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4127 }
4128
4129 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
4130 {
4131 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4132 }
4133
4134 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
4135 {
4136 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4137 }
4138
4139 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
4140 {
4141 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4142 }
4143
4144 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4145 {
4146 return IfThenElse(x > y, x, y);
4147 }
4148
4149 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4150 {
4151 return IfThenElse(x < y, x, y);
4152 }
4153
4154 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4155 {
4156 return Min(Max(x, min), max);
4157 }
4158
4159 RValue<Int> RoundInt(RValue<Float> cast)
4160 {
Nicolas Capensf7b75882017-04-26 09:30:47 -04004161 if(emulateIntrinsics)
4162 {
4163 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
4164 return Int((cast + Float(0x00C00000)) - Float(0x00C00000));
4165 }
4166 else
4167 {
4168 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
4169 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
4170 auto target = ::context->getConstantUndef(Ice::IceType_i32);
4171 auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
4172 nearbyint->addArg(cast.value);
4173 ::basicBlock->appendInst(nearbyint);
Nicolas Capensa8086512016-11-07 17:32:17 -05004174
Nicolas Capensf7b75882017-04-26 09:30:47 -04004175 return RValue<Int>(V(result));
4176 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04004177 }
4178
4179 Type *Int::getType()
4180 {
4181 return T(Ice::IceType_i32);
4182 }
4183
4184 Long::Long(RValue<Int> cast)
4185 {
4186 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4187
4188 storeValue(integer);
4189 }
4190
4191 Long::Long(RValue<UInt> cast)
4192 {
4193 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4194
4195 storeValue(integer);
4196 }
4197
Nicolas Capens598f8d82016-09-26 15:09:10 -04004198 Long::Long(RValue<Long> rhs)
4199 {
4200 storeValue(rhs.value);
4201 }
4202
Nicolas Capens96d4e092016-11-18 14:22:38 -05004203 RValue<Long> Long::operator=(int64_t rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004204 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004205 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004206 }
4207
Nicolas Capens96d4e092016-11-18 14:22:38 -05004208 RValue<Long> Long::operator=(RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004209 {
4210 storeValue(rhs.value);
4211
4212 return rhs;
4213 }
4214
Nicolas Capens96d4e092016-11-18 14:22:38 -05004215 RValue<Long> Long::operator=(const Long &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004216 {
4217 Value *value = rhs.loadValue();
4218 storeValue(value);
4219
4220 return RValue<Long>(value);
4221 }
4222
Nicolas Capens96d4e092016-11-18 14:22:38 -05004223 RValue<Long> Long::operator=(const Reference<Long> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004224 {
4225 Value *value = rhs.loadValue();
4226 storeValue(value);
4227
4228 return RValue<Long>(value);
4229 }
4230
4231 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
4232 {
4233 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4234 }
4235
4236 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
4237 {
4238 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4239 }
4240
Nicolas Capens96d4e092016-11-18 14:22:38 -05004241 RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004242 {
4243 return lhs = lhs + rhs;
4244 }
4245
Nicolas Capens96d4e092016-11-18 14:22:38 -05004246 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004247 {
4248 return lhs = lhs - rhs;
4249 }
4250
4251 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
4252 {
4253 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
4254 }
4255
4256 Type *Long::getType()
4257 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004258 return T(Ice::IceType_i64);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004259 }
4260
Nicolas Capens598f8d82016-09-26 15:09:10 -04004261 UInt::UInt(Argument<UInt> argument)
4262 {
4263 storeValue(argument.value);
4264 }
4265
4266 UInt::UInt(RValue<UShort> cast)
4267 {
4268 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4269
4270 storeValue(integer);
4271 }
4272
4273 UInt::UInt(RValue<Long> cast)
4274 {
4275 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4276
4277 storeValue(integer);
4278 }
4279
4280 UInt::UInt(RValue<Float> cast)
4281 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004282 // Smallest positive value representable in UInt, but not in Int
4283 const unsigned int ustart = 0x80000000u;
4284 const float ustartf = float(ustart);
4285
4286 // If the value is negative, store 0, otherwise store the result of the conversion
4287 storeValue((~(As<Int>(cast) >> 31) &
4288 // Check if the value can be represented as an Int
4289 IfThenElse(cast >= ustartf,
4290 // If the value is too large, subtract ustart and re-add it after conversion.
4291 As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
4292 // Otherwise, just convert normally
4293 Int(cast))).value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004294 }
4295
Nicolas Capens598f8d82016-09-26 15:09:10 -04004296 UInt::UInt(int x)
4297 {
4298 storeValue(Nucleus::createConstantInt(x));
4299 }
4300
4301 UInt::UInt(unsigned int x)
4302 {
4303 storeValue(Nucleus::createConstantInt(x));
4304 }
4305
4306 UInt::UInt(RValue<UInt> rhs)
4307 {
4308 storeValue(rhs.value);
4309 }
4310
4311 UInt::UInt(RValue<Int> rhs)
4312 {
4313 storeValue(rhs.value);
4314 }
4315
4316 UInt::UInt(const UInt &rhs)
4317 {
4318 Value *value = rhs.loadValue();
4319 storeValue(value);
4320 }
4321
4322 UInt::UInt(const Reference<UInt> &rhs)
4323 {
4324 Value *value = rhs.loadValue();
4325 storeValue(value);
4326 }
4327
4328 UInt::UInt(const Int &rhs)
4329 {
4330 Value *value = rhs.loadValue();
4331 storeValue(value);
4332 }
4333
4334 UInt::UInt(const Reference<Int> &rhs)
4335 {
4336 Value *value = rhs.loadValue();
4337 storeValue(value);
4338 }
4339
Nicolas Capens96d4e092016-11-18 14:22:38 -05004340 RValue<UInt> UInt::operator=(unsigned int rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004341 {
4342 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
4343 }
4344
Nicolas Capens96d4e092016-11-18 14:22:38 -05004345 RValue<UInt> UInt::operator=(RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004346 {
4347 storeValue(rhs.value);
4348
4349 return rhs;
4350 }
4351
Nicolas Capens96d4e092016-11-18 14:22:38 -05004352 RValue<UInt> UInt::operator=(RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004353 {
4354 storeValue(rhs.value);
4355
4356 return RValue<UInt>(rhs);
4357 }
4358
Nicolas Capens96d4e092016-11-18 14:22:38 -05004359 RValue<UInt> UInt::operator=(const UInt &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004360 {
4361 Value *value = rhs.loadValue();
4362 storeValue(value);
4363
4364 return RValue<UInt>(value);
4365 }
4366
Nicolas Capens96d4e092016-11-18 14:22:38 -05004367 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004368 {
4369 Value *value = rhs.loadValue();
4370 storeValue(value);
4371
4372 return RValue<UInt>(value);
4373 }
4374
Nicolas Capens96d4e092016-11-18 14:22:38 -05004375 RValue<UInt> UInt::operator=(const Int &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004376 {
4377 Value *value = rhs.loadValue();
4378 storeValue(value);
4379
4380 return RValue<UInt>(value);
4381 }
4382
Nicolas Capens96d4e092016-11-18 14:22:38 -05004383 RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004384 {
4385 Value *value = rhs.loadValue();
4386 storeValue(value);
4387
4388 return RValue<UInt>(value);
4389 }
4390
4391 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
4392 {
4393 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4394 }
4395
4396 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
4397 {
4398 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4399 }
4400
4401 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
4402 {
4403 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4404 }
4405
4406 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
4407 {
4408 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4409 }
4410
4411 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
4412 {
4413 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4414 }
4415
4416 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
4417 {
4418 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4419 }
4420
4421 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
4422 {
4423 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4424 }
4425
4426 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
4427 {
4428 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4429 }
4430
4431 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
4432 {
4433 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4434 }
4435
4436 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
4437 {
4438 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4439 }
4440
Nicolas Capens96d4e092016-11-18 14:22:38 -05004441 RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004442 {
4443 return lhs = lhs + rhs;
4444 }
4445
Nicolas Capens96d4e092016-11-18 14:22:38 -05004446 RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004447 {
4448 return lhs = lhs - rhs;
4449 }
4450
Nicolas Capens96d4e092016-11-18 14:22:38 -05004451 RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004452 {
4453 return lhs = lhs * rhs;
4454 }
4455
Nicolas Capens96d4e092016-11-18 14:22:38 -05004456 RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004457 {
4458 return lhs = lhs / rhs;
4459 }
4460
Nicolas Capens96d4e092016-11-18 14:22:38 -05004461 RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004462 {
4463 return lhs = lhs % rhs;
4464 }
4465
Nicolas Capens96d4e092016-11-18 14:22:38 -05004466 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004467 {
4468 return lhs = lhs & rhs;
4469 }
4470
Nicolas Capens96d4e092016-11-18 14:22:38 -05004471 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004472 {
4473 return lhs = lhs | rhs;
4474 }
4475
Nicolas Capens96d4e092016-11-18 14:22:38 -05004476 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004477 {
4478 return lhs = lhs ^ rhs;
4479 }
4480
Nicolas Capens96d4e092016-11-18 14:22:38 -05004481 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004482 {
4483 return lhs = lhs << rhs;
4484 }
4485
Nicolas Capens96d4e092016-11-18 14:22:38 -05004486 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004487 {
4488 return lhs = lhs >> rhs;
4489 }
4490
4491 RValue<UInt> operator+(RValue<UInt> val)
4492 {
4493 return val;
4494 }
4495
4496 RValue<UInt> operator-(RValue<UInt> val)
4497 {
4498 return RValue<UInt>(Nucleus::createNeg(val.value));
4499 }
4500
4501 RValue<UInt> operator~(RValue<UInt> val)
4502 {
4503 return RValue<UInt>(Nucleus::createNot(val.value));
4504 }
4505
Nicolas Capens96d4e092016-11-18 14:22:38 -05004506 RValue<UInt> operator++(UInt &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004507 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004508 RValue<UInt> res = val;
4509 val += 1;
4510 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004511 }
4512
Nicolas Capens96d4e092016-11-18 14:22:38 -05004513 const UInt &operator++(UInt &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004514 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004515 val += 1;
4516 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004517 }
4518
Nicolas Capens96d4e092016-11-18 14:22:38 -05004519 RValue<UInt> operator--(UInt &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004520 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004521 RValue<UInt> res = val;
4522 val -= 1;
4523 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004524 }
4525
Nicolas Capens96d4e092016-11-18 14:22:38 -05004526 const UInt &operator--(UInt &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004527 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004528 val -= 1;
4529 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004530 }
4531
4532 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4533 {
4534 return IfThenElse(x > y, x, y);
4535 }
4536
4537 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4538 {
4539 return IfThenElse(x < y, x, y);
4540 }
4541
4542 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4543 {
4544 return Min(Max(x, min), max);
4545 }
4546
4547 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
4548 {
4549 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4550 }
4551
4552 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
4553 {
4554 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4555 }
4556
4557 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
4558 {
4559 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4560 }
4561
4562 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
4563 {
4564 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4565 }
4566
4567 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
4568 {
4569 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4570 }
4571
4572 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
4573 {
4574 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4575 }
4576
4577// RValue<UInt> RoundUInt(RValue<Float> cast)
4578// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004579// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004580// }
4581
4582 Type *UInt::getType()
4583 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004584 return T(Ice::IceType_i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004585 }
4586
4587// Int2::Int2(RValue<Int> cast)
4588// {
4589// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4590// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
4591//
4592// Constant *shuffle[2];
4593// shuffle[0] = Nucleus::createConstantInt(0);
4594// shuffle[1] = Nucleus::createConstantInt(0);
4595//
4596// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4597//
4598// storeValue(replicate);
4599// }
4600
4601 Int2::Int2(RValue<Int4> cast)
4602 {
Nicolas Capens22008782016-10-20 01:11:47 -04004603 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004604 }
4605
Nicolas Capens598f8d82016-09-26 15:09:10 -04004606 Int2::Int2(int x, int y)
4607 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004608 int64_t constantVector[2] = {x, y};
4609 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004610 }
4611
4612 Int2::Int2(RValue<Int2> rhs)
4613 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004614 storeValue(rhs.value);
4615 }
4616
4617 Int2::Int2(const Int2 &rhs)
4618 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004619 Value *value = rhs.loadValue();
4620 storeValue(value);
4621 }
4622
4623 Int2::Int2(const Reference<Int2> &rhs)
4624 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004625 Value *value = rhs.loadValue();
4626 storeValue(value);
4627 }
4628
4629 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4630 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004631 int shuffle[4] = {0, 4, 1, 5};
4632 Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
4633
4634 storeValue(Nucleus::createBitCast(packed, Int2::getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004635 }
4636
Nicolas Capens96d4e092016-11-18 14:22:38 -05004637 RValue<Int2> Int2::operator=(RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004638 {
4639 storeValue(rhs.value);
4640
4641 return rhs;
4642 }
4643
Nicolas Capens96d4e092016-11-18 14:22:38 -05004644 RValue<Int2> Int2::operator=(const Int2 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004645 {
4646 Value *value = rhs.loadValue();
4647 storeValue(value);
4648
4649 return RValue<Int2>(value);
4650 }
4651
Nicolas Capens96d4e092016-11-18 14:22:38 -05004652 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004653 {
4654 Value *value = rhs.loadValue();
4655 storeValue(value);
4656
4657 return RValue<Int2>(value);
4658 }
4659
4660 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
4661 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004662 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004663 }
4664
4665 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
4666 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004667 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004668 }
4669
4670// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4671// {
4672// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4673// }
4674
4675// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4676// {
4677// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4678// }
4679
4680// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4681// {
4682// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4683// }
4684
4685 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
4686 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004687 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004688 }
4689
4690 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
4691 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004692 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004693 }
4694
4695 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
4696 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004697 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004698 }
4699
4700 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
4701 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004702 return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004703 }
4704
4705 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
4706 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004707 return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004708 }
4709
Nicolas Capens96d4e092016-11-18 14:22:38 -05004710 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004711 {
4712 return lhs = lhs + rhs;
4713 }
4714
Nicolas Capens96d4e092016-11-18 14:22:38 -05004715 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004716 {
4717 return lhs = lhs - rhs;
4718 }
4719
Nicolas Capens96d4e092016-11-18 14:22:38 -05004720// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004721// {
4722// return lhs = lhs * rhs;
4723// }
4724
Nicolas Capens96d4e092016-11-18 14:22:38 -05004725// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004726// {
4727// return lhs = lhs / rhs;
4728// }
4729
Nicolas Capens96d4e092016-11-18 14:22:38 -05004730// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004731// {
4732// return lhs = lhs % rhs;
4733// }
4734
Nicolas Capens96d4e092016-11-18 14:22:38 -05004735 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004736 {
4737 return lhs = lhs & rhs;
4738 }
4739
Nicolas Capens96d4e092016-11-18 14:22:38 -05004740 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004741 {
4742 return lhs = lhs | rhs;
4743 }
4744
Nicolas Capens96d4e092016-11-18 14:22:38 -05004745 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004746 {
4747 return lhs = lhs ^ rhs;
4748 }
4749
Nicolas Capens96d4e092016-11-18 14:22:38 -05004750 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004751 {
4752 return lhs = lhs << rhs;
4753 }
4754
Nicolas Capens96d4e092016-11-18 14:22:38 -05004755 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004756 {
4757 return lhs = lhs >> rhs;
4758 }
4759
Nicolas Capens598f8d82016-09-26 15:09:10 -04004760// RValue<Int2> operator+(RValue<Int2> val)
4761// {
4762// return val;
4763// }
4764
4765// RValue<Int2> operator-(RValue<Int2> val)
4766// {
4767// return RValue<Int2>(Nucleus::createNeg(val.value));
4768// }
4769
4770 RValue<Int2> operator~(RValue<Int2> val)
4771 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05004772 return RValue<Int2>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004773 }
4774
Nicolas Capens45f187a2016-12-02 15:30:56 -05004775 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004776 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004777 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
4778 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004779 }
4780
Nicolas Capens45f187a2016-12-02 15:30:56 -05004781 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004782 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08004783 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
Nicolas Capensc70a1162016-12-03 00:16:14 -05004784 auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
4785 return As<Short4>(Swizzle(lowHigh, 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004786 }
4787
4788 RValue<Int> Extract(RValue<Int2> val, int i)
4789 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05004790 return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004791 }
4792
4793 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4794 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05004795 return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004796 }
4797
4798 Type *Int2::getType()
4799 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004800 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004801 }
4802
Nicolas Capens598f8d82016-09-26 15:09:10 -04004803 UInt2::UInt2(unsigned int x, unsigned int y)
4804 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004805 int64_t constantVector[2] = {x, y};
4806 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004807 }
4808
4809 UInt2::UInt2(RValue<UInt2> rhs)
4810 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004811 storeValue(rhs.value);
4812 }
4813
4814 UInt2::UInt2(const UInt2 &rhs)
4815 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004816 Value *value = rhs.loadValue();
4817 storeValue(value);
4818 }
4819
4820 UInt2::UInt2(const Reference<UInt2> &rhs)
4821 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004822 Value *value = rhs.loadValue();
4823 storeValue(value);
4824 }
4825
Nicolas Capens96d4e092016-11-18 14:22:38 -05004826 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004827 {
4828 storeValue(rhs.value);
4829
4830 return rhs;
4831 }
4832
Nicolas Capens96d4e092016-11-18 14:22:38 -05004833 RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004834 {
4835 Value *value = rhs.loadValue();
4836 storeValue(value);
4837
4838 return RValue<UInt2>(value);
4839 }
4840
Nicolas Capens96d4e092016-11-18 14:22:38 -05004841 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004842 {
4843 Value *value = rhs.loadValue();
4844 storeValue(value);
4845
4846 return RValue<UInt2>(value);
4847 }
4848
4849 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
4850 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004851 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004852 }
4853
4854 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
4855 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004856 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004857 }
4858
4859// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4860// {
4861// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4862// }
4863
4864// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4865// {
4866// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4867// }
4868
4869// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4870// {
4871// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4872// }
4873
4874 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
4875 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004876 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004877 }
4878
4879 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
4880 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004881 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004882 }
4883
4884 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
4885 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004886 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004887 }
4888
4889 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
4890 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004891 return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004892 }
4893
4894 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
4895 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004896 return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004897 }
4898
Nicolas Capens96d4e092016-11-18 14:22:38 -05004899 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004900 {
4901 return lhs = lhs + rhs;
4902 }
4903
Nicolas Capens96d4e092016-11-18 14:22:38 -05004904 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004905 {
4906 return lhs = lhs - rhs;
4907 }
4908
Nicolas Capens96d4e092016-11-18 14:22:38 -05004909// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004910// {
4911// return lhs = lhs * rhs;
4912// }
4913
Nicolas Capens96d4e092016-11-18 14:22:38 -05004914// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004915// {
4916// return lhs = lhs / rhs;
4917// }
4918
Nicolas Capens96d4e092016-11-18 14:22:38 -05004919// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004920// {
4921// return lhs = lhs % rhs;
4922// }
4923
Nicolas Capens96d4e092016-11-18 14:22:38 -05004924 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004925 {
4926 return lhs = lhs & rhs;
4927 }
4928
Nicolas Capens96d4e092016-11-18 14:22:38 -05004929 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004930 {
4931 return lhs = lhs | rhs;
4932 }
4933
Nicolas Capens96d4e092016-11-18 14:22:38 -05004934 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004935 {
4936 return lhs = lhs ^ rhs;
4937 }
4938
Nicolas Capens96d4e092016-11-18 14:22:38 -05004939 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004940 {
4941 return lhs = lhs << rhs;
4942 }
4943
Nicolas Capens96d4e092016-11-18 14:22:38 -05004944 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004945 {
4946 return lhs = lhs >> rhs;
4947 }
4948
Nicolas Capens598f8d82016-09-26 15:09:10 -04004949// RValue<UInt2> operator+(RValue<UInt2> val)
4950// {
4951// return val;
4952// }
4953
4954// RValue<UInt2> operator-(RValue<UInt2> val)
4955// {
4956// return RValue<UInt2>(Nucleus::createNeg(val.value));
4957// }
4958
4959 RValue<UInt2> operator~(RValue<UInt2> val)
4960 {
4961 return RValue<UInt2>(Nucleus::createNot(val.value));
4962 }
4963
4964 Type *UInt2::getType()
4965 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004966 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004967 }
4968
4969 Int4::Int4(RValue<Byte4> cast)
4970 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004971 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
4972 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
4973
4974 Value *e;
4975 int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
4976 Value *b = Nucleus::createBitCast(a, Byte16::getType());
4977 Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
4978
4979 int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
4980 Value *d = Nucleus::createBitCast(c, Short8::getType());
4981 e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
4982
4983 Value *f = Nucleus::createBitCast(e, Int4::getType());
4984 storeValue(f);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004985 }
4986
4987 Int4::Int4(RValue<SByte4> cast)
4988 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004989 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
4990 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
4991
4992 Value *e;
4993 int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
4994 Value *b = Nucleus::createBitCast(a, Byte16::getType());
4995 Value *c = Nucleus::createShuffleVector(b, b, swizzle);
4996
4997 int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
4998 Value *d = Nucleus::createBitCast(c, Short8::getType());
4999 e = Nucleus::createShuffleVector(d, d, swizzle2);
5000
5001 Value *f = Nucleus::createBitCast(e, Int4::getType());
Nicolas Capens15060bb2016-12-05 22:17:19 -05005002 Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24)));
Nicolas Capensd4227962016-11-09 14:24:25 -05005003 storeValue(g);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005004 }
5005
5006 Int4::Int4(RValue<Float4> cast)
5007 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005008 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
5009
5010 storeValue(xyzw);
5011 }
5012
5013 Int4::Int4(RValue<Short4> cast)
5014 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005015 int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
5016 Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
5017 Value *d = Nucleus::createBitCast(c, Int4::getType());
Nicolas Capens15060bb2016-12-05 22:17:19 -05005018 Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16)));
Nicolas Capensd4227962016-11-09 14:24:25 -05005019 storeValue(e);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005020 }
5021
5022 Int4::Int4(RValue<UShort4> cast)
5023 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005024 int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
5025 Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
5026 Value *d = Nucleus::createBitCast(c, Int4::getType());
5027 storeValue(d);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005028 }
5029
Nicolas Capens598f8d82016-09-26 15:09:10 -04005030 Int4::Int4(int xyzw)
5031 {
5032 constant(xyzw, xyzw, xyzw, xyzw);
5033 }
5034
5035 Int4::Int4(int x, int yzw)
5036 {
5037 constant(x, yzw, yzw, yzw);
5038 }
5039
5040 Int4::Int4(int x, int y, int zw)
5041 {
5042 constant(x, y, zw, zw);
5043 }
5044
5045 Int4::Int4(int x, int y, int z, int w)
5046 {
5047 constant(x, y, z, w);
5048 }
5049
5050 void Int4::constant(int x, int y, int z, int w)
5051 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005052 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005053 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005054 }
5055
5056 Int4::Int4(RValue<Int4> rhs)
5057 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005058 storeValue(rhs.value);
5059 }
5060
5061 Int4::Int4(const Int4 &rhs)
5062 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005063 Value *value = rhs.loadValue();
5064 storeValue(value);
5065 }
5066
5067 Int4::Int4(const Reference<Int4> &rhs)
5068 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005069 Value *value = rhs.loadValue();
5070 storeValue(value);
5071 }
5072
5073 Int4::Int4(RValue<UInt4> rhs)
5074 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005075 storeValue(rhs.value);
5076 }
5077
5078 Int4::Int4(const UInt4 &rhs)
5079 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005080 Value *value = rhs.loadValue();
5081 storeValue(value);
5082 }
5083
5084 Int4::Int4(const Reference<UInt4> &rhs)
5085 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005086 Value *value = rhs.loadValue();
5087 storeValue(value);
5088 }
5089
5090 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
5091 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005092 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5093 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5094
5095 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005096 }
5097
5098 Int4::Int4(RValue<Int> rhs)
5099 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08005100 Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType());
Nicolas Capensd4227962016-11-09 14:24:25 -05005101
5102 int swizzle[4] = {0, 0, 0, 0};
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08005103 Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
Nicolas Capensd4227962016-11-09 14:24:25 -05005104
5105 storeValue(replicate);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005106 }
5107
5108 Int4::Int4(const Int &rhs)
5109 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005110 *this = RValue<Int>(rhs.loadValue());
5111 }
5112
5113 Int4::Int4(const Reference<Int> &rhs)
5114 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005115 *this = RValue<Int>(rhs.loadValue());
5116 }
5117
Nicolas Capens96d4e092016-11-18 14:22:38 -05005118 RValue<Int4> Int4::operator=(RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005119 {
5120 storeValue(rhs.value);
5121
5122 return rhs;
5123 }
5124
Nicolas Capens96d4e092016-11-18 14:22:38 -05005125 RValue<Int4> Int4::operator=(const Int4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005126 {
5127 Value *value = rhs.loadValue();
5128 storeValue(value);
5129
5130 return RValue<Int4>(value);
5131 }
5132
Nicolas Capens96d4e092016-11-18 14:22:38 -05005133 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005134 {
5135 Value *value = rhs.loadValue();
5136 storeValue(value);
5137
5138 return RValue<Int4>(value);
5139 }
5140
5141 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
5142 {
5143 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5144 }
5145
5146 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
5147 {
5148 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5149 }
5150
5151 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
5152 {
5153 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5154 }
5155
5156 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5157 {
5158 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5159 }
5160
5161 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5162 {
5163 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5164 }
5165
5166 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
5167 {
5168 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5169 }
5170
5171 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
5172 {
5173 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5174 }
5175
5176 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
5177 {
5178 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5179 }
5180
5181 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
5182 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005183 return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005184 }
5185
5186 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
5187 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005188 return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005189 }
5190
5191 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5192 {
5193 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5194 }
5195
5196 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5197 {
5198 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5199 }
5200
Nicolas Capens96d4e092016-11-18 14:22:38 -05005201 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005202 {
5203 return lhs = lhs + rhs;
5204 }
5205
Nicolas Capens96d4e092016-11-18 14:22:38 -05005206 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005207 {
5208 return lhs = lhs - rhs;
5209 }
5210
Nicolas Capens96d4e092016-11-18 14:22:38 -05005211 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005212 {
5213 return lhs = lhs * rhs;
5214 }
5215
Nicolas Capens96d4e092016-11-18 14:22:38 -05005216// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005217// {
5218// return lhs = lhs / rhs;
5219// }
5220
Nicolas Capens96d4e092016-11-18 14:22:38 -05005221// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005222// {
5223// return lhs = lhs % rhs;
5224// }
5225
Nicolas Capens96d4e092016-11-18 14:22:38 -05005226 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005227 {
5228 return lhs = lhs & rhs;
5229 }
5230
Nicolas Capens96d4e092016-11-18 14:22:38 -05005231 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005232 {
5233 return lhs = lhs | rhs;
5234 }
5235
Nicolas Capens96d4e092016-11-18 14:22:38 -05005236 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005237 {
5238 return lhs = lhs ^ rhs;
5239 }
5240
Nicolas Capens96d4e092016-11-18 14:22:38 -05005241 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005242 {
5243 return lhs = lhs << rhs;
5244 }
5245
Nicolas Capens96d4e092016-11-18 14:22:38 -05005246 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005247 {
5248 return lhs = lhs >> rhs;
5249 }
5250
5251 RValue<Int4> operator+(RValue<Int4> val)
5252 {
5253 return val;
5254 }
5255
5256 RValue<Int4> operator-(RValue<Int4> val)
5257 {
5258 return RValue<Int4>(Nucleus::createNeg(val.value));
5259 }
5260
5261 RValue<Int4> operator~(RValue<Int4> val)
5262 {
5263 return RValue<Int4>(Nucleus::createNot(val.value));
5264 }
5265
5266 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5267 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005268 return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005269 }
5270
5271 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5272 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005273 return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005274 }
5275
5276 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5277 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005278 return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005279 }
5280
5281 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5282 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005283 return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005284 }
5285
5286 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5287 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005288 return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005289 }
5290
5291 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5292 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005293 return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005294 }
5295
5296 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5297 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005298 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5299 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
5300 ::basicBlock->appendInst(cmp);
5301
5302 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5303 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5304 ::basicBlock->appendInst(select);
5305
5306 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005307 }
5308
5309 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5310 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005311 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5312 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
5313 ::basicBlock->appendInst(cmp);
5314
5315 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5316 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5317 ::basicBlock->appendInst(select);
5318
5319 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005320 }
5321
5322 RValue<Int4> RoundInt(RValue<Float4> cast)
5323 {
Nicolas Capensf7b75882017-04-26 09:30:47 -04005324 if(emulateIntrinsics)
5325 {
5326 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
5327 return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000));
5328 }
5329 else
5330 {
5331 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5332 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5333 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5334 auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5335 nearbyint->addArg(cast.value);
5336 ::basicBlock->appendInst(nearbyint);
Nicolas Capensa8086512016-11-07 17:32:17 -05005337
Nicolas Capensf7b75882017-04-26 09:30:47 -04005338 return RValue<Int4>(V(result));
5339 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04005340 }
5341
5342 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
5343 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005344 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5345 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5346 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5347 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5348 pack->addArg(x.value);
5349 pack->addArg(y.value);
5350 ::basicBlock->appendInst(pack);
5351
5352 return RValue<Short8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005353 }
5354
5355 RValue<Int> Extract(RValue<Int4> x, int i)
5356 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005357 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005358 }
5359
5360 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
5361 {
5362 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5363 }
5364
5365 RValue<Int> SignMask(RValue<Int4> x)
5366 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04005367 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
5368 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5369 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5370 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5371 movmsk->addArg(x.value);
5372 ::basicBlock->appendInst(movmsk);
5373
5374 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005375 }
5376
5377 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
5378 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005379 return RValue<Int4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005380 }
5381
5382 Type *Int4::getType()
5383 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04005384 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005385 }
5386
5387 UInt4::UInt4(RValue<Float4> cast)
5388 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005389 // Smallest positive value representable in UInt, but not in Int
5390 const unsigned int ustart = 0x80000000u;
5391 const float ustartf = float(ustart);
5392
5393 // Check if the value can be represented as an Int
5394 Int4 uiValue = CmpNLT(cast, Float4(ustartf));
5395 // If the value is too large, subtract ustart and re-add it after conversion.
5396 uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
5397 // Otherwise, just convert normally
5398 (~uiValue & Int4(cast));
5399 // If the value is negative, store 0, otherwise store the result of the conversion
5400 storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005401 }
5402
Nicolas Capens598f8d82016-09-26 15:09:10 -04005403 UInt4::UInt4(int xyzw)
5404 {
5405 constant(xyzw, xyzw, xyzw, xyzw);
5406 }
5407
5408 UInt4::UInt4(int x, int yzw)
5409 {
5410 constant(x, yzw, yzw, yzw);
5411 }
5412
5413 UInt4::UInt4(int x, int y, int zw)
5414 {
5415 constant(x, y, zw, zw);
5416 }
5417
5418 UInt4::UInt4(int x, int y, int z, int w)
5419 {
5420 constant(x, y, z, w);
5421 }
5422
5423 void UInt4::constant(int x, int y, int z, int w)
5424 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005425 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005426 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005427 }
5428
5429 UInt4::UInt4(RValue<UInt4> rhs)
5430 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005431 storeValue(rhs.value);
5432 }
5433
5434 UInt4::UInt4(const UInt4 &rhs)
5435 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005436 Value *value = rhs.loadValue();
5437 storeValue(value);
5438 }
5439
5440 UInt4::UInt4(const Reference<UInt4> &rhs)
5441 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005442 Value *value = rhs.loadValue();
5443 storeValue(value);
5444 }
5445
5446 UInt4::UInt4(RValue<Int4> rhs)
5447 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005448 storeValue(rhs.value);
5449 }
5450
5451 UInt4::UInt4(const Int4 &rhs)
5452 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005453 Value *value = rhs.loadValue();
5454 storeValue(value);
5455 }
5456
5457 UInt4::UInt4(const Reference<Int4> &rhs)
5458 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005459 Value *value = rhs.loadValue();
5460 storeValue(value);
5461 }
5462
5463 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5464 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005465 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5466 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5467
5468 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005469 }
5470
Nicolas Capens96d4e092016-11-18 14:22:38 -05005471 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005472 {
5473 storeValue(rhs.value);
5474
5475 return rhs;
5476 }
5477
Nicolas Capens96d4e092016-11-18 14:22:38 -05005478 RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005479 {
5480 Value *value = rhs.loadValue();
5481 storeValue(value);
5482
5483 return RValue<UInt4>(value);
5484 }
5485
Nicolas Capens96d4e092016-11-18 14:22:38 -05005486 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005487 {
5488 Value *value = rhs.loadValue();
5489 storeValue(value);
5490
5491 return RValue<UInt4>(value);
5492 }
5493
5494 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
5495 {
5496 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5497 }
5498
5499 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
5500 {
5501 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5502 }
5503
5504 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
5505 {
5506 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5507 }
5508
5509 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5510 {
5511 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5512 }
5513
5514 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5515 {
5516 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5517 }
5518
5519 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
5520 {
5521 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5522 }
5523
5524 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
5525 {
5526 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5527 }
5528
5529 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
5530 {
5531 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5532 }
5533
5534 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
5535 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005536 return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005537 }
5538
5539 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
5540 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005541 return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005542 }
5543
5544 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5545 {
5546 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5547 }
5548
5549 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5550 {
5551 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5552 }
5553
Nicolas Capens96d4e092016-11-18 14:22:38 -05005554 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005555 {
5556 return lhs = lhs + rhs;
5557 }
5558
Nicolas Capens96d4e092016-11-18 14:22:38 -05005559 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005560 {
5561 return lhs = lhs - rhs;
5562 }
5563
Nicolas Capens96d4e092016-11-18 14:22:38 -05005564 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005565 {
5566 return lhs = lhs * rhs;
5567 }
5568
Nicolas Capens96d4e092016-11-18 14:22:38 -05005569// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005570// {
5571// return lhs = lhs / rhs;
5572// }
5573
Nicolas Capens96d4e092016-11-18 14:22:38 -05005574// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005575// {
5576// return lhs = lhs % rhs;
5577// }
5578
Nicolas Capens96d4e092016-11-18 14:22:38 -05005579 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005580 {
5581 return lhs = lhs & rhs;
5582 }
5583
Nicolas Capens96d4e092016-11-18 14:22:38 -05005584 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005585 {
5586 return lhs = lhs | rhs;
5587 }
5588
Nicolas Capens96d4e092016-11-18 14:22:38 -05005589 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005590 {
5591 return lhs = lhs ^ rhs;
5592 }
5593
Nicolas Capens96d4e092016-11-18 14:22:38 -05005594 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005595 {
5596 return lhs = lhs << rhs;
5597 }
5598
Nicolas Capens96d4e092016-11-18 14:22:38 -05005599 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005600 {
5601 return lhs = lhs >> rhs;
5602 }
5603
5604 RValue<UInt4> operator+(RValue<UInt4> val)
5605 {
5606 return val;
5607 }
5608
5609 RValue<UInt4> operator-(RValue<UInt4> val)
5610 {
5611 return RValue<UInt4>(Nucleus::createNeg(val.value));
5612 }
5613
5614 RValue<UInt4> operator~(RValue<UInt4> val)
5615 {
5616 return RValue<UInt4>(Nucleus::createNot(val.value));
5617 }
5618
5619 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5620 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005621 return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005622 }
5623
5624 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5625 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005626 return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005627 }
5628
5629 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5630 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005631 return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005632 }
5633
5634 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5635 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005636 return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005637 }
5638
5639 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5640 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005641 return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005642 }
5643
5644 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5645 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005646 return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005647 }
5648
5649 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5650 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005651 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5652 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
5653 ::basicBlock->appendInst(cmp);
5654
5655 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5656 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5657 ::basicBlock->appendInst(select);
5658
5659 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005660 }
5661
5662 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5663 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005664 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5665 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
5666 ::basicBlock->appendInst(cmp);
5667
5668 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5669 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5670 ::basicBlock->appendInst(select);
5671
5672 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005673 }
5674
5675 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
5676 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05005677 if(CPUID::SSE4_1)
5678 {
5679 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5680 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5681 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5682 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5683 pack->addArg(x.value);
5684 pack->addArg(y.value);
5685 ::basicBlock->appendInst(pack);
Nicolas Capensec54a172016-10-25 17:32:37 -04005686
Nicolas Capens9ca48d52017-01-14 12:52:55 -05005687 return RValue<UShort8>(V(result));
5688 }
5689 else
5690 {
5691 RValue<Int4> sx = As<Int4>(x);
5692 RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000);
5693
5694 RValue<Int4> sy = As<Int4>(y);
5695 RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000);
5696
5697 return As<UShort8>(Pack(bx, by) + Short8(0x8000u));
5698 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04005699 }
5700
5701 Type *UInt4::getType()
5702 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005703 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005704 }
5705
5706 Float::Float(RValue<Int> cast)
5707 {
5708 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5709
5710 storeValue(integer);
5711 }
5712
Nicolas Capens598f8d82016-09-26 15:09:10 -04005713 Float::Float(float x)
5714 {
5715 storeValue(Nucleus::createConstantFloat(x));
5716 }
5717
5718 Float::Float(RValue<Float> rhs)
5719 {
5720 storeValue(rhs.value);
5721 }
5722
5723 Float::Float(const Float &rhs)
5724 {
5725 Value *value = rhs.loadValue();
5726 storeValue(value);
5727 }
5728
5729 Float::Float(const Reference<Float> &rhs)
5730 {
5731 Value *value = rhs.loadValue();
5732 storeValue(value);
5733 }
5734
Nicolas Capens96d4e092016-11-18 14:22:38 -05005735 RValue<Float> Float::operator=(RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005736 {
5737 storeValue(rhs.value);
5738
5739 return rhs;
5740 }
5741
Nicolas Capens96d4e092016-11-18 14:22:38 -05005742 RValue<Float> Float::operator=(const Float &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005743 {
5744 Value *value = rhs.loadValue();
5745 storeValue(value);
5746
5747 return RValue<Float>(value);
5748 }
5749
Nicolas Capens96d4e092016-11-18 14:22:38 -05005750 RValue<Float> Float::operator=(const Reference<Float> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005751 {
5752 Value *value = rhs.loadValue();
5753 storeValue(value);
5754
5755 return RValue<Float>(value);
5756 }
5757
5758 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
5759 {
5760 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5761 }
5762
5763 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
5764 {
5765 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5766 }
5767
5768 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
5769 {
5770 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5771 }
5772
5773 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
5774 {
5775 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5776 }
5777
Nicolas Capens96d4e092016-11-18 14:22:38 -05005778 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005779 {
5780 return lhs = lhs + rhs;
5781 }
5782
Nicolas Capens96d4e092016-11-18 14:22:38 -05005783 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005784 {
5785 return lhs = lhs - rhs;
5786 }
5787
Nicolas Capens96d4e092016-11-18 14:22:38 -05005788 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005789 {
5790 return lhs = lhs * rhs;
5791 }
5792
Nicolas Capens96d4e092016-11-18 14:22:38 -05005793 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005794 {
5795 return lhs = lhs / rhs;
5796 }
5797
5798 RValue<Float> operator+(RValue<Float> val)
5799 {
5800 return val;
5801 }
5802
5803 RValue<Float> operator-(RValue<Float> val)
5804 {
5805 return RValue<Float>(Nucleus::createFNeg(val.value));
5806 }
5807
5808 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
5809 {
5810 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5811 }
5812
5813 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
5814 {
5815 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5816 }
5817
5818 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
5819 {
5820 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5821 }
5822
5823 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
5824 {
5825 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5826 }
5827
5828 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
5829 {
5830 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5831 }
5832
5833 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
5834 {
5835 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5836 }
5837
5838 RValue<Float> Abs(RValue<Float> x)
5839 {
5840 return IfThenElse(x > 0.0f, x, -x);
5841 }
5842
5843 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
5844 {
5845 return IfThenElse(x > y, x, y);
5846 }
5847
5848 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
5849 {
5850 return IfThenElse(x < y, x, y);
5851 }
5852
5853 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
5854 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005855 return 1.0f / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005856 }
5857
5858 RValue<Float> RcpSqrt_pp(RValue<Float> x)
5859 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005860 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005861 }
5862
5863 RValue<Float> Sqrt(RValue<Float> x)
5864 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005865 Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32);
5866 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5867 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5868 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5869 sqrt->addArg(x.value);
5870 ::basicBlock->appendInst(sqrt);
5871
5872 return RValue<Float>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005873 }
5874
5875 RValue<Float> Round(RValue<Float> x)
5876 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005877 return Float4(Round(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005878 }
5879
5880 RValue<Float> Trunc(RValue<Float> x)
5881 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005882 return Float4(Trunc(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005883 }
5884
5885 RValue<Float> Frac(RValue<Float> x)
5886 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005887 return Float4(Frac(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005888 }
5889
5890 RValue<Float> Floor(RValue<Float> x)
5891 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005892 return Float4(Floor(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005893 }
5894
5895 RValue<Float> Ceil(RValue<Float> x)
5896 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005897 return Float4(Ceil(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005898 }
5899
5900 Type *Float::getType()
5901 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04005902 return T(Ice::IceType_f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005903 }
5904
5905 Float2::Float2(RValue<Float4> cast)
5906 {
Nicolas Capens22008782016-10-20 01:11:47 -04005907 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005908 }
5909
5910 Type *Float2::getType()
5911 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005912 return T(Type_v2f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005913 }
5914
Nicolas Capensa25311a2017-01-16 17:19:00 -05005915 Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005916 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005917 Value *a = Int4(cast).loadValue();
5918 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
5919
5920 storeValue(xyzw);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005921 }
5922
Nicolas Capensa25311a2017-01-16 17:19:00 -05005923 Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005924 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005925 Value *a = Int4(cast).loadValue();
5926 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
5927
5928 storeValue(xyzw);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005929 }
5930
Nicolas Capensa25311a2017-01-16 17:19:00 -05005931 Float4::Float4(RValue<Short4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005932 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005933 Int4 c(cast);
5934 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5935 }
5936
Nicolas Capensa25311a2017-01-16 17:19:00 -05005937 Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005938 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005939 Int4 c(cast);
5940 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5941 }
5942
Nicolas Capensa25311a2017-01-16 17:19:00 -05005943 Float4::Float4(RValue<Int4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005944 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005945 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
5946
5947 storeValue(xyzw);
5948 }
5949
Nicolas Capensa25311a2017-01-16 17:19:00 -05005950 Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005951 {
Nicolas Capens96445fe2016-12-15 14:45:13 -05005952 RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
5953 As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005954
Nicolas Capens96445fe2016-12-15 14:45:13 -05005955 storeValue(result.value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005956 }
5957
Nicolas Capensa25311a2017-01-16 17:19:00 -05005958 Float4::Float4() : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005959 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005960 }
5961
Nicolas Capensa25311a2017-01-16 17:19:00 -05005962 Float4::Float4(float xyzw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005963 {
5964 constant(xyzw, xyzw, xyzw, xyzw);
5965 }
5966
Nicolas Capensa25311a2017-01-16 17:19:00 -05005967 Float4::Float4(float x, float yzw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005968 {
5969 constant(x, yzw, yzw, yzw);
5970 }
5971
Nicolas Capensa25311a2017-01-16 17:19:00 -05005972 Float4::Float4(float x, float y, float zw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005973 {
5974 constant(x, y, zw, zw);
5975 }
5976
Nicolas Capensa25311a2017-01-16 17:19:00 -05005977 Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005978 {
5979 constant(x, y, z, w);
5980 }
5981
5982 void Float4::constant(float x, float y, float z, float w)
5983 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005984 double constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005985 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005986 }
5987
Nicolas Capensa25311a2017-01-16 17:19:00 -05005988 Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005989 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005990 storeValue(rhs.value);
5991 }
5992
Nicolas Capensa25311a2017-01-16 17:19:00 -05005993 Float4::Float4(const Float4 &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005994 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005995 Value *value = rhs.loadValue();
5996 storeValue(value);
5997 }
5998
Nicolas Capensa25311a2017-01-16 17:19:00 -05005999 Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006000 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04006001 Value *value = rhs.loadValue();
6002 storeValue(value);
6003 }
6004
Nicolas Capensa25311a2017-01-16 17:19:00 -05006005 Float4::Float4(RValue<Float> rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006006 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08006007 Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType());
Nicolas Capensd4227962016-11-09 14:24:25 -05006008
6009 int swizzle[4] = {0, 0, 0, 0};
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08006010 Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
Nicolas Capensd4227962016-11-09 14:24:25 -05006011
6012 storeValue(replicate);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006013 }
6014
Nicolas Capensa25311a2017-01-16 17:19:00 -05006015 Float4::Float4(const Float &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006016 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04006017 *this = RValue<Float>(rhs.loadValue());
6018 }
6019
Nicolas Capensa25311a2017-01-16 17:19:00 -05006020 Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006021 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04006022 *this = RValue<Float>(rhs.loadValue());
6023 }
6024
Nicolas Capens96d4e092016-11-18 14:22:38 -05006025 RValue<Float4> Float4::operator=(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006026 {
6027 return *this = Float4(x, x, x, x);
6028 }
6029
Nicolas Capens96d4e092016-11-18 14:22:38 -05006030 RValue<Float4> Float4::operator=(RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006031 {
6032 storeValue(rhs.value);
6033
6034 return rhs;
6035 }
6036
Nicolas Capens96d4e092016-11-18 14:22:38 -05006037 RValue<Float4> Float4::operator=(const Float4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006038 {
6039 Value *value = rhs.loadValue();
6040 storeValue(value);
6041
6042 return RValue<Float4>(value);
6043 }
6044
Nicolas Capens96d4e092016-11-18 14:22:38 -05006045 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006046 {
6047 Value *value = rhs.loadValue();
6048 storeValue(value);
6049
6050 return RValue<Float4>(value);
6051 }
6052
Nicolas Capens96d4e092016-11-18 14:22:38 -05006053 RValue<Float4> Float4::operator=(RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006054 {
6055 return *this = Float4(rhs);
6056 }
6057
Nicolas Capens96d4e092016-11-18 14:22:38 -05006058 RValue<Float4> Float4::operator=(const Float &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006059 {
6060 return *this = Float4(rhs);
6061 }
6062
Nicolas Capens96d4e092016-11-18 14:22:38 -05006063 RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006064 {
6065 return *this = Float4(rhs);
6066 }
6067
6068 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
6069 {
6070 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
6071 }
6072
6073 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
6074 {
6075 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
6076 }
6077
6078 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
6079 {
6080 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
6081 }
6082
6083 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
6084 {
6085 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6086 }
6087
6088 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
6089 {
6090 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
6091 }
6092
Nicolas Capens96d4e092016-11-18 14:22:38 -05006093 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006094 {
6095 return lhs = lhs + rhs;
6096 }
6097
Nicolas Capens96d4e092016-11-18 14:22:38 -05006098 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006099 {
6100 return lhs = lhs - rhs;
6101 }
6102
Nicolas Capens96d4e092016-11-18 14:22:38 -05006103 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006104 {
6105 return lhs = lhs * rhs;
6106 }
6107
Nicolas Capens96d4e092016-11-18 14:22:38 -05006108 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006109 {
6110 return lhs = lhs / rhs;
6111 }
6112
Nicolas Capens96d4e092016-11-18 14:22:38 -05006113 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006114 {
6115 return lhs = lhs % rhs;
6116 }
6117
6118 RValue<Float4> operator+(RValue<Float4> val)
6119 {
6120 return val;
6121 }
6122
6123 RValue<Float4> operator-(RValue<Float4> val)
6124 {
6125 return RValue<Float4>(Nucleus::createFNeg(val.value));
6126 }
6127
6128 RValue<Float4> Abs(RValue<Float4> x)
6129 {
Nicolas Capens84272242016-11-09 13:31:06 -05006130 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6131 int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
6132 Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
6133
6134 return As<Float4>(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006135 }
6136
6137 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
6138 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006139 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006140 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ogt, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006141 ::basicBlock->appendInst(cmp);
6142
6143 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006144 auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006145 ::basicBlock->appendInst(select);
6146
6147 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006148 }
6149
6150 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
6151 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006152 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006153 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Olt, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006154 ::basicBlock->appendInst(cmp);
6155
6156 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006157 auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006158 ::basicBlock->appendInst(select);
6159
6160 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006161 }
6162
6163 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
6164 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006165 return Float4(1.0f) / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04006166 }
6167
6168 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
6169 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006170 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006171 }
6172
6173 RValue<Float4> Sqrt(RValue<Float4> x)
6174 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006175 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6176 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6177 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6178 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6179 sqrt->addArg(x.value);
6180 ::basicBlock->appendInst(sqrt);
6181
6182 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006183 }
6184
Nicolas Capensc94ab742016-11-08 15:15:31 -05006185 RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006186 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05006187 return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006188 }
6189
6190 RValue<Float> Extract(RValue<Float4> x, int i)
6191 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006192 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006193 }
6194
6195 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
6196 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006197 return RValue<Float4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006198 }
6199
6200 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
6201 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006202 int shuffle[4] =
6203 {
6204 ((imm >> 0) & 0x03) + 0,
6205 ((imm >> 2) & 0x03) + 0,
6206 ((imm >> 4) & 0x03) + 4,
6207 ((imm >> 6) & 0x03) + 4,
6208 };
6209
6210 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006211 }
6212
6213 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
6214 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006215 int shuffle[4] = {0, 4, 1, 5};
6216 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006217 }
6218
6219 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
6220 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006221 int shuffle[4] = {2, 6, 3, 7};
6222 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006223 }
6224
6225 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
6226 {
6227 Value *vector = lhs.loadValue();
Nicolas Capensa4c30b02016-11-08 15:43:17 -05006228 Value *result = createMask4(vector, rhs.value, select);
6229 lhs.storeValue(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006230
Nicolas Capensa4c30b02016-11-08 15:43:17 -05006231 return RValue<Float4>(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006232 }
6233
6234 RValue<Int> SignMask(RValue<Float4> x)
6235 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04006236 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
6237 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6238 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6239 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6240 movmsk->addArg(x.value);
6241 ::basicBlock->appendInst(movmsk);
6242
6243 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006244 }
6245
6246 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
6247 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006248 return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006249 }
6250
6251 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
6252 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006253 return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006254 }
6255
6256 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
6257 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006258 return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006259 }
6260
6261 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
6262 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006263 return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006264 }
6265
6266 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
6267 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006268 return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006269 }
6270
6271 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
6272 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006273 return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006274 }
6275
6276 RValue<Float4> Round(RValue<Float4> x)
6277 {
Nicolas Capensf7b75882017-04-26 09:30:47 -04006278 if(emulateIntrinsics)
6279 {
6280 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
6281 return (x + Float4(0x00C00000)) - Float4(0x00C00000);
6282 }
6283 else if(CPUID::SSE4_1)
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006284 {
6285 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6286 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6287 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6288 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6289 round->addArg(x.value);
6290 round->addArg(::context->getConstantInt32(0));
6291 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006292
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006293 return RValue<Float4>(V(result));
6294 }
6295 else
6296 {
6297 return Float4(RoundInt(x));
6298 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006299 }
6300
6301 RValue<Float4> Trunc(RValue<Float4> x)
6302 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006303 if(CPUID::SSE4_1)
6304 {
6305 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6306 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6307 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6308 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6309 round->addArg(x.value);
6310 round->addArg(::context->getConstantInt32(3));
6311 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006312
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006313 return RValue<Float4>(V(result));
6314 }
6315 else
6316 {
6317 return Float4(Int4(x));
6318 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006319 }
6320
6321 RValue<Float4> Frac(RValue<Float4> x)
6322 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006323 if(CPUID::SSE4_1)
6324 {
6325 return x - Floor(x);
6326 }
6327 else
6328 {
6329 Float4 frc = x - Float4(Int4(x)); // Signed fractional part
6330
6331 return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1)));
6332 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006333 }
6334
6335 RValue<Float4> Floor(RValue<Float4> x)
6336 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006337 if(CPUID::SSE4_1)
6338 {
6339 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6340 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6341 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6342 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6343 round->addArg(x.value);
6344 round->addArg(::context->getConstantInt32(1));
6345 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006346
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006347 return RValue<Float4>(V(result));
6348 }
6349 else
6350 {
6351 return x - Frac(x);
6352 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006353 }
6354
6355 RValue<Float4> Ceil(RValue<Float4> x)
6356 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006357 if(CPUID::SSE4_1)
6358 {
6359 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6360 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6361 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6362 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6363 round->addArg(x.value);
6364 round->addArg(::context->getConstantInt32(2));
6365 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006366
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006367 return RValue<Float4>(V(result));
6368 }
6369 else
6370 {
6371 return -Floor(-x);
6372 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006373 }
6374
6375 Type *Float4::getType()
6376 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04006377 return T(Ice::IceType_v4f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006378 }
6379
6380 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
6381 {
Nicolas Capens8820f642016-09-30 04:42:43 -04006382 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006383 }
6384
6385 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6386 {
Nicolas Capensd294def2017-01-26 17:44:37 -08006387 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006388 }
6389
6390 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6391 {
Nicolas Capensd294def2017-01-26 17:44:37 -08006392 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006393 }
6394
Nicolas Capens96d4e092016-11-18 14:22:38 -05006395 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006396 {
6397 return lhs = lhs + offset;
6398 }
6399
Nicolas Capens96d4e092016-11-18 14:22:38 -05006400 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006401 {
6402 return lhs = lhs + offset;
6403 }
6404
Nicolas Capens96d4e092016-11-18 14:22:38 -05006405 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006406 {
6407 return lhs = lhs + offset;
6408 }
6409
6410 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
6411 {
6412 return lhs + -offset;
6413 }
6414
6415 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6416 {
6417 return lhs + -offset;
6418 }
6419
6420 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6421 {
6422 return lhs + -offset;
6423 }
6424
Nicolas Capens96d4e092016-11-18 14:22:38 -05006425 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006426 {
6427 return lhs = lhs - offset;
6428 }
6429
Nicolas Capens96d4e092016-11-18 14:22:38 -05006430 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006431 {
6432 return lhs = lhs - offset;
6433 }
6434
Nicolas Capens96d4e092016-11-18 14:22:38 -05006435 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006436 {
6437 return lhs = lhs - offset;
6438 }
6439
6440 void Return()
6441 {
6442 Nucleus::createRetVoid();
6443 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6444 Nucleus::createUnreachable();
6445 }
6446
Nicolas Capenseb253d02016-11-18 14:40:40 -05006447 void Return(RValue<Int> ret)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006448 {
Nicolas Capenseb253d02016-11-18 14:40:40 -05006449 Nucleus::createRet(ret.value);
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006450 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6451 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006452 }
6453
Nicolas Capensf4eec2f2017-05-24 15:46:48 -04006454 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006455 {
6456 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
6457 Nucleus::setInsertBlock(bodyBB);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006458 }
6459
Nicolas Capens598f8d82016-09-26 15:09:10 -04006460 RValue<Long> Ticks()
6461 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006462 assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006463 }
6464}