blob: 0a78f6e3e66bff7e9d7499200f076803e11e6368 [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)
Nicolas Capens598f8d82016-09-26 15:09:10 -040034#define WIN32_LEAN_AND_MEAN
35#define NOMINMAX
36#include <Windows.h>
Nicolas Capensbd65da92017-01-05 16:31:06 -050037#else
38#include <sys/mman.h>
39#endif
Nicolas Capens598f8d82016-09-26 15:09:10 -040040
41#include <mutex>
42#include <limits>
43#include <iostream>
44#include <cassert>
45
46namespace
47{
48 Ice::GlobalContext *context = nullptr;
49 Ice::Cfg *function = nullptr;
50 Ice::CfgNode *basicBlock = nullptr;
51 Ice::CfgLocalAllocatorScope *allocator = nullptr;
52 sw::Routine *routine = nullptr;
53
54 std::mutex codegenMutex;
55
56 Ice::ELFFileStreamer *elfFile = nullptr;
57 Ice::Fdstream *out = nullptr;
58}
59
60namespace sw
61{
Nicolas Capens23d99a42016-09-30 14:57:16 -040062 enum EmulatedType
63 {
64 EmulatedShift = 16,
65 EmulatedV2 = 2 << EmulatedShift,
66 EmulatedV4 = 4 << EmulatedShift,
67 EmulatedV8 = 8 << EmulatedShift,
68 EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8,
69
70 Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2,
71 Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4,
72 Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2,
73 Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8,
74 Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4,
Nicolas Capens4cfd4572016-10-20 01:00:19 -040075 Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2,
Nicolas Capens23d99a42016-09-30 14:57:16 -040076 };
77
Nicolas Capens15060bb2016-12-05 22:17:19 -050078 class Value : public Ice::Operand {};
Nicolas Capensb98fe5c2016-11-09 12:24:06 -050079 class SwitchCases : public Ice::InstSwitch {};
Nicolas Capens598f8d82016-09-26 15:09:10 -040080 class BasicBlock : public Ice::CfgNode {};
81
82 Ice::Type T(Type *t)
83 {
Nicolas Capens23d99a42016-09-30 14:57:16 -040084 static_assert(Ice::IceType_NUM < EmulatedBits, "Ice::Type overlaps with our emulated types!");
85 return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits);
Nicolas Capens598f8d82016-09-26 15:09:10 -040086 }
87
88 Type *T(Ice::Type t)
89 {
90 return reinterpret_cast<Type*>(t);
91 }
92
Nicolas Capens23d99a42016-09-30 14:57:16 -040093 Type *T(EmulatedType t)
94 {
95 return reinterpret_cast<Type*>(t);
96 }
97
Nicolas Capens15060bb2016-12-05 22:17:19 -050098 Value *V(Ice::Operand *v)
Nicolas Capens598f8d82016-09-26 15:09:10 -040099 {
100 return reinterpret_cast<Value*>(v);
101 }
102
Nicolas Capens611642a2016-09-28 16:45:04 -0400103 BasicBlock *B(Ice::CfgNode *b)
104 {
105 return reinterpret_cast<BasicBlock*>(b);
106 }
107
Nicolas Capens598f8d82016-09-26 15:09:10 -0400108 Optimization optimization[10] = {InstructionCombining, Disabled};
109
Nicolas Capens66478362016-10-13 15:36:36 -0400110 using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type;
111 using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type;
112
113 inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader)
114 {
115 return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff);
116 }
Nicolas Capens87852e12016-11-24 14:45:06 -0500117
Nicolas Capens66478362016-10-13 15:36:36 -0400118 inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index)
119 {
120 return &sectionHeader(elfHeader)[index];
121 }
122
123 static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable)
124 {
125 const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info);
Nicolas Capens87852e12016-11-24 14:45:06 -0500126
Nicolas Capens66478362016-10-13 15:36:36 -0400127 intptr_t address = (intptr_t)elfHeader + target->sh_offset;
128 int32_t *patchSite = (int*)(address + relocation.r_offset);
129 uint32_t index = relocation.getSymbol();
130 int table = relocationTable.sh_link;
131 void *symbolValue = nullptr;
Nicolas Capens87852e12016-11-24 14:45:06 -0500132
Nicolas Capens66478362016-10-13 15:36:36 -0400133 if(index != SHN_UNDEF)
134 {
135 if(table == SHN_UNDEF) return nullptr;
136 const SectionHeader *symbolTable = elfSection(elfHeader, table);
Nicolas Capens87852e12016-11-24 14:45:06 -0500137
Nicolas Capens66478362016-10-13 15:36:36 -0400138 uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize;
139 if(index >= symtab_entries)
140 {
141 assert(index < symtab_entries && "Symbol Index out of range");
142 return nullptr;
143 }
Nicolas Capens87852e12016-11-24 14:45:06 -0500144
Nicolas Capens66478362016-10-13 15:36:36 -0400145 intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset;
146 Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index];
147 uint16_t section = symbol.st_shndx;
148
149 if(section != SHN_UNDEF && section < SHN_LORESERVE)
150 {
151 const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx);
152 symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset);
153 }
154 else
155 {
156 return nullptr;
157 }
158 }
159
160 switch(relocation.getType())
161 {
162 case R_386_NONE:
163 // No relocation
164 break;
165 case R_386_32:
166 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite);
167 break;
168 // case R_386_PC32:
169 // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite);
170 // break;
171 default:
172 assert(false && "Unsupported relocation type");
173 return nullptr;
174 }
175
176 return symbolValue;
177 }
178
179 static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable)
180 {
181 const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info);
Nicolas Capens87852e12016-11-24 14:45:06 -0500182
Nicolas Capens66478362016-10-13 15:36:36 -0400183 intptr_t address = (intptr_t)elfHeader + target->sh_offset;
184 int32_t *patchSite = (int*)(address + relocation.r_offset);
185 uint32_t index = relocation.getSymbol();
186 int table = relocationTable.sh_link;
187 void *symbolValue = nullptr;
188
189 if(index != SHN_UNDEF)
190 {
191 if(table == SHN_UNDEF) return nullptr;
192 const SectionHeader *symbolTable = elfSection(elfHeader, table);
Nicolas Capens87852e12016-11-24 14:45:06 -0500193
Nicolas Capens66478362016-10-13 15:36:36 -0400194 uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize;
195 if(index >= symtab_entries)
196 {
197 assert(index < symtab_entries && "Symbol Index out of range");
198 return nullptr;
199 }
Nicolas Capens87852e12016-11-24 14:45:06 -0500200
Nicolas Capens66478362016-10-13 15:36:36 -0400201 intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset;
202 Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index];
203 uint16_t section = symbol.st_shndx;
204
205 if(section != SHN_UNDEF && section < SHN_LORESERVE)
206 {
207 const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx);
208 symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset);
209 }
210 else
211 {
212 return nullptr;
213 }
214 }
215
216 switch(relocation.getType())
217 {
218 case R_X86_64_NONE:
219 // No relocation
220 break;
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500221 case R_X86_64_64:
222 *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend;
223 break;
Nicolas Capens66478362016-10-13 15:36:36 -0400224 case R_X86_64_PC32:
225 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend;
226 break;
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500227 case R_X86_64_32S:
228 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend;
229 break;
Nicolas Capens66478362016-10-13 15:36:36 -0400230 default:
231 assert(false && "Unsupported relocation type");
232 return nullptr;
233 }
234
235 return symbolValue;
236 }
237
Nicolas Capens598f8d82016-09-26 15:09:10 -0400238 void *loadImage(uint8_t *const elfImage)
239 {
Nicolas Capens598f8d82016-09-26 15:09:10 -0400240 ElfHeader *elfHeader = (ElfHeader*)elfImage;
241
242 if(!elfHeader->checkMagic())
243 {
244 return nullptr;
245 }
246
Nicolas Capens66478362016-10-13 15:36:36 -0400247 // Expect ELF bitness to match platform
Nicolas Capens65047112016-11-07 13:01:07 -0500248 assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32);
Nicolas Capens66478362016-10-13 15:36:36 -0400249 assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386);
250
Nicolas Capens598f8d82016-09-26 15:09:10 -0400251 SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff);
252 void *entry = nullptr;
253
254 for(int i = 0; i < elfHeader->e_shnum; i++)
255 {
Nicolas Capens66478362016-10-13 15:36:36 -0400256 if(sectionHeader[i].sh_type == SHT_PROGBITS)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400257 {
Nicolas Capens66478362016-10-13 15:36:36 -0400258 if(sectionHeader[i].sh_flags & SHF_EXECINSTR)
259 {
260 entry = elfImage + sectionHeader[i].sh_offset;
261 }
262 }
263 else if(sectionHeader[i].sh_type == SHT_REL)
264 {
265 assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code
266
267 for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
268 {
269 const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index];
270 void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]);
271 }
272 }
273 else if(sectionHeader[i].sh_type == SHT_RELA)
274 {
275 assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code
276
277 for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
278 {
279 const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index];
280 void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]);
281 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400282 }
283 }
284
285 return entry;
286 }
287
288 template<typename T>
289 struct ExecutableAllocator
290 {
291 ExecutableAllocator() {};
292 template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {};
293
294 using value_type = T;
295 using size_type = std::size_t;
296
297 T *allocate(size_type n)
298 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500299 #if defined(_WIN32)
300 return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
301 #else
302 return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
303 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400304 }
305
306 void deallocate(T *p, size_type n)
307 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500308 #if defined(_WIN32)
309 VirtualFree(p, 0, MEM_RELEASE);
310 #else
311 munmap(p, sizeof(T) * n);
312 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400313 }
314 };
315
316 class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine
317 {
318 ELFMemoryStreamer(const ELFMemoryStreamer &) = delete;
319 ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete;
320
321 public:
Nicolas Capens58274b52016-10-19 23:45:19 -0400322 ELFMemoryStreamer() : Routine(), entry(nullptr)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400323 {
324 position = 0;
325 buffer.reserve(0x1000);
326 }
327
328 virtual ~ELFMemoryStreamer()
329 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500330 #if defined(_WIN32)
331 if(buffer.size() != 0)
332 {
333 DWORD exeProtection;
334 VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection);
335 }
336 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400337 }
338
339 void write8(uint8_t Value) override
340 {
341 if(position == (uint64_t)buffer.size())
342 {
343 buffer.push_back(Value);
344 position++;
345 }
346 else if(position < (uint64_t)buffer.size())
347 {
348 buffer[position] = Value;
349 position++;
350 }
351 else assert(false && "UNIMPLEMENTED");
352 }
353
354 void writeBytes(llvm::StringRef Bytes) override
355 {
356 std::size_t oldSize = buffer.size();
357 buffer.resize(oldSize + Bytes.size());
358 memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size());
359 position += Bytes.size();
360 }
361
362 uint64_t tell() const override { return position; }
363
364 void seek(uint64_t Off) override { position = Off; }
365
366 const void *getEntry() override
367 {
Nicolas Capens58274b52016-10-19 23:45:19 -0400368 if(!entry)
369 {
Nicolas Capensbd65da92017-01-05 16:31:06 -0500370 #if defined(_WIN32)
371 VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection);
372 #else
373 mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_WRITE | PROT_EXEC);
374 #endif
375
376 position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this
Nicolas Capens598f8d82016-09-26 15:09:10 -0400377
Nicolas Capens58274b52016-10-19 23:45:19 -0400378 entry = loadImage(&buffer[0]);
379 }
380
381 return entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400382 }
383
384 private:
Nicolas Capens58274b52016-10-19 23:45:19 -0400385 void *entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400386 std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer;
387 std::size_t position;
Nicolas Capensbd65da92017-01-05 16:31:06 -0500388
389 #if defined(_WIN32)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400390 DWORD oldProtection;
Nicolas Capensbd65da92017-01-05 16:31:06 -0500391 #endif
Nicolas Capens598f8d82016-09-26 15:09:10 -0400392 };
393
394 Nucleus::Nucleus()
395 {
396 ::codegenMutex.lock(); // Reactor is currently not thread safe
397
Nicolas Capens66478362016-10-13 15:36:36 -0400398 Ice::ClFlags &Flags = Ice::ClFlags::Flags;
399 Ice::ClFlags::getParsedClFlags(Flags);
400
401 Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632);
402 Flags.setOutFileType(Ice::FT_Elf);
403 Flags.setOptLevel(Ice::Opt_2);
404 Flags.setApplicationBinaryInterface(Ice::ABI_Platform);
Nicolas Capensa8086512016-11-07 17:32:17 -0500405 Flags.setTargetInstructionSet(Ice::X86InstructionSet_SSE4_1);
Nicolas Capens65047112016-11-07 13:01:07 -0500406 Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400407
Nicolas Capens65047112016-11-07 13:01:07 -0500408 static llvm::raw_os_ostream cout(std::cout);
409 static llvm::raw_os_ostream cerr(std::cerr);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400410
411 if(false) // Write out to a file
412 {
413 std::error_code errorCode;
414 ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None);
415 ::elfFile = new Ice::ELFFileStreamer(*out);
Nicolas Capens65047112016-11-07 13:01:07 -0500416 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400417 }
418 else
419 {
420 ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer();
Nicolas Capens65047112016-11-07 13:01:07 -0500421 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400422 ::routine = elfMemory;
423 }
424 }
425
426 Nucleus::~Nucleus()
427 {
428 delete ::allocator;
429 delete ::function;
430 delete ::context;
431
432 delete ::elfFile;
433 delete ::out;
434
435 ::codegenMutex.unlock();
436 }
437
438 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
439 {
440 if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
441 {
442 createRetVoid();
443 }
444
445 std::wstring wideName(name);
446 std::string asciiName(wideName.begin(), wideName.end());
447 ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
448
Nicolas Capens2ae9d742016-11-24 14:43:05 -0500449 optimize();
450
Nicolas Capens598f8d82016-09-26 15:09:10 -0400451 ::function->translate();
Nicolas Capensde19f392016-10-19 10:29:49 -0400452 assert(!::function->hasError());
453
Nicolas Capens66478362016-10-13 15:36:36 -0400454 auto *globals = ::function->getGlobalInits().release();
455
456 if(globals && !globals->empty())
457 {
458 ::context->getGlobals()->merge(globals);
459 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400460
461 ::context->emitFileHeader();
462 ::function->emitIAS();
463 auto assembler = ::function->releaseAssembler();
Nicolas Capens66478362016-10-13 15:36:36 -0400464 auto objectWriter = ::context->getObjectWriter();
465 assembler->alignFunction();
466 objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
467 ::context->lowerGlobals("last");
Nicolas Capens73dd7a22016-10-20 13:20:34 -0400468 ::context->lowerConstants();
Nicolas Capensb98fe5c2016-11-09 12:24:06 -0500469 ::context->lowerJumpTables();
Nicolas Capens66478362016-10-13 15:36:36 -0400470 objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
471 objectWriter->writeNonUserSections();
Nicolas Capens598f8d82016-09-26 15:09:10 -0400472
473 return ::routine;
474 }
475
476 void Nucleus::optimize()
477 {
Nicolas Capens2ae9d742016-11-24 14:43:05 -0500478 sw::optimize(::function);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400479 }
480
481 Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
482 {
483 Ice::Type type = T(t);
Nicolas Capensa8f98632016-10-20 11:25:55 -0400484 int typeSize = Ice::typeWidthInBytes(type);
485 int totalSize = typeSize * (arraySize ? arraySize : 1);
Nicolas Capense12780d2016-09-27 14:18:07 -0400486
Nicolas Capensa8f98632016-10-20 11:25:55 -0400487 auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400488 auto address = ::function->makeVariable(T(getPointerType(t)));
Nicolas Capensa8f98632016-10-20 11:25:55 -0400489 auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400490 ::function->getEntryNode()->getInsts().push_front(alloca);
491
492 return V(address);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400493 }
494
495 BasicBlock *Nucleus::createBasicBlock()
496 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400497 return B(::function->makeNode());
Nicolas Capens598f8d82016-09-26 15:09:10 -0400498 }
499
500 BasicBlock *Nucleus::getInsertBlock()
501 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400502 return B(::basicBlock);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400503 }
504
505 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
506 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -0400507 // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator");
Nicolas Capens611642a2016-09-28 16:45:04 -0400508 ::basicBlock = basicBlock;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400509 }
510
Nicolas Capens598f8d82016-09-26 15:09:10 -0400511 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
512 {
513 uint32_t sequenceNumber = 0;
514 ::function = Ice::Cfg::create(::context, sequenceNumber).release();
515 ::allocator = new Ice::CfgLocalAllocatorScope(::function);
516
517 for(Type *type : Params)
518 {
519 Ice::Variable *arg = ::function->makeVariable(T(type));
520 ::function->addArg(arg);
521 }
522
523 Ice::CfgNode *node = ::function->makeNode();
524 ::function->setEntryNode(node);
525 ::basicBlock = node;
526 }
527
528 Value *Nucleus::getArgument(unsigned int index)
529 {
530 return V(::function->getArgs()[index]);
531 }
532
533 void Nucleus::createRetVoid()
534 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400535 Ice::InstRet *ret = Ice::InstRet::create(::function);
536 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400537 }
538
539 void Nucleus::createRet(Value *v)
540 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400541 Ice::InstRet *ret = Ice::InstRet::create(::function, v);
542 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400543 }
544
545 void Nucleus::createBr(BasicBlock *dest)
546 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400547 auto br = Ice::InstBr::create(::function, dest);
548 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400549 }
550
551 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
552 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400553 auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse);
554 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400555 }
556
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400557 static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
558 {
Nicolas Capens327f1df2016-10-21 14:26:34 -0400559 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 -0400560
561 Ice::Variable *result = ::function->makeVariable(lhs->getType());
562 Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs);
563 ::basicBlock->appendInst(arithmetic);
564
565 return V(result);
566 }
567
Nicolas Capens598f8d82016-09-26 15:09:10 -0400568 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
569 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400570 return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400571 }
572
573 Value *Nucleus::createSub(Value *lhs, Value *rhs)
574 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400575 return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400576 }
577
578 Value *Nucleus::createMul(Value *lhs, Value *rhs)
579 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400580 return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400581 }
582
583 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
584 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400585 return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400586 }
587
588 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
589 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400590 return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400591 }
592
593 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
594 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400595 return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400596 }
597
598 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
599 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400600 return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400601 }
602
603 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
604 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400605 return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400606 }
607
608 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
609 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400610 return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400611 }
612
613 Value *Nucleus::createURem(Value *lhs, Value *rhs)
614 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400615 return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400616 }
617
618 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
619 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400620 return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400621 }
622
623 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
624 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400625 return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400626 }
627
628 Value *Nucleus::createShl(Value *lhs, Value *rhs)
629 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400630 return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400631 }
632
633 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
634 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400635 return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400636 }
637
638 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
639 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400640 return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400641 }
642
643 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
644 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400645 return createArithmetic(Ice::InstArithmetic::And, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400646 }
647
648 Value *Nucleus::createOr(Value *lhs, Value *rhs)
649 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400650 return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400651 }
652
653 Value *Nucleus::createXor(Value *lhs, Value *rhs)
654 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400655 return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400656 }
657
Nicolas Capens15060bb2016-12-05 22:17:19 -0500658 static Ice::Variable *createAssign(Ice::Operand *constant)
Nicolas Capensb955d5b2016-09-28 22:36:28 -0400659 {
660 Ice::Variable *value = ::function->makeVariable(constant->getType());
661 auto assign = Ice::InstAssign::create(::function, value, constant);
662 ::basicBlock->appendInst(assign);
663
Nicolas Capens15060bb2016-12-05 22:17:19 -0500664 return value;
Nicolas Capensb955d5b2016-09-28 22:36:28 -0400665 }
666
Nicolas Capens598f8d82016-09-26 15:09:10 -0400667 Value *Nucleus::createNeg(Value *v)
668 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500669 return createSub(createNullValue(T(v->getType())), v);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400670 }
671
672 Value *Nucleus::createFNeg(Value *v)
673 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500674 double c[4] = {-0.0, -0.0, -0.0, -0.0};
675 Value *negativeZero = Ice::isVectorType(v->getType()) ?
676 createConstantVector(c, T(v->getType())) :
Nicolas Capens15060bb2016-12-05 22:17:19 -0500677 V(::context->getConstantFloat(-0.0f));
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500678
679 return createFSub(negativeZero, v);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400680 }
681
682 Value *Nucleus::createNot(Value *v)
683 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500684 if(Ice::isScalarIntegerType(v->getType()))
685 {
Nicolas Capens15060bb2016-12-05 22:17:19 -0500686 return createXor(v, V(::context->getConstantInt(v->getType(), -1)));
Nicolas Capensc5c0c332016-11-08 11:37:01 -0500687 }
688 else // Vector
689 {
690 int64_t c[4] = {-1, -1, -1, -1};
691 return createXor(v, createConstantVector(c, T(v->getType())));
692 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400693 }
694
Nicolas Capense12780d2016-09-27 14:18:07 -0400695 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400696 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400697 int valueType = (int)reinterpret_cast<intptr_t>(type);
698 Ice::Variable *result = ::function->makeVariable(T(type));
699
700 if(valueType & EmulatedBits)
701 {
702 switch(valueType)
703 {
704 case Type_v4i8:
705 case Type_v2i16:
706 {
707 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
708 auto target = ::context->getConstantUndef(Ice::IceType_i32);
709 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400710 load->addArg(ptr);
Nicolas Capens87852e12016-11-24 14:45:06 -0500711 load->addArg(::context->getConstantInt32(4));
Nicolas Capens23d99a42016-09-30 14:57:16 -0400712 ::basicBlock->appendInst(load);
713 }
714 break;
715 case Type_v2i32:
716 case Type_v8i8:
717 case Type_v4i16:
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400718 case Type_v2f32:
Nicolas Capens23d99a42016-09-30 14:57:16 -0400719 {
720 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
721 auto target = ::context->getConstantUndef(Ice::IceType_i32);
722 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400723 load->addArg(ptr);
Nicolas Capens87852e12016-11-24 14:45:06 -0500724 load->addArg(::context->getConstantInt32(8));
Nicolas Capens23d99a42016-09-30 14:57:16 -0400725 ::basicBlock->appendInst(load);
726 }
727 break;
728 default: assert(false && "UNIMPLEMENTED");
729 }
730 }
731 else
732 {
733 auto load = Ice::InstLoad::create(::function, result, ptr, align);
734 ::basicBlock->appendInst(load);
735 }
736
737 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400738 }
739
Nicolas Capens6d738712016-09-30 04:15:22 -0400740 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400741 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400742 int valueType = (int)reinterpret_cast<intptr_t>(type);
743
744 if(valueType & EmulatedBits)
745 {
746 switch(valueType)
747 {
748 case Type_v4i8:
749 case Type_v2i16:
750 {
751 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
752 auto target = ::context->getConstantUndef(Ice::IceType_i32);
753 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400754 store->addArg(value);
755 store->addArg(ptr);
Nicolas Capens87852e12016-11-24 14:45:06 -0500756 store->addArg(::context->getConstantInt32(4));
Nicolas Capens23d99a42016-09-30 14:57:16 -0400757 ::basicBlock->appendInst(store);
758 }
759 break;
760 case Type_v2i32:
761 case Type_v8i8:
762 case Type_v4i16:
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400763 case Type_v2f32:
Nicolas Capens23d99a42016-09-30 14:57:16 -0400764 {
765 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
766 auto target = ::context->getConstantUndef(Ice::IceType_i32);
767 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
Nicolas Capens23d99a42016-09-30 14:57:16 -0400768 store->addArg(value);
769 store->addArg(ptr);
Nicolas Capens87852e12016-11-24 14:45:06 -0500770 store->addArg(::context->getConstantInt32(8));
Nicolas Capens23d99a42016-09-30 14:57:16 -0400771 ::basicBlock->appendInst(store);
772 }
773 break;
774 default: assert(false && "UNIMPLEMENTED");
775 }
776 }
777 else
778 {
779 assert(T(value->getType()) == type);
780
781 auto store = Ice::InstStore::create(::function, value, ptr, align);
782 ::basicBlock->appendInst(store);
783 }
784
Nicolas Capens598f8d82016-09-26 15:09:10 -0400785 return value;
786 }
787
Nicolas Capens6d738712016-09-30 04:15:22 -0400788 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400789 {
Nicolas Capens8820f642016-09-30 04:42:43 -0400790 assert(index->getType() == Ice::IceType_i32);
791
Nicolas Capens15060bb2016-12-05 22:17:19 -0500792 if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index))
793 {
794 int32_t offset = constant->getValue() * (int)Ice::typeWidthInBytes(T(type));
795
796 if(offset == 0)
797 {
798 return ptr;
799 }
800
801 return createAdd(ptr, createConstantInt(offset));
802 }
803
Nicolas Capens8820f642016-09-30 04:42:43 -0400804 if(!Ice::isByteSizedType(T(type)))
805 {
Nicolas Capens13ac2322016-10-13 14:52:12 -0400806 index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type))));
Nicolas Capens8820f642016-09-30 04:42:43 -0400807 }
808
809 if(sizeof(void*) == 8)
810 {
811 index = createSExt(index, T(Ice::IceType_i64));
812 }
813
814 return createAdd(ptr, index);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400815 }
816
817 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
818 {
819 assert(false && "UNIMPLEMENTED"); return nullptr;
820 }
821
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400822 static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType)
823 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400824 if(v->getType() == T(destType))
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400825 {
826 return v;
827 }
828
829 Ice::Variable *result = ::function->makeVariable(T(destType));
830 Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v);
831 ::basicBlock->appendInst(cast);
832
833 return V(result);
834 }
835
Nicolas Capens598f8d82016-09-26 15:09:10 -0400836 Value *Nucleus::createTrunc(Value *v, Type *destType)
837 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400838 return createCast(Ice::InstCast::Trunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400839 }
840
841 Value *Nucleus::createZExt(Value *v, Type *destType)
842 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400843 return createCast(Ice::InstCast::Zext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400844 }
845
846 Value *Nucleus::createSExt(Value *v, Type *destType)
847 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400848 return createCast(Ice::InstCast::Sext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400849 }
850
851 Value *Nucleus::createFPToSI(Value *v, Type *destType)
852 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400853 return createCast(Ice::InstCast::Fptosi, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400854 }
855
Nicolas Capens598f8d82016-09-26 15:09:10 -0400856 Value *Nucleus::createSIToFP(Value *v, Type *destType)
857 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400858 return createCast(Ice::InstCast::Sitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400859 }
860
861 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
862 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400863 return createCast(Ice::InstCast::Fptrunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400864 }
865
866 Value *Nucleus::createFPExt(Value *v, Type *destType)
867 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400868 return createCast(Ice::InstCast::Fpext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400869 }
870
871 Value *Nucleus::createBitCast(Value *v, Type *destType)
872 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400873 return createCast(Ice::InstCast::Bitcast, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400874 }
875
Nicolas Capens43dc6292016-10-20 00:01:38 -0400876 static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400877 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400878 assert(lhs->getType() == rhs->getType());
879
Nicolas Capens43dc6292016-10-20 00:01:38 -0400880 auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType());
881 auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs);
Nicolas Capens611642a2016-09-28 16:45:04 -0400882 ::basicBlock->appendInst(cmp);
883
884 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400885 }
886
Nicolas Capens43dc6292016-10-20 00:01:38 -0400887 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
888 {
889 return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs);
890 }
891
892 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
893 {
894 return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs);
895 }
896
897 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
898 {
899 return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs);
900 }
901
902 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
903 {
904 return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs);
905 }
906
907 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
908 {
909 return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs);
910 }
911
912 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
913 {
914 return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs);
915 }
916
917 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
918 {
919 return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs);
920 }
921
922 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
923 {
924 return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs);
925 }
926
927 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
928 {
929 return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs);
930 }
931
Nicolas Capens598f8d82016-09-26 15:09:10 -0400932 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
933 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400934 return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs);
935 }
936
937 static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs)
938 {
939 assert(lhs->getType() == rhs->getType());
940 assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32);
941
942 auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32);
943 auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs);
944 ::basicBlock->appendInst(cmp);
945
946 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400947 }
948
949 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
950 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400951 return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400952 }
953
954 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
955 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400956 return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400957 }
958
959 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
960 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400961 return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400962 }
963
964 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
965 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400966 return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400967 }
968
969 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
970 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400971 return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400972 }
973
974 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
975 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400976 return createFloatCompare(Ice::InstFcmp::One, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400977 }
978
979 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
980 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400981 return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400982 }
983
984 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
985 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400986 return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400987 }
988
989 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
990 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400991 return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400992 }
993
994 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
995 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400996 return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400997 }
998
999 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
1000 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001001 return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001002 }
1003
1004 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
1005 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001006 return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001007 }
1008
1009 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
1010 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001011 return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001012 }
1013
1014 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
1015 {
Nicolas Capens43dc6292016-10-20 00:01:38 -04001016 return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001017 }
1018
Nicolas Capense95d5342016-09-30 11:37:28 -04001019 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001020 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001021 auto result = ::function->makeVariable(T(type));
1022 auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index));
1023 ::basicBlock->appendInst(extract);
1024
1025 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001026 }
1027
1028 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
1029 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001030 auto result = ::function->makeVariable(vector->getType());
1031 auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index));
1032 ::basicBlock->appendInst(insert);
1033
1034 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001035 }
1036
Nicolas Capense89cd582016-09-30 14:23:47 -04001037 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001038 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001039 assert(V1->getType() == V2->getType());
1040
1041 int size = Ice::typeNumElements(V1->getType());
1042 auto result = ::function->makeVariable(V1->getType());
1043 auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2);
1044
1045 for(int i = 0; i < size; i++)
1046 {
1047 shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i])));
1048 }
1049
1050 ::basicBlock->appendInst(shuffle);
1051
1052 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001053 }
1054
1055 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
1056 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04001057 assert(ifTrue->getType() == ifFalse->getType());
1058
1059 auto result = ::function->makeVariable(ifTrue->getType());
1060 auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse);
1061 ::basicBlock->appendInst(select);
1062
1063 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001064 }
1065
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001066 SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001067 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001068 auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch);
1069 ::basicBlock->appendInst(switchInst);
1070
1071 return reinterpret_cast<SwitchCases*>(switchInst);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001072 }
1073
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001074 void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001075 {
Nicolas Capensb98fe5c2016-11-09 12:24:06 -05001076 switchCases->addBranch(label, label, branch);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001077 }
1078
1079 void Nucleus::createUnreachable()
1080 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04001081 Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function);
1082 ::basicBlock->appendInst(unreachable);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001083 }
1084
Nicolas Capense95d5342016-09-30 11:37:28 -04001085 static Value *createSwizzle4(Value *val, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001086 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001087 int swizzle[4] =
1088 {
1089 (select >> 0) & 0x03,
1090 (select >> 2) & 0x03,
1091 (select >> 4) & 0x03,
1092 (select >> 6) & 0x03,
1093 };
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001094
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001095 return Nucleus::createShuffleVector(val, val, swizzle);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001096 }
1097
Nicolas Capense95d5342016-09-30 11:37:28 -04001098 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001099 {
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001100 int64_t mask[4] = {0, 0, 0, 0};
1101
1102 mask[(select >> 0) & 0x03] = -1;
1103 mask[(select >> 2) & 0x03] = -1;
1104 mask[(select >> 4) & 0x03] = -1;
1105 mask[(select >> 6) & 0x03] = -1;
1106
1107 Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1));
1108 Value *result = Nucleus::createSelect(condition, rhs, lhs);
1109
1110 return result;
Nicolas Capens598f8d82016-09-26 15:09:10 -04001111 }
1112
Nicolas Capens598f8d82016-09-26 15:09:10 -04001113 Type *Nucleus::getPointerType(Type *ElementType)
1114 {
Nicolas Capense12780d2016-09-27 14:18:07 -04001115 if(sizeof(void*) == 8)
1116 {
1117 return T(Ice::IceType_i64);
1118 }
1119 else
1120 {
1121 return T(Ice::IceType_i32);
1122 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001123 }
1124
Nicolas Capens13ac2322016-10-13 14:52:12 -04001125 Value *Nucleus::createNullValue(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001126 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001127 if(Ice::isVectorType(T(Ty)))
1128 {
1129 int64_t c[4] = {0, 0, 0, 0};
1130 return createConstantVector(c, Ty);
1131 }
1132 else
1133 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001134 return V(::context->getConstantZero(T(Ty)));
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001135 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001136 }
1137
Nicolas Capens13ac2322016-10-13 14:52:12 -04001138 Value *Nucleus::createConstantLong(int64_t i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001139 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001140 return V(::context->getConstantInt64(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001141 }
1142
Nicolas Capens13ac2322016-10-13 14:52:12 -04001143 Value *Nucleus::createConstantInt(int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001144 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001145 return V(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001146 }
1147
Nicolas Capens13ac2322016-10-13 14:52:12 -04001148 Value *Nucleus::createConstantInt(unsigned int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001149 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001150 return V(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001151 }
1152
Nicolas Capens13ac2322016-10-13 14:52:12 -04001153 Value *Nucleus::createConstantBool(bool b)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001154 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001155 return V(::context->getConstantInt1(b));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001156 }
1157
Nicolas Capens13ac2322016-10-13 14:52:12 -04001158 Value *Nucleus::createConstantByte(signed char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001159 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001160 return V(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001161 }
1162
Nicolas Capens13ac2322016-10-13 14:52:12 -04001163 Value *Nucleus::createConstantByte(unsigned char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001164 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001165 return V(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001166 }
1167
Nicolas Capens13ac2322016-10-13 14:52:12 -04001168 Value *Nucleus::createConstantShort(short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001169 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001170 return V(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001171 }
1172
Nicolas Capens13ac2322016-10-13 14:52:12 -04001173 Value *Nucleus::createConstantShort(unsigned short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001174 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001175 return V(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001176 }
1177
Nicolas Capens13ac2322016-10-13 14:52:12 -04001178 Value *Nucleus::createConstantFloat(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001179 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05001180 return V(::context->getConstantFloat(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001181 }
1182
Nicolas Capens13ac2322016-10-13 14:52:12 -04001183 Value *Nucleus::createNullPointer(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001184 {
Nicolas Capensa29d6532016-12-05 21:38:09 -05001185 return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001186 }
1187
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001188 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
Nicolas Capens13ac2322016-10-13 14:52:12 -04001189 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001190 const int vectorSize = 16;
1191 assert(Ice::typeWidthInBytes(T(type)) == vectorSize);
1192 const int alignment = vectorSize;
1193 auto globalPool = ::function->getGlobalPool();
1194
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001195 const int64_t *i = constants;
1196 const double *f = reinterpret_cast<const double*>(constants);
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001197 Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr;
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001198
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001199 switch((int)reinterpret_cast<intptr_t>(type))
1200 {
1201 case Ice::IceType_v4i32:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001202 case Ice::IceType_v4i1:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001203 {
1204 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]};
1205 static_assert(sizeof(initializer) == vectorSize, "!");
1206 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1207 }
1208 break;
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001209 case Ice::IceType_v4f32:
1210 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001211 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001212 static_assert(sizeof(initializer) == vectorSize, "!");
1213 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1214 }
1215 break;
1216 case Ice::IceType_v8i16:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001217 case Ice::IceType_v8i1:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001218 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001219 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 -04001220 static_assert(sizeof(initializer) == vectorSize, "!");
1221 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1222 }
1223 break;
1224 case Ice::IceType_v16i8:
Nicolas Capensa4c30b02016-11-08 15:43:17 -05001225 case Ice::IceType_v16i1:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001226 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001227 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 -04001228 static_assert(sizeof(initializer) == vectorSize, "!");
1229 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1230 }
1231 break;
1232 case Type_v2i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001233 {
1234 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]};
1235 static_assert(sizeof(initializer) == vectorSize, "!");
1236 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1237 }
1238 break;
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001239 case Type_v2f32:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001240 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001241 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001242 static_assert(sizeof(initializer) == vectorSize, "!");
1243 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1244 }
1245 break;
1246 case Type_v4i16:
1247 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001248 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 -04001249 static_assert(sizeof(initializer) == vectorSize, "!");
1250 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1251 }
1252 break;
1253 case Type_v8i8:
1254 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001255 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 -04001256 static_assert(sizeof(initializer) == vectorSize, "!");
1257 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1258 }
1259 break;
1260 case Type_v4i8:
1261 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001262 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 -04001263 static_assert(sizeof(initializer) == vectorSize, "!");
1264 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1265 }
1266 break;
1267 default:
1268 assert(false && "Unknown constant vector type" && type);
1269 }
1270
1271 auto name = Ice::GlobalString::createWithoutString(::context);
1272 auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool);
1273 variableDeclaration->setName(name);
1274 variableDeclaration->setAlignment(alignment);
1275 variableDeclaration->setIsConstant(true);
1276 variableDeclaration->addInitializer(dataInitializer);
Nicolas Capens87852e12016-11-24 14:45:06 -05001277
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001278 ::function->addGlobal(variableDeclaration);
1279
1280 constexpr int32_t offset = 0;
1281 Ice::Operand *ptr = ::context->getConstantSym(offset, name);
1282
1283 Ice::Variable *result = ::function->makeVariable(T(type));
1284 auto load = Ice::InstLoad::create(::function, result, ptr, alignment);
1285 ::basicBlock->appendInst(load);
1286
1287 return V(result);
Nicolas Capens13ac2322016-10-13 14:52:12 -04001288 }
1289
1290 Value *Nucleus::createConstantVector(const double *constants, Type *type)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001291 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001292 return createConstantVector((const int64_t*)constants, type);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001293 }
1294
1295 Type *Void::getType()
1296 {
1297 return T(Ice::IceType_void);
1298 }
1299
Nicolas Capens598f8d82016-09-26 15:09:10 -04001300 Bool::Bool(Argument<Bool> argument)
1301 {
1302 storeValue(argument.value);
1303 }
1304
Nicolas Capens598f8d82016-09-26 15:09:10 -04001305 Bool::Bool(bool x)
1306 {
1307 storeValue(Nucleus::createConstantBool(x));
1308 }
1309
1310 Bool::Bool(RValue<Bool> rhs)
1311 {
1312 storeValue(rhs.value);
1313 }
1314
1315 Bool::Bool(const Bool &rhs)
1316 {
1317 Value *value = rhs.loadValue();
1318 storeValue(value);
1319 }
1320
1321 Bool::Bool(const Reference<Bool> &rhs)
1322 {
1323 Value *value = rhs.loadValue();
1324 storeValue(value);
1325 }
1326
Nicolas Capens96d4e092016-11-18 14:22:38 -05001327 RValue<Bool> Bool::operator=(RValue<Bool> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001328 {
1329 storeValue(rhs.value);
1330
1331 return rhs;
1332 }
1333
Nicolas Capens96d4e092016-11-18 14:22:38 -05001334 RValue<Bool> Bool::operator=(const Bool &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001335 {
1336 Value *value = rhs.loadValue();
1337 storeValue(value);
1338
1339 return RValue<Bool>(value);
1340 }
1341
Nicolas Capens96d4e092016-11-18 14:22:38 -05001342 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001343 {
1344 Value *value = rhs.loadValue();
1345 storeValue(value);
1346
1347 return RValue<Bool>(value);
1348 }
1349
1350 RValue<Bool> operator!(RValue<Bool> val)
1351 {
1352 return RValue<Bool>(Nucleus::createNot(val.value));
1353 }
1354
1355 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
1356 {
1357 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1358 }
1359
1360 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
1361 {
1362 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1363 }
1364
1365 Type *Bool::getType()
1366 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001367 return T(Ice::IceType_i1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001368 }
1369
1370 Byte::Byte(Argument<Byte> argument)
1371 {
1372 storeValue(argument.value);
1373 }
1374
1375 Byte::Byte(RValue<Int> cast)
1376 {
1377 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1378
1379 storeValue(integer);
1380 }
1381
1382 Byte::Byte(RValue<UInt> cast)
1383 {
1384 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1385
1386 storeValue(integer);
1387 }
1388
1389 Byte::Byte(RValue<UShort> cast)
1390 {
1391 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1392
1393 storeValue(integer);
1394 }
1395
Nicolas Capens598f8d82016-09-26 15:09:10 -04001396 Byte::Byte(int x)
1397 {
1398 storeValue(Nucleus::createConstantByte((unsigned char)x));
1399 }
1400
1401 Byte::Byte(unsigned char x)
1402 {
1403 storeValue(Nucleus::createConstantByte(x));
1404 }
1405
1406 Byte::Byte(RValue<Byte> rhs)
1407 {
1408 storeValue(rhs.value);
1409 }
1410
1411 Byte::Byte(const Byte &rhs)
1412 {
1413 Value *value = rhs.loadValue();
1414 storeValue(value);
1415 }
1416
1417 Byte::Byte(const Reference<Byte> &rhs)
1418 {
1419 Value *value = rhs.loadValue();
1420 storeValue(value);
1421 }
1422
Nicolas Capens96d4e092016-11-18 14:22:38 -05001423 RValue<Byte> Byte::operator=(RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001424 {
1425 storeValue(rhs.value);
1426
1427 return rhs;
1428 }
1429
Nicolas Capens96d4e092016-11-18 14:22:38 -05001430 RValue<Byte> Byte::operator=(const Byte &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001431 {
1432 Value *value = rhs.loadValue();
1433 storeValue(value);
1434
1435 return RValue<Byte>(value);
1436 }
1437
Nicolas Capens96d4e092016-11-18 14:22:38 -05001438 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001439 {
1440 Value *value = rhs.loadValue();
1441 storeValue(value);
1442
1443 return RValue<Byte>(value);
1444 }
1445
1446 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
1447 {
1448 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1449 }
1450
1451 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
1452 {
1453 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1454 }
1455
1456 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
1457 {
1458 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1459 }
1460
1461 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
1462 {
1463 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1464 }
1465
1466 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
1467 {
1468 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1469 }
1470
1471 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
1472 {
1473 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1474 }
1475
1476 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
1477 {
1478 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1479 }
1480
1481 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
1482 {
1483 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1484 }
1485
1486 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
1487 {
1488 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1489 }
1490
1491 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
1492 {
1493 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1494 }
1495
Nicolas Capens96d4e092016-11-18 14:22:38 -05001496 RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001497 {
1498 return lhs = lhs + rhs;
1499 }
1500
Nicolas Capens96d4e092016-11-18 14:22:38 -05001501 RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001502 {
1503 return lhs = lhs - rhs;
1504 }
1505
Nicolas Capens96d4e092016-11-18 14:22:38 -05001506 RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001507 {
1508 return lhs = lhs * rhs;
1509 }
1510
Nicolas Capens96d4e092016-11-18 14:22:38 -05001511 RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001512 {
1513 return lhs = lhs / rhs;
1514 }
1515
Nicolas Capens96d4e092016-11-18 14:22:38 -05001516 RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001517 {
1518 return lhs = lhs % rhs;
1519 }
1520
Nicolas Capens96d4e092016-11-18 14:22:38 -05001521 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001522 {
1523 return lhs = lhs & rhs;
1524 }
1525
Nicolas Capens96d4e092016-11-18 14:22:38 -05001526 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001527 {
1528 return lhs = lhs | rhs;
1529 }
1530
Nicolas Capens96d4e092016-11-18 14:22:38 -05001531 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001532 {
1533 return lhs = lhs ^ rhs;
1534 }
1535
Nicolas Capens96d4e092016-11-18 14:22:38 -05001536 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001537 {
1538 return lhs = lhs << rhs;
1539 }
1540
Nicolas Capens96d4e092016-11-18 14:22:38 -05001541 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001542 {
1543 return lhs = lhs >> rhs;
1544 }
1545
1546 RValue<Byte> operator+(RValue<Byte> val)
1547 {
1548 return val;
1549 }
1550
1551 RValue<Byte> operator-(RValue<Byte> val)
1552 {
1553 return RValue<Byte>(Nucleus::createNeg(val.value));
1554 }
1555
1556 RValue<Byte> operator~(RValue<Byte> val)
1557 {
1558 return RValue<Byte>(Nucleus::createNot(val.value));
1559 }
1560
Nicolas Capens96d4e092016-11-18 14:22:38 -05001561 RValue<Byte> operator++(Byte &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001562 {
1563 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001564 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001565 return res;
1566 }
1567
Nicolas Capens96d4e092016-11-18 14:22:38 -05001568 const Byte &operator++(Byte &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001569 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001570 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001571 return val;
1572 }
1573
Nicolas Capens96d4e092016-11-18 14:22:38 -05001574 RValue<Byte> operator--(Byte &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001575 {
1576 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001577 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001578 return res;
1579 }
1580
Nicolas Capens96d4e092016-11-18 14:22:38 -05001581 const Byte &operator--(Byte &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001582 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001583 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001584 return val;
1585 }
1586
1587 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
1588 {
1589 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1590 }
1591
1592 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
1593 {
1594 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1595 }
1596
1597 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
1598 {
1599 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1600 }
1601
1602 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
1603 {
1604 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1605 }
1606
1607 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
1608 {
1609 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1610 }
1611
1612 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
1613 {
1614 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1615 }
1616
1617 Type *Byte::getType()
1618 {
Nicolas Capens6d738712016-09-30 04:15:22 -04001619 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001620 }
1621
1622 SByte::SByte(Argument<SByte> argument)
1623 {
1624 storeValue(argument.value);
1625 }
1626
1627 SByte::SByte(RValue<Int> cast)
1628 {
1629 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1630
1631 storeValue(integer);
1632 }
1633
1634 SByte::SByte(RValue<Short> cast)
1635 {
1636 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1637
1638 storeValue(integer);
1639 }
1640
Nicolas Capens598f8d82016-09-26 15:09:10 -04001641 SByte::SByte(signed char x)
1642 {
1643 storeValue(Nucleus::createConstantByte(x));
1644 }
1645
1646 SByte::SByte(RValue<SByte> rhs)
1647 {
1648 storeValue(rhs.value);
1649 }
1650
1651 SByte::SByte(const SByte &rhs)
1652 {
1653 Value *value = rhs.loadValue();
1654 storeValue(value);
1655 }
1656
1657 SByte::SByte(const Reference<SByte> &rhs)
1658 {
1659 Value *value = rhs.loadValue();
1660 storeValue(value);
1661 }
1662
Nicolas Capens96d4e092016-11-18 14:22:38 -05001663 RValue<SByte> SByte::operator=(RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001664 {
1665 storeValue(rhs.value);
1666
1667 return rhs;
1668 }
1669
Nicolas Capens96d4e092016-11-18 14:22:38 -05001670 RValue<SByte> SByte::operator=(const SByte &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001671 {
1672 Value *value = rhs.loadValue();
1673 storeValue(value);
1674
1675 return RValue<SByte>(value);
1676 }
1677
Nicolas Capens96d4e092016-11-18 14:22:38 -05001678 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001679 {
1680 Value *value = rhs.loadValue();
1681 storeValue(value);
1682
1683 return RValue<SByte>(value);
1684 }
1685
1686 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
1687 {
1688 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1689 }
1690
1691 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
1692 {
1693 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1694 }
1695
1696 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
1697 {
1698 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1699 }
1700
1701 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
1702 {
1703 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1704 }
1705
1706 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
1707 {
1708 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1709 }
1710
1711 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
1712 {
1713 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1714 }
1715
1716 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
1717 {
1718 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1719 }
1720
1721 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
1722 {
1723 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1724 }
1725
1726 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
1727 {
1728 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1729 }
1730
1731 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
1732 {
1733 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1734 }
1735
Nicolas Capens96d4e092016-11-18 14:22:38 -05001736 RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001737 {
1738 return lhs = lhs + rhs;
1739 }
1740
Nicolas Capens96d4e092016-11-18 14:22:38 -05001741 RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001742 {
1743 return lhs = lhs - rhs;
1744 }
1745
Nicolas Capens96d4e092016-11-18 14:22:38 -05001746 RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001747 {
1748 return lhs = lhs * rhs;
1749 }
1750
Nicolas Capens96d4e092016-11-18 14:22:38 -05001751 RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001752 {
1753 return lhs = lhs / rhs;
1754 }
1755
Nicolas Capens96d4e092016-11-18 14:22:38 -05001756 RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001757 {
1758 return lhs = lhs % rhs;
1759 }
1760
Nicolas Capens96d4e092016-11-18 14:22:38 -05001761 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001762 {
1763 return lhs = lhs & rhs;
1764 }
1765
Nicolas Capens96d4e092016-11-18 14:22:38 -05001766 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001767 {
1768 return lhs = lhs | rhs;
1769 }
1770
Nicolas Capens96d4e092016-11-18 14:22:38 -05001771 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001772 {
1773 return lhs = lhs ^ rhs;
1774 }
1775
Nicolas Capens96d4e092016-11-18 14:22:38 -05001776 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001777 {
1778 return lhs = lhs << rhs;
1779 }
1780
Nicolas Capens96d4e092016-11-18 14:22:38 -05001781 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001782 {
1783 return lhs = lhs >> rhs;
1784 }
1785
1786 RValue<SByte> operator+(RValue<SByte> val)
1787 {
1788 return val;
1789 }
1790
1791 RValue<SByte> operator-(RValue<SByte> val)
1792 {
1793 return RValue<SByte>(Nucleus::createNeg(val.value));
1794 }
1795
1796 RValue<SByte> operator~(RValue<SByte> val)
1797 {
1798 return RValue<SByte>(Nucleus::createNot(val.value));
1799 }
1800
Nicolas Capens96d4e092016-11-18 14:22:38 -05001801 RValue<SByte> operator++(SByte &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001802 {
1803 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001804 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001805 return res;
1806 }
1807
Nicolas Capens96d4e092016-11-18 14:22:38 -05001808 const SByte &operator++(SByte &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04001809 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001810 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001811 return val;
1812 }
1813
Nicolas Capens96d4e092016-11-18 14:22:38 -05001814 RValue<SByte> operator--(SByte &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001815 {
1816 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001817 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001818 return res;
1819 }
1820
Nicolas Capens96d4e092016-11-18 14:22:38 -05001821 const SByte &operator--(SByte &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04001822 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001823 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001824 return val;
1825 }
1826
1827 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
1828 {
1829 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1830 }
1831
1832 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
1833 {
1834 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1835 }
1836
1837 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
1838 {
1839 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1840 }
1841
1842 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
1843 {
1844 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1845 }
1846
1847 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
1848 {
1849 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1850 }
1851
1852 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
1853 {
1854 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1855 }
1856
1857 Type *SByte::getType()
1858 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001859 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001860 }
1861
1862 Short::Short(Argument<Short> argument)
1863 {
1864 storeValue(argument.value);
1865 }
1866
1867 Short::Short(RValue<Int> cast)
1868 {
1869 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1870
1871 storeValue(integer);
1872 }
1873
Nicolas Capens598f8d82016-09-26 15:09:10 -04001874 Short::Short(short x)
1875 {
1876 storeValue(Nucleus::createConstantShort(x));
1877 }
1878
1879 Short::Short(RValue<Short> rhs)
1880 {
1881 storeValue(rhs.value);
1882 }
1883
1884 Short::Short(const Short &rhs)
1885 {
1886 Value *value = rhs.loadValue();
1887 storeValue(value);
1888 }
1889
1890 Short::Short(const Reference<Short> &rhs)
1891 {
1892 Value *value = rhs.loadValue();
1893 storeValue(value);
1894 }
1895
Nicolas Capens96d4e092016-11-18 14:22:38 -05001896 RValue<Short> Short::operator=(RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001897 {
1898 storeValue(rhs.value);
1899
1900 return rhs;
1901 }
1902
Nicolas Capens96d4e092016-11-18 14:22:38 -05001903 RValue<Short> Short::operator=(const Short &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001904 {
1905 Value *value = rhs.loadValue();
1906 storeValue(value);
1907
1908 return RValue<Short>(value);
1909 }
1910
Nicolas Capens96d4e092016-11-18 14:22:38 -05001911 RValue<Short> Short::operator=(const Reference<Short> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001912 {
1913 Value *value = rhs.loadValue();
1914 storeValue(value);
1915
1916 return RValue<Short>(value);
1917 }
1918
1919 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
1920 {
1921 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
1922 }
1923
1924 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
1925 {
1926 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
1927 }
1928
1929 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
1930 {
1931 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
1932 }
1933
1934 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
1935 {
1936 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
1937 }
1938
1939 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
1940 {
1941 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
1942 }
1943
1944 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
1945 {
1946 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
1947 }
1948
1949 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
1950 {
1951 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
1952 }
1953
1954 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
1955 {
1956 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
1957 }
1958
1959 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
1960 {
1961 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
1962 }
1963
1964 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
1965 {
1966 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
1967 }
1968
Nicolas Capens96d4e092016-11-18 14:22:38 -05001969 RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001970 {
1971 return lhs = lhs + rhs;
1972 }
1973
Nicolas Capens96d4e092016-11-18 14:22:38 -05001974 RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001975 {
1976 return lhs = lhs - rhs;
1977 }
1978
Nicolas Capens96d4e092016-11-18 14:22:38 -05001979 RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001980 {
1981 return lhs = lhs * rhs;
1982 }
1983
Nicolas Capens96d4e092016-11-18 14:22:38 -05001984 RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001985 {
1986 return lhs = lhs / rhs;
1987 }
1988
Nicolas Capens96d4e092016-11-18 14:22:38 -05001989 RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001990 {
1991 return lhs = lhs % rhs;
1992 }
1993
Nicolas Capens96d4e092016-11-18 14:22:38 -05001994 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001995 {
1996 return lhs = lhs & rhs;
1997 }
1998
Nicolas Capens96d4e092016-11-18 14:22:38 -05001999 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002000 {
2001 return lhs = lhs | rhs;
2002 }
2003
Nicolas Capens96d4e092016-11-18 14:22:38 -05002004 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002005 {
2006 return lhs = lhs ^ rhs;
2007 }
2008
Nicolas Capens96d4e092016-11-18 14:22:38 -05002009 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002010 {
2011 return lhs = lhs << rhs;
2012 }
2013
Nicolas Capens96d4e092016-11-18 14:22:38 -05002014 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002015 {
2016 return lhs = lhs >> rhs;
2017 }
2018
2019 RValue<Short> operator+(RValue<Short> val)
2020 {
2021 return val;
2022 }
2023
2024 RValue<Short> operator-(RValue<Short> val)
2025 {
2026 return RValue<Short>(Nucleus::createNeg(val.value));
2027 }
2028
2029 RValue<Short> operator~(RValue<Short> val)
2030 {
2031 return RValue<Short>(Nucleus::createNot(val.value));
2032 }
2033
Nicolas Capens96d4e092016-11-18 14:22:38 -05002034 RValue<Short> operator++(Short &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002035 {
2036 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002037 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002038 return res;
2039 }
2040
Nicolas Capens96d4e092016-11-18 14:22:38 -05002041 const Short &operator++(Short &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002042 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002043 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002044 return val;
2045 }
2046
Nicolas Capens96d4e092016-11-18 14:22:38 -05002047 RValue<Short> operator--(Short &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002048 {
2049 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002050 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002051 return res;
2052 }
2053
Nicolas Capens96d4e092016-11-18 14:22:38 -05002054 const Short &operator--(Short &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002055 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002056 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002057 return val;
2058 }
2059
2060 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
2061 {
2062 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2063 }
2064
2065 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
2066 {
2067 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2068 }
2069
2070 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
2071 {
2072 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2073 }
2074
2075 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
2076 {
2077 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2078 }
2079
2080 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
2081 {
2082 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2083 }
2084
2085 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
2086 {
2087 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2088 }
2089
2090 Type *Short::getType()
2091 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002092 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002093 }
2094
2095 UShort::UShort(Argument<UShort> argument)
2096 {
2097 storeValue(argument.value);
2098 }
2099
2100 UShort::UShort(RValue<UInt> cast)
2101 {
2102 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2103
2104 storeValue(integer);
2105 }
2106
2107 UShort::UShort(RValue<Int> cast)
2108 {
2109 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2110
2111 storeValue(integer);
2112 }
2113
Nicolas Capens598f8d82016-09-26 15:09:10 -04002114 UShort::UShort(unsigned short x)
2115 {
2116 storeValue(Nucleus::createConstantShort(x));
2117 }
2118
2119 UShort::UShort(RValue<UShort> rhs)
2120 {
2121 storeValue(rhs.value);
2122 }
2123
2124 UShort::UShort(const UShort &rhs)
2125 {
2126 Value *value = rhs.loadValue();
2127 storeValue(value);
2128 }
2129
2130 UShort::UShort(const Reference<UShort> &rhs)
2131 {
2132 Value *value = rhs.loadValue();
2133 storeValue(value);
2134 }
2135
Nicolas Capens96d4e092016-11-18 14:22:38 -05002136 RValue<UShort> UShort::operator=(RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002137 {
2138 storeValue(rhs.value);
2139
2140 return rhs;
2141 }
2142
Nicolas Capens96d4e092016-11-18 14:22:38 -05002143 RValue<UShort> UShort::operator=(const UShort &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002144 {
2145 Value *value = rhs.loadValue();
2146 storeValue(value);
2147
2148 return RValue<UShort>(value);
2149 }
2150
Nicolas Capens96d4e092016-11-18 14:22:38 -05002151 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002152 {
2153 Value *value = rhs.loadValue();
2154 storeValue(value);
2155
2156 return RValue<UShort>(value);
2157 }
2158
2159 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
2160 {
2161 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
2162 }
2163
2164 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
2165 {
2166 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
2167 }
2168
2169 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
2170 {
2171 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
2172 }
2173
2174 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
2175 {
2176 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
2177 }
2178
2179 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
2180 {
2181 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
2182 }
2183
2184 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
2185 {
2186 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
2187 }
2188
2189 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
2190 {
2191 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
2192 }
2193
2194 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
2195 {
2196 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
2197 }
2198
2199 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
2200 {
2201 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
2202 }
2203
2204 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
2205 {
2206 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
2207 }
2208
Nicolas Capens96d4e092016-11-18 14:22:38 -05002209 RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002210 {
2211 return lhs = lhs + rhs;
2212 }
2213
Nicolas Capens96d4e092016-11-18 14:22:38 -05002214 RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002215 {
2216 return lhs = lhs - rhs;
2217 }
2218
Nicolas Capens96d4e092016-11-18 14:22:38 -05002219 RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002220 {
2221 return lhs = lhs * rhs;
2222 }
2223
Nicolas Capens96d4e092016-11-18 14:22:38 -05002224 RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002225 {
2226 return lhs = lhs / rhs;
2227 }
2228
Nicolas Capens96d4e092016-11-18 14:22:38 -05002229 RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002230 {
2231 return lhs = lhs % rhs;
2232 }
2233
Nicolas Capens96d4e092016-11-18 14:22:38 -05002234 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002235 {
2236 return lhs = lhs & rhs;
2237 }
2238
Nicolas Capens96d4e092016-11-18 14:22:38 -05002239 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002240 {
2241 return lhs = lhs | rhs;
2242 }
2243
Nicolas Capens96d4e092016-11-18 14:22:38 -05002244 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002245 {
2246 return lhs = lhs ^ rhs;
2247 }
2248
Nicolas Capens96d4e092016-11-18 14:22:38 -05002249 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002250 {
2251 return lhs = lhs << rhs;
2252 }
2253
Nicolas Capens96d4e092016-11-18 14:22:38 -05002254 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002255 {
2256 return lhs = lhs >> rhs;
2257 }
2258
2259 RValue<UShort> operator+(RValue<UShort> val)
2260 {
2261 return val;
2262 }
2263
2264 RValue<UShort> operator-(RValue<UShort> val)
2265 {
2266 return RValue<UShort>(Nucleus::createNeg(val.value));
2267 }
2268
2269 RValue<UShort> operator~(RValue<UShort> val)
2270 {
2271 return RValue<UShort>(Nucleus::createNot(val.value));
2272 }
2273
Nicolas Capens96d4e092016-11-18 14:22:38 -05002274 RValue<UShort> operator++(UShort &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002275 {
2276 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002277 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002278 return res;
2279 }
2280
Nicolas Capens96d4e092016-11-18 14:22:38 -05002281 const UShort &operator++(UShort &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04002282 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002283 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002284 return val;
2285 }
2286
Nicolas Capens96d4e092016-11-18 14:22:38 -05002287 RValue<UShort> operator--(UShort &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002288 {
2289 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002290 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002291 return res;
2292 }
2293
Nicolas Capens96d4e092016-11-18 14:22:38 -05002294 const UShort &operator--(UShort &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04002295 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002296 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002297 return val;
2298 }
2299
2300 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
2301 {
2302 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2303 }
2304
2305 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
2306 {
2307 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2308 }
2309
2310 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
2311 {
2312 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2313 }
2314
2315 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
2316 {
2317 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2318 }
2319
2320 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
2321 {
2322 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2323 }
2324
2325 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
2326 {
2327 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2328 }
2329
2330 Type *UShort::getType()
2331 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002332 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002333 }
2334
Nicolas Capens16b5f152016-10-13 13:39:01 -04002335 Byte4::Byte4(RValue<Byte8> cast)
2336 {
Nicolas Capens16b5f152016-10-13 13:39:01 -04002337 storeValue(Nucleus::createBitCast(cast.value, getType()));
2338 }
2339
2340 Byte4::Byte4(const Reference<Byte4> &rhs)
2341 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002342 Value *value = rhs.loadValue();
2343 storeValue(value);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002344 }
2345
Nicolas Capens598f8d82016-09-26 15:09:10 -04002346 Type *Byte4::getType()
2347 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002348 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002349 }
2350
2351 Type *SByte4::getType()
2352 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002353 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002354 }
2355
Nicolas Capens598f8d82016-09-26 15:09:10 -04002356 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)
2357 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002358 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
2359 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002360 }
2361
2362 Byte8::Byte8(RValue<Byte8> rhs)
2363 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002364 storeValue(rhs.value);
2365 }
2366
2367 Byte8::Byte8(const Byte8 &rhs)
2368 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002369 Value *value = rhs.loadValue();
2370 storeValue(value);
2371 }
2372
2373 Byte8::Byte8(const Reference<Byte8> &rhs)
2374 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002375 Value *value = rhs.loadValue();
2376 storeValue(value);
2377 }
2378
Nicolas Capens96d4e092016-11-18 14:22:38 -05002379 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002380 {
2381 storeValue(rhs.value);
2382
2383 return rhs;
2384 }
2385
Nicolas Capens96d4e092016-11-18 14:22:38 -05002386 RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002387 {
2388 Value *value = rhs.loadValue();
2389 storeValue(value);
2390
2391 return RValue<Byte8>(value);
2392 }
2393
Nicolas Capens96d4e092016-11-18 14:22:38 -05002394 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002395 {
2396 Value *value = rhs.loadValue();
2397 storeValue(value);
2398
2399 return RValue<Byte8>(value);
2400 }
2401
2402 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
2403 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002404 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002405 }
2406
2407 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
2408 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002409 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002410 }
2411
2412// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2413// {
2414// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2415// }
2416
2417// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2418// {
2419// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2420// }
2421
2422// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2423// {
2424// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2425// }
2426
2427 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
2428 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002429 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002430 }
2431
2432 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
2433 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002434 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002435 }
2436
2437 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
2438 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002439 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002440 }
2441
2442// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
2443// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002444// return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002445// }
2446
2447// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
2448// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002449// return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002450// }
2451
Nicolas Capens96d4e092016-11-18 14:22:38 -05002452 RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002453 {
2454 return lhs = lhs + rhs;
2455 }
2456
Nicolas Capens96d4e092016-11-18 14:22:38 -05002457 RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002458 {
2459 return lhs = lhs - rhs;
2460 }
2461
Nicolas Capens96d4e092016-11-18 14:22:38 -05002462// RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002463// {
2464// return lhs = lhs * rhs;
2465// }
2466
Nicolas Capens96d4e092016-11-18 14:22:38 -05002467// RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002468// {
2469// return lhs = lhs / rhs;
2470// }
2471
Nicolas Capens96d4e092016-11-18 14:22:38 -05002472// RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002473// {
2474// return lhs = lhs % rhs;
2475// }
2476
Nicolas Capens96d4e092016-11-18 14:22:38 -05002477 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002478 {
2479 return lhs = lhs & rhs;
2480 }
2481
Nicolas Capens96d4e092016-11-18 14:22:38 -05002482 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002483 {
2484 return lhs = lhs | rhs;
2485 }
2486
Nicolas Capens96d4e092016-11-18 14:22:38 -05002487 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002488 {
2489 return lhs = lhs ^ rhs;
2490 }
2491
Nicolas Capens96d4e092016-11-18 14:22:38 -05002492// RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002493// {
2494// return lhs = lhs << rhs;
2495// }
2496
Nicolas Capens96d4e092016-11-18 14:22:38 -05002497// RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002498// {
2499// return lhs = lhs >> rhs;
2500// }
2501
2502// RValue<Byte8> operator+(RValue<Byte8> val)
2503// {
2504// return val;
2505// }
2506
2507// RValue<Byte8> operator-(RValue<Byte8> val)
2508// {
2509// return RValue<Byte8>(Nucleus::createNeg(val.value));
2510// }
2511
2512 RValue<Byte8> operator~(RValue<Byte8> val)
2513 {
2514 return RValue<Byte8>(Nucleus::createNot(val.value));
2515 }
2516
2517 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
2518 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002519 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2520 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2521 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2522 auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2523 paddusb->addArg(x.value);
2524 paddusb->addArg(y.value);
2525 ::basicBlock->appendInst(paddusb);
2526
2527 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002528 }
2529
2530 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
2531 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002532 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2533 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2534 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2535 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2536 psubusw->addArg(x.value);
2537 psubusw->addArg(y.value);
2538 ::basicBlock->appendInst(psubusw);
2539
2540 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002541 }
2542
2543 RValue<Short4> Unpack(RValue<Byte4> x)
2544 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002545 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2546 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002547 }
2548
2549 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2550 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002551 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2552 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002553 }
2554
2555 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
2556 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002557 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2558 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2559 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002560 }
2561
2562 RValue<Int> SignMask(RValue<Byte8> x)
2563 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002564 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2565 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2566 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2567 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2568 movmsk->addArg(x.value);
2569 ::basicBlock->appendInst(movmsk);
2570
2571 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002572 }
2573
2574// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
2575// {
Nicolas Capens2f970b62016-11-08 14:28:59 -05002576// return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002577// }
2578
2579 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
2580 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05002581 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002582 }
2583
2584 Type *Byte8::getType()
2585 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002586 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002587 }
2588
Nicolas Capens598f8d82016-09-26 15:09:10 -04002589 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)
2590 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002591 int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
2592 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
2593
2594 storeValue(Nucleus::createBitCast(vector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002595 }
2596
Nicolas Capens598f8d82016-09-26 15:09:10 -04002597 SByte8::SByte8(RValue<SByte8> rhs)
2598 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002599 storeValue(rhs.value);
2600 }
2601
2602 SByte8::SByte8(const SByte8 &rhs)
2603 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002604 Value *value = rhs.loadValue();
2605 storeValue(value);
2606 }
2607
2608 SByte8::SByte8(const Reference<SByte8> &rhs)
2609 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002610 Value *value = rhs.loadValue();
2611 storeValue(value);
2612 }
2613
Nicolas Capens96d4e092016-11-18 14:22:38 -05002614 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002615 {
2616 storeValue(rhs.value);
2617
2618 return rhs;
2619 }
2620
Nicolas Capens96d4e092016-11-18 14:22:38 -05002621 RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002622 {
2623 Value *value = rhs.loadValue();
2624 storeValue(value);
2625
2626 return RValue<SByte8>(value);
2627 }
2628
Nicolas Capens96d4e092016-11-18 14:22:38 -05002629 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002630 {
2631 Value *value = rhs.loadValue();
2632 storeValue(value);
2633
2634 return RValue<SByte8>(value);
2635 }
2636
2637 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
2638 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002639 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002640 }
2641
2642 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
2643 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002644 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002645 }
2646
2647// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2648// {
2649// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2650// }
2651
2652// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2653// {
2654// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2655// }
2656
2657// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2658// {
2659// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2660// }
2661
2662 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
2663 {
2664 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2665 }
2666
2667 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
2668 {
2669 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2670 }
2671
2672 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
2673 {
2674 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2675 }
2676
2677// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
2678// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002679// return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002680// }
2681
2682// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
2683// {
Nicolas Capens15060bb2016-12-05 22:17:19 -05002684// return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002685// }
2686
Nicolas Capens96d4e092016-11-18 14:22:38 -05002687 RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002688 {
2689 return lhs = lhs + rhs;
2690 }
2691
Nicolas Capens96d4e092016-11-18 14:22:38 -05002692 RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002693 {
2694 return lhs = lhs - rhs;
2695 }
2696
Nicolas Capens96d4e092016-11-18 14:22:38 -05002697// RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002698// {
2699// return lhs = lhs * rhs;
2700// }
2701
Nicolas Capens96d4e092016-11-18 14:22:38 -05002702// RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002703// {
2704// return lhs = lhs / rhs;
2705// }
2706
Nicolas Capens96d4e092016-11-18 14:22:38 -05002707// RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002708// {
2709// return lhs = lhs % rhs;
2710// }
2711
Nicolas Capens96d4e092016-11-18 14:22:38 -05002712 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002713 {
2714 return lhs = lhs & rhs;
2715 }
2716
Nicolas Capens96d4e092016-11-18 14:22:38 -05002717 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002718 {
2719 return lhs = lhs | rhs;
2720 }
2721
Nicolas Capens96d4e092016-11-18 14:22:38 -05002722 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002723 {
2724 return lhs = lhs ^ rhs;
2725 }
2726
Nicolas Capens96d4e092016-11-18 14:22:38 -05002727// RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002728// {
2729// return lhs = lhs << rhs;
2730// }
2731
Nicolas Capens96d4e092016-11-18 14:22:38 -05002732// RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002733// {
2734// return lhs = lhs >> rhs;
2735// }
2736
2737// RValue<SByte8> operator+(RValue<SByte8> val)
2738// {
2739// return val;
2740// }
2741
2742// RValue<SByte8> operator-(RValue<SByte8> val)
2743// {
2744// return RValue<SByte8>(Nucleus::createNeg(val.value));
2745// }
2746
2747 RValue<SByte8> operator~(RValue<SByte8> val)
2748 {
2749 return RValue<SByte8>(Nucleus::createNot(val.value));
2750 }
2751
2752 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
2753 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002754 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2755 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2756 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2757 auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2758 paddsb->addArg(x.value);
2759 paddsb->addArg(y.value);
2760 ::basicBlock->appendInst(paddsb);
2761
2762 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002763 }
2764
2765 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
2766 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05002767 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2768 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2769 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2770 auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2771 psubsb->addArg(x.value);
2772 psubsb->addArg(y.value);
2773 ::basicBlock->appendInst(psubsb);
2774
2775 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002776 }
2777
2778 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
2779 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002780 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2781 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002782 }
2783
2784 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
2785 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002786 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2787 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2788 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002789 }
2790
2791 RValue<Int> SignMask(RValue<SByte8> x)
2792 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04002793 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2794 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2795 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2796 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2797 movmsk->addArg(x.value);
2798 ::basicBlock->appendInst(movmsk);
2799
2800 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002801 }
2802
2803 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
2804 {
Nicolas Capens2f970b62016-11-08 14:28:59 -05002805 return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002806 }
2807
2808 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
2809 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05002810 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002811 }
2812
2813 Type *SByte8::getType()
2814 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002815 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002816 }
2817
2818 Byte16::Byte16(RValue<Byte16> rhs)
2819 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002820 storeValue(rhs.value);
2821 }
2822
2823 Byte16::Byte16(const Byte16 &rhs)
2824 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002825 Value *value = rhs.loadValue();
2826 storeValue(value);
2827 }
2828
2829 Byte16::Byte16(const Reference<Byte16> &rhs)
2830 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002831 Value *value = rhs.loadValue();
2832 storeValue(value);
2833 }
2834
Nicolas Capens96d4e092016-11-18 14:22:38 -05002835 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002836 {
2837 storeValue(rhs.value);
2838
2839 return rhs;
2840 }
2841
Nicolas Capens96d4e092016-11-18 14:22:38 -05002842 RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002843 {
2844 Value *value = rhs.loadValue();
2845 storeValue(value);
2846
2847 return RValue<Byte16>(value);
2848 }
2849
Nicolas Capens96d4e092016-11-18 14:22:38 -05002850 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002851 {
2852 Value *value = rhs.loadValue();
2853 storeValue(value);
2854
2855 return RValue<Byte16>(value);
2856 }
2857
2858 Type *Byte16::getType()
2859 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002860 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002861 }
2862
2863 Type *SByte16::getType()
2864 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002865 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002866 }
2867
Nicolas Capens16b5f152016-10-13 13:39:01 -04002868 Short2::Short2(RValue<Short4> cast)
2869 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05002870 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002871 }
2872
2873 Type *Short2::getType()
2874 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002875 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002876 }
2877
2878 UShort2::UShort2(RValue<UShort4> cast)
2879 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05002880 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens16b5f152016-10-13 13:39:01 -04002881 }
2882
2883 Type *UShort2::getType()
2884 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002885 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002886 }
2887
Nicolas Capens598f8d82016-09-26 15:09:10 -04002888 Short4::Short4(RValue<Int> cast)
2889 {
Nicolas Capensd4227962016-11-09 14:24:25 -05002890 Value *vector = loadValue();
Nicolas Capensbf22bbf2017-01-13 17:37:45 -05002891 Value *element = Nucleus::createTrunc(cast.value, Short::getType());
2892 Value *insert = Nucleus::createInsertElement(vector, element, 0);
Nicolas Capensd4227962016-11-09 14:24:25 -05002893 Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
Nicolas Capens598f8d82016-09-26 15:09:10 -04002894
2895 storeValue(swizzle);
2896 }
2897
2898 Short4::Short4(RValue<Int4> cast)
2899 {
Nicolas Capensd4227962016-11-09 14:24:25 -05002900 int pshufb[16] = {0, 1, 4, 5, 8, 9, 12, 13, 0, 1, 4, 5, 8, 9, 12, 13};
2901 Value *byte16 = Nucleus::createBitCast(cast.value, Byte16::getType());
2902 Value *packed = Nucleus::createShuffleVector(byte16, byte16, pshufb);
2903
2904 Value *int2 = RValue<Int2>(Int2(RValue<Int4>(packed))).value;
2905 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
2906
2907 storeValue(short4);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002908 }
2909
2910// Short4::Short4(RValue<Float> cast)
2911// {
2912// }
2913
2914 Short4::Short4(RValue<Float4> cast)
2915 {
2916 assert(false && "UNIMPLEMENTED");
2917 }
2918
Nicolas Capens598f8d82016-09-26 15:09:10 -04002919 Short4::Short4(short xyzw)
2920 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002921 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
2922 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002923 }
2924
2925 Short4::Short4(short x, short y, short z, short w)
2926 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002927 int64_t constantVector[4] = {x, y, z, w};
2928 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002929 }
2930
2931 Short4::Short4(RValue<Short4> rhs)
2932 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002933 storeValue(rhs.value);
2934 }
2935
2936 Short4::Short4(const Short4 &rhs)
2937 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002938 Value *value = rhs.loadValue();
2939 storeValue(value);
2940 }
2941
2942 Short4::Short4(const Reference<Short4> &rhs)
2943 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002944 Value *value = rhs.loadValue();
2945 storeValue(value);
2946 }
2947
2948 Short4::Short4(RValue<UShort4> rhs)
2949 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002950 storeValue(rhs.value);
2951 }
2952
2953 Short4::Short4(const UShort4 &rhs)
2954 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002955 storeValue(rhs.loadValue());
2956 }
2957
2958 Short4::Short4(const Reference<UShort4> &rhs)
2959 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002960 storeValue(rhs.loadValue());
2961 }
2962
Nicolas Capens96d4e092016-11-18 14:22:38 -05002963 RValue<Short4> Short4::operator=(RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002964 {
2965 storeValue(rhs.value);
2966
2967 return rhs;
2968 }
2969
Nicolas Capens96d4e092016-11-18 14:22:38 -05002970 RValue<Short4> Short4::operator=(const Short4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002971 {
2972 Value *value = rhs.loadValue();
2973 storeValue(value);
2974
2975 return RValue<Short4>(value);
2976 }
2977
Nicolas Capens96d4e092016-11-18 14:22:38 -05002978 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002979 {
2980 Value *value = rhs.loadValue();
2981 storeValue(value);
2982
2983 return RValue<Short4>(value);
2984 }
2985
Nicolas Capens96d4e092016-11-18 14:22:38 -05002986 RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002987 {
2988 storeValue(rhs.value);
2989
2990 return RValue<Short4>(rhs);
2991 }
2992
Nicolas Capens96d4e092016-11-18 14:22:38 -05002993 RValue<Short4> Short4::operator=(const UShort4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04002994 {
2995 Value *value = rhs.loadValue();
2996 storeValue(value);
2997
2998 return RValue<Short4>(value);
2999 }
3000
Nicolas Capens96d4e092016-11-18 14:22:38 -05003001 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003002 {
3003 Value *value = rhs.loadValue();
3004 storeValue(value);
3005
3006 return RValue<Short4>(value);
3007 }
3008
3009 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
3010 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003011 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003012 }
3013
3014 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
3015 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003016 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003017 }
3018
3019 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
3020 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003021 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003022 }
3023
3024// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
3025// {
3026// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
3027// }
3028
3029// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
3030// {
3031// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
3032// }
3033
3034 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
3035 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003036 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003037 }
3038
3039 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
3040 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003041 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003042 }
3043
3044 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
3045 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003046 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003047 }
3048
3049 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
3050 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003051 return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003052 }
3053
3054 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
3055 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003056 return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003057 }
3058
Nicolas Capens96d4e092016-11-18 14:22:38 -05003059 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003060 {
3061 return lhs = lhs + rhs;
3062 }
3063
Nicolas Capens96d4e092016-11-18 14:22:38 -05003064 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003065 {
3066 return lhs = lhs - rhs;
3067 }
3068
Nicolas Capens96d4e092016-11-18 14:22:38 -05003069 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003070 {
3071 return lhs = lhs * rhs;
3072 }
3073
Nicolas Capens96d4e092016-11-18 14:22:38 -05003074// RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003075// {
3076// return lhs = lhs / rhs;
3077// }
3078
Nicolas Capens96d4e092016-11-18 14:22:38 -05003079// RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003080// {
3081// return lhs = lhs % rhs;
3082// }
3083
Nicolas Capens96d4e092016-11-18 14:22:38 -05003084 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003085 {
3086 return lhs = lhs & rhs;
3087 }
3088
Nicolas Capens96d4e092016-11-18 14:22:38 -05003089 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003090 {
3091 return lhs = lhs | rhs;
3092 }
3093
Nicolas Capens96d4e092016-11-18 14:22:38 -05003094 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003095 {
3096 return lhs = lhs ^ rhs;
3097 }
3098
Nicolas Capens96d4e092016-11-18 14:22:38 -05003099 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003100 {
3101 return lhs = lhs << rhs;
3102 }
3103
Nicolas Capens96d4e092016-11-18 14:22:38 -05003104 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003105 {
3106 return lhs = lhs >> rhs;
3107 }
3108
Nicolas Capens598f8d82016-09-26 15:09:10 -04003109// RValue<Short4> operator+(RValue<Short4> val)
3110// {
3111// return val;
3112// }
3113
3114 RValue<Short4> operator-(RValue<Short4> val)
3115 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003116 return RValue<Short4>(Nucleus::createNeg(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003117 }
3118
3119 RValue<Short4> operator~(RValue<Short4> val)
3120 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003121 return RValue<Short4>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003122 }
3123
3124 RValue<Short4> RoundShort4(RValue<Float4> cast)
3125 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003126 RValue<Int4> int4 = RoundInt(cast);
3127 return As<Short4>(Pack(int4, int4));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003128 }
3129
3130 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
3131 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003132 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3133 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
3134 ::basicBlock->appendInst(cmp);
3135
3136 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3137 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3138 ::basicBlock->appendInst(select);
3139
3140 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003141 }
3142
3143 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
3144 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003145 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3146 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
3147 ::basicBlock->appendInst(cmp);
3148
3149 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3150 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3151 ::basicBlock->appendInst(select);
3152
3153 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003154 }
3155
3156 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
3157 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003158 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3159 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3160 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3161 auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3162 paddsw->addArg(x.value);
3163 paddsw->addArg(y.value);
3164 ::basicBlock->appendInst(paddsw);
3165
3166 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003167 }
3168
3169 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
3170 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003171 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3172 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3173 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3174 auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3175 psubsw->addArg(x.value);
3176 psubsw->addArg(y.value);
3177 ::basicBlock->appendInst(psubsw);
3178
3179 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003180 }
3181
3182 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
3183 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003184 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3185 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3186 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3187 auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3188 pmulhw->addArg(x.value);
3189 pmulhw->addArg(y.value);
3190 ::basicBlock->appendInst(pmulhw);
3191
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003192 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003193 }
3194
3195 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
3196 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003197 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3198 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3199 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3200 auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3201 pmaddwd->addArg(x.value);
3202 pmaddwd->addArg(y.value);
3203 ::basicBlock->appendInst(pmaddwd);
3204
3205 return RValue<Int2>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003206 }
3207
3208 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
3209 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003210 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3211 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3212 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3213 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3214 pack->addArg(x.value);
3215 pack->addArg(y.value);
3216 ::basicBlock->appendInst(pack);
3217
Nicolas Capens70dfff42016-10-27 10:20:28 -04003218 return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003219 }
3220
3221 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
3222 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003223 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3224 return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003225 }
3226
3227 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
3228 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04003229 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3230 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3231 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003232 }
3233
3234 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
3235 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003236 // Real type is v8i16
3237 int shuffle[8] =
3238 {
3239 (select >> 0) & 0x03,
3240 (select >> 2) & 0x03,
3241 (select >> 4) & 0x03,
3242 (select >> 6) & 0x03,
3243 (select >> 0) & 0x03,
3244 (select >> 2) & 0x03,
3245 (select >> 4) & 0x03,
3246 (select >> 6) & 0x03,
3247 };
3248
3249 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003250 }
3251
3252 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
3253 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05003254 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003255 }
3256
3257 RValue<Short> Extract(RValue<Short4> val, int i)
3258 {
Nicolas Capens0133d0f2017-01-16 16:25:08 -05003259 return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003260 }
3261
3262 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
3263 {
Nicolas Capens2f970b62016-11-08 14:28:59 -05003264 return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003265 }
3266
3267 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
3268 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05003269 return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003270 }
3271
3272 Type *Short4::getType()
3273 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003274 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003275 }
3276
3277 UShort4::UShort4(RValue<Int4> cast)
3278 {
3279 *this = Short4(cast);
3280 }
3281
3282 UShort4::UShort4(RValue<Float4> cast, bool saturate)
3283 {
Nicolas Capensd4227962016-11-09 14:24:25 -05003284 if(saturate)
3285 {
3286 if(true) // SSE 4.1
3287 {
3288 Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
3289 *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4)));
3290 }
3291 else
3292 {
3293 *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
3294 }
3295 }
3296 else
3297 {
3298 *this = Short4(Int4(cast));
3299 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04003300 }
3301
Nicolas Capens598f8d82016-09-26 15:09:10 -04003302 UShort4::UShort4(unsigned short xyzw)
3303 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003304 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3305 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003306 }
3307
3308 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3309 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003310 int64_t constantVector[4] = {x, y, z, w};
3311 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003312 }
3313
3314 UShort4::UShort4(RValue<UShort4> rhs)
3315 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003316 storeValue(rhs.value);
3317 }
3318
3319 UShort4::UShort4(const UShort4 &rhs)
3320 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003321 Value *value = rhs.loadValue();
3322 storeValue(value);
3323 }
3324
3325 UShort4::UShort4(const Reference<UShort4> &rhs)
3326 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003327 Value *value = rhs.loadValue();
3328 storeValue(value);
3329 }
3330
3331 UShort4::UShort4(RValue<Short4> rhs)
3332 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003333 storeValue(rhs.value);
3334 }
3335
3336 UShort4::UShort4(const Short4 &rhs)
3337 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003338 Value *value = rhs.loadValue();
3339 storeValue(value);
3340 }
3341
3342 UShort4::UShort4(const Reference<Short4> &rhs)
3343 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003344 Value *value = rhs.loadValue();
3345 storeValue(value);
3346 }
3347
Nicolas Capens96d4e092016-11-18 14:22:38 -05003348 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003349 {
3350 storeValue(rhs.value);
3351
3352 return rhs;
3353 }
3354
Nicolas Capens96d4e092016-11-18 14:22:38 -05003355 RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003356 {
3357 Value *value = rhs.loadValue();
3358 storeValue(value);
3359
3360 return RValue<UShort4>(value);
3361 }
3362
Nicolas Capens96d4e092016-11-18 14:22:38 -05003363 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003364 {
3365 Value *value = rhs.loadValue();
3366 storeValue(value);
3367
3368 return RValue<UShort4>(value);
3369 }
3370
Nicolas Capens96d4e092016-11-18 14:22:38 -05003371 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003372 {
3373 storeValue(rhs.value);
3374
3375 return RValue<UShort4>(rhs);
3376 }
3377
Nicolas Capens96d4e092016-11-18 14:22:38 -05003378 RValue<UShort4> UShort4::operator=(const Short4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003379 {
3380 Value *value = rhs.loadValue();
3381 storeValue(value);
3382
3383 return RValue<UShort4>(value);
3384 }
3385
Nicolas Capens96d4e092016-11-18 14:22:38 -05003386 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003387 {
3388 Value *value = rhs.loadValue();
3389 storeValue(value);
3390
3391 return RValue<UShort4>(value);
3392 }
3393
3394 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
3395 {
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003396 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003397 }
3398
3399 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
3400 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003401 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003402 }
3403
3404 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
3405 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003406 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003407 }
3408
Nicolas Capens16b5f152016-10-13 13:39:01 -04003409 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3410 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003411 return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003412 }
3413
3414 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
3415 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003416 return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003417 }
3418
3419 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3420 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003421 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003422 }
3423
Nicolas Capens598f8d82016-09-26 15:09:10 -04003424 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
3425 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003426 return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003427 }
3428
3429 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
3430 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003431 return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003432 }
3433
Nicolas Capens96d4e092016-11-18 14:22:38 -05003434 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003435 {
3436 return lhs = lhs << rhs;
3437 }
3438
Nicolas Capens96d4e092016-11-18 14:22:38 -05003439 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003440 {
3441 return lhs = lhs >> rhs;
3442 }
3443
Nicolas Capens598f8d82016-09-26 15:09:10 -04003444 RValue<UShort4> operator~(RValue<UShort4> val)
3445 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05003446 return RValue<UShort4>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003447 }
3448
3449 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
3450 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003451 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3452 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
3453 ::basicBlock->appendInst(cmp);
3454
3455 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3456 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3457 ::basicBlock->appendInst(select);
3458
3459 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003460 }
3461
3462 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
3463 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003464 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3465 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
3466 ::basicBlock->appendInst(cmp);
3467
3468 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3469 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3470 ::basicBlock->appendInst(select);
3471
3472 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003473 }
3474
3475 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
3476 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003477 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3478 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3479 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3480 auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3481 paddusw->addArg(x.value);
3482 paddusw->addArg(y.value);
3483 ::basicBlock->appendInst(paddusw);
3484
3485 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003486 }
3487
3488 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
3489 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003490 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3491 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3492 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3493 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3494 psubusw->addArg(x.value);
3495 psubusw->addArg(y.value);
3496 ::basicBlock->appendInst(psubusw);
3497
3498 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003499 }
3500
3501 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
3502 {
Nicolas Capensc71bed22016-11-07 22:25:14 -05003503 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3504 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3505 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3506 auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3507 pmulhuw->addArg(x.value);
3508 pmulhuw->addArg(y.value);
3509 ::basicBlock->appendInst(pmulhuw);
3510
3511 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003512 }
3513
3514 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
3515 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003516 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003517 }
3518
3519 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
3520 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003521 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3522 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3523 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3524 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3525 pack->addArg(x.value);
3526 pack->addArg(y.value);
3527 ::basicBlock->appendInst(pack);
3528
Nicolas Capens70dfff42016-10-27 10:20:28 -04003529 return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003530 }
3531
3532 Type *UShort4::getType()
3533 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003534 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003535 }
3536
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003537 Short8::Short8(short c)
3538 {
3539 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3540 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3541 }
3542
Nicolas Capens598f8d82016-09-26 15:09:10 -04003543 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3544 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003545 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3546 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003547 }
3548
3549 Short8::Short8(RValue<Short8> rhs)
3550 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003551 storeValue(rhs.value);
3552 }
3553
3554 Short8::Short8(const Reference<Short8> &rhs)
3555 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003556 Value *value = rhs.loadValue();
3557 storeValue(value);
3558 }
3559
3560 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3561 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05003562 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3563 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3564
3565 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003566 }
3567
3568 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
3569 {
3570 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3571 }
3572
3573 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
3574 {
3575 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3576 }
3577
3578 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
3579 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003580 return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003581 }
3582
3583 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
3584 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003585 return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003586 }
3587
3588 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
3589 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003590 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003591 }
3592
3593 RValue<Int4> Abs(RValue<Int4> x)
3594 {
Nicolas Capens84272242016-11-09 13:31:06 -05003595 auto negative = x >> 31;
3596 return (x ^ negative) - negative;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003597 }
3598
3599 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
3600 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003601 assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003602 }
3603
3604 Type *Short8::getType()
3605 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003606 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003607 }
3608
Nicolas Capens3e7062b2017-01-17 14:01:33 -05003609 UShort8::UShort8(unsigned short c)
3610 {
3611 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3612 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3613 }
3614
Nicolas Capens598f8d82016-09-26 15:09:10 -04003615 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)
3616 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003617 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3618 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003619 }
3620
3621 UShort8::UShort8(RValue<UShort8> rhs)
3622 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003623 storeValue(rhs.value);
3624 }
3625
3626 UShort8::UShort8(const Reference<UShort8> &rhs)
3627 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003628 Value *value = rhs.loadValue();
3629 storeValue(value);
3630 }
3631
3632 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3633 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05003634 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3635 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3636
3637 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003638 }
3639
Nicolas Capens96d4e092016-11-18 14:22:38 -05003640 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003641 {
3642 storeValue(rhs.value);
3643
3644 return rhs;
3645 }
3646
Nicolas Capens96d4e092016-11-18 14:22:38 -05003647 RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003648 {
3649 Value *value = rhs.loadValue();
3650 storeValue(value);
3651
3652 return RValue<UShort8>(value);
3653 }
3654
Nicolas Capens96d4e092016-11-18 14:22:38 -05003655 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003656 {
3657 Value *value = rhs.loadValue();
3658 storeValue(value);
3659
3660 return RValue<UShort8>(value);
3661 }
3662
3663 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
3664 {
3665 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3666 }
3667
3668 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
3669 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003670 return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003671 }
3672
3673 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
3674 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05003675 return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003676 }
3677
3678 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
3679 {
3680 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3681 }
3682
3683 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
3684 {
3685 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3686 }
3687
Nicolas Capens96d4e092016-11-18 14:22:38 -05003688 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003689 {
3690 return lhs = lhs + rhs;
3691 }
3692
3693 RValue<UShort8> operator~(RValue<UShort8> val)
3694 {
3695 return RValue<UShort8>(Nucleus::createNot(val.value));
3696 }
3697
3698 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
3699 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003700 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003701 }
3702
3703 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
3704 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003705 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003706 }
3707
3708 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
3709// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
3710// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003711// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003712// }
3713
3714 Type *UShort8::getType()
3715 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003716 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003717 }
3718
3719 Int::Int(Argument<Int> argument)
3720 {
3721 storeValue(argument.value);
3722 }
3723
3724 Int::Int(RValue<Byte> cast)
3725 {
3726 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3727
3728 storeValue(integer);
3729 }
3730
3731 Int::Int(RValue<SByte> cast)
3732 {
3733 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3734
3735 storeValue(integer);
3736 }
3737
3738 Int::Int(RValue<Short> cast)
3739 {
3740 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3741
3742 storeValue(integer);
3743 }
3744
3745 Int::Int(RValue<UShort> cast)
3746 {
3747 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3748
3749 storeValue(integer);
3750 }
3751
3752 Int::Int(RValue<Int2> cast)
3753 {
3754 *this = Extract(cast, 0);
3755 }
3756
3757 Int::Int(RValue<Long> cast)
3758 {
3759 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3760
3761 storeValue(integer);
3762 }
3763
3764 Int::Int(RValue<Float> cast)
3765 {
3766 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3767
3768 storeValue(integer);
3769 }
3770
Nicolas Capens598f8d82016-09-26 15:09:10 -04003771 Int::Int(int x)
3772 {
3773 storeValue(Nucleus::createConstantInt(x));
3774 }
3775
3776 Int::Int(RValue<Int> rhs)
3777 {
3778 storeValue(rhs.value);
3779 }
3780
3781 Int::Int(RValue<UInt> rhs)
3782 {
3783 storeValue(rhs.value);
3784 }
3785
3786 Int::Int(const Int &rhs)
3787 {
3788 Value *value = rhs.loadValue();
3789 storeValue(value);
3790 }
3791
3792 Int::Int(const Reference<Int> &rhs)
3793 {
3794 Value *value = rhs.loadValue();
3795 storeValue(value);
3796 }
3797
3798 Int::Int(const UInt &rhs)
3799 {
3800 Value *value = rhs.loadValue();
3801 storeValue(value);
3802 }
3803
3804 Int::Int(const Reference<UInt> &rhs)
3805 {
3806 Value *value = rhs.loadValue();
3807 storeValue(value);
3808 }
3809
Nicolas Capens96d4e092016-11-18 14:22:38 -05003810 RValue<Int> Int::operator=(int rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003811 {
3812 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
3813 }
3814
Nicolas Capens96d4e092016-11-18 14:22:38 -05003815 RValue<Int> Int::operator=(RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003816 {
3817 storeValue(rhs.value);
3818
3819 return rhs;
3820 }
3821
Nicolas Capens96d4e092016-11-18 14:22:38 -05003822 RValue<Int> Int::operator=(RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003823 {
3824 storeValue(rhs.value);
3825
3826 return RValue<Int>(rhs);
3827 }
3828
Nicolas Capens96d4e092016-11-18 14:22:38 -05003829 RValue<Int> Int::operator=(const Int &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003830 {
3831 Value *value = rhs.loadValue();
3832 storeValue(value);
3833
3834 return RValue<Int>(value);
3835 }
3836
Nicolas Capens96d4e092016-11-18 14:22:38 -05003837 RValue<Int> Int::operator=(const Reference<Int> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003838 {
3839 Value *value = rhs.loadValue();
3840 storeValue(value);
3841
3842 return RValue<Int>(value);
3843 }
3844
Nicolas Capens96d4e092016-11-18 14:22:38 -05003845 RValue<Int> Int::operator=(const UInt &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003846 {
3847 Value *value = rhs.loadValue();
3848 storeValue(value);
3849
3850 return RValue<Int>(value);
3851 }
3852
Nicolas Capens96d4e092016-11-18 14:22:38 -05003853 RValue<Int> Int::operator=(const Reference<UInt> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003854 {
3855 Value *value = rhs.loadValue();
3856 storeValue(value);
3857
3858 return RValue<Int>(value);
3859 }
3860
3861 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
3862 {
3863 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3864 }
3865
3866 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
3867 {
3868 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3869 }
3870
3871 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
3872 {
3873 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3874 }
3875
3876 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
3877 {
3878 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3879 }
3880
3881 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
3882 {
3883 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3884 }
3885
3886 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
3887 {
3888 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3889 }
3890
3891 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
3892 {
3893 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3894 }
3895
3896 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
3897 {
3898 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
3899 }
3900
3901 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
3902 {
3903 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
3904 }
3905
3906 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
3907 {
3908 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
3909 }
3910
Nicolas Capens96d4e092016-11-18 14:22:38 -05003911 RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003912 {
3913 return lhs = lhs + rhs;
3914 }
3915
Nicolas Capens96d4e092016-11-18 14:22:38 -05003916 RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003917 {
3918 return lhs = lhs - rhs;
3919 }
3920
Nicolas Capens96d4e092016-11-18 14:22:38 -05003921 RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003922 {
3923 return lhs = lhs * rhs;
3924 }
3925
Nicolas Capens96d4e092016-11-18 14:22:38 -05003926 RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003927 {
3928 return lhs = lhs / rhs;
3929 }
3930
Nicolas Capens96d4e092016-11-18 14:22:38 -05003931 RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003932 {
3933 return lhs = lhs % rhs;
3934 }
3935
Nicolas Capens96d4e092016-11-18 14:22:38 -05003936 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003937 {
3938 return lhs = lhs & rhs;
3939 }
3940
Nicolas Capens96d4e092016-11-18 14:22:38 -05003941 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003942 {
3943 return lhs = lhs | rhs;
3944 }
3945
Nicolas Capens96d4e092016-11-18 14:22:38 -05003946 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003947 {
3948 return lhs = lhs ^ rhs;
3949 }
3950
Nicolas Capens96d4e092016-11-18 14:22:38 -05003951 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003952 {
3953 return lhs = lhs << rhs;
3954 }
3955
Nicolas Capens96d4e092016-11-18 14:22:38 -05003956 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04003957 {
3958 return lhs = lhs >> rhs;
3959 }
3960
3961 RValue<Int> operator+(RValue<Int> val)
3962 {
3963 return val;
3964 }
3965
3966 RValue<Int> operator-(RValue<Int> val)
3967 {
3968 return RValue<Int>(Nucleus::createNeg(val.value));
3969 }
3970
3971 RValue<Int> operator~(RValue<Int> val)
3972 {
3973 return RValue<Int>(Nucleus::createNot(val.value));
3974 }
3975
Nicolas Capens96d4e092016-11-18 14:22:38 -05003976 RValue<Int> operator++(Int &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04003977 {
Nicolas Capens5b41ba32016-12-08 14:34:00 -05003978 RValue<Int> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05003979 val += 1;
3980 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003981 }
3982
Nicolas Capens96d4e092016-11-18 14:22:38 -05003983 const Int &operator++(Int &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04003984 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003985 val += 1;
3986 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003987 }
3988
Nicolas Capens96d4e092016-11-18 14:22:38 -05003989 RValue<Int> operator--(Int &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04003990 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003991 RValue<Int> res = val;
3992 val -= 1;
3993 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003994 }
3995
Nicolas Capens96d4e092016-11-18 14:22:38 -05003996 const Int &operator--(Int &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04003997 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003998 val -= 1;
3999 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004000 }
4001
4002 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
4003 {
4004 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4005 }
4006
4007 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
4008 {
4009 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4010 }
4011
4012 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
4013 {
4014 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4015 }
4016
4017 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
4018 {
4019 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4020 }
4021
4022 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
4023 {
4024 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4025 }
4026
4027 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
4028 {
4029 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4030 }
4031
4032 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4033 {
4034 return IfThenElse(x > y, x, y);
4035 }
4036
4037 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4038 {
4039 return IfThenElse(x < y, x, y);
4040 }
4041
4042 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4043 {
4044 return Min(Max(x, min), max);
4045 }
4046
4047 RValue<Int> RoundInt(RValue<Float> cast)
4048 {
Nicolas Capensb13cf492016-12-08 08:58:54 -05004049 RValue<Float> rounded = Round(cast);
4050
Nicolas Capensa8086512016-11-07 17:32:17 -05004051 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
Nicolas Capensb13cf492016-12-08 08:58:54 -05004052 auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value);
Nicolas Capensa8086512016-11-07 17:32:17 -05004053 ::basicBlock->appendInst(round);
4054
4055 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004056 }
4057
4058 Type *Int::getType()
4059 {
4060 return T(Ice::IceType_i32);
4061 }
4062
4063 Long::Long(RValue<Int> cast)
4064 {
4065 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4066
4067 storeValue(integer);
4068 }
4069
4070 Long::Long(RValue<UInt> cast)
4071 {
4072 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4073
4074 storeValue(integer);
4075 }
4076
Nicolas Capens598f8d82016-09-26 15:09:10 -04004077 Long::Long(RValue<Long> rhs)
4078 {
4079 storeValue(rhs.value);
4080 }
4081
Nicolas Capens96d4e092016-11-18 14:22:38 -05004082 RValue<Long> Long::operator=(int64_t rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004083 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004084 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004085 }
4086
Nicolas Capens96d4e092016-11-18 14:22:38 -05004087 RValue<Long> Long::operator=(RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004088 {
4089 storeValue(rhs.value);
4090
4091 return rhs;
4092 }
4093
Nicolas Capens96d4e092016-11-18 14:22:38 -05004094 RValue<Long> Long::operator=(const Long &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004095 {
4096 Value *value = rhs.loadValue();
4097 storeValue(value);
4098
4099 return RValue<Long>(value);
4100 }
4101
Nicolas Capens96d4e092016-11-18 14:22:38 -05004102 RValue<Long> Long::operator=(const Reference<Long> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004103 {
4104 Value *value = rhs.loadValue();
4105 storeValue(value);
4106
4107 return RValue<Long>(value);
4108 }
4109
4110 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
4111 {
4112 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4113 }
4114
4115 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
4116 {
4117 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4118 }
4119
Nicolas Capens96d4e092016-11-18 14:22:38 -05004120 RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004121 {
4122 return lhs = lhs + rhs;
4123 }
4124
Nicolas Capens96d4e092016-11-18 14:22:38 -05004125 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004126 {
4127 return lhs = lhs - rhs;
4128 }
4129
4130 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
4131 {
4132 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
4133 }
4134
4135 Type *Long::getType()
4136 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004137 return T(Ice::IceType_i64);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004138 }
4139
Nicolas Capens598f8d82016-09-26 15:09:10 -04004140 UInt::UInt(Argument<UInt> argument)
4141 {
4142 storeValue(argument.value);
4143 }
4144
4145 UInt::UInt(RValue<UShort> cast)
4146 {
4147 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4148
4149 storeValue(integer);
4150 }
4151
4152 UInt::UInt(RValue<Long> cast)
4153 {
4154 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4155
4156 storeValue(integer);
4157 }
4158
4159 UInt::UInt(RValue<Float> cast)
4160 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004161 // Smallest positive value representable in UInt, but not in Int
4162 const unsigned int ustart = 0x80000000u;
4163 const float ustartf = float(ustart);
4164
4165 // If the value is negative, store 0, otherwise store the result of the conversion
4166 storeValue((~(As<Int>(cast) >> 31) &
4167 // Check if the value can be represented as an Int
4168 IfThenElse(cast >= ustartf,
4169 // If the value is too large, subtract ustart and re-add it after conversion.
4170 As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
4171 // Otherwise, just convert normally
4172 Int(cast))).value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004173 }
4174
Nicolas Capens598f8d82016-09-26 15:09:10 -04004175 UInt::UInt(int x)
4176 {
4177 storeValue(Nucleus::createConstantInt(x));
4178 }
4179
4180 UInt::UInt(unsigned int x)
4181 {
4182 storeValue(Nucleus::createConstantInt(x));
4183 }
4184
4185 UInt::UInt(RValue<UInt> rhs)
4186 {
4187 storeValue(rhs.value);
4188 }
4189
4190 UInt::UInt(RValue<Int> rhs)
4191 {
4192 storeValue(rhs.value);
4193 }
4194
4195 UInt::UInt(const UInt &rhs)
4196 {
4197 Value *value = rhs.loadValue();
4198 storeValue(value);
4199 }
4200
4201 UInt::UInt(const Reference<UInt> &rhs)
4202 {
4203 Value *value = rhs.loadValue();
4204 storeValue(value);
4205 }
4206
4207 UInt::UInt(const Int &rhs)
4208 {
4209 Value *value = rhs.loadValue();
4210 storeValue(value);
4211 }
4212
4213 UInt::UInt(const Reference<Int> &rhs)
4214 {
4215 Value *value = rhs.loadValue();
4216 storeValue(value);
4217 }
4218
Nicolas Capens96d4e092016-11-18 14:22:38 -05004219 RValue<UInt> UInt::operator=(unsigned int rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004220 {
4221 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
4222 }
4223
Nicolas Capens96d4e092016-11-18 14:22:38 -05004224 RValue<UInt> UInt::operator=(RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004225 {
4226 storeValue(rhs.value);
4227
4228 return rhs;
4229 }
4230
Nicolas Capens96d4e092016-11-18 14:22:38 -05004231 RValue<UInt> UInt::operator=(RValue<Int> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004232 {
4233 storeValue(rhs.value);
4234
4235 return RValue<UInt>(rhs);
4236 }
4237
Nicolas Capens96d4e092016-11-18 14:22:38 -05004238 RValue<UInt> UInt::operator=(const UInt &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004239 {
4240 Value *value = rhs.loadValue();
4241 storeValue(value);
4242
4243 return RValue<UInt>(value);
4244 }
4245
Nicolas Capens96d4e092016-11-18 14:22:38 -05004246 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004247 {
4248 Value *value = rhs.loadValue();
4249 storeValue(value);
4250
4251 return RValue<UInt>(value);
4252 }
4253
Nicolas Capens96d4e092016-11-18 14:22:38 -05004254 RValue<UInt> UInt::operator=(const Int &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004255 {
4256 Value *value = rhs.loadValue();
4257 storeValue(value);
4258
4259 return RValue<UInt>(value);
4260 }
4261
Nicolas Capens96d4e092016-11-18 14:22:38 -05004262 RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004263 {
4264 Value *value = rhs.loadValue();
4265 storeValue(value);
4266
4267 return RValue<UInt>(value);
4268 }
4269
4270 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
4271 {
4272 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4273 }
4274
4275 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
4276 {
4277 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4278 }
4279
4280 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
4281 {
4282 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4283 }
4284
4285 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
4286 {
4287 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4288 }
4289
4290 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
4291 {
4292 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4293 }
4294
4295 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
4296 {
4297 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4298 }
4299
4300 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
4301 {
4302 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4303 }
4304
4305 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
4306 {
4307 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4308 }
4309
4310 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
4311 {
4312 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4313 }
4314
4315 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
4316 {
4317 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4318 }
4319
Nicolas Capens96d4e092016-11-18 14:22:38 -05004320 RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004321 {
4322 return lhs = lhs + rhs;
4323 }
4324
Nicolas Capens96d4e092016-11-18 14:22:38 -05004325 RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004326 {
4327 return lhs = lhs - rhs;
4328 }
4329
Nicolas Capens96d4e092016-11-18 14:22:38 -05004330 RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004331 {
4332 return lhs = lhs * rhs;
4333 }
4334
Nicolas Capens96d4e092016-11-18 14:22:38 -05004335 RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004336 {
4337 return lhs = lhs / rhs;
4338 }
4339
Nicolas Capens96d4e092016-11-18 14:22:38 -05004340 RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004341 {
4342 return lhs = lhs % rhs;
4343 }
4344
Nicolas Capens96d4e092016-11-18 14:22:38 -05004345 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004346 {
4347 return lhs = lhs & rhs;
4348 }
4349
Nicolas Capens96d4e092016-11-18 14:22:38 -05004350 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004351 {
4352 return lhs = lhs | rhs;
4353 }
4354
Nicolas Capens96d4e092016-11-18 14:22:38 -05004355 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004356 {
4357 return lhs = lhs ^ rhs;
4358 }
4359
Nicolas Capens96d4e092016-11-18 14:22:38 -05004360 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004361 {
4362 return lhs = lhs << rhs;
4363 }
4364
Nicolas Capens96d4e092016-11-18 14:22:38 -05004365 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004366 {
4367 return lhs = lhs >> rhs;
4368 }
4369
4370 RValue<UInt> operator+(RValue<UInt> val)
4371 {
4372 return val;
4373 }
4374
4375 RValue<UInt> operator-(RValue<UInt> val)
4376 {
4377 return RValue<UInt>(Nucleus::createNeg(val.value));
4378 }
4379
4380 RValue<UInt> operator~(RValue<UInt> val)
4381 {
4382 return RValue<UInt>(Nucleus::createNot(val.value));
4383 }
4384
Nicolas Capens96d4e092016-11-18 14:22:38 -05004385 RValue<UInt> operator++(UInt &val, int) // Post-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004386 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004387 RValue<UInt> res = val;
4388 val += 1;
4389 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004390 }
4391
Nicolas Capens96d4e092016-11-18 14:22:38 -05004392 const UInt &operator++(UInt &val) // Pre-increment
Nicolas Capens598f8d82016-09-26 15:09:10 -04004393 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004394 val += 1;
4395 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004396 }
4397
Nicolas Capens96d4e092016-11-18 14:22:38 -05004398 RValue<UInt> operator--(UInt &val, int) // Post-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004399 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004400 RValue<UInt> res = val;
4401 val -= 1;
4402 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004403 }
4404
Nicolas Capens96d4e092016-11-18 14:22:38 -05004405 const UInt &operator--(UInt &val) // Pre-decrement
Nicolas Capens598f8d82016-09-26 15:09:10 -04004406 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004407 val -= 1;
4408 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004409 }
4410
4411 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4412 {
4413 return IfThenElse(x > y, x, y);
4414 }
4415
4416 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4417 {
4418 return IfThenElse(x < y, x, y);
4419 }
4420
4421 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4422 {
4423 return Min(Max(x, min), max);
4424 }
4425
4426 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
4427 {
4428 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4429 }
4430
4431 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
4432 {
4433 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4434 }
4435
4436 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
4437 {
4438 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4439 }
4440
4441 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
4442 {
4443 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4444 }
4445
4446 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
4447 {
4448 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4449 }
4450
4451 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
4452 {
4453 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4454 }
4455
4456// RValue<UInt> RoundUInt(RValue<Float> cast)
4457// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004458// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004459// }
4460
4461 Type *UInt::getType()
4462 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004463 return T(Ice::IceType_i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004464 }
4465
4466// Int2::Int2(RValue<Int> cast)
4467// {
4468// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4469// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
4470//
4471// Constant *shuffle[2];
4472// shuffle[0] = Nucleus::createConstantInt(0);
4473// shuffle[1] = Nucleus::createConstantInt(0);
4474//
4475// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4476//
4477// storeValue(replicate);
4478// }
4479
4480 Int2::Int2(RValue<Int4> cast)
4481 {
Nicolas Capens22008782016-10-20 01:11:47 -04004482 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004483 }
4484
Nicolas Capens598f8d82016-09-26 15:09:10 -04004485 Int2::Int2(int x, int y)
4486 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004487 int64_t constantVector[2] = {x, y};
4488 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004489 }
4490
4491 Int2::Int2(RValue<Int2> rhs)
4492 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004493 storeValue(rhs.value);
4494 }
4495
4496 Int2::Int2(const Int2 &rhs)
4497 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004498 Value *value = rhs.loadValue();
4499 storeValue(value);
4500 }
4501
4502 Int2::Int2(const Reference<Int2> &rhs)
4503 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004504 Value *value = rhs.loadValue();
4505 storeValue(value);
4506 }
4507
4508 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4509 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004510 int shuffle[4] = {0, 4, 1, 5};
4511 Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
4512
4513 storeValue(Nucleus::createBitCast(packed, Int2::getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004514 }
4515
Nicolas Capens96d4e092016-11-18 14:22:38 -05004516 RValue<Int2> Int2::operator=(RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004517 {
4518 storeValue(rhs.value);
4519
4520 return rhs;
4521 }
4522
Nicolas Capens96d4e092016-11-18 14:22:38 -05004523 RValue<Int2> Int2::operator=(const Int2 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004524 {
4525 Value *value = rhs.loadValue();
4526 storeValue(value);
4527
4528 return RValue<Int2>(value);
4529 }
4530
Nicolas Capens96d4e092016-11-18 14:22:38 -05004531 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004532 {
4533 Value *value = rhs.loadValue();
4534 storeValue(value);
4535
4536 return RValue<Int2>(value);
4537 }
4538
4539 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
4540 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004541 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004542 }
4543
4544 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
4545 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004546 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004547 }
4548
4549// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4550// {
4551// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4552// }
4553
4554// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4555// {
4556// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4557// }
4558
4559// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4560// {
4561// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4562// }
4563
4564 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
4565 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004566 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004567 }
4568
4569 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
4570 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004571 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004572 }
4573
4574 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
4575 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004576 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004577 }
4578
4579 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
4580 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004581 return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004582 }
4583
4584 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
4585 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004586 return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004587 }
4588
Nicolas Capens96d4e092016-11-18 14:22:38 -05004589 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004590 {
4591 return lhs = lhs + rhs;
4592 }
4593
Nicolas Capens96d4e092016-11-18 14:22:38 -05004594 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004595 {
4596 return lhs = lhs - rhs;
4597 }
4598
Nicolas Capens96d4e092016-11-18 14:22:38 -05004599// RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004600// {
4601// return lhs = lhs * rhs;
4602// }
4603
Nicolas Capens96d4e092016-11-18 14:22:38 -05004604// RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004605// {
4606// return lhs = lhs / rhs;
4607// }
4608
Nicolas Capens96d4e092016-11-18 14:22:38 -05004609// RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004610// {
4611// return lhs = lhs % rhs;
4612// }
4613
Nicolas Capens96d4e092016-11-18 14:22:38 -05004614 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004615 {
4616 return lhs = lhs & rhs;
4617 }
4618
Nicolas Capens96d4e092016-11-18 14:22:38 -05004619 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004620 {
4621 return lhs = lhs | rhs;
4622 }
4623
Nicolas Capens96d4e092016-11-18 14:22:38 -05004624 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004625 {
4626 return lhs = lhs ^ rhs;
4627 }
4628
Nicolas Capens96d4e092016-11-18 14:22:38 -05004629 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004630 {
4631 return lhs = lhs << rhs;
4632 }
4633
Nicolas Capens96d4e092016-11-18 14:22:38 -05004634 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004635 {
4636 return lhs = lhs >> rhs;
4637 }
4638
Nicolas Capens598f8d82016-09-26 15:09:10 -04004639// RValue<Int2> operator+(RValue<Int2> val)
4640// {
4641// return val;
4642// }
4643
4644// RValue<Int2> operator-(RValue<Int2> val)
4645// {
4646// return RValue<Int2>(Nucleus::createNeg(val.value));
4647// }
4648
4649 RValue<Int2> operator~(RValue<Int2> val)
4650 {
Nicolas Capensc5c0c332016-11-08 11:37:01 -05004651 return RValue<Int2>(Nucleus::createNot(val.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004652 }
4653
Nicolas Capens45f187a2016-12-02 15:30:56 -05004654 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004655 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004656 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
4657 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004658 }
4659
Nicolas Capens45f187a2016-12-02 15:30:56 -05004660 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004661 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004662 int shuffle[16] = {0, 4, 1, 5}; // Real type is v4i32
4663 auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
4664 return As<Short4>(Swizzle(lowHigh, 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004665 }
4666
4667 RValue<Int> Extract(RValue<Int2> val, int i)
4668 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05004669 return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004670 }
4671
4672 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4673 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05004674 return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004675 }
4676
4677 Type *Int2::getType()
4678 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004679 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004680 }
4681
Nicolas Capens598f8d82016-09-26 15:09:10 -04004682 UInt2::UInt2(unsigned int x, unsigned int y)
4683 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004684 int64_t constantVector[2] = {x, y};
4685 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004686 }
4687
4688 UInt2::UInt2(RValue<UInt2> rhs)
4689 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004690 storeValue(rhs.value);
4691 }
4692
4693 UInt2::UInt2(const UInt2 &rhs)
4694 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004695 Value *value = rhs.loadValue();
4696 storeValue(value);
4697 }
4698
4699 UInt2::UInt2(const Reference<UInt2> &rhs)
4700 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004701 Value *value = rhs.loadValue();
4702 storeValue(value);
4703 }
4704
Nicolas Capens96d4e092016-11-18 14:22:38 -05004705 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004706 {
4707 storeValue(rhs.value);
4708
4709 return rhs;
4710 }
4711
Nicolas Capens96d4e092016-11-18 14:22:38 -05004712 RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004713 {
4714 Value *value = rhs.loadValue();
4715 storeValue(value);
4716
4717 return RValue<UInt2>(value);
4718 }
4719
Nicolas Capens96d4e092016-11-18 14:22:38 -05004720 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004721 {
4722 Value *value = rhs.loadValue();
4723 storeValue(value);
4724
4725 return RValue<UInt2>(value);
4726 }
4727
4728 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
4729 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004730 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004731 }
4732
4733 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
4734 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004735 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004736 }
4737
4738// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4739// {
4740// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4741// }
4742
4743// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4744// {
4745// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4746// }
4747
4748// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4749// {
4750// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4751// }
4752
4753 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
4754 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004755 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004756 }
4757
4758 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
4759 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004760 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004761 }
4762
4763 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
4764 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004765 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004766 }
4767
4768 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
4769 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004770 return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004771 }
4772
4773 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
4774 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05004775 return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004776 }
4777
Nicolas Capens96d4e092016-11-18 14:22:38 -05004778 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004779 {
4780 return lhs = lhs + rhs;
4781 }
4782
Nicolas Capens96d4e092016-11-18 14:22:38 -05004783 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004784 {
4785 return lhs = lhs - rhs;
4786 }
4787
Nicolas Capens96d4e092016-11-18 14:22:38 -05004788// RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004789// {
4790// return lhs = lhs * rhs;
4791// }
4792
Nicolas Capens96d4e092016-11-18 14:22:38 -05004793// RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004794// {
4795// return lhs = lhs / rhs;
4796// }
4797
Nicolas Capens96d4e092016-11-18 14:22:38 -05004798// RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004799// {
4800// return lhs = lhs % rhs;
4801// }
4802
Nicolas Capens96d4e092016-11-18 14:22:38 -05004803 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004804 {
4805 return lhs = lhs & rhs;
4806 }
4807
Nicolas Capens96d4e092016-11-18 14:22:38 -05004808 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004809 {
4810 return lhs = lhs | rhs;
4811 }
4812
Nicolas Capens96d4e092016-11-18 14:22:38 -05004813 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004814 {
4815 return lhs = lhs ^ rhs;
4816 }
4817
Nicolas Capens96d4e092016-11-18 14:22:38 -05004818 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004819 {
4820 return lhs = lhs << rhs;
4821 }
4822
Nicolas Capens96d4e092016-11-18 14:22:38 -05004823 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004824 {
4825 return lhs = lhs >> rhs;
4826 }
4827
Nicolas Capens598f8d82016-09-26 15:09:10 -04004828// RValue<UInt2> operator+(RValue<UInt2> val)
4829// {
4830// return val;
4831// }
4832
4833// RValue<UInt2> operator-(RValue<UInt2> val)
4834// {
4835// return RValue<UInt2>(Nucleus::createNeg(val.value));
4836// }
4837
4838 RValue<UInt2> operator~(RValue<UInt2> val)
4839 {
4840 return RValue<UInt2>(Nucleus::createNot(val.value));
4841 }
4842
4843 Type *UInt2::getType()
4844 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004845 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004846 }
4847
4848 Int4::Int4(RValue<Byte4> cast)
4849 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004850 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
4851 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
4852
4853 Value *e;
4854 int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
4855 Value *b = Nucleus::createBitCast(a, Byte16::getType());
4856 Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
4857
4858 int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
4859 Value *d = Nucleus::createBitCast(c, Short8::getType());
4860 e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
4861
4862 Value *f = Nucleus::createBitCast(e, Int4::getType());
4863 storeValue(f);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004864 }
4865
4866 Int4::Int4(RValue<SByte4> cast)
4867 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004868 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
4869 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
4870
4871 Value *e;
4872 int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
4873 Value *b = Nucleus::createBitCast(a, Byte16::getType());
4874 Value *c = Nucleus::createShuffleVector(b, b, swizzle);
4875
4876 int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
4877 Value *d = Nucleus::createBitCast(c, Short8::getType());
4878 e = Nucleus::createShuffleVector(d, d, swizzle2);
4879
4880 Value *f = Nucleus::createBitCast(e, Int4::getType());
Nicolas Capens15060bb2016-12-05 22:17:19 -05004881 Value *g = Nucleus::createAShr(f, V(::context->getConstantInt32(24)));
Nicolas Capensd4227962016-11-09 14:24:25 -05004882 storeValue(g);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004883 }
4884
4885 Int4::Int4(RValue<Float4> cast)
4886 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004887 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
4888
4889 storeValue(xyzw);
4890 }
4891
4892 Int4::Int4(RValue<Short4> cast)
4893 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004894 int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
4895 Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
4896 Value *d = Nucleus::createBitCast(c, Int4::getType());
Nicolas Capens15060bb2016-12-05 22:17:19 -05004897 Value *e = Nucleus::createAShr(d, V(::context->getConstantInt32(16)));
Nicolas Capensd4227962016-11-09 14:24:25 -05004898 storeValue(e);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004899 }
4900
4901 Int4::Int4(RValue<UShort4> cast)
4902 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004903 int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
4904 Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
4905 Value *d = Nucleus::createBitCast(c, Int4::getType());
4906 storeValue(d);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004907 }
4908
Nicolas Capens598f8d82016-09-26 15:09:10 -04004909 Int4::Int4(int xyzw)
4910 {
4911 constant(xyzw, xyzw, xyzw, xyzw);
4912 }
4913
4914 Int4::Int4(int x, int yzw)
4915 {
4916 constant(x, yzw, yzw, yzw);
4917 }
4918
4919 Int4::Int4(int x, int y, int zw)
4920 {
4921 constant(x, y, zw, zw);
4922 }
4923
4924 Int4::Int4(int x, int y, int z, int w)
4925 {
4926 constant(x, y, z, w);
4927 }
4928
4929 void Int4::constant(int x, int y, int z, int w)
4930 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004931 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004932 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004933 }
4934
4935 Int4::Int4(RValue<Int4> rhs)
4936 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004937 storeValue(rhs.value);
4938 }
4939
4940 Int4::Int4(const Int4 &rhs)
4941 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004942 Value *value = rhs.loadValue();
4943 storeValue(value);
4944 }
4945
4946 Int4::Int4(const Reference<Int4> &rhs)
4947 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004948 Value *value = rhs.loadValue();
4949 storeValue(value);
4950 }
4951
4952 Int4::Int4(RValue<UInt4> rhs)
4953 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004954 storeValue(rhs.value);
4955 }
4956
4957 Int4::Int4(const UInt4 &rhs)
4958 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004959 Value *value = rhs.loadValue();
4960 storeValue(value);
4961 }
4962
4963 Int4::Int4(const Reference<UInt4> &rhs)
4964 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004965 Value *value = rhs.loadValue();
4966 storeValue(value);
4967 }
4968
4969 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
4970 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05004971 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
4972 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
4973
4974 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004975 }
4976
4977 Int4::Int4(RValue<Int> rhs)
4978 {
Nicolas Capensd4227962016-11-09 14:24:25 -05004979 Value *vector = loadValue();
4980 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
4981
4982 int swizzle[4] = {0, 0, 0, 0};
4983 Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle);
4984
4985 storeValue(replicate);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004986 }
4987
4988 Int4::Int4(const Int &rhs)
4989 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004990 *this = RValue<Int>(rhs.loadValue());
4991 }
4992
4993 Int4::Int4(const Reference<Int> &rhs)
4994 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04004995 *this = RValue<Int>(rhs.loadValue());
4996 }
4997
Nicolas Capens96d4e092016-11-18 14:22:38 -05004998 RValue<Int4> Int4::operator=(RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04004999 {
5000 storeValue(rhs.value);
5001
5002 return rhs;
5003 }
5004
Nicolas Capens96d4e092016-11-18 14:22:38 -05005005 RValue<Int4> Int4::operator=(const Int4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005006 {
5007 Value *value = rhs.loadValue();
5008 storeValue(value);
5009
5010 return RValue<Int4>(value);
5011 }
5012
Nicolas Capens96d4e092016-11-18 14:22:38 -05005013 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005014 {
5015 Value *value = rhs.loadValue();
5016 storeValue(value);
5017
5018 return RValue<Int4>(value);
5019 }
5020
5021 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
5022 {
5023 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5024 }
5025
5026 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
5027 {
5028 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5029 }
5030
5031 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
5032 {
5033 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5034 }
5035
5036 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5037 {
5038 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5039 }
5040
5041 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5042 {
5043 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5044 }
5045
5046 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
5047 {
5048 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5049 }
5050
5051 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
5052 {
5053 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5054 }
5055
5056 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
5057 {
5058 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5059 }
5060
5061 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
5062 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005063 return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005064 }
5065
5066 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
5067 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005068 return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005069 }
5070
5071 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5072 {
5073 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5074 }
5075
5076 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5077 {
5078 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5079 }
5080
Nicolas Capens96d4e092016-11-18 14:22:38 -05005081 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005082 {
5083 return lhs = lhs + rhs;
5084 }
5085
Nicolas Capens96d4e092016-11-18 14:22:38 -05005086 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005087 {
5088 return lhs = lhs - rhs;
5089 }
5090
Nicolas Capens96d4e092016-11-18 14:22:38 -05005091 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005092 {
5093 return lhs = lhs * rhs;
5094 }
5095
Nicolas Capens96d4e092016-11-18 14:22:38 -05005096// RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005097// {
5098// return lhs = lhs / rhs;
5099// }
5100
Nicolas Capens96d4e092016-11-18 14:22:38 -05005101// RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005102// {
5103// return lhs = lhs % rhs;
5104// }
5105
Nicolas Capens96d4e092016-11-18 14:22:38 -05005106 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005107 {
5108 return lhs = lhs & rhs;
5109 }
5110
Nicolas Capens96d4e092016-11-18 14:22:38 -05005111 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005112 {
5113 return lhs = lhs | rhs;
5114 }
5115
Nicolas Capens96d4e092016-11-18 14:22:38 -05005116 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005117 {
5118 return lhs = lhs ^ rhs;
5119 }
5120
Nicolas Capens96d4e092016-11-18 14:22:38 -05005121 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005122 {
5123 return lhs = lhs << rhs;
5124 }
5125
Nicolas Capens96d4e092016-11-18 14:22:38 -05005126 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005127 {
5128 return lhs = lhs >> rhs;
5129 }
5130
5131 RValue<Int4> operator+(RValue<Int4> val)
5132 {
5133 return val;
5134 }
5135
5136 RValue<Int4> operator-(RValue<Int4> val)
5137 {
5138 return RValue<Int4>(Nucleus::createNeg(val.value));
5139 }
5140
5141 RValue<Int4> operator~(RValue<Int4> val)
5142 {
5143 return RValue<Int4>(Nucleus::createNot(val.value));
5144 }
5145
5146 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5147 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005148 return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005149 }
5150
5151 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5152 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005153 return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005154 }
5155
5156 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5157 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005158 return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005159 }
5160
5161 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5162 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005163 return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005164 }
5165
5166 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5167 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005168 return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005169 }
5170
5171 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5172 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005173 return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005174 }
5175
5176 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5177 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005178 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5179 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
5180 ::basicBlock->appendInst(cmp);
5181
5182 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5183 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5184 ::basicBlock->appendInst(select);
5185
5186 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005187 }
5188
5189 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5190 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005191 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5192 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
5193 ::basicBlock->appendInst(cmp);
5194
5195 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5196 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5197 ::basicBlock->appendInst(select);
5198
5199 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005200 }
5201
5202 RValue<Int4> RoundInt(RValue<Float4> cast)
5203 {
Nicolas Capensb13cf492016-12-08 08:58:54 -05005204 RValue<Float4> rounded = Round(cast);
5205
Nicolas Capensa8086512016-11-07 17:32:17 -05005206 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
Nicolas Capensb13cf492016-12-08 08:58:54 -05005207 auto round = Ice::InstCast::create(::function, Ice::InstCast::Fptosi, result, rounded.value);
Nicolas Capensa8086512016-11-07 17:32:17 -05005208 ::basicBlock->appendInst(round);
5209
5210 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005211 }
5212
5213 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
5214 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005215 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5216 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5217 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5218 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5219 pack->addArg(x.value);
5220 pack->addArg(y.value);
5221 ::basicBlock->appendInst(pack);
5222
5223 return RValue<Short8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005224 }
5225
5226 RValue<Int> Extract(RValue<Int4> x, int i)
5227 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005228 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005229 }
5230
5231 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
5232 {
5233 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5234 }
5235
5236 RValue<Int> SignMask(RValue<Int4> x)
5237 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04005238 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
5239 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5240 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5241 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5242 movmsk->addArg(x.value);
5243 ::basicBlock->appendInst(movmsk);
5244
5245 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005246 }
5247
5248 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
5249 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005250 return RValue<Int4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005251 }
5252
5253 Type *Int4::getType()
5254 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04005255 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005256 }
5257
5258 UInt4::UInt4(RValue<Float4> cast)
5259 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005260 // Smallest positive value representable in UInt, but not in Int
5261 const unsigned int ustart = 0x80000000u;
5262 const float ustartf = float(ustart);
5263
5264 // Check if the value can be represented as an Int
5265 Int4 uiValue = CmpNLT(cast, Float4(ustartf));
5266 // If the value is too large, subtract ustart and re-add it after conversion.
5267 uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
5268 // Otherwise, just convert normally
5269 (~uiValue & Int4(cast));
5270 // If the value is negative, store 0, otherwise store the result of the conversion
5271 storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005272 }
5273
Nicolas Capens598f8d82016-09-26 15:09:10 -04005274 UInt4::UInt4(int xyzw)
5275 {
5276 constant(xyzw, xyzw, xyzw, xyzw);
5277 }
5278
5279 UInt4::UInt4(int x, int yzw)
5280 {
5281 constant(x, yzw, yzw, yzw);
5282 }
5283
5284 UInt4::UInt4(int x, int y, int zw)
5285 {
5286 constant(x, y, zw, zw);
5287 }
5288
5289 UInt4::UInt4(int x, int y, int z, int w)
5290 {
5291 constant(x, y, z, w);
5292 }
5293
5294 void UInt4::constant(int x, int y, int z, int w)
5295 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005296 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005297 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005298 }
5299
5300 UInt4::UInt4(RValue<UInt4> rhs)
5301 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005302 storeValue(rhs.value);
5303 }
5304
5305 UInt4::UInt4(const UInt4 &rhs)
5306 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005307 Value *value = rhs.loadValue();
5308 storeValue(value);
5309 }
5310
5311 UInt4::UInt4(const Reference<UInt4> &rhs)
5312 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005313 Value *value = rhs.loadValue();
5314 storeValue(value);
5315 }
5316
5317 UInt4::UInt4(RValue<Int4> rhs)
5318 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005319 storeValue(rhs.value);
5320 }
5321
5322 UInt4::UInt4(const Int4 &rhs)
5323 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005324 Value *value = rhs.loadValue();
5325 storeValue(value);
5326 }
5327
5328 UInt4::UInt4(const Reference<Int4> &rhs)
5329 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005330 Value *value = rhs.loadValue();
5331 storeValue(value);
5332 }
5333
5334 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5335 {
Nicolas Capensc70a1162016-12-03 00:16:14 -05005336 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5337 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5338
5339 storeValue(packed);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005340 }
5341
Nicolas Capens96d4e092016-11-18 14:22:38 -05005342 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005343 {
5344 storeValue(rhs.value);
5345
5346 return rhs;
5347 }
5348
Nicolas Capens96d4e092016-11-18 14:22:38 -05005349 RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005350 {
5351 Value *value = rhs.loadValue();
5352 storeValue(value);
5353
5354 return RValue<UInt4>(value);
5355 }
5356
Nicolas Capens96d4e092016-11-18 14:22:38 -05005357 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005358 {
5359 Value *value = rhs.loadValue();
5360 storeValue(value);
5361
5362 return RValue<UInt4>(value);
5363 }
5364
5365 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
5366 {
5367 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5368 }
5369
5370 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
5371 {
5372 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5373 }
5374
5375 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
5376 {
5377 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5378 }
5379
5380 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5381 {
5382 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5383 }
5384
5385 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5386 {
5387 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5388 }
5389
5390 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
5391 {
5392 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5393 }
5394
5395 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
5396 {
5397 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5398 }
5399
5400 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
5401 {
5402 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5403 }
5404
5405 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
5406 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005407 return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005408 }
5409
5410 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
5411 {
Nicolas Capens15060bb2016-12-05 22:17:19 -05005412 return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005413 }
5414
5415 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5416 {
5417 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5418 }
5419
5420 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5421 {
5422 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5423 }
5424
Nicolas Capens96d4e092016-11-18 14:22:38 -05005425 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005426 {
5427 return lhs = lhs + rhs;
5428 }
5429
Nicolas Capens96d4e092016-11-18 14:22:38 -05005430 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005431 {
5432 return lhs = lhs - rhs;
5433 }
5434
Nicolas Capens96d4e092016-11-18 14:22:38 -05005435 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005436 {
5437 return lhs = lhs * rhs;
5438 }
5439
Nicolas Capens96d4e092016-11-18 14:22:38 -05005440// RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005441// {
5442// return lhs = lhs / rhs;
5443// }
5444
Nicolas Capens96d4e092016-11-18 14:22:38 -05005445// RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005446// {
5447// return lhs = lhs % rhs;
5448// }
5449
Nicolas Capens96d4e092016-11-18 14:22:38 -05005450 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005451 {
5452 return lhs = lhs & rhs;
5453 }
5454
Nicolas Capens96d4e092016-11-18 14:22:38 -05005455 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005456 {
5457 return lhs = lhs | rhs;
5458 }
5459
Nicolas Capens96d4e092016-11-18 14:22:38 -05005460 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005461 {
5462 return lhs = lhs ^ rhs;
5463 }
5464
Nicolas Capens96d4e092016-11-18 14:22:38 -05005465 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005466 {
5467 return lhs = lhs << rhs;
5468 }
5469
Nicolas Capens96d4e092016-11-18 14:22:38 -05005470 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005471 {
5472 return lhs = lhs >> rhs;
5473 }
5474
5475 RValue<UInt4> operator+(RValue<UInt4> val)
5476 {
5477 return val;
5478 }
5479
5480 RValue<UInt4> operator-(RValue<UInt4> val)
5481 {
5482 return RValue<UInt4>(Nucleus::createNeg(val.value));
5483 }
5484
5485 RValue<UInt4> operator~(RValue<UInt4> val)
5486 {
5487 return RValue<UInt4>(Nucleus::createNot(val.value));
5488 }
5489
5490 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5491 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005492 return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005493 }
5494
5495 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5496 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005497 return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005498 }
5499
5500 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5501 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005502 return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005503 }
5504
5505 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5506 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005507 return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005508 }
5509
5510 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5511 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005512 return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005513 }
5514
5515 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5516 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05005517 return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005518 }
5519
5520 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5521 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005522 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5523 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
5524 ::basicBlock->appendInst(cmp);
5525
5526 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5527 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5528 ::basicBlock->appendInst(select);
5529
5530 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005531 }
5532
5533 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5534 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005535 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5536 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
5537 ::basicBlock->appendInst(cmp);
5538
5539 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5540 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5541 ::basicBlock->appendInst(select);
5542
5543 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005544 }
5545
5546 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
5547 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005548 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5549 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5550 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5551 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5552 pack->addArg(x.value);
5553 pack->addArg(y.value);
5554 ::basicBlock->appendInst(pack);
5555
5556 return RValue<UShort8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005557 }
5558
5559 Type *UInt4::getType()
5560 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005561 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005562 }
5563
5564 Float::Float(RValue<Int> cast)
5565 {
5566 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5567
5568 storeValue(integer);
5569 }
5570
Nicolas Capens598f8d82016-09-26 15:09:10 -04005571 Float::Float(float x)
5572 {
5573 storeValue(Nucleus::createConstantFloat(x));
5574 }
5575
5576 Float::Float(RValue<Float> rhs)
5577 {
5578 storeValue(rhs.value);
5579 }
5580
5581 Float::Float(const Float &rhs)
5582 {
5583 Value *value = rhs.loadValue();
5584 storeValue(value);
5585 }
5586
5587 Float::Float(const Reference<Float> &rhs)
5588 {
5589 Value *value = rhs.loadValue();
5590 storeValue(value);
5591 }
5592
Nicolas Capens96d4e092016-11-18 14:22:38 -05005593 RValue<Float> Float::operator=(RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005594 {
5595 storeValue(rhs.value);
5596
5597 return rhs;
5598 }
5599
Nicolas Capens96d4e092016-11-18 14:22:38 -05005600 RValue<Float> Float::operator=(const Float &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005601 {
5602 Value *value = rhs.loadValue();
5603 storeValue(value);
5604
5605 return RValue<Float>(value);
5606 }
5607
Nicolas Capens96d4e092016-11-18 14:22:38 -05005608 RValue<Float> Float::operator=(const Reference<Float> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005609 {
5610 Value *value = rhs.loadValue();
5611 storeValue(value);
5612
5613 return RValue<Float>(value);
5614 }
5615
5616 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
5617 {
5618 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5619 }
5620
5621 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
5622 {
5623 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5624 }
5625
5626 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
5627 {
5628 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5629 }
5630
5631 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
5632 {
5633 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5634 }
5635
Nicolas Capens96d4e092016-11-18 14:22:38 -05005636 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005637 {
5638 return lhs = lhs + rhs;
5639 }
5640
Nicolas Capens96d4e092016-11-18 14:22:38 -05005641 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005642 {
5643 return lhs = lhs - rhs;
5644 }
5645
Nicolas Capens96d4e092016-11-18 14:22:38 -05005646 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005647 {
5648 return lhs = lhs * rhs;
5649 }
5650
Nicolas Capens96d4e092016-11-18 14:22:38 -05005651 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005652 {
5653 return lhs = lhs / rhs;
5654 }
5655
5656 RValue<Float> operator+(RValue<Float> val)
5657 {
5658 return val;
5659 }
5660
5661 RValue<Float> operator-(RValue<Float> val)
5662 {
5663 return RValue<Float>(Nucleus::createFNeg(val.value));
5664 }
5665
5666 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
5667 {
5668 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5669 }
5670
5671 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
5672 {
5673 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5674 }
5675
5676 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
5677 {
5678 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5679 }
5680
5681 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
5682 {
5683 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5684 }
5685
5686 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
5687 {
5688 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5689 }
5690
5691 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
5692 {
5693 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5694 }
5695
5696 RValue<Float> Abs(RValue<Float> x)
5697 {
5698 return IfThenElse(x > 0.0f, x, -x);
5699 }
5700
5701 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
5702 {
5703 return IfThenElse(x > y, x, y);
5704 }
5705
5706 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
5707 {
5708 return IfThenElse(x < y, x, y);
5709 }
5710
5711 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
5712 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005713 return 1.0f / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005714 }
5715
5716 RValue<Float> RcpSqrt_pp(RValue<Float> x)
5717 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005718 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005719 }
5720
5721 RValue<Float> Sqrt(RValue<Float> x)
5722 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005723 Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32);
5724 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5725 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5726 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5727 sqrt->addArg(x.value);
5728 ::basicBlock->appendInst(sqrt);
5729
5730 return RValue<Float>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005731 }
5732
5733 RValue<Float> Round(RValue<Float> x)
5734 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005735 return Float4(Round(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005736 }
5737
5738 RValue<Float> Trunc(RValue<Float> x)
5739 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005740 return Float4(Trunc(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005741 }
5742
5743 RValue<Float> Frac(RValue<Float> x)
5744 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005745 return Float4(Frac(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005746 }
5747
5748 RValue<Float> Floor(RValue<Float> x)
5749 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005750 return Float4(Floor(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005751 }
5752
5753 RValue<Float> Ceil(RValue<Float> x)
5754 {
Nicolas Capensa8086512016-11-07 17:32:17 -05005755 return Float4(Ceil(Float4(x))).x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005756 }
5757
5758 Type *Float::getType()
5759 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04005760 return T(Ice::IceType_f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005761 }
5762
5763 Float2::Float2(RValue<Float4> cast)
5764 {
Nicolas Capens22008782016-10-20 01:11:47 -04005765 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005766 }
5767
5768 Type *Float2::getType()
5769 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005770 return T(Type_v2f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005771 }
5772
Nicolas Capensa25311a2017-01-16 17:19:00 -05005773 Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005774 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005775 Value *a = Int4(cast).loadValue();
5776 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
5777
5778 storeValue(xyzw);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005779 }
5780
Nicolas Capensa25311a2017-01-16 17:19:00 -05005781 Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005782 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005783 Value *a = Int4(cast).loadValue();
5784 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
5785
5786 storeValue(xyzw);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005787 }
5788
Nicolas Capensa25311a2017-01-16 17:19:00 -05005789 Float4::Float4(RValue<Short4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005790 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005791 Int4 c(cast);
5792 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5793 }
5794
Nicolas Capensa25311a2017-01-16 17:19:00 -05005795 Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005796 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005797 Int4 c(cast);
5798 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5799 }
5800
Nicolas Capensa25311a2017-01-16 17:19:00 -05005801 Float4::Float4(RValue<Int4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005802 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005803 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
5804
5805 storeValue(xyzw);
5806 }
5807
Nicolas Capensa25311a2017-01-16 17:19:00 -05005808 Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005809 {
Nicolas Capens96445fe2016-12-15 14:45:13 -05005810 RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
5811 As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005812
Nicolas Capens96445fe2016-12-15 14:45:13 -05005813 storeValue(result.value);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005814 }
5815
Nicolas Capensa25311a2017-01-16 17:19:00 -05005816 Float4::Float4() : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005817 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005818 }
5819
Nicolas Capensa25311a2017-01-16 17:19:00 -05005820 Float4::Float4(float xyzw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005821 {
5822 constant(xyzw, xyzw, xyzw, xyzw);
5823 }
5824
Nicolas Capensa25311a2017-01-16 17:19:00 -05005825 Float4::Float4(float x, float yzw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005826 {
5827 constant(x, yzw, yzw, yzw);
5828 }
5829
Nicolas Capensa25311a2017-01-16 17:19:00 -05005830 Float4::Float4(float x, float y, float zw) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005831 {
5832 constant(x, y, zw, zw);
5833 }
5834
Nicolas Capensa25311a2017-01-16 17:19:00 -05005835 Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005836 {
5837 constant(x, y, z, w);
5838 }
5839
5840 void Float4::constant(float x, float y, float z, float w)
5841 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04005842 double constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005843 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005844 }
5845
Nicolas Capensa25311a2017-01-16 17:19:00 -05005846 Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005847 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005848 storeValue(rhs.value);
5849 }
5850
Nicolas Capensa25311a2017-01-16 17:19:00 -05005851 Float4::Float4(const Float4 &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005852 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005853 Value *value = rhs.loadValue();
5854 storeValue(value);
5855 }
5856
Nicolas Capensa25311a2017-01-16 17:19:00 -05005857 Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005858 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005859 Value *value = rhs.loadValue();
5860 storeValue(value);
5861 }
5862
Nicolas Capensa25311a2017-01-16 17:19:00 -05005863 Float4::Float4(RValue<Float> rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005864 {
Nicolas Capensd4227962016-11-09 14:24:25 -05005865 Value *vector = loadValue();
5866 Value *insert = Nucleus::createInsertElement(vector, rhs.value, 0);
5867
5868 int swizzle[4] = {0, 0, 0, 0};
5869 Value *replicate = Nucleus::createShuffleVector(insert, insert, swizzle);
5870
5871 storeValue(replicate);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005872 }
5873
Nicolas Capensa25311a2017-01-16 17:19:00 -05005874 Float4::Float4(const Float &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005875 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005876 *this = RValue<Float>(rhs.loadValue());
5877 }
5878
Nicolas Capensa25311a2017-01-16 17:19:00 -05005879 Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005880 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04005881 *this = RValue<Float>(rhs.loadValue());
5882 }
5883
Nicolas Capens96d4e092016-11-18 14:22:38 -05005884 RValue<Float4> Float4::operator=(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005885 {
5886 return *this = Float4(x, x, x, x);
5887 }
5888
Nicolas Capens96d4e092016-11-18 14:22:38 -05005889 RValue<Float4> Float4::operator=(RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005890 {
5891 storeValue(rhs.value);
5892
5893 return rhs;
5894 }
5895
Nicolas Capens96d4e092016-11-18 14:22:38 -05005896 RValue<Float4> Float4::operator=(const Float4 &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005897 {
5898 Value *value = rhs.loadValue();
5899 storeValue(value);
5900
5901 return RValue<Float4>(value);
5902 }
5903
Nicolas Capens96d4e092016-11-18 14:22:38 -05005904 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005905 {
5906 Value *value = rhs.loadValue();
5907 storeValue(value);
5908
5909 return RValue<Float4>(value);
5910 }
5911
Nicolas Capens96d4e092016-11-18 14:22:38 -05005912 RValue<Float4> Float4::operator=(RValue<Float> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005913 {
5914 return *this = Float4(rhs);
5915 }
5916
Nicolas Capens96d4e092016-11-18 14:22:38 -05005917 RValue<Float4> Float4::operator=(const Float &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005918 {
5919 return *this = Float4(rhs);
5920 }
5921
Nicolas Capens96d4e092016-11-18 14:22:38 -05005922 RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005923 {
5924 return *this = Float4(rhs);
5925 }
5926
5927 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
5928 {
5929 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
5930 }
5931
5932 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
5933 {
5934 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
5935 }
5936
5937 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
5938 {
5939 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
5940 }
5941
5942 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
5943 {
5944 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
5945 }
5946
5947 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
5948 {
5949 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
5950 }
5951
Nicolas Capens96d4e092016-11-18 14:22:38 -05005952 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005953 {
5954 return lhs = lhs + rhs;
5955 }
5956
Nicolas Capens96d4e092016-11-18 14:22:38 -05005957 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005958 {
5959 return lhs = lhs - rhs;
5960 }
5961
Nicolas Capens96d4e092016-11-18 14:22:38 -05005962 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005963 {
5964 return lhs = lhs * rhs;
5965 }
5966
Nicolas Capens96d4e092016-11-18 14:22:38 -05005967 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005968 {
5969 return lhs = lhs / rhs;
5970 }
5971
Nicolas Capens96d4e092016-11-18 14:22:38 -05005972 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -04005973 {
5974 return lhs = lhs % rhs;
5975 }
5976
5977 RValue<Float4> operator+(RValue<Float4> val)
5978 {
5979 return val;
5980 }
5981
5982 RValue<Float4> operator-(RValue<Float4> val)
5983 {
5984 return RValue<Float4>(Nucleus::createFNeg(val.value));
5985 }
5986
5987 RValue<Float4> Abs(RValue<Float4> x)
5988 {
Nicolas Capens84272242016-11-09 13:31:06 -05005989 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
5990 int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
5991 Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
5992
5993 return As<Float4>(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005994 }
5995
5996 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
5997 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005998 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5999 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value);
6000 ::basicBlock->appendInst(cmp);
6001
6002 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6003 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
6004 ::basicBlock->appendInst(select);
6005
6006 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006007 }
6008
6009 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
6010 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006011 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6012 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value);
6013 ::basicBlock->appendInst(cmp);
6014
6015 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6016 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
6017 ::basicBlock->appendInst(select);
6018
6019 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006020 }
6021
6022 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
6023 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006024 return Float4(1.0f) / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04006025 }
6026
6027 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
6028 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006029 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006030 }
6031
6032 RValue<Float4> Sqrt(RValue<Float4> x)
6033 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006034 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6035 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6036 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6037 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6038 sqrt->addArg(x.value);
6039 ::basicBlock->appendInst(sqrt);
6040
6041 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006042 }
6043
Nicolas Capensc94ab742016-11-08 15:15:31 -05006044 RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006045 {
Nicolas Capensc94ab742016-11-08 15:15:31 -05006046 return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006047 }
6048
6049 RValue<Float> Extract(RValue<Float4> x, int i)
6050 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006051 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006052 }
6053
6054 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
6055 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006056 return RValue<Float4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006057 }
6058
6059 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
6060 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006061 int shuffle[4] =
6062 {
6063 ((imm >> 0) & 0x03) + 0,
6064 ((imm >> 2) & 0x03) + 0,
6065 ((imm >> 4) & 0x03) + 4,
6066 ((imm >> 6) & 0x03) + 4,
6067 };
6068
6069 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006070 }
6071
6072 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
6073 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006074 int shuffle[4] = {0, 4, 1, 5};
6075 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006076 }
6077
6078 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
6079 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006080 int shuffle[4] = {2, 6, 3, 7};
6081 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006082 }
6083
6084 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
6085 {
6086 Value *vector = lhs.loadValue();
Nicolas Capensa4c30b02016-11-08 15:43:17 -05006087 Value *result = createMask4(vector, rhs.value, select);
6088 lhs.storeValue(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006089
Nicolas Capensa4c30b02016-11-08 15:43:17 -05006090 return RValue<Float4>(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006091 }
6092
6093 RValue<Int> SignMask(RValue<Float4> x)
6094 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04006095 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
6096 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6097 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6098 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6099 movmsk->addArg(x.value);
6100 ::basicBlock->appendInst(movmsk);
6101
6102 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006103 }
6104
6105 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
6106 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006107 return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006108 }
6109
6110 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
6111 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006112 return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006113 }
6114
6115 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
6116 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006117 return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006118 }
6119
6120 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
6121 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006122 return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006123 }
6124
6125 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
6126 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006127 return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006128 }
6129
6130 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
6131 {
Nicolas Capens5e6ca092017-01-13 15:09:21 -05006132 return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006133 }
6134
6135 RValue<Float4> Round(RValue<Float4> x)
6136 {
Nicolas Capensa8086512016-11-07 17:32:17 -05006137 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6138 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6139 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6140 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6141 round->addArg(x.value);
6142 round->addArg(::context->getConstantInt32(0));
6143 ::basicBlock->appendInst(round);
6144
6145 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006146 }
6147
6148 RValue<Float4> Trunc(RValue<Float4> x)
6149 {
Nicolas Capensa8086512016-11-07 17:32:17 -05006150 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6151 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6152 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6153 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6154 round->addArg(x.value);
6155 round->addArg(::context->getConstantInt32(3));
6156 ::basicBlock->appendInst(round);
6157
6158 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006159 }
6160
6161 RValue<Float4> Frac(RValue<Float4> x)
6162 {
Nicolas Capensa8086512016-11-07 17:32:17 -05006163 return x - Floor(x);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006164 }
6165
6166 RValue<Float4> Floor(RValue<Float4> x)
6167 {
Nicolas Capensa8086512016-11-07 17:32:17 -05006168 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6169 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6170 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6171 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6172 round->addArg(x.value);
6173 round->addArg(::context->getConstantInt32(1));
6174 ::basicBlock->appendInst(round);
6175
6176 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006177 }
6178
6179 RValue<Float4> Ceil(RValue<Float4> x)
6180 {
Nicolas Capensa8086512016-11-07 17:32:17 -05006181 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6182 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6183 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6184 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6185 round->addArg(x.value);
6186 round->addArg(::context->getConstantInt32(2));
6187 ::basicBlock->appendInst(round);
6188
6189 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006190 }
6191
6192 Type *Float4::getType()
6193 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04006194 return T(Ice::IceType_v4f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006195 }
6196
6197 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
6198 {
Nicolas Capens8820f642016-09-30 04:42:43 -04006199 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006200 }
6201
6202 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6203 {
Nicolas Capens6d738712016-09-30 04:15:22 -04006204 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006205 }
6206
6207 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6208 {
Nicolas Capens6d738712016-09-30 04:15:22 -04006209 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006210 }
6211
Nicolas Capens96d4e092016-11-18 14:22:38 -05006212 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006213 {
6214 return lhs = lhs + offset;
6215 }
6216
Nicolas Capens96d4e092016-11-18 14:22:38 -05006217 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006218 {
6219 return lhs = lhs + offset;
6220 }
6221
Nicolas Capens96d4e092016-11-18 14:22:38 -05006222 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006223 {
6224 return lhs = lhs + offset;
6225 }
6226
6227 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
6228 {
6229 return lhs + -offset;
6230 }
6231
6232 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6233 {
6234 return lhs + -offset;
6235 }
6236
6237 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6238 {
6239 return lhs + -offset;
6240 }
6241
Nicolas Capens96d4e092016-11-18 14:22:38 -05006242 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006243 {
6244 return lhs = lhs - offset;
6245 }
6246
Nicolas Capens96d4e092016-11-18 14:22:38 -05006247 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006248 {
6249 return lhs = lhs - offset;
6250 }
6251
Nicolas Capens96d4e092016-11-18 14:22:38 -05006252 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006253 {
6254 return lhs = lhs - offset;
6255 }
6256
6257 void Return()
6258 {
6259 Nucleus::createRetVoid();
6260 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6261 Nucleus::createUnreachable();
6262 }
6263
Nicolas Capenseb253d02016-11-18 14:40:40 -05006264 void Return(RValue<Int> ret)
Nicolas Capens598f8d82016-09-26 15:09:10 -04006265 {
Nicolas Capenseb253d02016-11-18 14:40:40 -05006266 Nucleus::createRet(ret.value);
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006267 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6268 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006269 }
6270
Nicolas Capens598f8d82016-09-26 15:09:10 -04006271 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
6272 {
6273 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
6274 Nucleus::setInsertBlock(bodyBB);
6275
6276 return true;
6277 }
6278
Nicolas Capens598f8d82016-09-26 15:09:10 -04006279 RValue<Long> Ticks()
6280 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006281 assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006282 }
6283}