blob: aeed845e88efe8f432c1a8c74fa6902a975a242d [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 {
Nicolas Capens619a8c52017-07-05 14:10:46 -0400562 delete ::routine;
563
Nicolas Capens598f8d82016-09-26 15:09:10 -0400564 delete ::allocator;
565 delete ::function;
566 delete ::context;
567
568 delete ::elfFile;
569 delete ::out;
570
571 ::codegenMutex.unlock();
572 }
573
574 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
575 {
576 if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
577 {
578 createRetVoid();
579 }
580
581 std::wstring wideName(name);
582 std::string asciiName(wideName.begin(), wideName.end());
583 ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
584
Nicolas Capens2ae9d742016-11-24 14:43:05 -0500585 optimize();
586
Nicolas Capens598f8d82016-09-26 15:09:10 -0400587 ::function->translate();
Nicolas Capensde19f392016-10-19 10:29:49 -0400588 assert(!::function->hasError());
589
Nicolas Capens66478362016-10-13 15:36:36 -0400590 auto *globals = ::function->getGlobalInits().release();
591
592 if(globals && !globals->empty())
593 {
594 ::context->getGlobals()->merge(globals);
595 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400596
597 ::context->emitFileHeader();
598 ::function->emitIAS();
599 auto assembler = ::function->releaseAssembler();
Nicolas Capens66478362016-10-13 15:36:36 -0400600 auto objectWriter = ::context->getObjectWriter();
601 assembler->alignFunction();
602 objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
603 ::context->lowerGlobals("last");
Nicolas Capens73dd7a22016-10-20 13:20:34 -0400604 ::context->lowerConstants();
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500605 ::context->lowerJumpTables();
Nicolas Capens66478362016-10-13 15:36:36 -0400606 objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
607 objectWriter->writeNonUserSections();
Nicolas Capens598f8d82016-09-26 15:09:10 -0400608
Nicolas Capens619a8c52017-07-05 14:10:46 -0400609 Routine *handoffRoutine = ::routine;
610 ::routine = nullptr;
611
612 return handoffRoutine;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400613 }
614
615 void Nucleus::optimize()
616 {
Nicolas Capens2ae9d742016-11-24 14:43:05 -0500617 sw::optimize(::function);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400618 }
619
620 Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
621 {
622 Ice::Type type = T(t);
Nicolas Capensa8f98632016-10-20 11:25:55 -0400623 int typeSize = Ice::typeWidthInBytes(type);
624 int totalSize = typeSize * (arraySize ? arraySize : 1);
Nicolas Capense12780d2016-09-27 14:18:07 -0400625
Nicolas Capensa8f98632016-10-20 11:25:55 -0400626 auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400627 auto address = ::function->makeVariable(T(getPointerType(t)));
Nicolas Capensa8f98632016-10-20 11:25:55 -0400628 auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400629 ::function->getEntryNode()->getInsts().push_front(alloca);
630
631 return V(address);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400632 }
633
634 BasicBlock *Nucleus::createBasicBlock()
635 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400636 return B(::function->makeNode());
Nicolas Capens598f8d82016-09-26 15:09:10 -0400637 }
638
639 BasicBlock *Nucleus::getInsertBlock()
640 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400641 return B(::basicBlock);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400642 }
643
644 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
645 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -0400646 // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator");
Nicolas Capens611642a2016-09-28 16:45:04 -0400647 ::basicBlock = basicBlock;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400648 }
649
Nicolas Capens598f8d82016-09-26 15:09:10 -0400650 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
651 {
652 uint32_t sequenceNumber = 0;
653 ::function = Ice::Cfg::create(::context, sequenceNumber).release();
654 ::allocator = new Ice::CfgLocalAllocatorScope(::function);
655
656 for(Type *type : Params)
657 {
658 Ice::Variable *arg = ::function->makeVariable(T(type));
659 ::function->addArg(arg);
660 }
661
662 Ice::CfgNode *node = ::function->makeNode();
663 ::function->setEntryNode(node);
664 ::basicBlock = node;
665 }
666
667 Value *Nucleus::getArgument(unsigned int index)
668 {
669 return V(::function->getArgs()[index]);
670 }
671
672 void Nucleus::createRetVoid()
673 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400674 Ice::InstRet *ret = Ice::InstRet::create(::function);
675 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400676 }
677
678 void Nucleus::createRet(Value *v)
679 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400680 Ice::InstRet *ret = Ice::InstRet::create(::function, v);
681 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400682 }
683
684 void Nucleus::createBr(BasicBlock *dest)
685 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400686 auto br = Ice::InstBr::create(::function, dest);
687 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400688 }
689
690 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
691 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400692 auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse);
693 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400694 }
695
Nicolas Capensf8360ba2017-01-25 11:35:00 -0800696 static bool isCommutative(Ice::InstArithmetic::OpKind op)
697 {
698 switch(op)
699 {
700 case Ice::InstArithmetic::Add:
701 case Ice::InstArithmetic::Fadd:
702 case Ice::InstArithmetic::Mul:
703 case Ice::InstArithmetic::Fmul:
704 case Ice::InstArithmetic::And:
705 case Ice::InstArithmetic::Or:
706 case Ice::InstArithmetic::Xor:
707 return true;
708 default:
709 return false;
710 }
711 }
712
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400713 static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
714 {
Nicolas Capens327f1df2016-10-21 14:26:34 -0400715 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 -0400716
Nicolas Capensf8360ba2017-01-25 11:35:00 -0800717 bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op);
718
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400719 Ice::Variable *result = ::function->makeVariable(lhs->getType());
Nicolas Capensf8360ba2017-01-25 11:35:00 -0800720 Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, swapOperands ? rhs : lhs, swapOperands ? lhs : rhs);
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400721 ::basicBlock->appendInst(arithmetic);
722
723 return V(result);
724 }
725
Nicolas Capens598f8d82016-09-26 15:09:10 -0400726 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
727 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400728 return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400729 }
730
731 Value *Nucleus::createSub(Value *lhs, Value *rhs)
732 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400733 return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400734 }
735
736 Value *Nucleus::createMul(Value *lhs, Value *rhs)
737 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400738 return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400739 }
740
741 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
742 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400743 return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400744 }
745
746 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
747 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400748 return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400749 }
750
751 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
752 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400753 return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400754 }
755
756 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
757 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400758 return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400759 }
760
761 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
762 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400763 return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400764 }
765
766 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
767 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400768 return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400769 }
770
771 Value *Nucleus::createURem(Value *lhs, Value *rhs)
772 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400773 return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400774 }
775
776 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
777 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400778 return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400779 }
780
781 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
782 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400783 return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400784 }
785
786 Value *Nucleus::createShl(Value *lhs, Value *rhs)
787 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400788 return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400789 }
790
791 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
792 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400793 return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400794 }
795
796 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
797 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400798 return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400799 }
800
801 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
802 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400803 return createArithmetic(Ice::InstArithmetic::And, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400804 }
805
806 Value *Nucleus::createOr(Value *lhs, Value *rhs)
807 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400808 return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400809 }
810
811 Value *Nucleus::createXor(Value *lhs, Value *rhs)
812 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400813 return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400814 }
815
816 Value *Nucleus::createNeg(Value *v)
817 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500818 return createSub(createNullValue(T(v->getType())), v);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400819 }
820
821 Value *Nucleus::createFNeg(Value *v)
822 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500823 double c[4] = {-0.0, -0.0, -0.0, -0.0};
824 Value *negativeZero = Ice::isVectorType(v->getType()) ?
825 createConstantVector(c, T(v->getType())) :
Nicolas Capens15060bb2016-12-05 22:17:19 -0500826 V(::context->getConstantFloat(-0.0f));
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500827
828 return createFSub(negativeZero, v);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400829 }
830
831 Value *Nucleus::createNot(Value *v)
832 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500833 if(Ice::isScalarIntegerType(v->getType()))
834 {
Nicolas Capens15060bb2016-12-05 22:17:19 -0500835 return createXor(v, V(::context->getConstantInt(v->getType(), -1)));
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500836 }
837 else // Vector
838 {
Nicolas Capensf34d1ac2017-05-08 17:06:11 -0400839 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 -0500840 return createXor(v, createConstantVector(c, T(v->getType())));
841 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400842 }
843
Nicolas Capense12780d2016-09-27 14:18:07 -0400844 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400845 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400846 int valueType = (int)reinterpret_cast<intptr_t>(type);
847 Ice::Variable *result = ::function->makeVariable(T(type));
848
849 if(valueType & EmulatedBits)
850 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800851 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
852 auto target = ::context->getConstantUndef(Ice::IceType_i32);
853 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
854 load->addArg(ptr);
855 load->addArg(::context->getConstantInt32(typeSize(type)));
856 ::basicBlock->appendInst(load);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400857 }
858 else
859 {
860 auto load = Ice::InstLoad::create(::function, result, ptr, align);
861 ::basicBlock->appendInst(load);
862 }
863
864 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400865 }
866
Nicolas Capens6d738712016-09-30 04:15:22 -0400867 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400868 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400869 int valueType = (int)reinterpret_cast<intptr_t>(type);
870
871 if(valueType & EmulatedBits)
872 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800873 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
874 auto target = ::context->getConstantUndef(Ice::IceType_i32);
875 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
876 store->addArg(value);
877 store->addArg(ptr);
878 store->addArg(::context->getConstantInt32(typeSize(type)));
879 ::basicBlock->appendInst(store);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400880 }
881 else
882 {
883 assert(T(value->getType()) == type);
884
885 auto store = Ice::InstStore::create(::function, value, ptr, align);
886 ::basicBlock->appendInst(store);
887 }
888
Nicolas Capens598f8d82016-09-26 15:09:10 -0400889 return value;
890 }
891
Nicolas Capensd294def2017-01-26 17:44:37 -0800892 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400893 {
Nicolas Capens8820f642016-09-30 04:42:43 -0400894 assert(index->getType() == Ice::IceType_i32);
895
Nicolas Capens15060bb2016-12-05 22:17:19 -0500896 if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index))
897 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800898 int32_t offset = constant->getValue() * (int)typeSize(type);
Nicolas Capens15060bb2016-12-05 22:17:19 -0500899
900 if(offset == 0)
901 {
902 return ptr;
903 }
904
905 return createAdd(ptr, createConstantInt(offset));
906 }
907
Nicolas Capens8820f642016-09-30 04:42:43 -0400908 if(!Ice::isByteSizedType(T(type)))
909 {
Nicolas Capens584088c2017-01-26 16:05:18 -0800910 index = createMul(index, createConstantInt((int)typeSize(type)));
Nicolas Capens8820f642016-09-30 04:42:43 -0400911 }
912
913 if(sizeof(void*) == 8)
914 {
Nicolas Capensd294def2017-01-26 17:44:37 -0800915 if(unsignedIndex)
916 {
917 index = createZExt(index, T(Ice::IceType_i64));
918 }
919 else
920 {
921 index = createSExt(index, T(Ice::IceType_i64));
922 }
Nicolas Capens8820f642016-09-30 04:42:43 -0400923 }
924
925 return createAdd(ptr, index);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400926 }
927
928 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
929 {
930 assert(false && "UNIMPLEMENTED"); return nullptr;
931 }
932
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400933 static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType)
934 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400935 if(v->getType() == T(destType))
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400936 {
937 return v;
938 }
939
940 Ice::Variable *result = ::function->makeVariable(T(destType));
941 Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v);
942 ::basicBlock->appendInst(cast);
943
944 return V(result);
945 }
946
Nicolas Capens598f8d82016-09-26 15:09:10 -0400947 Value *Nucleus::createTrunc(Value *v, Type *destType)
948 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400949 return createCast(Ice::InstCast::Trunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400950 }
951
952 Value *Nucleus::createZExt(Value *v, Type *destType)
953 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400954 return createCast(Ice::InstCast::Zext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400955 }
956
957 Value *Nucleus::createSExt(Value *v, Type *destType)
958 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400959 return createCast(Ice::InstCast::Sext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400960 }
961
962 Value *Nucleus::createFPToSI(Value *v, Type *destType)
963 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400964 return createCast(Ice::InstCast::Fptosi, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400965 }
966
Nicolas Capens598f8d82016-09-26 15:09:10 -0400967 Value *Nucleus::createSIToFP(Value *v, Type *destType)
968 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400969 return createCast(Ice::InstCast::Sitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400970 }
971
972 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
973 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400974 return createCast(Ice::InstCast::Fptrunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400975 }
976
977 Value *Nucleus::createFPExt(Value *v, Type *destType)
978 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400979 return createCast(Ice::InstCast::Fpext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400980 }
981
982 Value *Nucleus::createBitCast(Value *v, Type *destType)
983 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400984 return createCast(Ice::InstCast::Bitcast, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400985 }
986
Nicolas Capens43dc6292016-10-20 00:01:38 -0400987 static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400988 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400989 assert(lhs->getType() == rhs->getType());
990
Nicolas Capens43dc6292016-10-20 00:01:38 -0400991 auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType());
992 auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs);
Nicolas Capens611642a2016-09-28 16:45:04 -0400993 ::basicBlock->appendInst(cmp);
994
995 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400996 }
997
Nicolas Capens43dc6292016-10-20 00:01:38 -0400998 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
999 {
1000 return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs);
1001 }
1002
1003 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
1004 {
1005 return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs);
1006 }
1007
1008 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
1009 {
1010 return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs);
1011 }
1012
1013 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
1014 {
1015 return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs);
1016 }
1017
1018 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
1019 {
1020 return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs);
1021 }
1022
1023 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
1024 {
1025 return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs);
1026 }
1027
1028 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
1029 {
1030 return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs);
1031 }
1032
1033 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
1034 {
1035 return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs);
1036 }
1037
1038 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
1039 {
1040 return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs);
1041 }
1042
Nicolas Capens598f8d82016-09-26 15:09:10 -04001043 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
1044 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001045 return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs);
1046 }
1047
1048 static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs)
1049 {
1050 assert(lhs->getType() == rhs->getType());
1051 assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32);
1052
1053 auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32);
1054 auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs);
1055 ::basicBlock->appendInst(cmp);
1056
1057 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001058 }
1059
1060 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
1061 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001062 return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001063 }
1064
1065 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
1066 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001067 return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001068 }
1069
1070 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
1071 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001072 return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001073 }
1074
1075 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
1076 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001077 return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001078 }
1079
1080 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
1081 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001082 return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001083 }
1084
1085 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
1086 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001087 return createFloatCompare(Ice::InstFcmp::One, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001088 }
1089
1090 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
1091 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001092 return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001093 }
1094
1095 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
1096 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001097 return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001098 }
1099
1100 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
1101 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001102 return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001103 }
1104
1105 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
1106 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001107 return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001108 }
1109
1110 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
1111 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001112 return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001113 }
1114
1115 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
1116 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001117 return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001118 }
1119
1120 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
1121 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001122 return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001123 }
1124
1125 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
1126 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001127 return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001128 }
1129
Nicolas Capense95d5342016-09-30 11:37:28 -04001130 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001131 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001132 auto result = ::function->makeVariable(T(type));
1133 auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index));
1134 ::basicBlock->appendInst(extract);
1135
1136 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001137 }
1138
1139 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
1140 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001141 auto result = ::function->makeVariable(vector->getType());
1142 auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index));
1143 ::basicBlock->appendInst(insert);
1144
1145 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001146 }
1147
Nicolas Capense89cd582016-09-30 14:23:47 -04001148 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001149 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001150 assert(V1->getType() == V2->getType());
1151
1152 int size = Ice::typeNumElements(V1->getType());
1153 auto result = ::function->makeVariable(V1->getType());
1154 auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2);
1155
1156 for(int i = 0; i < size; i++)
1157 {
1158 shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i])));
1159 }
1160
1161 ::basicBlock->appendInst(shuffle);
1162
1163 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001164 }
1165
1166 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
1167 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04001168 assert(ifTrue->getType() == ifFalse->getType());
1169
1170 auto result = ::function->makeVariable(ifTrue->getType());
1171 auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse);
1172 ::basicBlock->appendInst(select);
1173
1174 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001175 }
1176
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001177 SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001178 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001179 auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch);
1180 ::basicBlock->appendInst(switchInst);
1181
1182 return reinterpret_cast<SwitchCases*>(switchInst);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001183 }
1184
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001185 void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001186 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001187 switchCases->addBranch(label, label, branch);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001188 }
1189
1190 void Nucleus::createUnreachable()
1191 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04001192 Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function);
1193 ::basicBlock->appendInst(unreachable);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001194 }
1195
Nicolas Capense95d5342016-09-30 11:37:28 -04001196 static Value *createSwizzle4(Value *val, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001197 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001198 int swizzle[4] =
1199 {
1200 (select >> 0) & 0x03,
1201 (select >> 2) & 0x03,
1202 (select >> 4) & 0x03,
1203 (select >> 6) & 0x03,
1204 };
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001205
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001206 return Nucleus::createShuffleVector(val, val, swizzle);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001207 }
1208
Nicolas Capense95d5342016-09-30 11:37:28 -04001209 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001210 {
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001211 int64_t mask[4] = {0, 0, 0, 0};
1212
1213 mask[(select >> 0) & 0x03] = -1;
1214 mask[(select >> 2) & 0x03] = -1;
1215 mask[(select >> 4) & 0x03] = -1;
1216 mask[(select >> 6) & 0x03] = -1;
1217
1218 Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1));
1219 Value *result = Nucleus::createSelect(condition, rhs, lhs);
1220
1221 return result;
Nicolas Capens598f8d82016-09-26 15:09:10 -04001222 }
1223
Nicolas Capens598f8d82016-09-26 15:09:10 -04001224 Type *Nucleus::getPointerType(Type *ElementType)
1225 {
Nicolas Capense12780d2016-09-27 14:18:07 -04001226 if(sizeof(void*) == 8)
1227 {
1228 return T(Ice::IceType_i64);
1229 }
1230 else
1231 {
1232 return T(Ice::IceType_i32);
1233 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001234 }
1235
Nicolas Capens13ac2322016-10-13 14:52:12 -04001236 Value *Nucleus::createNullValue(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001237 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001238 if(Ice::isVectorType(T(Ty)))
1239 {
Nicolas Capens30385f02017-04-18 13:03:47 -04001240 assert(Ice::typeNumElements(T(Ty)) <= 16);
1241 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 -04001242 return createConstantVector(c, Ty);
1243 }
1244 else
1245 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001246 return V(::context->getConstantZero(T(Ty)));
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001247 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001248 }
1249
Nicolas Capens13ac2322016-10-13 14:52:12 -04001250 Value *Nucleus::createConstantLong(int64_t i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001251 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001252 return V(::context->getConstantInt64(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001253 }
1254
Nicolas Capens13ac2322016-10-13 14:52:12 -04001255 Value *Nucleus::createConstantInt(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::createConstantInt(unsigned int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001261 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001262 return V(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001263 }
1264
Nicolas Capens13ac2322016-10-13 14:52:12 -04001265 Value *Nucleus::createConstantBool(bool b)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001266 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001267 return V(::context->getConstantInt1(b));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001268 }
1269
Nicolas Capens13ac2322016-10-13 14:52:12 -04001270 Value *Nucleus::createConstantByte(signed 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::createConstantByte(unsigned char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001276 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001277 return V(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001278 }
1279
Nicolas Capens13ac2322016-10-13 14:52:12 -04001280 Value *Nucleus::createConstantShort(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::createConstantShort(unsigned short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001286 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001287 return V(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001288 }
1289
Nicolas Capens13ac2322016-10-13 14:52:12 -04001290 Value *Nucleus::createConstantFloat(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001291 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001292 return V(::context->getConstantFloat(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001293 }
1294
Nicolas Capens13ac2322016-10-13 14:52:12 -04001295 Value *Nucleus::createNullPointer(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001296 {
Nicolas Capensa29d6532016-12-05 21:38:09 -05001297 return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001298 }
1299
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001300 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
Nicolas Capens13ac2322016-10-13 14:52:12 -04001301 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001302 const int vectorSize = 16;
1303 assert(Ice::typeWidthInBytes(T(type)) == vectorSize);
1304 const int alignment = vectorSize;
1305 auto globalPool = ::function->getGlobalPool();
1306
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001307 const int64_t *i = constants;
1308 const double *f = reinterpret_cast<const double*>(constants);
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001309 Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr;
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001310
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001311 switch((int)reinterpret_cast<intptr_t>(type))
1312 {
1313 case Ice::IceType_v4i32:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001314 case Ice::IceType_v4i1:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001315 {
1316 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]};
1317 static_assert(sizeof(initializer) == vectorSize, "!");
1318 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1319 }
1320 break;
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001321 case Ice::IceType_v4f32:
1322 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001323 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001324 static_assert(sizeof(initializer) == vectorSize, "!");
1325 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1326 }
1327 break;
1328 case Ice::IceType_v8i16:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001329 case Ice::IceType_v8i1:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001330 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001331 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 -04001332 static_assert(sizeof(initializer) == vectorSize, "!");
1333 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1334 }
1335 break;
1336 case Ice::IceType_v16i8:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001337 case Ice::IceType_v16i1:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001338 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001339 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 -04001340 static_assert(sizeof(initializer) == vectorSize, "!");
1341 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1342 }
1343 break;
1344 case Type_v2i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001345 {
1346 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]};
1347 static_assert(sizeof(initializer) == vectorSize, "!");
1348 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1349 }
1350 break;
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001351 case Type_v2f32:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001352 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001353 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001354 static_assert(sizeof(initializer) == vectorSize, "!");
1355 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1356 }
1357 break;
1358 case Type_v4i16:
1359 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001360 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 -04001361 static_assert(sizeof(initializer) == vectorSize, "!");
1362 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1363 }
1364 break;
1365 case Type_v8i8:
1366 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001367 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 -04001368 static_assert(sizeof(initializer) == vectorSize, "!");
1369 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1370 }
1371 break;
1372 case Type_v4i8:
1373 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001374 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 -04001375 static_assert(sizeof(initializer) == vectorSize, "!");
1376 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1377 }
1378 break;
1379 default:
1380 assert(false && "Unknown constant vector type" && type);
1381 }
1382
1383 auto name = Ice::GlobalString::createWithoutString(::context);
1384 auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool);
1385 variableDeclaration->setName(name);
1386 variableDeclaration->setAlignment(alignment);
1387 variableDeclaration->setIsConstant(true);
1388 variableDeclaration->addInitializer(dataInitializer);
Nicolas Capens87852e12016-11-24 14:45:06 -05001389
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001390 ::function->addGlobal(variableDeclaration);
1391
1392 constexpr int32_t offset = 0;
1393 Ice::Operand *ptr = ::context->getConstantSym(offset, name);
1394
1395 Ice::Variable *result = ::function->makeVariable(T(type));
1396 auto load = Ice::InstLoad::create(::function, result, ptr, alignment);
1397 ::basicBlock->appendInst(load);
1398
1399 return V(result);
Nicolas Capens13ac2322016-10-13 14:52:12 -04001400 }
1401
1402 Value *Nucleus::createConstantVector(const double *constants, Type *type)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001403 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001404 return createConstantVector((const int64_t*)constants, type);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001405 }
1406
1407 Type *Void::getType()
1408 {
1409 return T(Ice::IceType_void);
1410 }
1411
Nicolas Capens598f8d82016-09-26 15:09:10 -04001412 Bool::Bool(Argument<Bool> argument)
1413 {
1414 storeValue(argument.value);
1415 }
1416
Nicolas Capens598f8d82016-09-26 15:09:10 -04001417 Bool::Bool(bool x)
1418 {
1419 storeValue(Nucleus::createConstantBool(x));
1420 }
1421
1422 Bool::Bool(RValue<Bool> rhs)
1423 {
1424 storeValue(rhs.value);
1425 }
1426
1427 Bool::Bool(const Bool &rhs)
1428 {
1429 Value *value = rhs.loadValue();
1430 storeValue(value);
1431 }
1432
1433 Bool::Bool(const Reference<Bool> &rhs)
1434 {
1435 Value *value = rhs.loadValue();
1436 storeValue(value);
1437 }
1438
Nicolas Capens96d4e092016-11-18 14:22:38 -05001439 RValue<Bool> Bool::operator=(RValue<Bool> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001440 {
1441 storeValue(rhs.value);
1442
1443 return rhs;
1444 }
1445
Nicolas Capens96d4e092016-11-18 14:22:38 -05001446 RValue<Bool> Bool::operator=(const Bool &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001447 {
1448 Value *value = rhs.loadValue();
1449 storeValue(value);
1450
1451 return RValue<Bool>(value);
1452 }
1453
Nicolas Capens96d4e092016-11-18 14:22:38 -05001454 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001455 {
1456 Value *value = rhs.loadValue();
1457 storeValue(value);
1458
1459 return RValue<Bool>(value);
1460 }
1461
1462 RValue<Bool> operator!(RValue<Bool> val)
1463 {
1464 return RValue<Bool>(Nucleus::createNot(val.value));
1465 }
1466
1467 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
1468 {
1469 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1470 }
1471
1472 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
1473 {
1474 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1475 }
1476
1477 Type *Bool::getType()
1478 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001479 return T(Ice::IceType_i1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001480 }
1481
1482 Byte::Byte(Argument<Byte> argument)
1483 {
1484 storeValue(argument.value);
1485 }
1486
1487 Byte::Byte(RValue<Int> cast)
1488 {
1489 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1490
1491 storeValue(integer);
1492 }
1493
1494 Byte::Byte(RValue<UInt> cast)
1495 {
1496 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1497
1498 storeValue(integer);
1499 }
1500
1501 Byte::Byte(RValue<UShort> cast)
1502 {
1503 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1504
1505 storeValue(integer);
1506 }
1507
Nicolas Capens598f8d82016-09-26 15:09:10 -04001508 Byte::Byte(int x)
1509 {
1510 storeValue(Nucleus::createConstantByte((unsigned char)x));
1511 }
1512
1513 Byte::Byte(unsigned char x)
1514 {
1515 storeValue(Nucleus::createConstantByte(x));
1516 }
1517
1518 Byte::Byte(RValue<Byte> rhs)
1519 {
1520 storeValue(rhs.value);
1521 }
1522
1523 Byte::Byte(const Byte &rhs)
1524 {
1525 Value *value = rhs.loadValue();
1526 storeValue(value);
1527 }
1528
1529 Byte::Byte(const Reference<Byte> &rhs)
1530 {
1531 Value *value = rhs.loadValue();
1532 storeValue(value);
1533 }
1534
Nicolas Capens96d4e092016-11-18 14:22:38 -05001535 RValue<Byte> Byte::operator=(RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001536 {
1537 storeValue(rhs.value);
1538
1539 return rhs;
1540 }
1541
Nicolas Capens96d4e092016-11-18 14:22:38 -05001542 RValue<Byte> Byte::operator=(const Byte &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001543 {
1544 Value *value = rhs.loadValue();
1545 storeValue(value);
1546
1547 return RValue<Byte>(value);
1548 }
1549
Nicolas Capens96d4e092016-11-18 14:22:38 -05001550 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001551 {
1552 Value *value = rhs.loadValue();
1553 storeValue(value);
1554
1555 return RValue<Byte>(value);
1556 }
1557
1558 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
1559 {
1560 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1561 }
1562
1563 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
1564 {
1565 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1566 }
1567
1568 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
1569 {
1570 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1571 }
1572
1573 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
1574 {
1575 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1576 }
1577
1578 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
1579 {
1580 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1581 }
1582
1583 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
1584 {
1585 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1586 }
1587
1588 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
1589 {
1590 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1591 }
1592
1593 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
1594 {
1595 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1596 }
1597
1598 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
1599 {
1600 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1601 }
1602
1603 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
1604 {
1605 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05001653 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001654 {
1655 return lhs = lhs >> rhs;
1656 }
1657
1658 RValue<Byte> operator+(RValue<Byte> val)
1659 {
1660 return val;
1661 }
1662
1663 RValue<Byte> operator-(RValue<Byte> val)
1664 {
1665 return RValue<Byte>(Nucleus::createNeg(val.value));
1666 }
1667
1668 RValue<Byte> operator~(RValue<Byte> val)
1669 {
1670 return RValue<Byte>(Nucleus::createNot(val.value));
1671 }
1672
Nicolas Capens96d4e092016-11-18 14:22:38 -05001673 RValue<Byte> operator++(Byte &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001674 {
1675 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001676 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001677 return res;
1678 }
1679
Nicolas Capens96d4e092016-11-18 14:22:38 -05001680 const Byte &operator++(Byte &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001681 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001682 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001683 return val;
1684 }
1685
Nicolas Capens96d4e092016-11-18 14:22:38 -05001686 RValue<Byte> operator--(Byte &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001687 {
1688 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001689 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001690 return res;
1691 }
1692
Nicolas Capens96d4e092016-11-18 14:22:38 -05001693 const Byte &operator--(Byte &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001694 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001695 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001696 return val;
1697 }
1698
1699 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
1700 {
1701 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1702 }
1703
1704 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
1705 {
1706 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1707 }
1708
1709 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
1710 {
1711 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1712 }
1713
1714 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
1715 {
1716 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1717 }
1718
1719 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
1720 {
1721 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1722 }
1723
1724 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
1725 {
1726 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1727 }
1728
1729 Type *Byte::getType()
1730 {
Nicolas Capens6d738712016-09-30 04:15:22 -04001731 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001732 }
1733
1734 SByte::SByte(Argument<SByte> argument)
1735 {
1736 storeValue(argument.value);
1737 }
1738
1739 SByte::SByte(RValue<Int> cast)
1740 {
1741 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1742
1743 storeValue(integer);
1744 }
1745
1746 SByte::SByte(RValue<Short> cast)
1747 {
1748 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1749
1750 storeValue(integer);
1751 }
1752
Nicolas Capens598f8d82016-09-26 15:09:10 -04001753 SByte::SByte(signed char x)
1754 {
1755 storeValue(Nucleus::createConstantByte(x));
1756 }
1757
1758 SByte::SByte(RValue<SByte> rhs)
1759 {
1760 storeValue(rhs.value);
1761 }
1762
1763 SByte::SByte(const SByte &rhs)
1764 {
1765 Value *value = rhs.loadValue();
1766 storeValue(value);
1767 }
1768
1769 SByte::SByte(const Reference<SByte> &rhs)
1770 {
1771 Value *value = rhs.loadValue();
1772 storeValue(value);
1773 }
1774
Nicolas Capens96d4e092016-11-18 14:22:38 -05001775 RValue<SByte> SByte::operator=(RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001776 {
1777 storeValue(rhs.value);
1778
1779 return rhs;
1780 }
1781
Nicolas Capens96d4e092016-11-18 14:22:38 -05001782 RValue<SByte> SByte::operator=(const SByte &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001783 {
1784 Value *value = rhs.loadValue();
1785 storeValue(value);
1786
1787 return RValue<SByte>(value);
1788 }
1789
Nicolas Capens96d4e092016-11-18 14:22:38 -05001790 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001791 {
1792 Value *value = rhs.loadValue();
1793 storeValue(value);
1794
1795 return RValue<SByte>(value);
1796 }
1797
1798 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
1799 {
1800 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1801 }
1802
1803 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
1804 {
1805 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1806 }
1807
1808 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
1809 {
1810 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1811 }
1812
1813 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
1814 {
1815 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1816 }
1817
1818 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
1819 {
1820 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1821 }
1822
1823 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
1824 {
1825 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1826 }
1827
1828 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
1829 {
1830 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1831 }
1832
1833 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
1834 {
1835 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1836 }
1837
1838 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
1839 {
1840 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1841 }
1842
1843 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
1844 {
1845 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05001893 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001894 {
1895 return lhs = lhs >> rhs;
1896 }
1897
1898 RValue<SByte> operator+(RValue<SByte> val)
1899 {
1900 return val;
1901 }
1902
1903 RValue<SByte> operator-(RValue<SByte> val)
1904 {
1905 return RValue<SByte>(Nucleus::createNeg(val.value));
1906 }
1907
1908 RValue<SByte> operator~(RValue<SByte> val)
1909 {
1910 return RValue<SByte>(Nucleus::createNot(val.value));
1911 }
1912
Nicolas Capens96d4e092016-11-18 14:22:38 -05001913 RValue<SByte> operator++(SByte &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001914 {
1915 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001916 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001917 return res;
1918 }
1919
Nicolas Capens96d4e092016-11-18 14:22:38 -05001920 const SByte &operator++(SByte &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001921 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001922 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001923 return val;
1924 }
1925
Nicolas Capens96d4e092016-11-18 14:22:38 -05001926 RValue<SByte> operator--(SByte &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001927 {
1928 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001929 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001930 return res;
1931 }
1932
Nicolas Capens96d4e092016-11-18 14:22:38 -05001933 const SByte &operator--(SByte &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001934 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001935 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001936 return val;
1937 }
1938
1939 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
1940 {
1941 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1942 }
1943
1944 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
1945 {
1946 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1947 }
1948
1949 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
1950 {
1951 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1952 }
1953
1954 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
1955 {
1956 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1957 }
1958
1959 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
1960 {
1961 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1962 }
1963
1964 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
1965 {
1966 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1967 }
1968
1969 Type *SByte::getType()
1970 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001971 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001972 }
1973
1974 Short::Short(Argument<Short> argument)
1975 {
1976 storeValue(argument.value);
1977 }
1978
1979 Short::Short(RValue<Int> cast)
1980 {
1981 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1982
1983 storeValue(integer);
1984 }
1985
Nicolas Capens598f8d82016-09-26 15:09:10 -04001986 Short::Short(short x)
1987 {
1988 storeValue(Nucleus::createConstantShort(x));
1989 }
1990
1991 Short::Short(RValue<Short> rhs)
1992 {
1993 storeValue(rhs.value);
1994 }
1995
1996 Short::Short(const Short &rhs)
1997 {
1998 Value *value = rhs.loadValue();
1999 storeValue(value);
2000 }
2001
2002 Short::Short(const Reference<Short> &rhs)
2003 {
2004 Value *value = rhs.loadValue();
2005 storeValue(value);
2006 }
2007
Nicolas Capens96d4e092016-11-18 14:22:38 -05002008 RValue<Short> Short::operator=(RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002009 {
2010 storeValue(rhs.value);
2011
2012 return rhs;
2013 }
2014
Nicolas Capens96d4e092016-11-18 14:22:38 -05002015 RValue<Short> Short::operator=(const Short &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002016 {
2017 Value *value = rhs.loadValue();
2018 storeValue(value);
2019
2020 return RValue<Short>(value);
2021 }
2022
Nicolas Capens96d4e092016-11-18 14:22:38 -05002023 RValue<Short> Short::operator=(const Reference<Short> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002024 {
2025 Value *value = rhs.loadValue();
2026 storeValue(value);
2027
2028 return RValue<Short>(value);
2029 }
2030
2031 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
2032 {
2033 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
2034 }
2035
2036 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
2037 {
2038 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
2039 }
2040
2041 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
2042 {
2043 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
2044 }
2045
2046 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
2047 {
2048 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
2049 }
2050
2051 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
2052 {
2053 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
2054 }
2055
2056 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
2057 {
2058 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
2059 }
2060
2061 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
2062 {
2063 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
2064 }
2065
2066 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
2067 {
2068 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
2069 }
2070
2071 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
2072 {
2073 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
2074 }
2075
2076 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
2077 {
2078 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05002126 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002127 {
2128 return lhs = lhs >> rhs;
2129 }
2130
2131 RValue<Short> operator+(RValue<Short> val)
2132 {
2133 return val;
2134 }
2135
2136 RValue<Short> operator-(RValue<Short> val)
2137 {
2138 return RValue<Short>(Nucleus::createNeg(val.value));
2139 }
2140
2141 RValue<Short> operator~(RValue<Short> val)
2142 {
2143 return RValue<Short>(Nucleus::createNot(val.value));
2144 }
2145
Nicolas Capens96d4e092016-11-18 14:22:38 -05002146 RValue<Short> operator++(Short &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002147 {
2148 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002149 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002150 return res;
2151 }
2152
Nicolas Capens96d4e092016-11-18 14:22:38 -05002153 const Short &operator++(Short &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002154 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002155 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002156 return val;
2157 }
2158
Nicolas Capens96d4e092016-11-18 14:22:38 -05002159 RValue<Short> operator--(Short &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002160 {
2161 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002162 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002163 return res;
2164 }
2165
Nicolas Capens96d4e092016-11-18 14:22:38 -05002166 const Short &operator--(Short &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002167 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002168 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002169 return val;
2170 }
2171
2172 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
2173 {
2174 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2175 }
2176
2177 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
2178 {
2179 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2180 }
2181
2182 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
2183 {
2184 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2185 }
2186
2187 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
2188 {
2189 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2190 }
2191
2192 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
2193 {
2194 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2195 }
2196
2197 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
2198 {
2199 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2200 }
2201
2202 Type *Short::getType()
2203 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002204 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002205 }
2206
2207 UShort::UShort(Argument<UShort> argument)
2208 {
2209 storeValue(argument.value);
2210 }
2211
2212 UShort::UShort(RValue<UInt> cast)
2213 {
2214 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2215
2216 storeValue(integer);
2217 }
2218
2219 UShort::UShort(RValue<Int> cast)
2220 {
2221 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2222
2223 storeValue(integer);
2224 }
2225
Nicolas Capens598f8d82016-09-26 15:09:10 -04002226 UShort::UShort(unsigned short x)
2227 {
2228 storeValue(Nucleus::createConstantShort(x));
2229 }
2230
2231 UShort::UShort(RValue<UShort> rhs)
2232 {
2233 storeValue(rhs.value);
2234 }
2235
2236 UShort::UShort(const UShort &rhs)
2237 {
2238 Value *value = rhs.loadValue();
2239 storeValue(value);
2240 }
2241
2242 UShort::UShort(const Reference<UShort> &rhs)
2243 {
2244 Value *value = rhs.loadValue();
2245 storeValue(value);
2246 }
2247
Nicolas Capens96d4e092016-11-18 14:22:38 -05002248 RValue<UShort> UShort::operator=(RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002249 {
2250 storeValue(rhs.value);
2251
2252 return rhs;
2253 }
2254
Nicolas Capens96d4e092016-11-18 14:22:38 -05002255 RValue<UShort> UShort::operator=(const UShort &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002256 {
2257 Value *value = rhs.loadValue();
2258 storeValue(value);
2259
2260 return RValue<UShort>(value);
2261 }
2262
Nicolas Capens96d4e092016-11-18 14:22:38 -05002263 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002264 {
2265 Value *value = rhs.loadValue();
2266 storeValue(value);
2267
2268 return RValue<UShort>(value);
2269 }
2270
2271 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
2272 {
2273 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
2274 }
2275
2276 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
2277 {
2278 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
2279 }
2280
2281 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
2282 {
2283 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
2284 }
2285
2286 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
2287 {
2288 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
2289 }
2290
2291 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
2292 {
2293 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
2294 }
2295
2296 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
2297 {
2298 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
2299 }
2300
2301 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
2302 {
2303 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
2304 }
2305
2306 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
2307 {
2308 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
2309 }
2310
2311 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
2312 {
2313 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
2314 }
2315
2316 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
2317 {
2318 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05002366 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002367 {
2368 return lhs = lhs >> rhs;
2369 }
2370
2371 RValue<UShort> operator+(RValue<UShort> val)
2372 {
2373 return val;
2374 }
2375
2376 RValue<UShort> operator-(RValue<UShort> val)
2377 {
2378 return RValue<UShort>(Nucleus::createNeg(val.value));
2379 }
2380
2381 RValue<UShort> operator~(RValue<UShort> val)
2382 {
2383 return RValue<UShort>(Nucleus::createNot(val.value));
2384 }
2385
Nicolas Capens96d4e092016-11-18 14:22:38 -05002386 RValue<UShort> operator++(UShort &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002387 {
2388 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002389 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002390 return res;
2391 }
2392
Nicolas Capens96d4e092016-11-18 14:22:38 -05002393 const UShort &operator++(UShort &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002394 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002395 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002396 return val;
2397 }
2398
Nicolas Capens96d4e092016-11-18 14:22:38 -05002399 RValue<UShort> operator--(UShort &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002400 {
2401 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002402 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002403 return res;
2404 }
2405
Nicolas Capens96d4e092016-11-18 14:22:38 -05002406 const UShort &operator--(UShort &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002407 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002408 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002409 return val;
2410 }
2411
2412 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
2413 {
2414 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2415 }
2416
2417 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
2418 {
2419 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2420 }
2421
2422 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
2423 {
2424 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2425 }
2426
2427 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
2428 {
2429 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2430 }
2431
2432 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
2433 {
2434 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2435 }
2436
2437 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
2438 {
2439 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2440 }
2441
2442 Type *UShort::getType()
2443 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002444 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002445 }
2446
Nicolas Capens16b5f152016-10-13 13:39:01 -04002447 Byte4::Byte4(RValue<Byte8> cast)
2448 {
Nicolas Capens16b5f152016-10-13 13:39:01 -04002449 storeValue(Nucleus::createBitCast(cast.value, getType()));
2450 }
2451
2452 Byte4::Byte4(const Reference<Byte4> &rhs)
2453 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002454 Value *value = rhs.loadValue();
2455 storeValue(value);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002456 }
2457
Nicolas Capens598f8d82016-09-26 15:09:10 -04002458 Type *Byte4::getType()
2459 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002460 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002461 }
2462
2463 Type *SByte4::getType()
2464 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002465 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002466 }
2467
Nicolas Capens598f8d82016-09-26 15:09:10 -04002468 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)
2469 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002470 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
2471 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002472 }
2473
2474 Byte8::Byte8(RValue<Byte8> rhs)
2475 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002476 storeValue(rhs.value);
2477 }
2478
2479 Byte8::Byte8(const Byte8 &rhs)
2480 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002481 Value *value = rhs.loadValue();
2482 storeValue(value);
2483 }
2484
2485 Byte8::Byte8(const Reference<Byte8> &rhs)
2486 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002487 Value *value = rhs.loadValue();
2488 storeValue(value);
2489 }
2490
Nicolas Capens96d4e092016-11-18 14:22:38 -05002491 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002492 {
2493 storeValue(rhs.value);
2494
2495 return rhs;
2496 }
2497
Nicolas Capens96d4e092016-11-18 14:22:38 -05002498 RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002499 {
2500 Value *value = rhs.loadValue();
2501 storeValue(value);
2502
2503 return RValue<Byte8>(value);
2504 }
2505
Nicolas Capens96d4e092016-11-18 14:22:38 -05002506 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002507 {
2508 Value *value = rhs.loadValue();
2509 storeValue(value);
2510
2511 return RValue<Byte8>(value);
2512 }
2513
2514 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
2515 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002516 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002517 }
2518
2519 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
2520 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002521 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002522 }
2523
2524// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2525// {
2526// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2527// }
2528
2529// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2530// {
2531// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2532// }
2533
2534// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2535// {
2536// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2537// }
2538
2539 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
2540 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002541 return RValue<Byte8>(Nucleus::createAnd(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::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002547 }
2548
2549 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
2550 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002551 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
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::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002557// }
2558
2559// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
2560// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002561// return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002562// }
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05002609// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002610// {
2611// return lhs = lhs >> rhs;
2612// }
2613
2614// RValue<Byte8> operator+(RValue<Byte8> val)
2615// {
2616// return val;
2617// }
2618
2619// RValue<Byte8> operator-(RValue<Byte8> val)
2620// {
2621// return RValue<Byte8>(Nucleus::createNeg(val.value));
2622// }
2623
2624 RValue<Byte8> operator~(RValue<Byte8> val)
2625 {
2626 return RValue<Byte8>(Nucleus::createNot(val.value));
2627 }
2628
2629 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
2630 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002631 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2632 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2633 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2634 auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2635 paddusb->addArg(x.value);
2636 paddusb->addArg(y.value);
2637 ::basicBlock->appendInst(paddusb);
2638
2639 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002640 }
2641
2642 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
2643 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002644 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2645 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2646 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2647 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2648 psubusw->addArg(x.value);
2649 psubusw->addArg(y.value);
2650 ::basicBlock->appendInst(psubusw);
2651
2652 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002653 }
2654
2655 RValue<Short4> Unpack(RValue<Byte4> x)
2656 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002657 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2658 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002659 }
2660
Nicolas Capens411273e2017-01-26 15:13:36 -08002661 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
2662 {
2663 return UnpackLow(As<Byte8>(x), As<Byte8>(y));
2664 }
2665
Nicolas Capens598f8d82016-09-26 15:09:10 -04002666 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2667 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002668 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2669 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002670 }
2671
2672 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
2673 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002674 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2675 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2676 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002677 }
2678
2679 RValue<Int> SignMask(RValue<Byte8> x)
2680 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002681 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2682 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2683 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2684 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2685 movmsk->addArg(x.value);
2686 ::basicBlock->appendInst(movmsk);
2687
2688 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002689 }
2690
2691// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
2692// {
Nicolas Capens2f970b62016-11-08 14:28:59 -05002693// return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002694// }
2695
2696 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
2697 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05002698 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002699 }
2700
2701 Type *Byte8::getType()
2702 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002703 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002704 }
2705
Nicolas Capens598f8d82016-09-26 15:09:10 -04002706 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)
2707 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002708 int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
2709 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
2710
2711 storeValue(Nucleus::createBitCast(vector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002712 }
2713
Nicolas Capens598f8d82016-09-26 15:09:10 -04002714 SByte8::SByte8(RValue<SByte8> rhs)
2715 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002716 storeValue(rhs.value);
2717 }
2718
2719 SByte8::SByte8(const SByte8 &rhs)
2720 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002721 Value *value = rhs.loadValue();
2722 storeValue(value);
2723 }
2724
2725 SByte8::SByte8(const Reference<SByte8> &rhs)
2726 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002727 Value *value = rhs.loadValue();
2728 storeValue(value);
2729 }
2730
Nicolas Capens96d4e092016-11-18 14:22:38 -05002731 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002732 {
2733 storeValue(rhs.value);
2734
2735 return rhs;
2736 }
2737
Nicolas Capens96d4e092016-11-18 14:22:38 -05002738 RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002739 {
2740 Value *value = rhs.loadValue();
2741 storeValue(value);
2742
2743 return RValue<SByte8>(value);
2744 }
2745
Nicolas Capens96d4e092016-11-18 14:22:38 -05002746 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002747 {
2748 Value *value = rhs.loadValue();
2749 storeValue(value);
2750
2751 return RValue<SByte8>(value);
2752 }
2753
2754 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
2755 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002756 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002757 }
2758
2759 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
2760 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002761 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002762 }
2763
2764// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2765// {
2766// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2767// }
2768
2769// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2770// {
2771// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2772// }
2773
2774// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2775// {
2776// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2777// }
2778
2779 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
2780 {
2781 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2782 }
2783
2784 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
2785 {
2786 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2787 }
2788
2789 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
2790 {
2791 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2792 }
2793
2794// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
2795// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002796// return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002797// }
2798
2799// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
2800// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002801// return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002802// }
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05002849// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002850// {
2851// return lhs = lhs >> rhs;
2852// }
2853
2854// RValue<SByte8> operator+(RValue<SByte8> val)
2855// {
2856// return val;
2857// }
2858
2859// RValue<SByte8> operator-(RValue<SByte8> val)
2860// {
2861// return RValue<SByte8>(Nucleus::createNeg(val.value));
2862// }
2863
2864 RValue<SByte8> operator~(RValue<SByte8> val)
2865 {
2866 return RValue<SByte8>(Nucleus::createNot(val.value));
2867 }
2868
2869 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
2870 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002871 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2872 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2873 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2874 auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2875 paddsb->addArg(x.value);
2876 paddsb->addArg(y.value);
2877 ::basicBlock->appendInst(paddsb);
2878
2879 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002880 }
2881
2882 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
2883 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002884 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2885 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2886 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2887 auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2888 psubsb->addArg(x.value);
2889 psubsb->addArg(y.value);
2890 ::basicBlock->appendInst(psubsb);
2891
2892 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002893 }
2894
2895 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
2896 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002897 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2898 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002899 }
2900
2901 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
2902 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002903 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2904 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2905 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002906 }
2907
2908 RValue<Int> SignMask(RValue<SByte8> x)
2909 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04002910 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2911 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2912 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2913 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2914 movmsk->addArg(x.value);
2915 ::basicBlock->appendInst(movmsk);
2916
2917 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002918 }
2919
2920 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
2921 {
Nicolas Capens2f970b62016-11-08 14:28:59 -05002922 return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002923 }
2924
2925 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
2926 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05002927 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002928 }
2929
2930 Type *SByte8::getType()
2931 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002932 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002933 }
2934
2935 Byte16::Byte16(RValue<Byte16> rhs)
2936 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002937 storeValue(rhs.value);
2938 }
2939
2940 Byte16::Byte16(const Byte16 &rhs)
2941 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002942 Value *value = rhs.loadValue();
2943 storeValue(value);
2944 }
2945
2946 Byte16::Byte16(const Reference<Byte16> &rhs)
2947 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002948 Value *value = rhs.loadValue();
2949 storeValue(value);
2950 }
2951
Nicolas Capens96d4e092016-11-18 14:22:38 -05002952 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002953 {
2954 storeValue(rhs.value);
2955
2956 return rhs;
2957 }
2958
Nicolas Capens96d4e092016-11-18 14:22:38 -05002959 RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002960 {
2961 Value *value = rhs.loadValue();
2962 storeValue(value);
2963
2964 return RValue<Byte16>(value);
2965 }
2966
Nicolas Capens96d4e092016-11-18 14:22:38 -05002967 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002968 {
2969 Value *value = rhs.loadValue();
2970 storeValue(value);
2971
2972 return RValue<Byte16>(value);
2973 }
2974
2975 Type *Byte16::getType()
2976 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002977 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002978 }
2979
2980 Type *SByte16::getType()
2981 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002982 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002983 }
2984
Nicolas Capens16b5f152016-10-13 13:39:01 -04002985 Short2::Short2(RValue<Short4> cast)
2986 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05002987 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002988 }
2989
2990 Type *Short2::getType()
2991 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002992 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002993 }
2994
2995 UShort2::UShort2(RValue<UShort4> cast)
2996 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05002997 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002998 }
2999
3000 Type *UShort2::getType()
3001 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003002 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04003003 }
3004
Nicolas Capens598f8d82016-09-26 15:09:10 -04003005 Short4::Short4(RValue<Int> cast)
3006 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003007 Value *vector = loadValue();
Nicolas Capensbf22bbf2017-01-13 17:37:45 -05003008 Value *element = Nucleus::createTrunc(cast.value, Short::getType());
3009 Value *insert = Nucleus::createInsertElement(vector, element, 0);
Nicolas Capensd4227962016-11-09 14:24:25 -05003010 Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003011
3012 storeValue(swizzle);
3013 }
3014
3015 Short4::Short4(RValue<Int4> cast)
3016 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08003017 int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
3018 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
3019 Value *packed = Nucleus::createShuffleVector(short8, short8, select);
Nicolas Capensd4227962016-11-09 14:24:25 -05003020
3021 Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
3022 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
3023
3024 storeValue(short4);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003025 }
3026
3027// Short4::Short4(RValue<Float> cast)
3028// {
3029// }
3030
3031 Short4::Short4(RValue<Float4> cast)
3032 {
3033 assert(false && "UNIMPLEMENTED");
3034 }
3035
Nicolas Capens598f8d82016-09-26 15:09:10 -04003036 Short4::Short4(short xyzw)
3037 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003038 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3039 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003040 }
3041
3042 Short4::Short4(short x, short y, short z, short w)
3043 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003044 int64_t constantVector[4] = {x, y, z, w};
3045 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003046 }
3047
3048 Short4::Short4(RValue<Short4> rhs)
3049 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003050 storeValue(rhs.value);
3051 }
3052
3053 Short4::Short4(const Short4 &rhs)
3054 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003055 Value *value = rhs.loadValue();
3056 storeValue(value);
3057 }
3058
3059 Short4::Short4(const Reference<Short4> &rhs)
3060 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003061 Value *value = rhs.loadValue();
3062 storeValue(value);
3063 }
3064
3065 Short4::Short4(RValue<UShort4> rhs)
3066 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003067 storeValue(rhs.value);
3068 }
3069
3070 Short4::Short4(const UShort4 &rhs)
3071 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003072 storeValue(rhs.loadValue());
3073 }
3074
3075 Short4::Short4(const Reference<UShort4> &rhs)
3076 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003077 storeValue(rhs.loadValue());
3078 }
3079
Nicolas Capens96d4e092016-11-18 14:22:38 -05003080 RValue<Short4> Short4::operator=(RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003081 {
3082 storeValue(rhs.value);
3083
3084 return rhs;
3085 }
3086
Nicolas Capens96d4e092016-11-18 14:22:38 -05003087 RValue<Short4> Short4::operator=(const Short4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003088 {
3089 Value *value = rhs.loadValue();
3090 storeValue(value);
3091
3092 return RValue<Short4>(value);
3093 }
3094
Nicolas Capens96d4e092016-11-18 14:22:38 -05003095 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003096 {
3097 Value *value = rhs.loadValue();
3098 storeValue(value);
3099
3100 return RValue<Short4>(value);
3101 }
3102
Nicolas Capens96d4e092016-11-18 14:22:38 -05003103 RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003104 {
3105 storeValue(rhs.value);
3106
3107 return RValue<Short4>(rhs);
3108 }
3109
Nicolas Capens96d4e092016-11-18 14:22:38 -05003110 RValue<Short4> Short4::operator=(const UShort4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003111 {
3112 Value *value = rhs.loadValue();
3113 storeValue(value);
3114
3115 return RValue<Short4>(value);
3116 }
3117
Nicolas Capens96d4e092016-11-18 14:22:38 -05003118 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003119 {
3120 Value *value = rhs.loadValue();
3121 storeValue(value);
3122
3123 return RValue<Short4>(value);
3124 }
3125
3126 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
3127 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003128 return RValue<Short4>(Nucleus::createAdd(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::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003134 }
3135
3136 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
3137 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003138 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003139 }
3140
3141// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
3142// {
3143// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
3144// }
3145
3146// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
3147// {
3148// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
3149// }
3150
3151 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
3152 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003153 return RValue<Short4>(Nucleus::createAnd(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::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003159 }
3160
3161 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
3162 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003163 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
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::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003169 }
3170
3171 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
3172 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003173 return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003174 }
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, RValue<Short4> 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 Capens96d4e092016-11-18 14:22:38 -05003221 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003222 {
3223 return lhs = lhs >> rhs;
3224 }
3225
Nicolas Capens598f8d82016-09-26 15:09:10 -04003226// RValue<Short4> operator+(RValue<Short4> val)
3227// {
3228// return val;
3229// }
3230
3231 RValue<Short4> operator-(RValue<Short4> val)
3232 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003233 return RValue<Short4>(Nucleus::createNeg(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003234 }
3235
3236 RValue<Short4> operator~(RValue<Short4> val)
3237 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003238 return RValue<Short4>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003239 }
3240
3241 RValue<Short4> RoundShort4(RValue<Float4> cast)
3242 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003243 RValue<Int4> int4 = RoundInt(cast);
3244 return As<Short4>(Pack(int4, int4));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003245 }
3246
3247 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
3248 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003249 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3250 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
3251 ::basicBlock->appendInst(cmp);
3252
3253 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3254 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3255 ::basicBlock->appendInst(select);
3256
3257 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003258 }
3259
3260 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
3261 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003262 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3263 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
3264 ::basicBlock->appendInst(cmp);
3265
3266 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3267 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3268 ::basicBlock->appendInst(select);
3269
3270 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003271 }
3272
3273 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
3274 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003275 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3276 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3277 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3278 auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3279 paddsw->addArg(x.value);
3280 paddsw->addArg(y.value);
3281 ::basicBlock->appendInst(paddsw);
3282
3283 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003284 }
3285
3286 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
3287 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003288 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3289 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3290 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3291 auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3292 psubsw->addArg(x.value);
3293 psubsw->addArg(y.value);
3294 ::basicBlock->appendInst(psubsw);
3295
3296 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003297 }
3298
3299 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
3300 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003301 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3302 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3303 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3304 auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3305 pmulhw->addArg(x.value);
3306 pmulhw->addArg(y.value);
3307 ::basicBlock->appendInst(pmulhw);
3308
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003309 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003310 }
3311
3312 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
3313 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003314 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3315 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3316 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3317 auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3318 pmaddwd->addArg(x.value);
3319 pmaddwd->addArg(y.value);
3320 ::basicBlock->appendInst(pmaddwd);
3321
3322 return RValue<Int2>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003323 }
3324
3325 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
3326 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003327 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3328 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3329 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3330 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3331 pack->addArg(x.value);
3332 pack->addArg(y.value);
3333 ::basicBlock->appendInst(pack);
3334
Nicolas Capens70dfff42016-10-27 10:20:28 -04003335 return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003336 }
3337
3338 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
3339 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003340 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3341 return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003342 }
3343
3344 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
3345 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04003346 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3347 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3348 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003349 }
3350
3351 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
3352 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003353 // Real type is v8i16
3354 int shuffle[8] =
3355 {
3356 (select >> 0) & 0x03,
3357 (select >> 2) & 0x03,
3358 (select >> 4) & 0x03,
3359 (select >> 6) & 0x03,
3360 (select >> 0) & 0x03,
3361 (select >> 2) & 0x03,
3362 (select >> 4) & 0x03,
3363 (select >> 6) & 0x03,
3364 };
3365
3366 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003367 }
3368
3369 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
3370 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05003371 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003372 }
3373
3374 RValue<Short> Extract(RValue<Short4> val, int i)
3375 {
Nicolas Capens0133d0f2017-01-16 16:25:08 -05003376 return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003377 }
3378
3379 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
3380 {
Nicolas Capens2f970b62016-11-08 14:28:59 -05003381 return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003382 }
3383
3384 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
3385 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05003386 return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003387 }
3388
3389 Type *Short4::getType()
3390 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003391 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003392 }
3393
3394 UShort4::UShort4(RValue<Int4> cast)
3395 {
3396 *this = Short4(cast);
3397 }
3398
3399 UShort4::UShort4(RValue<Float4> cast, bool saturate)
3400 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003401 if(saturate)
3402 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05003403 if(CPUID::SSE4_1)
Nicolas Capensd4227962016-11-09 14:24:25 -05003404 {
3405 Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
3406 *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4)));
3407 }
3408 else
3409 {
3410 *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
3411 }
3412 }
3413 else
3414 {
3415 *this = Short4(Int4(cast));
3416 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04003417 }
3418
Nicolas Capens598f8d82016-09-26 15:09:10 -04003419 UShort4::UShort4(unsigned short xyzw)
3420 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003421 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3422 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003423 }
3424
3425 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3426 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003427 int64_t constantVector[4] = {x, y, z, w};
3428 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003429 }
3430
3431 UShort4::UShort4(RValue<UShort4> rhs)
3432 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003433 storeValue(rhs.value);
3434 }
3435
3436 UShort4::UShort4(const UShort4 &rhs)
3437 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003438 Value *value = rhs.loadValue();
3439 storeValue(value);
3440 }
3441
3442 UShort4::UShort4(const Reference<UShort4> &rhs)
3443 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003444 Value *value = rhs.loadValue();
3445 storeValue(value);
3446 }
3447
3448 UShort4::UShort4(RValue<Short4> rhs)
3449 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003450 storeValue(rhs.value);
3451 }
3452
3453 UShort4::UShort4(const Short4 &rhs)
3454 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003455 Value *value = rhs.loadValue();
3456 storeValue(value);
3457 }
3458
3459 UShort4::UShort4(const Reference<Short4> &rhs)
3460 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003461 Value *value = rhs.loadValue();
3462 storeValue(value);
3463 }
3464
Nicolas Capens96d4e092016-11-18 14:22:38 -05003465 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003466 {
3467 storeValue(rhs.value);
3468
3469 return rhs;
3470 }
3471
Nicolas Capens96d4e092016-11-18 14:22:38 -05003472 RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003473 {
3474 Value *value = rhs.loadValue();
3475 storeValue(value);
3476
3477 return RValue<UShort4>(value);
3478 }
3479
Nicolas Capens96d4e092016-11-18 14:22:38 -05003480 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003481 {
3482 Value *value = rhs.loadValue();
3483 storeValue(value);
3484
3485 return RValue<UShort4>(value);
3486 }
3487
Nicolas Capens96d4e092016-11-18 14:22:38 -05003488 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003489 {
3490 storeValue(rhs.value);
3491
3492 return RValue<UShort4>(rhs);
3493 }
3494
Nicolas Capens96d4e092016-11-18 14:22:38 -05003495 RValue<UShort4> UShort4::operator=(const Short4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003496 {
3497 Value *value = rhs.loadValue();
3498 storeValue(value);
3499
3500 return RValue<UShort4>(value);
3501 }
3502
Nicolas Capens96d4e092016-11-18 14:22:38 -05003503 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003504 {
3505 Value *value = rhs.loadValue();
3506 storeValue(value);
3507
3508 return RValue<UShort4>(value);
3509 }
3510
3511 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
3512 {
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003513 return RValue<UShort4>(Nucleus::createAdd(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::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003519 }
3520
3521 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
3522 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003523 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003524 }
3525
Nicolas Capens16b5f152016-10-13 13:39:01 -04003526 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3527 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003528 return RValue<UShort4>(Nucleus::createAnd(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::createOr(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003534 }
3535
3536 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3537 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003538 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003539 }
3540
Nicolas Capens598f8d82016-09-26 15:09:10 -04003541 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
3542 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003543 return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003544 }
3545
3546 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
3547 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003548 return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003549 }
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 Capens96d4e092016-11-18 14:22:38 -05003556 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003557 {
3558 return lhs = lhs >> rhs;
3559 }
3560
Nicolas Capens598f8d82016-09-26 15:09:10 -04003561 RValue<UShort4> operator~(RValue<UShort4> val)
3562 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003563 return RValue<UShort4>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003564 }
3565
3566 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
3567 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003568 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3569 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
3570 ::basicBlock->appendInst(cmp);
3571
3572 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3573 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3574 ::basicBlock->appendInst(select);
3575
3576 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003577 }
3578
3579 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
3580 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003581 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3582 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
3583 ::basicBlock->appendInst(cmp);
3584
3585 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3586 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3587 ::basicBlock->appendInst(select);
3588
3589 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003590 }
3591
3592 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
3593 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003594 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3595 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3596 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3597 auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3598 paddusw->addArg(x.value);
3599 paddusw->addArg(y.value);
3600 ::basicBlock->appendInst(paddusw);
3601
3602 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003603 }
3604
3605 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
3606 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003607 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3608 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3609 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3610 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3611 psubusw->addArg(x.value);
3612 psubusw->addArg(y.value);
3613 ::basicBlock->appendInst(psubusw);
3614
3615 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003616 }
3617
3618 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
3619 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003620 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3621 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3622 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3623 auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3624 pmulhuw->addArg(x.value);
3625 pmulhuw->addArg(y.value);
3626 ::basicBlock->appendInst(pmulhuw);
3627
3628 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003629 }
3630
3631 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
3632 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003633 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003634 }
3635
3636 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
3637 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003638 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3639 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3640 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3641 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3642 pack->addArg(x.value);
3643 pack->addArg(y.value);
3644 ::basicBlock->appendInst(pack);
3645
Nicolas Capens70dfff42016-10-27 10:20:28 -04003646 return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003647 }
3648
3649 Type *UShort4::getType()
3650 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003651 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003652 }
3653
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003654 Short8::Short8(short c)
3655 {
3656 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3657 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3658 }
3659
Nicolas Capens598f8d82016-09-26 15:09:10 -04003660 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3661 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003662 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3663 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003664 }
3665
3666 Short8::Short8(RValue<Short8> rhs)
3667 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003668 storeValue(rhs.value);
3669 }
3670
3671 Short8::Short8(const Reference<Short8> &rhs)
3672 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003673 Value *value = rhs.loadValue();
3674 storeValue(value);
3675 }
3676
3677 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3678 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05003679 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3680 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3681
3682 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003683 }
3684
3685 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
3686 {
3687 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3688 }
3689
3690 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
3691 {
3692 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3693 }
3694
3695 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
3696 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003697 return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003698 }
3699
3700 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
3701 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003702 return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003703 }
3704
3705 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
3706 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003707 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003708 }
3709
3710 RValue<Int4> Abs(RValue<Int4> x)
3711 {
Nicolas Capens84272242016-11-09 13:31:06 -05003712 auto negative = x >> 31;
3713 return (x ^ negative) - negative;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003714 }
3715
3716 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
3717 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003718 assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003719 }
3720
3721 Type *Short8::getType()
3722 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003723 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003724 }
3725
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003726 UShort8::UShort8(unsigned short c)
3727 {
3728 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3729 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3730 }
3731
Nicolas Capens598f8d82016-09-26 15:09:10 -04003732 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)
3733 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003734 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3735 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003736 }
3737
3738 UShort8::UShort8(RValue<UShort8> rhs)
3739 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003740 storeValue(rhs.value);
3741 }
3742
3743 UShort8::UShort8(const Reference<UShort8> &rhs)
3744 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003745 Value *value = rhs.loadValue();
3746 storeValue(value);
3747 }
3748
3749 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3750 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05003751 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3752 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3753
3754 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003755 }
3756
Nicolas Capens96d4e092016-11-18 14:22:38 -05003757 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003758 {
3759 storeValue(rhs.value);
3760
3761 return rhs;
3762 }
3763
Nicolas Capens96d4e092016-11-18 14:22:38 -05003764 RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003765 {
3766 Value *value = rhs.loadValue();
3767 storeValue(value);
3768
3769 return RValue<UShort8>(value);
3770 }
3771
Nicolas Capens96d4e092016-11-18 14:22:38 -05003772 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003773 {
3774 Value *value = rhs.loadValue();
3775 storeValue(value);
3776
3777 return RValue<UShort8>(value);
3778 }
3779
3780 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
3781 {
3782 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3783 }
3784
3785 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
3786 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003787 return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003788 }
3789
3790 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
3791 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003792 return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003793 }
3794
3795 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
3796 {
3797 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3798 }
3799
3800 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
3801 {
3802 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3803 }
3804
Nicolas Capens96d4e092016-11-18 14:22:38 -05003805 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003806 {
3807 return lhs = lhs + rhs;
3808 }
3809
3810 RValue<UShort8> operator~(RValue<UShort8> val)
3811 {
3812 return RValue<UShort8>(Nucleus::createNot(val.value));
3813 }
3814
3815 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
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 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
3821 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003822 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003823 }
3824
3825 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
3826// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
3827// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003828// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003829// }
3830
3831 Type *UShort8::getType()
3832 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003833 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003834 }
3835
3836 Int::Int(Argument<Int> argument)
3837 {
3838 storeValue(argument.value);
3839 }
3840
3841 Int::Int(RValue<Byte> cast)
3842 {
3843 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3844
3845 storeValue(integer);
3846 }
3847
3848 Int::Int(RValue<SByte> cast)
3849 {
3850 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3851
3852 storeValue(integer);
3853 }
3854
3855 Int::Int(RValue<Short> cast)
3856 {
3857 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3858
3859 storeValue(integer);
3860 }
3861
3862 Int::Int(RValue<UShort> cast)
3863 {
3864 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3865
3866 storeValue(integer);
3867 }
3868
3869 Int::Int(RValue<Int2> cast)
3870 {
3871 *this = Extract(cast, 0);
3872 }
3873
3874 Int::Int(RValue<Long> cast)
3875 {
3876 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3877
3878 storeValue(integer);
3879 }
3880
3881 Int::Int(RValue<Float> cast)
3882 {
3883 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3884
3885 storeValue(integer);
3886 }
3887
Nicolas Capens598f8d82016-09-26 15:09:10 -04003888 Int::Int(int x)
3889 {
3890 storeValue(Nucleus::createConstantInt(x));
3891 }
3892
3893 Int::Int(RValue<Int> rhs)
3894 {
3895 storeValue(rhs.value);
3896 }
3897
3898 Int::Int(RValue<UInt> rhs)
3899 {
3900 storeValue(rhs.value);
3901 }
3902
3903 Int::Int(const Int &rhs)
3904 {
3905 Value *value = rhs.loadValue();
3906 storeValue(value);
3907 }
3908
3909 Int::Int(const Reference<Int> &rhs)
3910 {
3911 Value *value = rhs.loadValue();
3912 storeValue(value);
3913 }
3914
3915 Int::Int(const UInt &rhs)
3916 {
3917 Value *value = rhs.loadValue();
3918 storeValue(value);
3919 }
3920
3921 Int::Int(const Reference<UInt> &rhs)
3922 {
3923 Value *value = rhs.loadValue();
3924 storeValue(value);
3925 }
3926
Nicolas Capens96d4e092016-11-18 14:22:38 -05003927 RValue<Int> Int::operator=(int rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003928 {
3929 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
3930 }
3931
Nicolas Capens96d4e092016-11-18 14:22:38 -05003932 RValue<Int> Int::operator=(RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003933 {
3934 storeValue(rhs.value);
3935
3936 return rhs;
3937 }
3938
Nicolas Capens96d4e092016-11-18 14:22:38 -05003939 RValue<Int> Int::operator=(RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003940 {
3941 storeValue(rhs.value);
3942
3943 return RValue<Int>(rhs);
3944 }
3945
Nicolas Capens96d4e092016-11-18 14:22:38 -05003946 RValue<Int> Int::operator=(const Int &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003947 {
3948 Value *value = rhs.loadValue();
3949 storeValue(value);
3950
3951 return RValue<Int>(value);
3952 }
3953
Nicolas Capens96d4e092016-11-18 14:22:38 -05003954 RValue<Int> Int::operator=(const Reference<Int> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003955 {
3956 Value *value = rhs.loadValue();
3957 storeValue(value);
3958
3959 return RValue<Int>(value);
3960 }
3961
Nicolas Capens96d4e092016-11-18 14:22:38 -05003962 RValue<Int> Int::operator=(const UInt &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003963 {
3964 Value *value = rhs.loadValue();
3965 storeValue(value);
3966
3967 return RValue<Int>(value);
3968 }
3969
Nicolas Capens96d4e092016-11-18 14:22:38 -05003970 RValue<Int> Int::operator=(const Reference<UInt> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003971 {
3972 Value *value = rhs.loadValue();
3973 storeValue(value);
3974
3975 return RValue<Int>(value);
3976 }
3977
3978 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
3979 {
3980 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3981 }
3982
3983 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
3984 {
3985 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3986 }
3987
3988 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
3989 {
3990 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3991 }
3992
3993 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
3994 {
3995 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3996 }
3997
3998 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
3999 {
4000 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
4001 }
4002
4003 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
4004 {
4005 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
4006 }
4007
4008 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
4009 {
4010 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
4011 }
4012
4013 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
4014 {
4015 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
4016 }
4017
4018 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
4019 {
4020 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
4021 }
4022
4023 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
4024 {
4025 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05004073 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004074 {
4075 return lhs = lhs >> rhs;
4076 }
4077
4078 RValue<Int> operator+(RValue<Int> val)
4079 {
4080 return val;
4081 }
4082
4083 RValue<Int> operator-(RValue<Int> val)
4084 {
4085 return RValue<Int>(Nucleus::createNeg(val.value));
4086 }
4087
4088 RValue<Int> operator~(RValue<Int> val)
4089 {
4090 return RValue<Int>(Nucleus::createNot(val.value));
4091 }
4092
Nicolas Capens96d4e092016-11-18 14:22:38 -05004093 RValue<Int> operator++(Int &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004094 {
Nicolas Capens5b41ba32016-12-08 14:34:00 -05004095 RValue<Int> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05004096 val += 1;
4097 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004098 }
4099
Nicolas Capens96d4e092016-11-18 14:22:38 -05004100 const Int &operator++(Int &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004101 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004102 val += 1;
4103 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004104 }
4105
Nicolas Capens96d4e092016-11-18 14:22:38 -05004106 RValue<Int> operator--(Int &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004107 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004108 RValue<Int> res = val;
4109 val -= 1;
4110 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004111 }
4112
Nicolas Capens96d4e092016-11-18 14:22:38 -05004113 const Int &operator--(Int &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004114 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004115 val -= 1;
4116 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004117 }
4118
4119 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
4120 {
4121 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4122 }
4123
4124 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
4125 {
4126 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4127 }
4128
4129 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
4130 {
4131 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4132 }
4133
4134 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
4135 {
4136 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4137 }
4138
4139 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
4140 {
4141 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4142 }
4143
4144 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
4145 {
4146 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4147 }
4148
4149 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4150 {
4151 return IfThenElse(x > y, x, y);
4152 }
4153
4154 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4155 {
4156 return IfThenElse(x < y, x, y);
4157 }
4158
4159 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4160 {
4161 return Min(Max(x, min), max);
4162 }
4163
4164 RValue<Int> RoundInt(RValue<Float> cast)
4165 {
Nicolas Capensf7b75882017-04-26 09:30:47 -04004166 if(emulateIntrinsics)
4167 {
4168 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
4169 return Int((cast + Float(0x00C00000)) - Float(0x00C00000));
4170 }
4171 else
4172 {
4173 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
4174 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
4175 auto target = ::context->getConstantUndef(Ice::IceType_i32);
4176 auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
4177 nearbyint->addArg(cast.value);
4178 ::basicBlock->appendInst(nearbyint);
Nicolas Capensa8086512016-11-07 17:32:17 -05004179
Nicolas Capensf7b75882017-04-26 09:30:47 -04004180 return RValue<Int>(V(result));
4181 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04004182 }
4183
4184 Type *Int::getType()
4185 {
4186 return T(Ice::IceType_i32);
4187 }
4188
4189 Long::Long(RValue<Int> cast)
4190 {
4191 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4192
4193 storeValue(integer);
4194 }
4195
4196 Long::Long(RValue<UInt> cast)
4197 {
4198 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4199
4200 storeValue(integer);
4201 }
4202
Nicolas Capens598f8d82016-09-26 15:09:10 -04004203 Long::Long(RValue<Long> rhs)
4204 {
4205 storeValue(rhs.value);
4206 }
4207
Nicolas Capens96d4e092016-11-18 14:22:38 -05004208 RValue<Long> Long::operator=(int64_t rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004209 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004210 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004211 }
4212
Nicolas Capens96d4e092016-11-18 14:22:38 -05004213 RValue<Long> Long::operator=(RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004214 {
4215 storeValue(rhs.value);
4216
4217 return rhs;
4218 }
4219
Nicolas Capens96d4e092016-11-18 14:22:38 -05004220 RValue<Long> Long::operator=(const Long &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004221 {
4222 Value *value = rhs.loadValue();
4223 storeValue(value);
4224
4225 return RValue<Long>(value);
4226 }
4227
Nicolas Capens96d4e092016-11-18 14:22:38 -05004228 RValue<Long> Long::operator=(const Reference<Long> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004229 {
4230 Value *value = rhs.loadValue();
4231 storeValue(value);
4232
4233 return RValue<Long>(value);
4234 }
4235
4236 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
4237 {
4238 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4239 }
4240
4241 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
4242 {
4243 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05004251 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004252 {
4253 return lhs = lhs - rhs;
4254 }
4255
4256 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
4257 {
4258 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
4259 }
4260
4261 Type *Long::getType()
4262 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004263 return T(Ice::IceType_i64);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004264 }
4265
Nicolas Capens598f8d82016-09-26 15:09:10 -04004266 UInt::UInt(Argument<UInt> argument)
4267 {
4268 storeValue(argument.value);
4269 }
4270
4271 UInt::UInt(RValue<UShort> cast)
4272 {
4273 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4274
4275 storeValue(integer);
4276 }
4277
4278 UInt::UInt(RValue<Long> cast)
4279 {
4280 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4281
4282 storeValue(integer);
4283 }
4284
4285 UInt::UInt(RValue<Float> cast)
4286 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004287 // Smallest positive value representable in UInt, but not in Int
4288 const unsigned int ustart = 0x80000000u;
4289 const float ustartf = float(ustart);
4290
4291 // If the value is negative, store 0, otherwise store the result of the conversion
4292 storeValue((~(As<Int>(cast) >> 31) &
4293 // Check if the value can be represented as an Int
4294 IfThenElse(cast >= ustartf,
4295 // If the value is too large, subtract ustart and re-add it after conversion.
4296 As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
4297 // Otherwise, just convert normally
4298 Int(cast))).value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004299 }
4300
Nicolas Capens598f8d82016-09-26 15:09:10 -04004301 UInt::UInt(int x)
4302 {
4303 storeValue(Nucleus::createConstantInt(x));
4304 }
4305
4306 UInt::UInt(unsigned int x)
4307 {
4308 storeValue(Nucleus::createConstantInt(x));
4309 }
4310
4311 UInt::UInt(RValue<UInt> rhs)
4312 {
4313 storeValue(rhs.value);
4314 }
4315
4316 UInt::UInt(RValue<Int> rhs)
4317 {
4318 storeValue(rhs.value);
4319 }
4320
4321 UInt::UInt(const UInt &rhs)
4322 {
4323 Value *value = rhs.loadValue();
4324 storeValue(value);
4325 }
4326
4327 UInt::UInt(const Reference<UInt> &rhs)
4328 {
4329 Value *value = rhs.loadValue();
4330 storeValue(value);
4331 }
4332
4333 UInt::UInt(const Int &rhs)
4334 {
4335 Value *value = rhs.loadValue();
4336 storeValue(value);
4337 }
4338
4339 UInt::UInt(const Reference<Int> &rhs)
4340 {
4341 Value *value = rhs.loadValue();
4342 storeValue(value);
4343 }
4344
Nicolas Capens96d4e092016-11-18 14:22:38 -05004345 RValue<UInt> UInt::operator=(unsigned int rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004346 {
4347 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
4348 }
4349
Nicolas Capens96d4e092016-11-18 14:22:38 -05004350 RValue<UInt> UInt::operator=(RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004351 {
4352 storeValue(rhs.value);
4353
4354 return rhs;
4355 }
4356
Nicolas Capens96d4e092016-11-18 14:22:38 -05004357 RValue<UInt> UInt::operator=(RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004358 {
4359 storeValue(rhs.value);
4360
4361 return RValue<UInt>(rhs);
4362 }
4363
Nicolas Capens96d4e092016-11-18 14:22:38 -05004364 RValue<UInt> UInt::operator=(const UInt &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004365 {
4366 Value *value = rhs.loadValue();
4367 storeValue(value);
4368
4369 return RValue<UInt>(value);
4370 }
4371
Nicolas Capens96d4e092016-11-18 14:22:38 -05004372 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004373 {
4374 Value *value = rhs.loadValue();
4375 storeValue(value);
4376
4377 return RValue<UInt>(value);
4378 }
4379
Nicolas Capens96d4e092016-11-18 14:22:38 -05004380 RValue<UInt> UInt::operator=(const Int &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004381 {
4382 Value *value = rhs.loadValue();
4383 storeValue(value);
4384
4385 return RValue<UInt>(value);
4386 }
4387
Nicolas Capens96d4e092016-11-18 14:22:38 -05004388 RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004389 {
4390 Value *value = rhs.loadValue();
4391 storeValue(value);
4392
4393 return RValue<UInt>(value);
4394 }
4395
4396 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
4397 {
4398 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4399 }
4400
4401 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
4402 {
4403 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4404 }
4405
4406 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
4407 {
4408 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4409 }
4410
4411 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
4412 {
4413 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4414 }
4415
4416 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
4417 {
4418 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4419 }
4420
4421 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
4422 {
4423 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4424 }
4425
4426 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
4427 {
4428 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4429 }
4430
4431 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
4432 {
4433 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4434 }
4435
4436 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
4437 {
4438 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4439 }
4440
4441 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
4442 {
4443 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05004491 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004492 {
4493 return lhs = lhs >> rhs;
4494 }
4495
4496 RValue<UInt> operator+(RValue<UInt> val)
4497 {
4498 return val;
4499 }
4500
4501 RValue<UInt> operator-(RValue<UInt> val)
4502 {
4503 return RValue<UInt>(Nucleus::createNeg(val.value));
4504 }
4505
4506 RValue<UInt> operator~(RValue<UInt> val)
4507 {
4508 return RValue<UInt>(Nucleus::createNot(val.value));
4509 }
4510
Nicolas Capens96d4e092016-11-18 14:22:38 -05004511 RValue<UInt> operator++(UInt &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004512 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004513 RValue<UInt> res = val;
4514 val += 1;
4515 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004516 }
4517
Nicolas Capens96d4e092016-11-18 14:22:38 -05004518 const UInt &operator++(UInt &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004519 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004520 val += 1;
4521 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004522 }
4523
Nicolas Capens96d4e092016-11-18 14:22:38 -05004524 RValue<UInt> operator--(UInt &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004525 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004526 RValue<UInt> res = val;
4527 val -= 1;
4528 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004529 }
4530
Nicolas Capens96d4e092016-11-18 14:22:38 -05004531 const UInt &operator--(UInt &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004532 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004533 val -= 1;
4534 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004535 }
4536
4537 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4538 {
4539 return IfThenElse(x > y, x, y);
4540 }
4541
4542 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4543 {
4544 return IfThenElse(x < y, x, y);
4545 }
4546
4547 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4548 {
4549 return Min(Max(x, min), max);
4550 }
4551
4552 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
4553 {
4554 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4555 }
4556
4557 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
4558 {
4559 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4560 }
4561
4562 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
4563 {
4564 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4565 }
4566
4567 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
4568 {
4569 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4570 }
4571
4572 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
4573 {
4574 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4575 }
4576
4577 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
4578 {
4579 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4580 }
4581
4582// RValue<UInt> RoundUInt(RValue<Float> cast)
4583// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004584// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004585// }
4586
4587 Type *UInt::getType()
4588 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004589 return T(Ice::IceType_i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004590 }
4591
4592// Int2::Int2(RValue<Int> cast)
4593// {
4594// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4595// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
4596//
4597// Constant *shuffle[2];
4598// shuffle[0] = Nucleus::createConstantInt(0);
4599// shuffle[1] = Nucleus::createConstantInt(0);
4600//
4601// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4602//
4603// storeValue(replicate);
4604// }
4605
4606 Int2::Int2(RValue<Int4> cast)
4607 {
Nicolas Capens22008782016-10-20 01:11:47 -04004608 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004609 }
4610
Nicolas Capens598f8d82016-09-26 15:09:10 -04004611 Int2::Int2(int x, int y)
4612 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004613 int64_t constantVector[2] = {x, y};
4614 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004615 }
4616
4617 Int2::Int2(RValue<Int2> rhs)
4618 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004619 storeValue(rhs.value);
4620 }
4621
4622 Int2::Int2(const Int2 &rhs)
4623 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004624 Value *value = rhs.loadValue();
4625 storeValue(value);
4626 }
4627
4628 Int2::Int2(const Reference<Int2> &rhs)
4629 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004630 Value *value = rhs.loadValue();
4631 storeValue(value);
4632 }
4633
4634 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4635 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004636 int shuffle[4] = {0, 4, 1, 5};
4637 Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
4638
4639 storeValue(Nucleus::createBitCast(packed, Int2::getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004640 }
4641
Nicolas Capens96d4e092016-11-18 14:22:38 -05004642 RValue<Int2> Int2::operator=(RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004643 {
4644 storeValue(rhs.value);
4645
4646 return rhs;
4647 }
4648
Nicolas Capens96d4e092016-11-18 14:22:38 -05004649 RValue<Int2> Int2::operator=(const Int2 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004650 {
4651 Value *value = rhs.loadValue();
4652 storeValue(value);
4653
4654 return RValue<Int2>(value);
4655 }
4656
Nicolas Capens96d4e092016-11-18 14:22:38 -05004657 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004658 {
4659 Value *value = rhs.loadValue();
4660 storeValue(value);
4661
4662 return RValue<Int2>(value);
4663 }
4664
4665 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
4666 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004667 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004668 }
4669
4670 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
4671 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004672 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004673 }
4674
4675// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4676// {
4677// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4678// }
4679
4680// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4681// {
4682// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4683// }
4684
4685// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4686// {
4687// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4688// }
4689
4690 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
4691 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004692 return RValue<Int2>(Nucleus::createAnd(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::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004698 }
4699
4700 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
4701 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004702 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
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::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004708 }
4709
4710 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
4711 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004712 return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004713 }
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, RValue<Int2> 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 Capens96d4e092016-11-18 14:22:38 -05004760 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004761 {
4762 return lhs = lhs >> rhs;
4763 }
4764
Nicolas Capens598f8d82016-09-26 15:09:10 -04004765// RValue<Int2> operator+(RValue<Int2> val)
4766// {
4767// return val;
4768// }
4769
4770// RValue<Int2> operator-(RValue<Int2> val)
4771// {
4772// return RValue<Int2>(Nucleus::createNeg(val.value));
4773// }
4774
4775 RValue<Int2> operator~(RValue<Int2> val)
4776 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05004777 return RValue<Int2>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004778 }
4779
Nicolas Capens45f187a2016-12-02 15:30:56 -05004780 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004781 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004782 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
4783 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004784 }
4785
Nicolas Capens45f187a2016-12-02 15:30:56 -05004786 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004787 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08004788 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
Nicolas Capensc70a1162016-12-03 00:16:14 -05004789 auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
4790 return As<Short4>(Swizzle(lowHigh, 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004791 }
4792
4793 RValue<Int> Extract(RValue<Int2> val, int i)
4794 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05004795 return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004796 }
4797
4798 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4799 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05004800 return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004801 }
4802
4803 Type *Int2::getType()
4804 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004805 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004806 }
4807
Nicolas Capens598f8d82016-09-26 15:09:10 -04004808 UInt2::UInt2(unsigned int x, unsigned int y)
4809 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004810 int64_t constantVector[2] = {x, y};
4811 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004812 }
4813
4814 UInt2::UInt2(RValue<UInt2> rhs)
4815 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004816 storeValue(rhs.value);
4817 }
4818
4819 UInt2::UInt2(const UInt2 &rhs)
4820 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004821 Value *value = rhs.loadValue();
4822 storeValue(value);
4823 }
4824
4825 UInt2::UInt2(const Reference<UInt2> &rhs)
4826 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004827 Value *value = rhs.loadValue();
4828 storeValue(value);
4829 }
4830
Nicolas Capens96d4e092016-11-18 14:22:38 -05004831 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004832 {
4833 storeValue(rhs.value);
4834
4835 return rhs;
4836 }
4837
Nicolas Capens96d4e092016-11-18 14:22:38 -05004838 RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004839 {
4840 Value *value = rhs.loadValue();
4841 storeValue(value);
4842
4843 return RValue<UInt2>(value);
4844 }
4845
Nicolas Capens96d4e092016-11-18 14:22:38 -05004846 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004847 {
4848 Value *value = rhs.loadValue();
4849 storeValue(value);
4850
4851 return RValue<UInt2>(value);
4852 }
4853
4854 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
4855 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004856 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004857 }
4858
4859 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
4860 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004861 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004862 }
4863
4864// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4865// {
4866// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4867// }
4868
4869// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4870// {
4871// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4872// }
4873
4874// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4875// {
4876// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4877// }
4878
4879 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
4880 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004881 return RValue<UInt2>(Nucleus::createAnd(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::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004887 }
4888
4889 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
4890 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004891 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
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::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004897 }
4898
4899 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
4900 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004901 return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004902 }
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, RValue<UInt2> 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 Capens96d4e092016-11-18 14:22:38 -05004949 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004950 {
4951 return lhs = lhs >> rhs;
4952 }
4953
Nicolas Capens598f8d82016-09-26 15:09:10 -04004954// RValue<UInt2> operator+(RValue<UInt2> val)
4955// {
4956// return val;
4957// }
4958
4959// RValue<UInt2> operator-(RValue<UInt2> val)
4960// {
4961// return RValue<UInt2>(Nucleus::createNeg(val.value));
4962// }
4963
4964 RValue<UInt2> operator~(RValue<UInt2> val)
4965 {
4966 return RValue<UInt2>(Nucleus::createNot(val.value));
4967 }
4968
4969 Type *UInt2::getType()
4970 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004971 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004972 }
4973
4974 Int4::Int4(RValue<Byte4> cast)
4975 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004976 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
4977 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
4978
4979 Value *e;
4980 int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
4981 Value *b = Nucleus::createBitCast(a, Byte16::getType());
4982 Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
4983
4984 int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
4985 Value *d = Nucleus::createBitCast(c, Short8::getType());
4986 e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
4987
4988 Value *f = Nucleus::createBitCast(e, Int4::getType());
4989 storeValue(f);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004990 }
4991
4992 Int4::Int4(RValue<SByte4> cast)
4993 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004994 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
4995 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
4996
4997 Value *e;
4998 int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
4999 Value *b = Nucleus::createBitCast(a, Byte16::getType());
5000 Value *c = Nucleus::createShuffleVector(b, b, swizzle);
5001
5002 int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
5003 Value *d = Nucleus::createBitCast(c, Short8::getType());
5004 e = Nucleus::createShuffleVector(d, d, swizzle2);
5005
5006 Value *f = Nucleus::createBitCast(e, Int4::getType());
Nicolas Capens15060bb2016-12-05 22:17:19 -05005007 Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24)));
Nicolas Capensd4227962016-11-09 14:24:25 -05005008 storeValue(g);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005009 }
5010
5011 Int4::Int4(RValue<Float4> cast)
5012 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005013 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
5014
5015 storeValue(xyzw);
5016 }
5017
5018 Int4::Int4(RValue<Short4> cast)
5019 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005020 int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
5021 Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
5022 Value *d = Nucleus::createBitCast(c, Int4::getType());
Nicolas Capens15060bb2016-12-05 22:17:19 -05005023 Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16)));
Nicolas Capensd4227962016-11-09 14:24:25 -05005024 storeValue(e);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005025 }
5026
5027 Int4::Int4(RValue<UShort4> cast)
5028 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005029 int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
5030 Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
5031 Value *d = Nucleus::createBitCast(c, Int4::getType());
5032 storeValue(d);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005033 }
5034
Nicolas Capens598f8d82016-09-26 15:09:10 -04005035 Int4::Int4(int xyzw)
5036 {
5037 constant(xyzw, xyzw, xyzw, xyzw);
5038 }
5039
5040 Int4::Int4(int x, int yzw)
5041 {
5042 constant(x, yzw, yzw, yzw);
5043 }
5044
5045 Int4::Int4(int x, int y, int zw)
5046 {
5047 constant(x, y, zw, zw);
5048 }
5049
5050 Int4::Int4(int x, int y, int z, int w)
5051 {
5052 constant(x, y, z, w);
5053 }
5054
5055 void Int4::constant(int x, int y, int z, int w)
5056 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005057 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005058 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005059 }
5060
5061 Int4::Int4(RValue<Int4> rhs)
5062 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005063 storeValue(rhs.value);
5064 }
5065
5066 Int4::Int4(const Int4 &rhs)
5067 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005068 Value *value = rhs.loadValue();
5069 storeValue(value);
5070 }
5071
5072 Int4::Int4(const Reference<Int4> &rhs)
5073 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005074 Value *value = rhs.loadValue();
5075 storeValue(value);
5076 }
5077
5078 Int4::Int4(RValue<UInt4> rhs)
5079 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005080 storeValue(rhs.value);
5081 }
5082
5083 Int4::Int4(const UInt4 &rhs)
5084 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005085 Value *value = rhs.loadValue();
5086 storeValue(value);
5087 }
5088
5089 Int4::Int4(const Reference<UInt4> &rhs)
5090 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005091 Value *value = rhs.loadValue();
5092 storeValue(value);
5093 }
5094
5095 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
5096 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005097 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5098 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5099
5100 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005101 }
5102
5103 Int4::Int4(RValue<Int> rhs)
5104 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08005105 Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType());
Nicolas Capensd4227962016-11-09 14:24:25 -05005106
5107 int swizzle[4] = {0, 0, 0, 0};
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08005108 Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
Nicolas Capensd4227962016-11-09 14:24:25 -05005109
5110 storeValue(replicate);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005111 }
5112
5113 Int4::Int4(const Int &rhs)
5114 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005115 *this = RValue<Int>(rhs.loadValue());
5116 }
5117
5118 Int4::Int4(const Reference<Int> &rhs)
5119 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005120 *this = RValue<Int>(rhs.loadValue());
5121 }
5122
Nicolas Capens96d4e092016-11-18 14:22:38 -05005123 RValue<Int4> Int4::operator=(RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005124 {
5125 storeValue(rhs.value);
5126
5127 return rhs;
5128 }
5129
Nicolas Capens96d4e092016-11-18 14:22:38 -05005130 RValue<Int4> Int4::operator=(const Int4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005131 {
5132 Value *value = rhs.loadValue();
5133 storeValue(value);
5134
5135 return RValue<Int4>(value);
5136 }
5137
Nicolas Capens96d4e092016-11-18 14:22:38 -05005138 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005139 {
5140 Value *value = rhs.loadValue();
5141 storeValue(value);
5142
5143 return RValue<Int4>(value);
5144 }
5145
5146 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
5147 {
5148 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5149 }
5150
5151 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
5152 {
5153 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5154 }
5155
5156 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
5157 {
5158 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5159 }
5160
5161 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5162 {
5163 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5164 }
5165
5166 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5167 {
5168 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5169 }
5170
5171 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
5172 {
5173 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5174 }
5175
5176 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
5177 {
5178 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5179 }
5180
5181 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
5182 {
5183 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5184 }
5185
5186 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
5187 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005188 return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005189 }
5190
5191 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
5192 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005193 return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005194 }
5195
5196 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5197 {
5198 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5199 }
5200
5201 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5202 {
5203 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
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, RValue<Int4> 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
Nicolas Capens96d4e092016-11-18 14:22:38 -05005251 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005252 {
5253 return lhs = lhs >> rhs;
5254 }
5255
5256 RValue<Int4> operator+(RValue<Int4> val)
5257 {
5258 return val;
5259 }
5260
5261 RValue<Int4> operator-(RValue<Int4> val)
5262 {
5263 return RValue<Int4>(Nucleus::createNeg(val.value));
5264 }
5265
5266 RValue<Int4> operator~(RValue<Int4> val)
5267 {
5268 return RValue<Int4>(Nucleus::createNot(val.value));
5269 }
5270
5271 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5272 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005273 return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005274 }
5275
5276 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5277 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005278 return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005279 }
5280
5281 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5282 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005283 return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005284 }
5285
5286 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5287 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005288 return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005289 }
5290
5291 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5292 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005293 return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005294 }
5295
5296 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5297 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005298 return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005299 }
5300
5301 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5302 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005303 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5304 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
5305 ::basicBlock->appendInst(cmp);
5306
5307 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5308 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5309 ::basicBlock->appendInst(select);
5310
5311 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005312 }
5313
5314 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5315 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005316 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5317 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
5318 ::basicBlock->appendInst(cmp);
5319
5320 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5321 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5322 ::basicBlock->appendInst(select);
5323
5324 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005325 }
5326
5327 RValue<Int4> RoundInt(RValue<Float4> cast)
5328 {
Nicolas Capensf7b75882017-04-26 09:30:47 -04005329 if(emulateIntrinsics)
5330 {
5331 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
5332 return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000));
5333 }
5334 else
5335 {
5336 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5337 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5338 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5339 auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5340 nearbyint->addArg(cast.value);
5341 ::basicBlock->appendInst(nearbyint);
Nicolas Capensa8086512016-11-07 17:32:17 -05005342
Nicolas Capensf7b75882017-04-26 09:30:47 -04005343 return RValue<Int4>(V(result));
5344 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04005345 }
5346
5347 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
5348 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005349 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5350 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5351 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5352 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5353 pack->addArg(x.value);
5354 pack->addArg(y.value);
5355 ::basicBlock->appendInst(pack);
5356
5357 return RValue<Short8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005358 }
5359
5360 RValue<Int> Extract(RValue<Int4> x, int i)
5361 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005362 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005363 }
5364
5365 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
5366 {
5367 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5368 }
5369
5370 RValue<Int> SignMask(RValue<Int4> x)
5371 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04005372 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
5373 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5374 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5375 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5376 movmsk->addArg(x.value);
5377 ::basicBlock->appendInst(movmsk);
5378
5379 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005380 }
5381
5382 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
5383 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005384 return RValue<Int4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005385 }
5386
5387 Type *Int4::getType()
5388 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04005389 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005390 }
5391
5392 UInt4::UInt4(RValue<Float4> cast)
5393 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005394 // Smallest positive value representable in UInt, but not in Int
5395 const unsigned int ustart = 0x80000000u;
5396 const float ustartf = float(ustart);
5397
5398 // Check if the value can be represented as an Int
5399 Int4 uiValue = CmpNLT(cast, Float4(ustartf));
5400 // If the value is too large, subtract ustart and re-add it after conversion.
5401 uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
5402 // Otherwise, just convert normally
5403 (~uiValue & Int4(cast));
5404 // If the value is negative, store 0, otherwise store the result of the conversion
5405 storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005406 }
5407
Nicolas Capens598f8d82016-09-26 15:09:10 -04005408 UInt4::UInt4(int xyzw)
5409 {
5410 constant(xyzw, xyzw, xyzw, xyzw);
5411 }
5412
5413 UInt4::UInt4(int x, int yzw)
5414 {
5415 constant(x, yzw, yzw, yzw);
5416 }
5417
5418 UInt4::UInt4(int x, int y, int zw)
5419 {
5420 constant(x, y, zw, zw);
5421 }
5422
5423 UInt4::UInt4(int x, int y, int z, int w)
5424 {
5425 constant(x, y, z, w);
5426 }
5427
5428 void UInt4::constant(int x, int y, int z, int w)
5429 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005430 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005431 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005432 }
5433
5434 UInt4::UInt4(RValue<UInt4> rhs)
5435 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005436 storeValue(rhs.value);
5437 }
5438
5439 UInt4::UInt4(const UInt4 &rhs)
5440 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005441 Value *value = rhs.loadValue();
5442 storeValue(value);
5443 }
5444
5445 UInt4::UInt4(const Reference<UInt4> &rhs)
5446 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005447 Value *value = rhs.loadValue();
5448 storeValue(value);
5449 }
5450
5451 UInt4::UInt4(RValue<Int4> rhs)
5452 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005453 storeValue(rhs.value);
5454 }
5455
5456 UInt4::UInt4(const Int4 &rhs)
5457 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005458 Value *value = rhs.loadValue();
5459 storeValue(value);
5460 }
5461
5462 UInt4::UInt4(const Reference<Int4> &rhs)
5463 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005464 Value *value = rhs.loadValue();
5465 storeValue(value);
5466 }
5467
5468 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5469 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005470 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5471 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5472
5473 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005474 }
5475
Nicolas Capens96d4e092016-11-18 14:22:38 -05005476 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005477 {
5478 storeValue(rhs.value);
5479
5480 return rhs;
5481 }
5482
Nicolas Capens96d4e092016-11-18 14:22:38 -05005483 RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005484 {
5485 Value *value = rhs.loadValue();
5486 storeValue(value);
5487
5488 return RValue<UInt4>(value);
5489 }
5490
Nicolas Capens96d4e092016-11-18 14:22:38 -05005491 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005492 {
5493 Value *value = rhs.loadValue();
5494 storeValue(value);
5495
5496 return RValue<UInt4>(value);
5497 }
5498
5499 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
5500 {
5501 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5502 }
5503
5504 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
5505 {
5506 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5507 }
5508
5509 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
5510 {
5511 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5512 }
5513
5514 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5515 {
5516 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5517 }
5518
5519 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5520 {
5521 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5522 }
5523
5524 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
5525 {
5526 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5527 }
5528
5529 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
5530 {
5531 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5532 }
5533
5534 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
5535 {
5536 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5537 }
5538
5539 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
5540 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005541 return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005542 }
5543
5544 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
5545 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005546 return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005547 }
5548
5549 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5550 {
5551 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5552 }
5553
5554 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5555 {
5556 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
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, RValue<UInt4> 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
Nicolas Capens96d4e092016-11-18 14:22:38 -05005604 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005605 {
5606 return lhs = lhs >> rhs;
5607 }
5608
5609 RValue<UInt4> operator+(RValue<UInt4> val)
5610 {
5611 return val;
5612 }
5613
5614 RValue<UInt4> operator-(RValue<UInt4> val)
5615 {
5616 return RValue<UInt4>(Nucleus::createNeg(val.value));
5617 }
5618
5619 RValue<UInt4> operator~(RValue<UInt4> val)
5620 {
5621 return RValue<UInt4>(Nucleus::createNot(val.value));
5622 }
5623
5624 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5625 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005626 return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005627 }
5628
5629 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5630 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005631 return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005632 }
5633
5634 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5635 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005636 return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005637 }
5638
5639 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5640 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005641 return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005642 }
5643
5644 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5645 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005646 return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005647 }
5648
5649 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5650 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005651 return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005652 }
5653
5654 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5655 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005656 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5657 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
5658 ::basicBlock->appendInst(cmp);
5659
5660 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5661 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5662 ::basicBlock->appendInst(select);
5663
5664 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005665 }
5666
5667 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5668 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005669 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5670 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
5671 ::basicBlock->appendInst(cmp);
5672
5673 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5674 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5675 ::basicBlock->appendInst(select);
5676
5677 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005678 }
5679
5680 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
5681 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05005682 if(CPUID::SSE4_1)
5683 {
5684 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5685 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5686 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5687 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5688 pack->addArg(x.value);
5689 pack->addArg(y.value);
5690 ::basicBlock->appendInst(pack);
Nicolas Capensec54a172016-10-25 17:32:37 -04005691
Nicolas Capens9ca48d52017-01-14 12:52:55 -05005692 return RValue<UShort8>(V(result));
5693 }
5694 else
5695 {
5696 RValue<Int4> sx = As<Int4>(x);
5697 RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000);
5698
5699 RValue<Int4> sy = As<Int4>(y);
5700 RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000);
5701
5702 return As<UShort8>(Pack(bx, by) + Short8(0x8000u));
5703 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04005704 }
5705
5706 Type *UInt4::getType()
5707 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005708 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005709 }
5710
5711 Float::Float(RValue<Int> cast)
5712 {
5713 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5714
5715 storeValue(integer);
5716 }
5717
Nicolas Capens598f8d82016-09-26 15:09:10 -04005718 Float::Float(float x)
5719 {
5720 storeValue(Nucleus::createConstantFloat(x));
5721 }
5722
5723 Float::Float(RValue<Float> rhs)
5724 {
5725 storeValue(rhs.value);
5726 }
5727
5728 Float::Float(const Float &rhs)
5729 {
5730 Value *value = rhs.loadValue();
5731 storeValue(value);
5732 }
5733
5734 Float::Float(const Reference<Float> &rhs)
5735 {
5736 Value *value = rhs.loadValue();
5737 storeValue(value);
5738 }
5739
Nicolas Capens96d4e092016-11-18 14:22:38 -05005740 RValue<Float> Float::operator=(RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005741 {
5742 storeValue(rhs.value);
5743
5744 return rhs;
5745 }
5746
Nicolas Capens96d4e092016-11-18 14:22:38 -05005747 RValue<Float> Float::operator=(const Float &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005748 {
5749 Value *value = rhs.loadValue();
5750 storeValue(value);
5751
5752 return RValue<Float>(value);
5753 }
5754
Nicolas Capens96d4e092016-11-18 14:22:38 -05005755 RValue<Float> Float::operator=(const Reference<Float> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005756 {
5757 Value *value = rhs.loadValue();
5758 storeValue(value);
5759
5760 return RValue<Float>(value);
5761 }
5762
5763 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
5764 {
5765 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5766 }
5767
5768 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
5769 {
5770 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5771 }
5772
5773 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
5774 {
5775 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5776 }
5777
5778 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
5779 {
5780 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05005798 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005799 {
5800 return lhs = lhs / rhs;
5801 }
5802
5803 RValue<Float> operator+(RValue<Float> val)
5804 {
5805 return val;
5806 }
5807
5808 RValue<Float> operator-(RValue<Float> val)
5809 {
5810 return RValue<Float>(Nucleus::createFNeg(val.value));
5811 }
5812
5813 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
5814 {
5815 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5816 }
5817
5818 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
5819 {
5820 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5821 }
5822
5823 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
5824 {
5825 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5826 }
5827
5828 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
5829 {
5830 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5831 }
5832
5833 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
5834 {
5835 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5836 }
5837
5838 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
5839 {
5840 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5841 }
5842
5843 RValue<Float> Abs(RValue<Float> x)
5844 {
5845 return IfThenElse(x > 0.0f, x, -x);
5846 }
5847
5848 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
5849 {
5850 return IfThenElse(x > y, x, y);
5851 }
5852
5853 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
5854 {
5855 return IfThenElse(x < y, x, y);
5856 }
5857
5858 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
5859 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005860 return 1.0f / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005861 }
5862
5863 RValue<Float> RcpSqrt_pp(RValue<Float> x)
5864 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005865 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005866 }
5867
5868 RValue<Float> Sqrt(RValue<Float> x)
5869 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005870 Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32);
5871 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5872 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5873 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5874 sqrt->addArg(x.value);
5875 ::basicBlock->appendInst(sqrt);
5876
5877 return RValue<Float>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005878 }
5879
5880 RValue<Float> Round(RValue<Float> x)
5881 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005882 return Float4(Round(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005883 }
5884
5885 RValue<Float> Trunc(RValue<Float> x)
5886 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005887 return Float4(Trunc(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005888 }
5889
5890 RValue<Float> Frac(RValue<Float> x)
5891 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005892 return Float4(Frac(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005893 }
5894
5895 RValue<Float> Floor(RValue<Float> x)
5896 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005897 return Float4(Floor(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005898 }
5899
5900 RValue<Float> Ceil(RValue<Float> x)
5901 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005902 return Float4(Ceil(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005903 }
5904
5905 Type *Float::getType()
5906 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04005907 return T(Ice::IceType_f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005908 }
5909
5910 Float2::Float2(RValue<Float4> cast)
5911 {
Nicolas Capens22008782016-10-20 01:11:47 -04005912 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005913 }
5914
5915 Type *Float2::getType()
5916 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005917 return T(Type_v2f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005918 }
5919
Nicolas Capensa25311a2017-01-16 17:19:00 -05005920 Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005921 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005922 Value *a = Int4(cast).loadValue();
5923 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
5924
5925 storeValue(xyzw);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005926 }
5927
Nicolas Capensa25311a2017-01-16 17:19:00 -05005928 Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005929 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005930 Value *a = Int4(cast).loadValue();
5931 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
5932
5933 storeValue(xyzw);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005934 }
5935
Nicolas Capensa25311a2017-01-16 17:19:00 -05005936 Float4::Float4(RValue<Short4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005937 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005938 Int4 c(cast);
5939 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5940 }
5941
Nicolas Capensa25311a2017-01-16 17:19:00 -05005942 Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005943 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005944 Int4 c(cast);
5945 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5946 }
5947
Nicolas Capensa25311a2017-01-16 17:19:00 -05005948 Float4::Float4(RValue<Int4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005949 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005950 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
5951
5952 storeValue(xyzw);
5953 }
5954
Nicolas Capensa25311a2017-01-16 17:19:00 -05005955 Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005956 {
Nicolas Capens96445fe2016-12-15 14:45:13 -05005957 RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
5958 As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005959
Nicolas Capens96445fe2016-12-15 14:45:13 -05005960 storeValue(result.value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005961 }
5962
Nicolas Capensa25311a2017-01-16 17:19:00 -05005963 Float4::Float4() : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005964 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005965 }
5966
Nicolas Capensa25311a2017-01-16 17:19:00 -05005967 Float4::Float4(float xyzw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005968 {
5969 constant(xyzw, xyzw, xyzw, xyzw);
5970 }
5971
Nicolas Capensa25311a2017-01-16 17:19:00 -05005972 Float4::Float4(float x, float yzw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005973 {
5974 constant(x, yzw, yzw, yzw);
5975 }
5976
Nicolas Capensa25311a2017-01-16 17:19:00 -05005977 Float4::Float4(float x, float y, float zw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005978 {
5979 constant(x, y, zw, zw);
5980 }
5981
Nicolas Capensa25311a2017-01-16 17:19:00 -05005982 Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005983 {
5984 constant(x, y, z, w);
5985 }
5986
5987 void Float4::constant(float x, float y, float z, float w)
5988 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005989 double constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005990 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005991 }
5992
Nicolas Capensa25311a2017-01-16 17:19:00 -05005993 Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005994 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005995 storeValue(rhs.value);
5996 }
5997
Nicolas Capensa25311a2017-01-16 17:19:00 -05005998 Float4::Float4(const Float4 &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005999 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04006000 Value *value = rhs.loadValue();
6001 storeValue(value);
6002 }
6003
Nicolas Capensa25311a2017-01-16 17:19:00 -05006004 Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006005 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04006006 Value *value = rhs.loadValue();
6007 storeValue(value);
6008 }
6009
Nicolas Capensa25311a2017-01-16 17:19:00 -05006010 Float4::Float4(RValue<Float> rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006011 {
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08006012 Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType());
Nicolas Capensd4227962016-11-09 14:24:25 -05006013
6014 int swizzle[4] = {0, 0, 0, 0};
Nicolas Capensf8beb4b2017-01-27 02:55:44 -08006015 Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
Nicolas Capensd4227962016-11-09 14:24:25 -05006016
6017 storeValue(replicate);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006018 }
6019
Nicolas Capensa25311a2017-01-16 17:19:00 -05006020 Float4::Float4(const 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 Capensa25311a2017-01-16 17:19:00 -05006025 Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006026 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04006027 *this = RValue<Float>(rhs.loadValue());
6028 }
6029
Nicolas Capens96d4e092016-11-18 14:22:38 -05006030 RValue<Float4> Float4::operator=(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006031 {
6032 return *this = Float4(x, x, x, x);
6033 }
6034
Nicolas Capens96d4e092016-11-18 14:22:38 -05006035 RValue<Float4> Float4::operator=(RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006036 {
6037 storeValue(rhs.value);
6038
6039 return rhs;
6040 }
6041
Nicolas Capens96d4e092016-11-18 14:22:38 -05006042 RValue<Float4> Float4::operator=(const Float4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006043 {
6044 Value *value = rhs.loadValue();
6045 storeValue(value);
6046
6047 return RValue<Float4>(value);
6048 }
6049
Nicolas Capens96d4e092016-11-18 14:22:38 -05006050 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006051 {
6052 Value *value = rhs.loadValue();
6053 storeValue(value);
6054
6055 return RValue<Float4>(value);
6056 }
6057
Nicolas Capens96d4e092016-11-18 14:22:38 -05006058 RValue<Float4> Float4::operator=(RValue<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 Float &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006064 {
6065 return *this = Float4(rhs);
6066 }
6067
Nicolas Capens96d4e092016-11-18 14:22:38 -05006068 RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006069 {
6070 return *this = Float4(rhs);
6071 }
6072
6073 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
6074 {
6075 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
6076 }
6077
6078 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
6079 {
6080 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
6081 }
6082
6083 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
6084 {
6085 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
6086 }
6087
6088 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
6089 {
6090 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6091 }
6092
6093 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
6094 {
6095 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
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
Nicolas Capens96d4e092016-11-18 14:22:38 -05006118 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006119 {
6120 return lhs = lhs % rhs;
6121 }
6122
6123 RValue<Float4> operator+(RValue<Float4> val)
6124 {
6125 return val;
6126 }
6127
6128 RValue<Float4> operator-(RValue<Float4> val)
6129 {
6130 return RValue<Float4>(Nucleus::createFNeg(val.value));
6131 }
6132
6133 RValue<Float4> Abs(RValue<Float4> x)
6134 {
Nicolas Capens84272242016-11-09 13:31:06 -05006135 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6136 int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
6137 Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
6138
6139 return As<Float4>(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006140 }
6141
6142 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
6143 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006144 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006145 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ogt, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006146 ::basicBlock->appendInst(cmp);
6147
6148 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006149 auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006150 ::basicBlock->appendInst(select);
6151
6152 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006153 }
6154
6155 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
6156 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006157 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006158 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Olt, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006159 ::basicBlock->appendInst(cmp);
6160
6161 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
Nicolas Capens5cdb91a2017-02-13 12:39:18 -05006162 auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006163 ::basicBlock->appendInst(select);
6164
6165 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006166 }
6167
6168 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
6169 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006170 return Float4(1.0f) / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04006171 }
6172
6173 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
6174 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006175 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006176 }
6177
6178 RValue<Float4> Sqrt(RValue<Float4> x)
6179 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006180 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6181 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6182 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6183 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6184 sqrt->addArg(x.value);
6185 ::basicBlock->appendInst(sqrt);
6186
6187 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006188 }
6189
Nicolas Capensc94ab742016-11-08 15:15:31 -05006190 RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006191 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05006192 return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006193 }
6194
6195 RValue<Float> Extract(RValue<Float4> x, int i)
6196 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006197 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006198 }
6199
6200 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
6201 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006202 return RValue<Float4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006203 }
6204
6205 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
6206 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006207 int shuffle[4] =
6208 {
6209 ((imm >> 0) & 0x03) + 0,
6210 ((imm >> 2) & 0x03) + 0,
6211 ((imm >> 4) & 0x03) + 4,
6212 ((imm >> 6) & 0x03) + 4,
6213 };
6214
6215 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006216 }
6217
6218 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
6219 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006220 int shuffle[4] = {0, 4, 1, 5};
6221 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006222 }
6223
6224 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
6225 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006226 int shuffle[4] = {2, 6, 3, 7};
6227 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006228 }
6229
6230 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
6231 {
6232 Value *vector = lhs.loadValue();
Nicolas Capensa4c30b02016-11-08 15:43:17 -05006233 Value *result = createMask4(vector, rhs.value, select);
6234 lhs.storeValue(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006235
Nicolas Capensa4c30b02016-11-08 15:43:17 -05006236 return RValue<Float4>(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006237 }
6238
6239 RValue<Int> SignMask(RValue<Float4> x)
6240 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04006241 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
6242 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6243 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6244 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6245 movmsk->addArg(x.value);
6246 ::basicBlock->appendInst(movmsk);
6247
6248 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006249 }
6250
6251 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
6252 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006253 return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006254 }
6255
6256 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
6257 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006258 return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006259 }
6260
6261 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
6262 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006263 return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006264 }
6265
6266 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
6267 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006268 return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006269 }
6270
6271 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
6272 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006273 return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006274 }
6275
6276 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
6277 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006278 return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006279 }
6280
6281 RValue<Float4> Round(RValue<Float4> x)
6282 {
Nicolas Capensf7b75882017-04-26 09:30:47 -04006283 if(emulateIntrinsics)
6284 {
6285 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
6286 return (x + Float4(0x00C00000)) - Float4(0x00C00000);
6287 }
6288 else if(CPUID::SSE4_1)
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006289 {
6290 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6291 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6292 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6293 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6294 round->addArg(x.value);
6295 round->addArg(::context->getConstantInt32(0));
6296 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006297
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006298 return RValue<Float4>(V(result));
6299 }
6300 else
6301 {
6302 return Float4(RoundInt(x));
6303 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006304 }
6305
6306 RValue<Float4> Trunc(RValue<Float4> x)
6307 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006308 if(CPUID::SSE4_1)
6309 {
6310 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6311 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6312 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6313 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6314 round->addArg(x.value);
6315 round->addArg(::context->getConstantInt32(3));
6316 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006317
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006318 return RValue<Float4>(V(result));
6319 }
6320 else
6321 {
6322 return Float4(Int4(x));
6323 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006324 }
6325
6326 RValue<Float4> Frac(RValue<Float4> x)
6327 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006328 if(CPUID::SSE4_1)
6329 {
6330 return x - Floor(x);
6331 }
6332 else
6333 {
6334 Float4 frc = x - Float4(Int4(x)); // Signed fractional part
6335
6336 return frc + As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1)));
6337 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006338 }
6339
6340 RValue<Float4> Floor(RValue<Float4> x)
6341 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006342 if(CPUID::SSE4_1)
6343 {
6344 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6345 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6346 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6347 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6348 round->addArg(x.value);
6349 round->addArg(::context->getConstantInt32(1));
6350 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006351
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006352 return RValue<Float4>(V(result));
6353 }
6354 else
6355 {
6356 return x - Frac(x);
6357 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006358 }
6359
6360 RValue<Float4> Ceil(RValue<Float4> x)
6361 {
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006362 if(CPUID::SSE4_1)
6363 {
6364 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6365 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6366 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6367 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6368 round->addArg(x.value);
6369 round->addArg(::context->getConstantInt32(2));
6370 ::basicBlock->appendInst(round);
Nicolas Capensa8086512016-11-07 17:32:17 -05006371
Nicolas Capens9ca48d52017-01-14 12:52:55 -05006372 return RValue<Float4>(V(result));
6373 }
6374 else
6375 {
6376 return -Floor(-x);
6377 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04006378 }
6379
6380 Type *Float4::getType()
6381 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04006382 return T(Ice::IceType_v4f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006383 }
6384
6385 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
6386 {
Nicolas Capens8820f642016-09-30 04:42:43 -04006387 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006388 }
6389
6390 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6391 {
Nicolas Capensd294def2017-01-26 17:44:37 -08006392 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006393 }
6394
6395 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6396 {
Nicolas Capensd294def2017-01-26 17:44:37 -08006397 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006398 }
6399
Nicolas Capens96d4e092016-11-18 14:22:38 -05006400 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, 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<Int> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006406 {
6407 return lhs = lhs + offset;
6408 }
6409
Nicolas Capens96d4e092016-11-18 14:22:38 -05006410 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006411 {
6412 return lhs = lhs + offset;
6413 }
6414
6415 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
6416 {
6417 return lhs + -offset;
6418 }
6419
6420 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6421 {
6422 return lhs + -offset;
6423 }
6424
6425 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6426 {
6427 return lhs + -offset;
6428 }
6429
Nicolas Capens96d4e092016-11-18 14:22:38 -05006430 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, 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<Int> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006436 {
6437 return lhs = lhs - offset;
6438 }
6439
Nicolas Capens96d4e092016-11-18 14:22:38 -05006440 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006441 {
6442 return lhs = lhs - offset;
6443 }
6444
6445 void Return()
6446 {
6447 Nucleus::createRetVoid();
6448 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6449 Nucleus::createUnreachable();
6450 }
6451
Nicolas Capenseb253d02016-11-18 14:40:40 -05006452 void Return(RValue<Int> ret)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006453 {
Nicolas Capenseb253d02016-11-18 14:40:40 -05006454 Nucleus::createRet(ret.value);
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006455 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6456 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006457 }
6458
Nicolas Capensf4eec2f2017-05-24 15:46:48 -04006459 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006460 {
6461 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
6462 Nucleus::setInsertBlock(bodyBB);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006463 }
6464
Nicolas Capens598f8d82016-09-26 15:09:10 -04006465 RValue<Long> Ticks()
6466 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006467 assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006468 }
6469}