blob: 13c01c64d659af5bd8677ea082d11d19a0e43499 [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
20#include "src/IceTypes.h"
21#include "src/IceCfg.h"
22#include "src/IceELFStreamer.h"
23#include "src/IceGlobalContext.h"
24#include "src/IceCfgNode.h"
25#include "src/IceELFObjectWriter.h"
Nicolas Capens8dfd9a72016-10-13 17:44:51 -040026#include "src/IceGlobalInits.h"
Nicolas Capens598f8d82016-09-26 15:09:10 -040027
28#include "llvm/Support/FileSystem.h"
29#include "llvm/Support/raw_os_ostream.h"
30
31#define WIN32_LEAN_AND_MEAN
32#define NOMINMAX
33#include <Windows.h>
34
35#include <mutex>
36#include <limits>
37#include <iostream>
38#include <cassert>
39
40namespace
41{
42 Ice::GlobalContext *context = nullptr;
43 Ice::Cfg *function = nullptr;
44 Ice::CfgNode *basicBlock = nullptr;
45 Ice::CfgLocalAllocatorScope *allocator = nullptr;
46 sw::Routine *routine = nullptr;
47
48 std::mutex codegenMutex;
49
Nicolas Capens9ed1a182016-10-24 09:52:23 -040050 sw::BasicBlock *falseBB = nullptr;
51
Nicolas Capens598f8d82016-09-26 15:09:10 -040052 Ice::ELFFileStreamer *elfFile = nullptr;
53 Ice::Fdstream *out = nullptr;
54}
55
56namespace sw
57{
Nicolas Capens23d99a42016-09-30 14:57:16 -040058 enum EmulatedType
59 {
60 EmulatedShift = 16,
61 EmulatedV2 = 2 << EmulatedShift,
62 EmulatedV4 = 4 << EmulatedShift,
63 EmulatedV8 = 8 << EmulatedShift,
64 EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8,
65
66 Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2,
67 Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4,
68 Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2,
69 Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8,
70 Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4,
Nicolas Capens4cfd4572016-10-20 01:00:19 -040071 Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2,
Nicolas Capens23d99a42016-09-30 14:57:16 -040072 };
73
Nicolas Capens598f8d82016-09-26 15:09:10 -040074 class Value : public Ice::Variable {};
75 class BasicBlock : public Ice::CfgNode {};
76
77 Ice::Type T(Type *t)
78 {
Nicolas Capens23d99a42016-09-30 14:57:16 -040079 static_assert(Ice::IceType_NUM < EmulatedBits, "Ice::Type overlaps with our emulated types!");
80 return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits);
Nicolas Capens598f8d82016-09-26 15:09:10 -040081 }
82
83 Type *T(Ice::Type t)
84 {
85 return reinterpret_cast<Type*>(t);
86 }
87
Nicolas Capens23d99a42016-09-30 14:57:16 -040088 Type *T(EmulatedType t)
89 {
90 return reinterpret_cast<Type*>(t);
91 }
92
Nicolas Capens598f8d82016-09-26 15:09:10 -040093 Value *V(Ice::Variable *v)
94 {
95 return reinterpret_cast<Value*>(v);
96 }
97
Nicolas Capens327f1df2016-10-21 14:26:34 -040098 Value *C(Ice::Constant *c) // Only safe for casting right-hand side operand
99 {
100 return reinterpret_cast<Value*>(c);
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 }
117
118 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);
126
127 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;
132
133 if(index != SHN_UNDEF)
134 {
135 if(table == SHN_UNDEF) return nullptr;
136 const SectionHeader *symbolTable = elfSection(elfHeader, table);
137
138 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 }
144
145 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);
182
183 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);
193
194 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 }
200
201 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;
221 // case R_X86_64_64:
222 // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation->r_addend;
223 // break;
224 case R_X86_64_PC32:
225 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend;
226 break;
227 // case R_X86_64_32S:
228 // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend;
229 // break;
230 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 {
299 return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
300 }
301
302 void deallocate(T *p, size_type n)
303 {
304 VirtualFree(p, 0, MEM_RELEASE);
305 }
306 };
307
308 class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine
309 {
310 ELFMemoryStreamer(const ELFMemoryStreamer &) = delete;
311 ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete;
312
313 public:
Nicolas Capens58274b52016-10-19 23:45:19 -0400314 ELFMemoryStreamer() : Routine(), entry(nullptr)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400315 {
316 position = 0;
317 buffer.reserve(0x1000);
318 }
319
320 virtual ~ELFMemoryStreamer()
321 {
322 if(buffer.size() != 0)
323 {
324 DWORD exeProtection;
325 VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection);
326 }
327 }
328
329 void write8(uint8_t Value) override
330 {
331 if(position == (uint64_t)buffer.size())
332 {
333 buffer.push_back(Value);
334 position++;
335 }
336 else if(position < (uint64_t)buffer.size())
337 {
338 buffer[position] = Value;
339 position++;
340 }
341 else assert(false && "UNIMPLEMENTED");
342 }
343
344 void writeBytes(llvm::StringRef Bytes) override
345 {
346 std::size_t oldSize = buffer.size();
347 buffer.resize(oldSize + Bytes.size());
348 memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size());
349 position += Bytes.size();
350 }
351
352 uint64_t tell() const override { return position; }
353
354 void seek(uint64_t Off) override { position = Off; }
355
356 const void *getEntry() override
357 {
Nicolas Capens58274b52016-10-19 23:45:19 -0400358 if(!entry)
359 {
360 VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection);
361 position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this
Nicolas Capens598f8d82016-09-26 15:09:10 -0400362
Nicolas Capens58274b52016-10-19 23:45:19 -0400363 entry = loadImage(&buffer[0]);
364 }
365
366 return entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400367 }
368
369 private:
Nicolas Capens58274b52016-10-19 23:45:19 -0400370 void *entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400371 std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer;
372 std::size_t position;
373 DWORD oldProtection;
374 };
375
376 Nucleus::Nucleus()
377 {
378 ::codegenMutex.lock(); // Reactor is currently not thread safe
379
Nicolas Capens66478362016-10-13 15:36:36 -0400380 Ice::ClFlags &Flags = Ice::ClFlags::Flags;
381 Ice::ClFlags::getParsedClFlags(Flags);
382
383 Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632);
384 Flags.setOutFileType(Ice::FT_Elf);
385 Flags.setOptLevel(Ice::Opt_2);
386 Flags.setApplicationBinaryInterface(Ice::ABI_Platform);
Nicolas Capens65047112016-11-07 13:01:07 -0500387 Flags.setVerbose(false ? Ice::IceV_All : Ice::IceV_None);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400388
Nicolas Capens65047112016-11-07 13:01:07 -0500389 static llvm::raw_os_ostream cout(std::cout);
390 static llvm::raw_os_ostream cerr(std::cerr);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400391
392 if(false) // Write out to a file
393 {
394 std::error_code errorCode;
395 ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None);
396 ::elfFile = new Ice::ELFFileStreamer(*out);
Nicolas Capens65047112016-11-07 13:01:07 -0500397 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400398 }
399 else
400 {
401 ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer();
Nicolas Capens65047112016-11-07 13:01:07 -0500402 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400403 ::routine = elfMemory;
404 }
405 }
406
407 Nucleus::~Nucleus()
408 {
409 delete ::allocator;
410 delete ::function;
411 delete ::context;
412
413 delete ::elfFile;
414 delete ::out;
415
416 ::codegenMutex.unlock();
417 }
418
419 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
420 {
421 if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
422 {
423 createRetVoid();
424 }
425
426 std::wstring wideName(name);
427 std::string asciiName(wideName.begin(), wideName.end());
428 ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
429
430 ::function->translate();
Nicolas Capensde19f392016-10-19 10:29:49 -0400431 assert(!::function->hasError());
432
Nicolas Capens66478362016-10-13 15:36:36 -0400433 auto *globals = ::function->getGlobalInits().release();
434
435 if(globals && !globals->empty())
436 {
437 ::context->getGlobals()->merge(globals);
438 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400439
440 ::context->emitFileHeader();
441 ::function->emitIAS();
442 auto assembler = ::function->releaseAssembler();
Nicolas Capens66478362016-10-13 15:36:36 -0400443 auto objectWriter = ::context->getObjectWriter();
444 assembler->alignFunction();
445 objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
446 ::context->lowerGlobals("last");
Nicolas Capens73dd7a22016-10-20 13:20:34 -0400447 ::context->lowerConstants();
Nicolas Capens66478362016-10-13 15:36:36 -0400448 objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
449 objectWriter->writeNonUserSections();
Nicolas Capens598f8d82016-09-26 15:09:10 -0400450
451 return ::routine;
452 }
453
454 void Nucleus::optimize()
455 {
456 }
457
458 Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
459 {
460 Ice::Type type = T(t);
Nicolas Capensa8f98632016-10-20 11:25:55 -0400461 int typeSize = Ice::typeWidthInBytes(type);
462 int totalSize = typeSize * (arraySize ? arraySize : 1);
Nicolas Capense12780d2016-09-27 14:18:07 -0400463
Nicolas Capensa8f98632016-10-20 11:25:55 -0400464 auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400465 auto address = ::function->makeVariable(T(getPointerType(t)));
Nicolas Capensa8f98632016-10-20 11:25:55 -0400466 auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400467 ::function->getEntryNode()->getInsts().push_front(alloca);
468
469 return V(address);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400470 }
471
472 BasicBlock *Nucleus::createBasicBlock()
473 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400474 return B(::function->makeNode());
Nicolas Capens598f8d82016-09-26 15:09:10 -0400475 }
476
477 BasicBlock *Nucleus::getInsertBlock()
478 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400479 return B(::basicBlock);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400480 }
481
482 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
483 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -0400484 // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator");
Nicolas Capens611642a2016-09-28 16:45:04 -0400485 ::basicBlock = basicBlock;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400486 }
487
Nicolas Capens598f8d82016-09-26 15:09:10 -0400488 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
489 {
490 uint32_t sequenceNumber = 0;
491 ::function = Ice::Cfg::create(::context, sequenceNumber).release();
492 ::allocator = new Ice::CfgLocalAllocatorScope(::function);
493
494 for(Type *type : Params)
495 {
496 Ice::Variable *arg = ::function->makeVariable(T(type));
497 ::function->addArg(arg);
498 }
499
500 Ice::CfgNode *node = ::function->makeNode();
501 ::function->setEntryNode(node);
502 ::basicBlock = node;
503 }
504
505 Value *Nucleus::getArgument(unsigned int index)
506 {
507 return V(::function->getArgs()[index]);
508 }
509
510 void Nucleus::createRetVoid()
511 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400512 Ice::InstRet *ret = Ice::InstRet::create(::function);
513 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400514 }
515
516 void Nucleus::createRet(Value *v)
517 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400518 Ice::InstRet *ret = Ice::InstRet::create(::function, v);
519 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400520 }
521
522 void Nucleus::createBr(BasicBlock *dest)
523 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400524 auto br = Ice::InstBr::create(::function, dest);
525 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400526 }
527
528 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
529 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400530 auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse);
531 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400532 }
533
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400534 static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
535 {
Nicolas Capens327f1df2016-10-21 14:26:34 -0400536 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 -0400537
538 Ice::Variable *result = ::function->makeVariable(lhs->getType());
539 Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs);
540 ::basicBlock->appendInst(arithmetic);
541
542 return V(result);
543 }
544
Nicolas Capens598f8d82016-09-26 15:09:10 -0400545 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
546 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400547 return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400548 }
549
550 Value *Nucleus::createSub(Value *lhs, Value *rhs)
551 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400552 return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400553 }
554
555 Value *Nucleus::createMul(Value *lhs, Value *rhs)
556 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400557 return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400558 }
559
560 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
561 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400562 return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400563 }
564
565 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
566 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400567 return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400568 }
569
570 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
571 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400572 return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400573 }
574
575 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
576 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400577 return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400578 }
579
580 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
581 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400582 return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400583 }
584
585 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
586 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400587 return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400588 }
589
590 Value *Nucleus::createURem(Value *lhs, Value *rhs)
591 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400592 return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400593 }
594
595 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
596 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400597 return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400598 }
599
600 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
601 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400602 return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400603 }
604
605 Value *Nucleus::createShl(Value *lhs, Value *rhs)
606 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400607 return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400608 }
609
610 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
611 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400612 return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400613 }
614
615 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
616 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400617 return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400618 }
619
620 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
621 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400622 return createArithmetic(Ice::InstArithmetic::And, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400623 }
624
625 Value *Nucleus::createOr(Value *lhs, Value *rhs)
626 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400627 return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400628 }
629
630 Value *Nucleus::createXor(Value *lhs, Value *rhs)
631 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400632 return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400633 }
634
Nicolas Capens13ac2322016-10-13 14:52:12 -0400635 static Value *createAssign(Ice::Constant *constant)
Nicolas Capensb955d5b2016-09-28 22:36:28 -0400636 {
637 Ice::Variable *value = ::function->makeVariable(constant->getType());
638 auto assign = Ice::InstAssign::create(::function, value, constant);
639 ::basicBlock->appendInst(assign);
640
641 return V(value);
642 }
643
Nicolas Capens598f8d82016-09-26 15:09:10 -0400644 Value *Nucleus::createNeg(Value *v)
645 {
646 assert(false && "UNIMPLEMENTED"); return nullptr;
647 }
648
649 Value *Nucleus::createFNeg(Value *v)
650 {
651 assert(false && "UNIMPLEMENTED"); return nullptr;
652 }
653
654 Value *Nucleus::createNot(Value *v)
655 {
656 assert(false && "UNIMPLEMENTED"); return nullptr;
657 }
658
Nicolas Capense12780d2016-09-27 14:18:07 -0400659 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400660 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400661 int valueType = (int)reinterpret_cast<intptr_t>(type);
662 Ice::Variable *result = ::function->makeVariable(T(type));
663
664 if(valueType & EmulatedBits)
665 {
666 switch(valueType)
667 {
668 case Type_v4i8:
669 case Type_v2i16:
670 {
671 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
672 auto target = ::context->getConstantUndef(Ice::IceType_i32);
673 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
674 load->addArg(::context->getConstantInt32(4));
675 load->addArg(ptr);
676 ::basicBlock->appendInst(load);
677 }
678 break;
679 case Type_v2i32:
680 case Type_v8i8:
681 case Type_v4i16:
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400682 case Type_v2f32:
Nicolas Capens23d99a42016-09-30 14:57:16 -0400683 {
684 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
685 auto target = ::context->getConstantUndef(Ice::IceType_i32);
686 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
687 load->addArg(::context->getConstantInt32(8));
688 load->addArg(ptr);
689 ::basicBlock->appendInst(load);
690 }
691 break;
692 default: assert(false && "UNIMPLEMENTED");
693 }
694 }
695 else
696 {
697 auto load = Ice::InstLoad::create(::function, result, ptr, align);
698 ::basicBlock->appendInst(load);
699 }
700
701 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400702 }
703
Nicolas Capens6d738712016-09-30 04:15:22 -0400704 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400705 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400706 int valueType = (int)reinterpret_cast<intptr_t>(type);
707
708 if(valueType & EmulatedBits)
709 {
710 switch(valueType)
711 {
712 case Type_v4i8:
713 case Type_v2i16:
714 {
715 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
716 auto target = ::context->getConstantUndef(Ice::IceType_i32);
717 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
718 store->addArg(::context->getConstantInt32(4));
719 store->addArg(value);
720 store->addArg(ptr);
721 ::basicBlock->appendInst(store);
722 }
723 break;
724 case Type_v2i32:
725 case Type_v8i8:
726 case Type_v4i16:
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400727 case Type_v2f32:
Nicolas Capens23d99a42016-09-30 14:57:16 -0400728 {
729 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
730 auto target = ::context->getConstantUndef(Ice::IceType_i32);
731 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
732 store->addArg(::context->getConstantInt32(8));
733 store->addArg(value);
734 store->addArg(ptr);
735 ::basicBlock->appendInst(store);
736 }
737 break;
738 default: assert(false && "UNIMPLEMENTED");
739 }
740 }
741 else
742 {
743 assert(T(value->getType()) == type);
744
745 auto store = Ice::InstStore::create(::function, value, ptr, align);
746 ::basicBlock->appendInst(store);
747 }
748
Nicolas Capens598f8d82016-09-26 15:09:10 -0400749 return value;
750 }
751
Nicolas Capens6d738712016-09-30 04:15:22 -0400752 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400753 {
Nicolas Capens8820f642016-09-30 04:42:43 -0400754 assert(index->getType() == Ice::IceType_i32);
755
756 if(!Ice::isByteSizedType(T(type)))
757 {
Nicolas Capens13ac2322016-10-13 14:52:12 -0400758 index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type))));
Nicolas Capens8820f642016-09-30 04:42:43 -0400759 }
760
761 if(sizeof(void*) == 8)
762 {
763 index = createSExt(index, T(Ice::IceType_i64));
764 }
765
766 return createAdd(ptr, index);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400767 }
768
769 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
770 {
771 assert(false && "UNIMPLEMENTED"); return nullptr;
772 }
773
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400774 static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType)
775 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400776 if(v->getType() == T(destType))
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400777 {
778 return v;
779 }
780
781 Ice::Variable *result = ::function->makeVariable(T(destType));
782 Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v);
783 ::basicBlock->appendInst(cast);
784
785 return V(result);
786 }
787
Nicolas Capens598f8d82016-09-26 15:09:10 -0400788 Value *Nucleus::createTrunc(Value *v, Type *destType)
789 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400790 return createCast(Ice::InstCast::Trunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400791 }
792
793 Value *Nucleus::createZExt(Value *v, Type *destType)
794 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400795 return createCast(Ice::InstCast::Zext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400796 }
797
798 Value *Nucleus::createSExt(Value *v, Type *destType)
799 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400800 return createCast(Ice::InstCast::Sext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400801 }
802
803 Value *Nucleus::createFPToSI(Value *v, Type *destType)
804 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400805 return createCast(Ice::InstCast::Fptosi, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400806 }
807
808 Value *Nucleus::createUIToFP(Value *v, Type *destType)
809 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400810 return createCast(Ice::InstCast::Uitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400811 }
812
813 Value *Nucleus::createSIToFP(Value *v, Type *destType)
814 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400815 return createCast(Ice::InstCast::Sitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400816 }
817
818 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
819 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400820 return createCast(Ice::InstCast::Fptrunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400821 }
822
823 Value *Nucleus::createFPExt(Value *v, Type *destType)
824 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400825 return createCast(Ice::InstCast::Fpext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400826 }
827
828 Value *Nucleus::createBitCast(Value *v, Type *destType)
829 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400830 return createCast(Ice::InstCast::Bitcast, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400831 }
832
Nicolas Capens43dc6292016-10-20 00:01:38 -0400833 static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400834 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400835 assert(lhs->getType() == rhs->getType());
836
Nicolas Capens43dc6292016-10-20 00:01:38 -0400837 auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType());
838 auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs);
Nicolas Capens611642a2016-09-28 16:45:04 -0400839 ::basicBlock->appendInst(cmp);
840
841 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400842 }
843
Nicolas Capens43dc6292016-10-20 00:01:38 -0400844 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
845 {
846 return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs);
847 }
848
849 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
850 {
851 return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs);
852 }
853
854 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
855 {
856 return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs);
857 }
858
859 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
860 {
861 return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs);
862 }
863
864 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
865 {
866 return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs);
867 }
868
869 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
870 {
871 return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs);
872 }
873
874 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
875 {
876 return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs);
877 }
878
879 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
880 {
881 return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs);
882 }
883
884 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
885 {
886 return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs);
887 }
888
Nicolas Capens598f8d82016-09-26 15:09:10 -0400889 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
890 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400891 return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs);
892 }
893
894 static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs)
895 {
896 assert(lhs->getType() == rhs->getType());
897 assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32);
898
899 auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32);
900 auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs);
901 ::basicBlock->appendInst(cmp);
902
903 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400904 }
905
906 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
907 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400908 return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400909 }
910
911 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
912 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400913 return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400914 }
915
916 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
917 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400918 return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400919 }
920
921 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
922 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400923 return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400924 }
925
926 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
927 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400928 return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400929 }
930
931 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
932 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400933 return createFloatCompare(Ice::InstFcmp::One, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400934 }
935
936 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
937 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400938 return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400939 }
940
941 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
942 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400943 return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400944 }
945
946 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
947 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400948 return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400949 }
950
951 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
952 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400953 return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400954 }
955
956 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
957 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400958 return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400959 }
960
961 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
962 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400963 return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400964 }
965
966 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
967 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400968 return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400969 }
970
971 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
972 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400973 return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400974 }
975
Nicolas Capense95d5342016-09-30 11:37:28 -0400976 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400977 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -0400978 auto result = ::function->makeVariable(T(type));
979 auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index));
980 ::basicBlock->appendInst(extract);
981
982 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400983 }
984
985 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
986 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -0400987 auto result = ::function->makeVariable(vector->getType());
988 auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index));
989 ::basicBlock->appendInst(insert);
990
991 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400992 }
993
Nicolas Capense89cd582016-09-30 14:23:47 -0400994 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400995 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -0400996 assert(V1->getType() == V2->getType());
997
998 int size = Ice::typeNumElements(V1->getType());
999 auto result = ::function->makeVariable(V1->getType());
1000 auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2);
1001
1002 for(int i = 0; i < size; i++)
1003 {
1004 shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i])));
1005 }
1006
1007 ::basicBlock->appendInst(shuffle);
1008
1009 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001010 }
1011
1012 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
1013 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04001014 assert(ifTrue->getType() == ifFalse->getType());
1015
1016 auto result = ::function->makeVariable(ifTrue->getType());
1017 auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse);
1018 ::basicBlock->appendInst(select);
1019
1020 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001021 }
1022
1023 Value *Nucleus::createSwitch(Value *v, BasicBlock *Dest, unsigned NumCases)
1024 {
1025 assert(false && "UNIMPLEMENTED"); return nullptr;
1026 }
1027
1028 void Nucleus::addSwitchCase(Value *Switch, int Case, BasicBlock *Branch)
1029 {
1030 assert(false && "UNIMPLEMENTED"); return;
1031 }
1032
1033 void Nucleus::createUnreachable()
1034 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04001035 Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function);
1036 ::basicBlock->appendInst(unreachable);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001037 }
1038
Nicolas Capense95d5342016-09-30 11:37:28 -04001039 static Value *createSwizzle4(Value *val, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001040 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001041 int swizzle[4] =
1042 {
1043 (select >> 0) & 0x03,
1044 (select >> 2) & 0x03,
1045 (select >> 4) & 0x03,
1046 (select >> 6) & 0x03,
1047 };
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001048
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001049 return Nucleus::createShuffleVector(val, val, swizzle);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001050 }
1051
Nicolas Capense95d5342016-09-30 11:37:28 -04001052 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001053 {
1054 assert(false && "UNIMPLEMENTED"); return nullptr;
1055 }
1056
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001057 Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001058 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001059 if(sizeof(void*) == 8)
1060 {
1061 return createAssign(::context->getConstantInt64(reinterpret_cast<intptr_t>(address)));
1062 }
1063 else
1064 {
1065 return createAssign(::context->getConstantInt32(reinterpret_cast<intptr_t>(address)));
1066 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001067 }
1068
1069 Type *Nucleus::getPointerType(Type *ElementType)
1070 {
Nicolas Capense12780d2016-09-27 14:18:07 -04001071 if(sizeof(void*) == 8)
1072 {
1073 return T(Ice::IceType_i64);
1074 }
1075 else
1076 {
1077 return T(Ice::IceType_i32);
1078 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001079 }
1080
Nicolas Capens13ac2322016-10-13 14:52:12 -04001081 Value *Nucleus::createNullValue(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001082 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001083 if(Ice::isVectorType(T(Ty)))
1084 {
1085 int64_t c[4] = {0, 0, 0, 0};
1086 return createConstantVector(c, Ty);
1087 }
1088 else
1089 {
1090 return createAssign(::context->getConstantZero(T(Ty)));
1091 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001092 }
1093
Nicolas Capens13ac2322016-10-13 14:52:12 -04001094 Value *Nucleus::createConstantLong(int64_t i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001095 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001096 return createAssign(::context->getConstantInt64(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001097 }
1098
Nicolas Capens13ac2322016-10-13 14:52:12 -04001099 Value *Nucleus::createConstantInt(int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001100 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04001101 return createAssign(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001102 }
1103
Nicolas Capens13ac2322016-10-13 14:52:12 -04001104 Value *Nucleus::createConstantInt(unsigned int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001105 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001106 return createAssign(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001107 }
1108
Nicolas Capens13ac2322016-10-13 14:52:12 -04001109 Value *Nucleus::createConstantBool(bool b)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001110 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001111 return createAssign(::context->getConstantInt1(b));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001112 }
1113
Nicolas Capens13ac2322016-10-13 14:52:12 -04001114 Value *Nucleus::createConstantByte(signed char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001115 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001116 return createAssign(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001117 }
1118
Nicolas Capens13ac2322016-10-13 14:52:12 -04001119 Value *Nucleus::createConstantByte(unsigned char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001120 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001121 return createAssign(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001122 }
1123
Nicolas Capens13ac2322016-10-13 14:52:12 -04001124 Value *Nucleus::createConstantShort(short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001125 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001126 return createAssign(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001127 }
1128
Nicolas Capens13ac2322016-10-13 14:52:12 -04001129 Value *Nucleus::createConstantShort(unsigned short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001130 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001131 return createAssign(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001132 }
1133
Nicolas Capens13ac2322016-10-13 14:52:12 -04001134 Value *Nucleus::createConstantFloat(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001135 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001136 return createAssign(::context->getConstantFloat(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001137 }
1138
Nicolas Capens13ac2322016-10-13 14:52:12 -04001139 Value *Nucleus::createNullPointer(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001140 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001141 if(true)
1142 {
1143 return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
1144 }
1145 else
1146 {
1147 return createConstantPointer(nullptr, Ty);
1148 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001149 }
1150
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001151 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
Nicolas Capens13ac2322016-10-13 14:52:12 -04001152 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001153 const int vectorSize = 16;
1154 assert(Ice::typeWidthInBytes(T(type)) == vectorSize);
1155 const int alignment = vectorSize;
1156 auto globalPool = ::function->getGlobalPool();
1157
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001158 const int64_t *i = constants;
1159 const double *f = reinterpret_cast<const double*>(constants);
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001160 Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr;
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001161
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001162 switch((int)reinterpret_cast<intptr_t>(type))
1163 {
1164 case Ice::IceType_v4i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001165 {
1166 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]};
1167 static_assert(sizeof(initializer) == vectorSize, "!");
1168 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1169 }
1170 break;
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001171 case Ice::IceType_v4f32:
1172 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001173 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001174 static_assert(sizeof(initializer) == vectorSize, "!");
1175 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1176 }
1177 break;
1178 case Ice::IceType_v8i16:
1179 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001180 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 -04001181 static_assert(sizeof(initializer) == vectorSize, "!");
1182 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1183 }
1184 break;
1185 case Ice::IceType_v16i8:
1186 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001187 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 -04001188 static_assert(sizeof(initializer) == vectorSize, "!");
1189 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1190 }
1191 break;
1192 case Type_v2i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001193 {
1194 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]};
1195 static_assert(sizeof(initializer) == vectorSize, "!");
1196 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1197 }
1198 break;
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001199 case Type_v2f32:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001200 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001201 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001202 static_assert(sizeof(initializer) == vectorSize, "!");
1203 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1204 }
1205 break;
1206 case Type_v4i16:
1207 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001208 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 -04001209 static_assert(sizeof(initializer) == vectorSize, "!");
1210 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1211 }
1212 break;
1213 case Type_v8i8:
1214 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001215 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 -04001216 static_assert(sizeof(initializer) == vectorSize, "!");
1217 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1218 }
1219 break;
1220 case Type_v4i8:
1221 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001222 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 -04001223 static_assert(sizeof(initializer) == vectorSize, "!");
1224 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1225 }
1226 break;
1227 default:
1228 assert(false && "Unknown constant vector type" && type);
1229 }
1230
1231 auto name = Ice::GlobalString::createWithoutString(::context);
1232 auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool);
1233 variableDeclaration->setName(name);
1234 variableDeclaration->setAlignment(alignment);
1235 variableDeclaration->setIsConstant(true);
1236 variableDeclaration->addInitializer(dataInitializer);
1237
1238 ::function->addGlobal(variableDeclaration);
1239
1240 constexpr int32_t offset = 0;
1241 Ice::Operand *ptr = ::context->getConstantSym(offset, name);
1242
1243 Ice::Variable *result = ::function->makeVariable(T(type));
1244 auto load = Ice::InstLoad::create(::function, result, ptr, alignment);
1245 ::basicBlock->appendInst(load);
1246
1247 return V(result);
Nicolas Capens13ac2322016-10-13 14:52:12 -04001248 }
1249
1250 Value *Nucleus::createConstantVector(const double *constants, Type *type)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001251 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001252 return createConstantVector((const int64_t*)constants, type);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001253 }
1254
1255 Type *Void::getType()
1256 {
1257 return T(Ice::IceType_void);
1258 }
1259
Nicolas Capens598f8d82016-09-26 15:09:10 -04001260 Bool::Bool(Argument<Bool> argument)
1261 {
1262 storeValue(argument.value);
1263 }
1264
1265 Bool::Bool()
1266 {
1267 }
1268
1269 Bool::Bool(bool x)
1270 {
1271 storeValue(Nucleus::createConstantBool(x));
1272 }
1273
1274 Bool::Bool(RValue<Bool> rhs)
1275 {
1276 storeValue(rhs.value);
1277 }
1278
1279 Bool::Bool(const Bool &rhs)
1280 {
1281 Value *value = rhs.loadValue();
1282 storeValue(value);
1283 }
1284
1285 Bool::Bool(const Reference<Bool> &rhs)
1286 {
1287 Value *value = rhs.loadValue();
1288 storeValue(value);
1289 }
1290
1291 RValue<Bool> Bool::operator=(RValue<Bool> rhs) const
1292 {
1293 storeValue(rhs.value);
1294
1295 return rhs;
1296 }
1297
1298 RValue<Bool> Bool::operator=(const Bool &rhs) const
1299 {
1300 Value *value = rhs.loadValue();
1301 storeValue(value);
1302
1303 return RValue<Bool>(value);
1304 }
1305
1306 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) const
1307 {
1308 Value *value = rhs.loadValue();
1309 storeValue(value);
1310
1311 return RValue<Bool>(value);
1312 }
1313
1314 RValue<Bool> operator!(RValue<Bool> val)
1315 {
1316 return RValue<Bool>(Nucleus::createNot(val.value));
1317 }
1318
1319 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
1320 {
1321 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1322 }
1323
1324 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
1325 {
1326 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1327 }
1328
1329 Type *Bool::getType()
1330 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001331 return T(Ice::IceType_i1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001332 }
1333
1334 Byte::Byte(Argument<Byte> argument)
1335 {
1336 storeValue(argument.value);
1337 }
1338
1339 Byte::Byte(RValue<Int> cast)
1340 {
1341 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1342
1343 storeValue(integer);
1344 }
1345
1346 Byte::Byte(RValue<UInt> cast)
1347 {
1348 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1349
1350 storeValue(integer);
1351 }
1352
1353 Byte::Byte(RValue<UShort> cast)
1354 {
1355 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1356
1357 storeValue(integer);
1358 }
1359
1360 Byte::Byte()
1361 {
1362 }
1363
1364 Byte::Byte(int x)
1365 {
1366 storeValue(Nucleus::createConstantByte((unsigned char)x));
1367 }
1368
1369 Byte::Byte(unsigned char x)
1370 {
1371 storeValue(Nucleus::createConstantByte(x));
1372 }
1373
1374 Byte::Byte(RValue<Byte> rhs)
1375 {
1376 storeValue(rhs.value);
1377 }
1378
1379 Byte::Byte(const Byte &rhs)
1380 {
1381 Value *value = rhs.loadValue();
1382 storeValue(value);
1383 }
1384
1385 Byte::Byte(const Reference<Byte> &rhs)
1386 {
1387 Value *value = rhs.loadValue();
1388 storeValue(value);
1389 }
1390
1391 RValue<Byte> Byte::operator=(RValue<Byte> rhs) const
1392 {
1393 storeValue(rhs.value);
1394
1395 return rhs;
1396 }
1397
1398 RValue<Byte> Byte::operator=(const Byte &rhs) const
1399 {
1400 Value *value = rhs.loadValue();
1401 storeValue(value);
1402
1403 return RValue<Byte>(value);
1404 }
1405
1406 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) const
1407 {
1408 Value *value = rhs.loadValue();
1409 storeValue(value);
1410
1411 return RValue<Byte>(value);
1412 }
1413
1414 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
1415 {
1416 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1417 }
1418
1419 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
1420 {
1421 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1422 }
1423
1424 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
1425 {
1426 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1427 }
1428
1429 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
1430 {
1431 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1432 }
1433
1434 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
1435 {
1436 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1437 }
1438
1439 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
1440 {
1441 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1442 }
1443
1444 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
1445 {
1446 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1447 }
1448
1449 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
1450 {
1451 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1452 }
1453
1454 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
1455 {
1456 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1457 }
1458
1459 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
1460 {
1461 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1462 }
1463
1464 RValue<Byte> operator+=(const Byte &lhs, RValue<Byte> rhs)
1465 {
1466 return lhs = lhs + rhs;
1467 }
1468
1469 RValue<Byte> operator-=(const Byte &lhs, RValue<Byte> rhs)
1470 {
1471 return lhs = lhs - rhs;
1472 }
1473
1474 RValue<Byte> operator*=(const Byte &lhs, RValue<Byte> rhs)
1475 {
1476 return lhs = lhs * rhs;
1477 }
1478
1479 RValue<Byte> operator/=(const Byte &lhs, RValue<Byte> rhs)
1480 {
1481 return lhs = lhs / rhs;
1482 }
1483
1484 RValue<Byte> operator%=(const Byte &lhs, RValue<Byte> rhs)
1485 {
1486 return lhs = lhs % rhs;
1487 }
1488
1489 RValue<Byte> operator&=(const Byte &lhs, RValue<Byte> rhs)
1490 {
1491 return lhs = lhs & rhs;
1492 }
1493
1494 RValue<Byte> operator|=(const Byte &lhs, RValue<Byte> rhs)
1495 {
1496 return lhs = lhs | rhs;
1497 }
1498
1499 RValue<Byte> operator^=(const Byte &lhs, RValue<Byte> rhs)
1500 {
1501 return lhs = lhs ^ rhs;
1502 }
1503
1504 RValue<Byte> operator<<=(const Byte &lhs, RValue<Byte> rhs)
1505 {
1506 return lhs = lhs << rhs;
1507 }
1508
1509 RValue<Byte> operator>>=(const Byte &lhs, RValue<Byte> rhs)
1510 {
1511 return lhs = lhs >> rhs;
1512 }
1513
1514 RValue<Byte> operator+(RValue<Byte> val)
1515 {
1516 return val;
1517 }
1518
1519 RValue<Byte> operator-(RValue<Byte> val)
1520 {
1521 return RValue<Byte>(Nucleus::createNeg(val.value));
1522 }
1523
1524 RValue<Byte> operator~(RValue<Byte> val)
1525 {
1526 return RValue<Byte>(Nucleus::createNot(val.value));
1527 }
1528
1529 RValue<Byte> operator++(const Byte &val, int) // Post-increment
1530 {
1531 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001532 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001533 return res;
1534 }
1535
1536 const Byte &operator++(const Byte &val) // Pre-increment
1537 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001538 val += Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001539 return val;
1540 }
1541
1542 RValue<Byte> operator--(const Byte &val, int) // Post-decrement
1543 {
1544 RValue<Byte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001545 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001546 return res;
1547 }
1548
1549 const Byte &operator--(const Byte &val) // Pre-decrement
1550 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001551 val -= Byte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001552 return val;
1553 }
1554
1555 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
1556 {
1557 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1558 }
1559
1560 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
1561 {
1562 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1563 }
1564
1565 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
1566 {
1567 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1568 }
1569
1570 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
1571 {
1572 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1573 }
1574
1575 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
1576 {
1577 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1578 }
1579
1580 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
1581 {
1582 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1583 }
1584
1585 Type *Byte::getType()
1586 {
Nicolas Capens6d738712016-09-30 04:15:22 -04001587 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001588 }
1589
1590 SByte::SByte(Argument<SByte> argument)
1591 {
1592 storeValue(argument.value);
1593 }
1594
1595 SByte::SByte(RValue<Int> cast)
1596 {
1597 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1598
1599 storeValue(integer);
1600 }
1601
1602 SByte::SByte(RValue<Short> cast)
1603 {
1604 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1605
1606 storeValue(integer);
1607 }
1608
1609 SByte::SByte()
1610 {
1611 }
1612
1613 SByte::SByte(signed char x)
1614 {
1615 storeValue(Nucleus::createConstantByte(x));
1616 }
1617
1618 SByte::SByte(RValue<SByte> rhs)
1619 {
1620 storeValue(rhs.value);
1621 }
1622
1623 SByte::SByte(const SByte &rhs)
1624 {
1625 Value *value = rhs.loadValue();
1626 storeValue(value);
1627 }
1628
1629 SByte::SByte(const Reference<SByte> &rhs)
1630 {
1631 Value *value = rhs.loadValue();
1632 storeValue(value);
1633 }
1634
1635 RValue<SByte> SByte::operator=(RValue<SByte> rhs) const
1636 {
1637 storeValue(rhs.value);
1638
1639 return rhs;
1640 }
1641
1642 RValue<SByte> SByte::operator=(const SByte &rhs) const
1643 {
1644 Value *value = rhs.loadValue();
1645 storeValue(value);
1646
1647 return RValue<SByte>(value);
1648 }
1649
1650 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) const
1651 {
1652 Value *value = rhs.loadValue();
1653 storeValue(value);
1654
1655 return RValue<SByte>(value);
1656 }
1657
1658 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
1659 {
1660 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1661 }
1662
1663 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
1664 {
1665 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1666 }
1667
1668 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
1669 {
1670 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1671 }
1672
1673 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
1674 {
1675 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1676 }
1677
1678 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
1679 {
1680 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1681 }
1682
1683 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
1684 {
1685 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1686 }
1687
1688 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
1689 {
1690 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1691 }
1692
1693 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
1694 {
1695 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1696 }
1697
1698 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
1699 {
1700 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1701 }
1702
1703 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
1704 {
1705 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1706 }
1707
1708 RValue<SByte> operator+=(const SByte &lhs, RValue<SByte> rhs)
1709 {
1710 return lhs = lhs + rhs;
1711 }
1712
1713 RValue<SByte> operator-=(const SByte &lhs, RValue<SByte> rhs)
1714 {
1715 return lhs = lhs - rhs;
1716 }
1717
1718 RValue<SByte> operator*=(const SByte &lhs, RValue<SByte> rhs)
1719 {
1720 return lhs = lhs * rhs;
1721 }
1722
1723 RValue<SByte> operator/=(const SByte &lhs, RValue<SByte> rhs)
1724 {
1725 return lhs = lhs / rhs;
1726 }
1727
1728 RValue<SByte> operator%=(const SByte &lhs, RValue<SByte> rhs)
1729 {
1730 return lhs = lhs % rhs;
1731 }
1732
1733 RValue<SByte> operator&=(const SByte &lhs, RValue<SByte> rhs)
1734 {
1735 return lhs = lhs & rhs;
1736 }
1737
1738 RValue<SByte> operator|=(const SByte &lhs, RValue<SByte> rhs)
1739 {
1740 return lhs = lhs | rhs;
1741 }
1742
1743 RValue<SByte> operator^=(const SByte &lhs, RValue<SByte> rhs)
1744 {
1745 return lhs = lhs ^ rhs;
1746 }
1747
1748 RValue<SByte> operator<<=(const SByte &lhs, RValue<SByte> rhs)
1749 {
1750 return lhs = lhs << rhs;
1751 }
1752
1753 RValue<SByte> operator>>=(const SByte &lhs, RValue<SByte> rhs)
1754 {
1755 return lhs = lhs >> rhs;
1756 }
1757
1758 RValue<SByte> operator+(RValue<SByte> val)
1759 {
1760 return val;
1761 }
1762
1763 RValue<SByte> operator-(RValue<SByte> val)
1764 {
1765 return RValue<SByte>(Nucleus::createNeg(val.value));
1766 }
1767
1768 RValue<SByte> operator~(RValue<SByte> val)
1769 {
1770 return RValue<SByte>(Nucleus::createNot(val.value));
1771 }
1772
1773 RValue<SByte> operator++(const SByte &val, int) // Post-increment
1774 {
1775 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001776 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001777 return res;
1778 }
1779
1780 const SByte &operator++(const SByte &val) // Pre-increment
1781 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001782 val += SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001783 return val;
1784 }
1785
1786 RValue<SByte> operator--(const SByte &val, int) // Post-decrement
1787 {
1788 RValue<SByte> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05001789 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001790 return res;
1791 }
1792
1793 const SByte &operator--(const SByte &val) // Pre-decrement
1794 {
Nicolas Capensd1229402016-11-07 16:05:22 -05001795 val -= SByte(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001796 return val;
1797 }
1798
1799 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
1800 {
1801 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1802 }
1803
1804 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
1805 {
1806 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1807 }
1808
1809 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
1810 {
1811 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1812 }
1813
1814 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
1815 {
1816 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1817 }
1818
1819 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
1820 {
1821 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1822 }
1823
1824 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
1825 {
1826 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1827 }
1828
1829 Type *SByte::getType()
1830 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001831 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001832 }
1833
1834 Short::Short(Argument<Short> argument)
1835 {
1836 storeValue(argument.value);
1837 }
1838
1839 Short::Short(RValue<Int> cast)
1840 {
1841 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1842
1843 storeValue(integer);
1844 }
1845
1846 Short::Short()
1847 {
1848 }
1849
1850 Short::Short(short x)
1851 {
1852 storeValue(Nucleus::createConstantShort(x));
1853 }
1854
1855 Short::Short(RValue<Short> rhs)
1856 {
1857 storeValue(rhs.value);
1858 }
1859
1860 Short::Short(const Short &rhs)
1861 {
1862 Value *value = rhs.loadValue();
1863 storeValue(value);
1864 }
1865
1866 Short::Short(const Reference<Short> &rhs)
1867 {
1868 Value *value = rhs.loadValue();
1869 storeValue(value);
1870 }
1871
1872 RValue<Short> Short::operator=(RValue<Short> rhs) const
1873 {
1874 storeValue(rhs.value);
1875
1876 return rhs;
1877 }
1878
1879 RValue<Short> Short::operator=(const Short &rhs) const
1880 {
1881 Value *value = rhs.loadValue();
1882 storeValue(value);
1883
1884 return RValue<Short>(value);
1885 }
1886
1887 RValue<Short> Short::operator=(const Reference<Short> &rhs) const
1888 {
1889 Value *value = rhs.loadValue();
1890 storeValue(value);
1891
1892 return RValue<Short>(value);
1893 }
1894
1895 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
1896 {
1897 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
1898 }
1899
1900 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
1901 {
1902 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
1903 }
1904
1905 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
1906 {
1907 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
1908 }
1909
1910 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
1911 {
1912 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
1913 }
1914
1915 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
1916 {
1917 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
1918 }
1919
1920 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
1921 {
1922 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
1923 }
1924
1925 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
1926 {
1927 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
1928 }
1929
1930 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
1931 {
1932 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
1933 }
1934
1935 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
1936 {
1937 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
1938 }
1939
1940 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
1941 {
1942 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
1943 }
1944
1945 RValue<Short> operator+=(const Short &lhs, RValue<Short> rhs)
1946 {
1947 return lhs = lhs + rhs;
1948 }
1949
1950 RValue<Short> operator-=(const Short &lhs, RValue<Short> rhs)
1951 {
1952 return lhs = lhs - rhs;
1953 }
1954
1955 RValue<Short> operator*=(const Short &lhs, RValue<Short> rhs)
1956 {
1957 return lhs = lhs * rhs;
1958 }
1959
1960 RValue<Short> operator/=(const Short &lhs, RValue<Short> rhs)
1961 {
1962 return lhs = lhs / rhs;
1963 }
1964
1965 RValue<Short> operator%=(const Short &lhs, RValue<Short> rhs)
1966 {
1967 return lhs = lhs % rhs;
1968 }
1969
1970 RValue<Short> operator&=(const Short &lhs, RValue<Short> rhs)
1971 {
1972 return lhs = lhs & rhs;
1973 }
1974
1975 RValue<Short> operator|=(const Short &lhs, RValue<Short> rhs)
1976 {
1977 return lhs = lhs | rhs;
1978 }
1979
1980 RValue<Short> operator^=(const Short &lhs, RValue<Short> rhs)
1981 {
1982 return lhs = lhs ^ rhs;
1983 }
1984
1985 RValue<Short> operator<<=(const Short &lhs, RValue<Short> rhs)
1986 {
1987 return lhs = lhs << rhs;
1988 }
1989
1990 RValue<Short> operator>>=(const Short &lhs, RValue<Short> rhs)
1991 {
1992 return lhs = lhs >> rhs;
1993 }
1994
1995 RValue<Short> operator+(RValue<Short> val)
1996 {
1997 return val;
1998 }
1999
2000 RValue<Short> operator-(RValue<Short> val)
2001 {
2002 return RValue<Short>(Nucleus::createNeg(val.value));
2003 }
2004
2005 RValue<Short> operator~(RValue<Short> val)
2006 {
2007 return RValue<Short>(Nucleus::createNot(val.value));
2008 }
2009
2010 RValue<Short> operator++(const Short &val, int) // Post-increment
2011 {
2012 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002013 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002014 return res;
2015 }
2016
2017 const Short &operator++(const Short &val) // Pre-increment
2018 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002019 val += Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002020 return val;
2021 }
2022
2023 RValue<Short> operator--(const Short &val, int) // Post-decrement
2024 {
2025 RValue<Short> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002026 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002027 return res;
2028 }
2029
2030 const Short &operator--(const Short &val) // Pre-decrement
2031 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002032 val -= Short(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002033 return val;
2034 }
2035
2036 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
2037 {
2038 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2039 }
2040
2041 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
2042 {
2043 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2044 }
2045
2046 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
2047 {
2048 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2049 }
2050
2051 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
2052 {
2053 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2054 }
2055
2056 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
2057 {
2058 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2059 }
2060
2061 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
2062 {
2063 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2064 }
2065
2066 Type *Short::getType()
2067 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002068 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002069 }
2070
2071 UShort::UShort(Argument<UShort> argument)
2072 {
2073 storeValue(argument.value);
2074 }
2075
2076 UShort::UShort(RValue<UInt> cast)
2077 {
2078 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2079
2080 storeValue(integer);
2081 }
2082
2083 UShort::UShort(RValue<Int> cast)
2084 {
2085 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2086
2087 storeValue(integer);
2088 }
2089
2090 UShort::UShort()
2091 {
2092 }
2093
2094 UShort::UShort(unsigned short x)
2095 {
2096 storeValue(Nucleus::createConstantShort(x));
2097 }
2098
2099 UShort::UShort(RValue<UShort> rhs)
2100 {
2101 storeValue(rhs.value);
2102 }
2103
2104 UShort::UShort(const UShort &rhs)
2105 {
2106 Value *value = rhs.loadValue();
2107 storeValue(value);
2108 }
2109
2110 UShort::UShort(const Reference<UShort> &rhs)
2111 {
2112 Value *value = rhs.loadValue();
2113 storeValue(value);
2114 }
2115
2116 RValue<UShort> UShort::operator=(RValue<UShort> rhs) const
2117 {
2118 storeValue(rhs.value);
2119
2120 return rhs;
2121 }
2122
2123 RValue<UShort> UShort::operator=(const UShort &rhs) const
2124 {
2125 Value *value = rhs.loadValue();
2126 storeValue(value);
2127
2128 return RValue<UShort>(value);
2129 }
2130
2131 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const
2132 {
2133 Value *value = rhs.loadValue();
2134 storeValue(value);
2135
2136 return RValue<UShort>(value);
2137 }
2138
2139 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
2140 {
2141 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
2142 }
2143
2144 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
2145 {
2146 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
2147 }
2148
2149 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
2150 {
2151 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
2152 }
2153
2154 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
2155 {
2156 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
2157 }
2158
2159 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
2160 {
2161 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
2162 }
2163
2164 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
2165 {
2166 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
2167 }
2168
2169 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
2170 {
2171 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
2172 }
2173
2174 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
2175 {
2176 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
2177 }
2178
2179 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
2180 {
2181 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
2182 }
2183
2184 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
2185 {
2186 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
2187 }
2188
2189 RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs)
2190 {
2191 return lhs = lhs + rhs;
2192 }
2193
2194 RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs)
2195 {
2196 return lhs = lhs - rhs;
2197 }
2198
2199 RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs)
2200 {
2201 return lhs = lhs * rhs;
2202 }
2203
2204 RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs)
2205 {
2206 return lhs = lhs / rhs;
2207 }
2208
2209 RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs)
2210 {
2211 return lhs = lhs % rhs;
2212 }
2213
2214 RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs)
2215 {
2216 return lhs = lhs & rhs;
2217 }
2218
2219 RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs)
2220 {
2221 return lhs = lhs | rhs;
2222 }
2223
2224 RValue<UShort> operator^=(const UShort &lhs, RValue<UShort> rhs)
2225 {
2226 return lhs = lhs ^ rhs;
2227 }
2228
2229 RValue<UShort> operator<<=(const UShort &lhs, RValue<UShort> rhs)
2230 {
2231 return lhs = lhs << rhs;
2232 }
2233
2234 RValue<UShort> operator>>=(const UShort &lhs, RValue<UShort> rhs)
2235 {
2236 return lhs = lhs >> rhs;
2237 }
2238
2239 RValue<UShort> operator+(RValue<UShort> val)
2240 {
2241 return val;
2242 }
2243
2244 RValue<UShort> operator-(RValue<UShort> val)
2245 {
2246 return RValue<UShort>(Nucleus::createNeg(val.value));
2247 }
2248
2249 RValue<UShort> operator~(RValue<UShort> val)
2250 {
2251 return RValue<UShort>(Nucleus::createNot(val.value));
2252 }
2253
2254 RValue<UShort> operator++(const UShort &val, int) // Post-increment
2255 {
2256 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002257 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002258 return res;
2259 }
2260
2261 const UShort &operator++(const UShort &val) // Pre-increment
2262 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002263 val += UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002264 return val;
2265 }
2266
2267 RValue<UShort> operator--(const UShort &val, int) // Post-decrement
2268 {
2269 RValue<UShort> res = val;
Nicolas Capensd1229402016-11-07 16:05:22 -05002270 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002271 return res;
2272 }
2273
2274 const UShort &operator--(const UShort &val) // Pre-decrement
2275 {
Nicolas Capensd1229402016-11-07 16:05:22 -05002276 val -= UShort(1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002277 return val;
2278 }
2279
2280 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
2281 {
2282 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2283 }
2284
2285 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
2286 {
2287 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2288 }
2289
2290 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
2291 {
2292 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2293 }
2294
2295 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
2296 {
2297 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2298 }
2299
2300 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
2301 {
2302 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2303 }
2304
2305 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
2306 {
2307 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2308 }
2309
2310 Type *UShort::getType()
2311 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002312 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002313 }
2314
Nicolas Capens16b5f152016-10-13 13:39:01 -04002315 Byte4::Byte4(RValue<Byte8> cast)
2316 {
2317 // xyzw.parent = this;
2318
2319 storeValue(Nucleus::createBitCast(cast.value, getType()));
2320 }
2321
2322 Byte4::Byte4(const Reference<Byte4> &rhs)
2323 {
2324 // xyzw.parent = this;
2325
Nicolas Capensd1229402016-11-07 16:05:22 -05002326 Value *value = rhs.loadValue();
2327 storeValue(value);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002328 }
2329
Nicolas Capens598f8d82016-09-26 15:09:10 -04002330 Type *Byte4::getType()
2331 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002332 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002333 }
2334
2335 Type *SByte4::getType()
2336 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002337 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002338 }
2339
2340 Byte8::Byte8()
2341 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002342 }
2343
2344 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)
2345 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002346 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
2347 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002348 }
2349
2350 Byte8::Byte8(RValue<Byte8> rhs)
2351 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002352 storeValue(rhs.value);
2353 }
2354
2355 Byte8::Byte8(const Byte8 &rhs)
2356 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002357 Value *value = rhs.loadValue();
2358 storeValue(value);
2359 }
2360
2361 Byte8::Byte8(const Reference<Byte8> &rhs)
2362 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002363 Value *value = rhs.loadValue();
2364 storeValue(value);
2365 }
2366
2367 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const
2368 {
2369 storeValue(rhs.value);
2370
2371 return rhs;
2372 }
2373
2374 RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const
2375 {
2376 Value *value = rhs.loadValue();
2377 storeValue(value);
2378
2379 return RValue<Byte8>(value);
2380 }
2381
2382 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const
2383 {
2384 Value *value = rhs.loadValue();
2385 storeValue(value);
2386
2387 return RValue<Byte8>(value);
2388 }
2389
2390 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
2391 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002392 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002393 }
2394
2395 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
2396 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002397 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002398 }
2399
2400// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2401// {
2402// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2403// }
2404
2405// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2406// {
2407// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2408// }
2409
2410// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2411// {
2412// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2413// }
2414
2415 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
2416 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002417 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002418 }
2419
2420 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
2421 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002422 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002423 }
2424
2425 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
2426 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002427 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002428 }
2429
2430// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
2431// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002432// return RValue<Byte8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002433// }
2434
2435// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
2436// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002437// return RValue<Byte8>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002438// }
2439
2440 RValue<Byte8> operator+=(const Byte8 &lhs, RValue<Byte8> rhs)
2441 {
2442 return lhs = lhs + rhs;
2443 }
2444
2445 RValue<Byte8> operator-=(const Byte8 &lhs, RValue<Byte8> rhs)
2446 {
2447 return lhs = lhs - rhs;
2448 }
2449
2450// RValue<Byte8> operator*=(const Byte8 &lhs, RValue<Byte8> rhs)
2451// {
2452// return lhs = lhs * rhs;
2453// }
2454
2455// RValue<Byte8> operator/=(const Byte8 &lhs, RValue<Byte8> rhs)
2456// {
2457// return lhs = lhs / rhs;
2458// }
2459
2460// RValue<Byte8> operator%=(const Byte8 &lhs, RValue<Byte8> rhs)
2461// {
2462// return lhs = lhs % rhs;
2463// }
2464
2465 RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs)
2466 {
2467 return lhs = lhs & rhs;
2468 }
2469
2470 RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs)
2471 {
2472 return lhs = lhs | rhs;
2473 }
2474
2475 RValue<Byte8> operator^=(const Byte8 &lhs, RValue<Byte8> rhs)
2476 {
2477 return lhs = lhs ^ rhs;
2478 }
2479
2480// RValue<Byte8> operator<<=(const Byte8 &lhs, RValue<Byte8> rhs)
2481// {
2482// return lhs = lhs << rhs;
2483// }
2484
2485// RValue<Byte8> operator>>=(const Byte8 &lhs, RValue<Byte8> rhs)
2486// {
2487// return lhs = lhs >> rhs;
2488// }
2489
2490// RValue<Byte8> operator+(RValue<Byte8> val)
2491// {
2492// return val;
2493// }
2494
2495// RValue<Byte8> operator-(RValue<Byte8> val)
2496// {
2497// return RValue<Byte8>(Nucleus::createNeg(val.value));
2498// }
2499
2500 RValue<Byte8> operator~(RValue<Byte8> val)
2501 {
2502 return RValue<Byte8>(Nucleus::createNot(val.value));
2503 }
2504
2505 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
2506 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002507 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002508 }
2509
2510 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
2511 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002512 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002513 }
2514
2515 RValue<Short4> Unpack(RValue<Byte4> x)
2516 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002517 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2518 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002519 }
2520
2521 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2522 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002523 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2524 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002525 }
2526
2527 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
2528 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002529 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2530 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2531 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002532 }
2533
2534 RValue<Int> SignMask(RValue<Byte8> x)
2535 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002536 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002537 }
2538
2539// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
2540// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002541// assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002542// }
2543
2544 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
2545 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002546 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002547 }
2548
2549 Type *Byte8::getType()
2550 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002551 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002552 }
2553
2554 SByte8::SByte8()
2555 {
2556 // xyzw.parent = this;
2557 }
2558
2559 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)
2560 {
2561 // xyzw.parent = this;
2562
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002563 int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
2564 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
2565
2566 storeValue(Nucleus::createBitCast(vector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002567 }
2568
Nicolas Capens598f8d82016-09-26 15:09:10 -04002569 SByte8::SByte8(RValue<SByte8> rhs)
2570 {
2571 // xyzw.parent = this;
2572
2573 storeValue(rhs.value);
2574 }
2575
2576 SByte8::SByte8(const SByte8 &rhs)
2577 {
2578 // xyzw.parent = this;
2579
2580 Value *value = rhs.loadValue();
2581 storeValue(value);
2582 }
2583
2584 SByte8::SByte8(const Reference<SByte8> &rhs)
2585 {
2586 // xyzw.parent = this;
2587
2588 Value *value = rhs.loadValue();
2589 storeValue(value);
2590 }
2591
2592 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const
2593 {
2594 storeValue(rhs.value);
2595
2596 return rhs;
2597 }
2598
2599 RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const
2600 {
2601 Value *value = rhs.loadValue();
2602 storeValue(value);
2603
2604 return RValue<SByte8>(value);
2605 }
2606
2607 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const
2608 {
2609 Value *value = rhs.loadValue();
2610 storeValue(value);
2611
2612 return RValue<SByte8>(value);
2613 }
2614
2615 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
2616 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002617 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002618 }
2619
2620 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
2621 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002622 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002623 }
2624
2625// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2626// {
2627// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2628// }
2629
2630// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2631// {
2632// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2633// }
2634
2635// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2636// {
2637// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2638// }
2639
2640 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
2641 {
2642 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2643 }
2644
2645 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
2646 {
2647 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2648 }
2649
2650 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
2651 {
2652 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2653 }
2654
2655// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
2656// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002657// return RValue<SByte8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002658// }
2659
2660// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
2661// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002662// return RValue<SByte8>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002663// }
2664
2665 RValue<SByte8> operator+=(const SByte8 &lhs, RValue<SByte8> rhs)
2666 {
2667 return lhs = lhs + rhs;
2668 }
2669
2670 RValue<SByte8> operator-=(const SByte8 &lhs, RValue<SByte8> rhs)
2671 {
2672 return lhs = lhs - rhs;
2673 }
2674
2675// RValue<SByte8> operator*=(const SByte8 &lhs, RValue<SByte8> rhs)
2676// {
2677// return lhs = lhs * rhs;
2678// }
2679
2680// RValue<SByte8> operator/=(const SByte8 &lhs, RValue<SByte8> rhs)
2681// {
2682// return lhs = lhs / rhs;
2683// }
2684
2685// RValue<SByte8> operator%=(const SByte8 &lhs, RValue<SByte8> rhs)
2686// {
2687// return lhs = lhs % rhs;
2688// }
2689
2690 RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs)
2691 {
2692 return lhs = lhs & rhs;
2693 }
2694
2695 RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs)
2696 {
2697 return lhs = lhs | rhs;
2698 }
2699
2700 RValue<SByte8> operator^=(const SByte8 &lhs, RValue<SByte8> rhs)
2701 {
2702 return lhs = lhs ^ rhs;
2703 }
2704
2705// RValue<SByte8> operator<<=(const SByte8 &lhs, RValue<SByte8> rhs)
2706// {
2707// return lhs = lhs << rhs;
2708// }
2709
2710// RValue<SByte8> operator>>=(const SByte8 &lhs, RValue<SByte8> rhs)
2711// {
2712// return lhs = lhs >> rhs;
2713// }
2714
2715// RValue<SByte8> operator+(RValue<SByte8> val)
2716// {
2717// return val;
2718// }
2719
2720// RValue<SByte8> operator-(RValue<SByte8> val)
2721// {
2722// return RValue<SByte8>(Nucleus::createNeg(val.value));
2723// }
2724
2725 RValue<SByte8> operator~(RValue<SByte8> val)
2726 {
2727 return RValue<SByte8>(Nucleus::createNot(val.value));
2728 }
2729
2730 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
2731 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002732 assert(false && "UNIMPLEMENTED"); return RValue<SByte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002733 }
2734
2735 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
2736 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002737 assert(false && "UNIMPLEMENTED"); return RValue<SByte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002738 }
2739
2740 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
2741 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002742 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2743 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002744 }
2745
2746 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
2747 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002748 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2749 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2750 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002751 }
2752
2753 RValue<Int> SignMask(RValue<SByte8> x)
2754 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04002755 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2756 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2757 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2758 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2759 movmsk->addArg(x.value);
2760 ::basicBlock->appendInst(movmsk);
2761
2762 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002763 }
2764
2765 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
2766 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002767 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002768 }
2769
2770 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
2771 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002772 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002773 }
2774
2775 Type *SByte8::getType()
2776 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002777 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002778 }
2779
2780 Byte16::Byte16(RValue<Byte16> rhs)
2781 {
2782 // xyzw.parent = this;
2783
2784 storeValue(rhs.value);
2785 }
2786
2787 Byte16::Byte16(const Byte16 &rhs)
2788 {
2789 // xyzw.parent = this;
2790
2791 Value *value = rhs.loadValue();
2792 storeValue(value);
2793 }
2794
2795 Byte16::Byte16(const Reference<Byte16> &rhs)
2796 {
2797 // xyzw.parent = this;
2798
2799 Value *value = rhs.loadValue();
2800 storeValue(value);
2801 }
2802
2803 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const
2804 {
2805 storeValue(rhs.value);
2806
2807 return rhs;
2808 }
2809
2810 RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const
2811 {
2812 Value *value = rhs.loadValue();
2813 storeValue(value);
2814
2815 return RValue<Byte16>(value);
2816 }
2817
2818 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const
2819 {
2820 Value *value = rhs.loadValue();
2821 storeValue(value);
2822
2823 return RValue<Byte16>(value);
2824 }
2825
2826 Type *Byte16::getType()
2827 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002828 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002829 }
2830
2831 Type *SByte16::getType()
2832 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002833 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002834 }
2835
Nicolas Capens16b5f152016-10-13 13:39:01 -04002836 Short2::Short2(RValue<Short4> cast)
2837 {
2838 assert(false && "UNIMPLEMENTED");
2839 }
2840
2841 Type *Short2::getType()
2842 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002843 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002844 }
2845
2846 UShort2::UShort2(RValue<UShort4> cast)
2847 {
2848 assert(false && "UNIMPLEMENTED");
2849 }
2850
2851 Type *UShort2::getType()
2852 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002853 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002854 }
2855
Nicolas Capens598f8d82016-09-26 15:09:10 -04002856 Short4::Short4(RValue<Int> cast)
2857 {
2858 Value *extend = Nucleus::createZExt(cast.value, Long::getType());
2859 Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value;
2860
2861 storeValue(swizzle);
2862 }
2863
2864 Short4::Short4(RValue<Int4> cast)
2865 {
2866 assert(false && "UNIMPLEMENTED");
2867 }
2868
2869// Short4::Short4(RValue<Float> cast)
2870// {
2871// }
2872
2873 Short4::Short4(RValue<Float4> cast)
2874 {
2875 assert(false && "UNIMPLEMENTED");
2876 }
2877
2878 Short4::Short4()
2879 {
2880 // xyzw.parent = this;
2881 }
2882
2883 Short4::Short4(short xyzw)
2884 {
2885 // xyzw.parent = this;
2886
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002887 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
2888 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002889 }
2890
2891 Short4::Short4(short x, short y, short z, short w)
2892 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002893 // xyzw.parent = this;
Nicolas Capens598f8d82016-09-26 15:09:10 -04002894
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002895 int64_t constantVector[4] = {x, y, z, w};
2896 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002897 }
2898
2899 Short4::Short4(RValue<Short4> rhs)
2900 {
2901 // xyzw.parent = this;
2902
2903 storeValue(rhs.value);
2904 }
2905
2906 Short4::Short4(const Short4 &rhs)
2907 {
2908 // xyzw.parent = this;
2909
2910 Value *value = rhs.loadValue();
2911 storeValue(value);
2912 }
2913
2914 Short4::Short4(const Reference<Short4> &rhs)
2915 {
2916 // xyzw.parent = this;
2917
2918 Value *value = rhs.loadValue();
2919 storeValue(value);
2920 }
2921
2922 Short4::Short4(RValue<UShort4> rhs)
2923 {
2924 // xyzw.parent = this;
2925
2926 storeValue(rhs.value);
2927 }
2928
2929 Short4::Short4(const UShort4 &rhs)
2930 {
2931 // xyzw.parent = this;
2932
2933 storeValue(rhs.loadValue());
2934 }
2935
2936 Short4::Short4(const Reference<UShort4> &rhs)
2937 {
2938 // xyzw.parent = this;
2939
2940 storeValue(rhs.loadValue());
2941 }
2942
2943 RValue<Short4> Short4::operator=(RValue<Short4> rhs) const
2944 {
2945 storeValue(rhs.value);
2946
2947 return rhs;
2948 }
2949
2950 RValue<Short4> Short4::operator=(const Short4 &rhs) const
2951 {
2952 Value *value = rhs.loadValue();
2953 storeValue(value);
2954
2955 return RValue<Short4>(value);
2956 }
2957
2958 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const
2959 {
2960 Value *value = rhs.loadValue();
2961 storeValue(value);
2962
2963 return RValue<Short4>(value);
2964 }
2965
2966 RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const
2967 {
2968 storeValue(rhs.value);
2969
2970 return RValue<Short4>(rhs);
2971 }
2972
2973 RValue<Short4> Short4::operator=(const UShort4 &rhs) const
2974 {
2975 Value *value = rhs.loadValue();
2976 storeValue(value);
2977
2978 return RValue<Short4>(value);
2979 }
2980
2981 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const
2982 {
2983 Value *value = rhs.loadValue();
2984 storeValue(value);
2985
2986 return RValue<Short4>(value);
2987 }
2988
2989 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
2990 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002991 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002992 }
2993
2994 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
2995 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002996 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002997 }
2998
2999 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
3000 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003001 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003002 }
3003
3004// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
3005// {
3006// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
3007// }
3008
3009// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
3010// {
3011// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
3012// }
3013
3014 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
3015 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003016 return RValue<Short4>(Nucleus::createAnd(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::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003022 }
3023
3024 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
3025 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003026 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003027 }
3028
3029 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
3030 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003031 return RValue<Short4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003032 }
3033
3034 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
3035 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003036 return RValue<Short4>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003037 }
3038
3039 RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs)
3040 {
3041 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3042
Nicolas Capensc37252c2016-09-28 16:11:54 -04003043 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003044 }
3045
3046 RValue<Short4> operator>>(RValue<Short4> lhs, RValue<Long1> rhs)
3047 {
3048 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
3049
Nicolas Capensc37252c2016-09-28 16:11:54 -04003050 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003051 }
3052
3053 RValue<Short4> operator+=(const Short4 &lhs, RValue<Short4> rhs)
3054 {
3055 return lhs = lhs + rhs;
3056 }
3057
3058 RValue<Short4> operator-=(const Short4 &lhs, RValue<Short4> rhs)
3059 {
3060 return lhs = lhs - rhs;
3061 }
3062
3063 RValue<Short4> operator*=(const Short4 &lhs, RValue<Short4> rhs)
3064 {
3065 return lhs = lhs * rhs;
3066 }
3067
3068// RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs)
3069// {
3070// return lhs = lhs / rhs;
3071// }
3072
3073// RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs)
3074// {
3075// return lhs = lhs % rhs;
3076// }
3077
3078 RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs)
3079 {
3080 return lhs = lhs & rhs;
3081 }
3082
3083 RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs)
3084 {
3085 return lhs = lhs | rhs;
3086 }
3087
3088 RValue<Short4> operator^=(const Short4 &lhs, RValue<Short4> rhs)
3089 {
3090 return lhs = lhs ^ rhs;
3091 }
3092
3093 RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs)
3094 {
3095 return lhs = lhs << rhs;
3096 }
3097
3098 RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs)
3099 {
3100 return lhs = lhs >> rhs;
3101 }
3102
3103 RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs)
3104 {
3105 return lhs = lhs << rhs;
3106 }
3107
3108 RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs)
3109 {
3110 return lhs = lhs >> rhs;
3111 }
3112
3113// RValue<Short4> operator+(RValue<Short4> val)
3114// {
3115// return val;
3116// }
3117
3118 RValue<Short4> operator-(RValue<Short4> val)
3119 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003120 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003121 }
3122
3123 RValue<Short4> operator~(RValue<Short4> val)
3124 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003125 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003126 }
3127
3128 RValue<Short4> RoundShort4(RValue<Float4> cast)
3129 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003130 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003131 }
3132
3133 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
3134 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003135 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3136 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
3137 ::basicBlock->appendInst(cmp);
3138
3139 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3140 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3141 ::basicBlock->appendInst(select);
3142
3143 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003144 }
3145
3146 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
3147 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003148 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3149 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
3150 ::basicBlock->appendInst(cmp);
3151
3152 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3153 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3154 ::basicBlock->appendInst(select);
3155
3156 return RValue<Short4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003157 }
3158
3159 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
3160 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003161 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003162 }
3163
3164 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
3165 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003166 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003167 }
3168
3169 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
3170 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003171 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003172 }
3173
3174 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
3175 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003176 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003177 }
3178
3179 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
3180 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003181 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3182 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3183 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3184 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3185 pack->addArg(x.value);
3186 pack->addArg(y.value);
3187 ::basicBlock->appendInst(pack);
3188
Nicolas Capens70dfff42016-10-27 10:20:28 -04003189 return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003190 }
3191
3192 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
3193 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003194 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3195 return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003196 }
3197
3198 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
3199 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04003200 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3201 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3202 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003203 }
3204
3205 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
3206 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003207 // Real type is v8i16
3208 int shuffle[8] =
3209 {
3210 (select >> 0) & 0x03,
3211 (select >> 2) & 0x03,
3212 (select >> 4) & 0x03,
3213 (select >> 6) & 0x03,
3214 (select >> 0) & 0x03,
3215 (select >> 2) & 0x03,
3216 (select >> 4) & 0x03,
3217 (select >> 6) & 0x03,
3218 };
3219
3220 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003221 }
3222
3223 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
3224 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003225 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003226 }
3227
3228 RValue<Short> Extract(RValue<Short4> val, int i)
3229 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003230 assert(false && "UNIMPLEMENTED"); return RValue<Short>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003231 }
3232
3233 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
3234 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003235 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003236 }
3237
3238 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
3239 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003240 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003241 }
3242
3243 Type *Short4::getType()
3244 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003245 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003246 }
3247
3248 UShort4::UShort4(RValue<Int4> cast)
3249 {
3250 *this = Short4(cast);
3251 }
3252
3253 UShort4::UShort4(RValue<Float4> cast, bool saturate)
3254 {
3255 assert(false && "UNIMPLEMENTED");
3256 }
3257
3258 UShort4::UShort4()
3259 {
3260 // xyzw.parent = this;
3261 }
3262
3263 UShort4::UShort4(unsigned short xyzw)
3264 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003265 // xyzw.parent = this;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003266
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003267 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3268 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003269 }
3270
3271 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3272 {
3273 // xyzw.parent = this;
3274
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003275 int64_t constantVector[4] = {x, y, z, w};
3276 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003277 }
3278
3279 UShort4::UShort4(RValue<UShort4> rhs)
3280 {
3281 // xyzw.parent = this;
3282
3283 storeValue(rhs.value);
3284 }
3285
3286 UShort4::UShort4(const UShort4 &rhs)
3287 {
3288 // xyzw.parent = this;
3289
3290 Value *value = rhs.loadValue();
3291 storeValue(value);
3292 }
3293
3294 UShort4::UShort4(const Reference<UShort4> &rhs)
3295 {
3296 // xyzw.parent = this;
3297
3298 Value *value = rhs.loadValue();
3299 storeValue(value);
3300 }
3301
3302 UShort4::UShort4(RValue<Short4> rhs)
3303 {
3304 // xyzw.parent = this;
3305
3306 storeValue(rhs.value);
3307 }
3308
3309 UShort4::UShort4(const Short4 &rhs)
3310 {
3311 // xyzw.parent = this;
3312
3313 Value *value = rhs.loadValue();
3314 storeValue(value);
3315 }
3316
3317 UShort4::UShort4(const Reference<Short4> &rhs)
3318 {
3319 // xyzw.parent = this;
3320
3321 Value *value = rhs.loadValue();
3322 storeValue(value);
3323 }
3324
3325 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const
3326 {
3327 storeValue(rhs.value);
3328
3329 return rhs;
3330 }
3331
3332 RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const
3333 {
3334 Value *value = rhs.loadValue();
3335 storeValue(value);
3336
3337 return RValue<UShort4>(value);
3338 }
3339
3340 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const
3341 {
3342 Value *value = rhs.loadValue();
3343 storeValue(value);
3344
3345 return RValue<UShort4>(value);
3346 }
3347
3348 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const
3349 {
3350 storeValue(rhs.value);
3351
3352 return RValue<UShort4>(rhs);
3353 }
3354
3355 RValue<UShort4> UShort4::operator=(const Short4 &rhs) const
3356 {
3357 Value *value = rhs.loadValue();
3358 storeValue(value);
3359
3360 return RValue<UShort4>(value);
3361 }
3362
3363 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const
3364 {
3365 Value *value = rhs.loadValue();
3366 storeValue(value);
3367
3368 return RValue<UShort4>(value);
3369 }
3370
3371 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
3372 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003373 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003374 }
3375
3376 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
3377 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003378 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003379 }
3380
3381 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
3382 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003383 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003384 }
3385
Nicolas Capens16b5f152016-10-13 13:39:01 -04003386 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3387 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003388 return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003389 }
3390
3391 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
3392 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003393 return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003394 }
3395
3396 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3397 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003398 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003399 }
3400
Nicolas Capens598f8d82016-09-26 15:09:10 -04003401 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
3402 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003403 return RValue<UShort4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003404 }
3405
3406 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
3407 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003408 return RValue<UShort4>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003409 }
3410
3411 RValue<UShort4> operator<<(RValue<UShort4> lhs, RValue<Long1> rhs)
3412 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003413 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003414 }
3415
3416 RValue<UShort4> operator>>(RValue<UShort4> lhs, RValue<Long1> rhs)
3417 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003418 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003419 }
3420
3421 RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs)
3422 {
3423 return lhs = lhs << rhs;
3424 }
3425
3426 RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs)
3427 {
3428 return lhs = lhs >> rhs;
3429 }
3430
3431 RValue<UShort4> operator<<=(const UShort4 &lhs, RValue<Long1> rhs)
3432 {
3433 return lhs = lhs << rhs;
3434 }
3435
3436 RValue<UShort4> operator>>=(const UShort4 &lhs, RValue<Long1> rhs)
3437 {
3438 return lhs = lhs >> rhs;
3439 }
3440
3441 RValue<UShort4> operator~(RValue<UShort4> val)
3442 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003443 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003444 }
3445
3446 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
3447 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003448 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3449 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
3450 ::basicBlock->appendInst(cmp);
3451
3452 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3453 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3454 ::basicBlock->appendInst(select);
3455
3456 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003457 }
3458
3459 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
3460 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04003461 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3462 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
3463 ::basicBlock->appendInst(cmp);
3464
3465 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3466 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3467 ::basicBlock->appendInst(select);
3468
3469 return RValue<UShort4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003470 }
3471
3472 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
3473 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003474 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003475 }
3476
3477 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
3478 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003479 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003480 }
3481
3482 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
3483 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003484 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003485 }
3486
3487 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
3488 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003489 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003490 }
3491
3492 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
3493 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003494 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3495 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3496 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3497 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3498 pack->addArg(x.value);
3499 pack->addArg(y.value);
3500 ::basicBlock->appendInst(pack);
3501
Nicolas Capens70dfff42016-10-27 10:20:28 -04003502 return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003503 }
3504
3505 Type *UShort4::getType()
3506 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003507 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003508 }
3509
3510 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3511 {
3512 // xyzw.parent = this;
3513
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003514 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3515 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003516 }
3517
3518 Short8::Short8(RValue<Short8> rhs)
3519 {
3520 // xyzw.parent = this;
3521
3522 storeValue(rhs.value);
3523 }
3524
3525 Short8::Short8(const Reference<Short8> &rhs)
3526 {
3527 // xyzw.parent = this;
3528
3529 Value *value = rhs.loadValue();
3530 storeValue(value);
3531 }
3532
3533 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3534 {
3535 assert(false && "UNIMPLEMENTED");
3536 }
3537
3538 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
3539 {
3540 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3541 }
3542
3543 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
3544 {
3545 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3546 }
3547
3548 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
3549 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003550 return RValue<Short8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003551 }
3552
3553 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
3554 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003555 return RValue<Short8>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003556 }
3557
3558 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
3559 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003560 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003561 }
3562
3563 RValue<Int4> Abs(RValue<Int4> x)
3564 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003565 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003566 }
3567
3568 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
3569 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003570 assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003571 }
3572
3573 Type *Short8::getType()
3574 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003575 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003576 }
3577
3578 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)
3579 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003580 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3581 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003582 }
3583
3584 UShort8::UShort8(RValue<UShort8> rhs)
3585 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003586 storeValue(rhs.value);
3587 }
3588
3589 UShort8::UShort8(const Reference<UShort8> &rhs)
3590 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003591 Value *value = rhs.loadValue();
3592 storeValue(value);
3593 }
3594
3595 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3596 {
3597 assert(false && "UNIMPLEMENTED");
3598 }
3599
3600 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) const
3601 {
3602 storeValue(rhs.value);
3603
3604 return rhs;
3605 }
3606
3607 RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const
3608 {
3609 Value *value = rhs.loadValue();
3610 storeValue(value);
3611
3612 return RValue<UShort8>(value);
3613 }
3614
3615 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) const
3616 {
3617 Value *value = rhs.loadValue();
3618 storeValue(value);
3619
3620 return RValue<UShort8>(value);
3621 }
3622
3623 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
3624 {
3625 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3626 }
3627
3628 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
3629 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003630 return RValue<UShort8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003631 }
3632
3633 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
3634 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003635 return RValue<UShort8>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003636 }
3637
3638 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
3639 {
3640 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3641 }
3642
3643 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
3644 {
3645 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3646 }
3647
3648 RValue<UShort8> operator+=(const UShort8 &lhs, RValue<UShort8> rhs)
3649 {
3650 return lhs = lhs + rhs;
3651 }
3652
3653 RValue<UShort8> operator~(RValue<UShort8> val)
3654 {
3655 return RValue<UShort8>(Nucleus::createNot(val.value));
3656 }
3657
3658 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
3659 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003660 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003661 }
3662
3663 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
3664 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003665 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003666 }
3667
3668 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
3669// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
3670// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003671// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003672// }
3673
3674 Type *UShort8::getType()
3675 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003676 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003677 }
3678
3679 Int::Int(Argument<Int> argument)
3680 {
3681 storeValue(argument.value);
3682 }
3683
3684 Int::Int(RValue<Byte> cast)
3685 {
3686 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3687
3688 storeValue(integer);
3689 }
3690
3691 Int::Int(RValue<SByte> cast)
3692 {
3693 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3694
3695 storeValue(integer);
3696 }
3697
3698 Int::Int(RValue<Short> cast)
3699 {
3700 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3701
3702 storeValue(integer);
3703 }
3704
3705 Int::Int(RValue<UShort> cast)
3706 {
3707 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3708
3709 storeValue(integer);
3710 }
3711
3712 Int::Int(RValue<Int2> cast)
3713 {
3714 *this = Extract(cast, 0);
3715 }
3716
3717 Int::Int(RValue<Long> cast)
3718 {
3719 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3720
3721 storeValue(integer);
3722 }
3723
3724 Int::Int(RValue<Float> cast)
3725 {
3726 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3727
3728 storeValue(integer);
3729 }
3730
3731 Int::Int()
3732 {
3733 }
3734
3735 Int::Int(int x)
3736 {
3737 storeValue(Nucleus::createConstantInt(x));
3738 }
3739
3740 Int::Int(RValue<Int> rhs)
3741 {
3742 storeValue(rhs.value);
3743 }
3744
3745 Int::Int(RValue<UInt> rhs)
3746 {
3747 storeValue(rhs.value);
3748 }
3749
3750 Int::Int(const Int &rhs)
3751 {
3752 Value *value = rhs.loadValue();
3753 storeValue(value);
3754 }
3755
3756 Int::Int(const Reference<Int> &rhs)
3757 {
3758 Value *value = rhs.loadValue();
3759 storeValue(value);
3760 }
3761
3762 Int::Int(const UInt &rhs)
3763 {
3764 Value *value = rhs.loadValue();
3765 storeValue(value);
3766 }
3767
3768 Int::Int(const Reference<UInt> &rhs)
3769 {
3770 Value *value = rhs.loadValue();
3771 storeValue(value);
3772 }
3773
3774 RValue<Int> Int::operator=(int rhs) const
3775 {
3776 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
3777 }
3778
3779 RValue<Int> Int::operator=(RValue<Int> rhs) const
3780 {
3781 storeValue(rhs.value);
3782
3783 return rhs;
3784 }
3785
3786 RValue<Int> Int::operator=(RValue<UInt> rhs) const
3787 {
3788 storeValue(rhs.value);
3789
3790 return RValue<Int>(rhs);
3791 }
3792
3793 RValue<Int> Int::operator=(const Int &rhs) const
3794 {
3795 Value *value = rhs.loadValue();
3796 storeValue(value);
3797
3798 return RValue<Int>(value);
3799 }
3800
3801 RValue<Int> Int::operator=(const Reference<Int> &rhs) const
3802 {
3803 Value *value = rhs.loadValue();
3804 storeValue(value);
3805
3806 return RValue<Int>(value);
3807 }
3808
3809 RValue<Int> Int::operator=(const UInt &rhs) const
3810 {
3811 Value *value = rhs.loadValue();
3812 storeValue(value);
3813
3814 return RValue<Int>(value);
3815 }
3816
3817 RValue<Int> Int::operator=(const Reference<UInt> &rhs) const
3818 {
3819 Value *value = rhs.loadValue();
3820 storeValue(value);
3821
3822 return RValue<Int>(value);
3823 }
3824
3825 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
3826 {
3827 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3828 }
3829
3830 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
3831 {
3832 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3833 }
3834
3835 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
3836 {
3837 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3838 }
3839
3840 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
3841 {
3842 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3843 }
3844
3845 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
3846 {
3847 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3848 }
3849
3850 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
3851 {
3852 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3853 }
3854
3855 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
3856 {
3857 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3858 }
3859
3860 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
3861 {
3862 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
3863 }
3864
3865 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
3866 {
3867 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
3868 }
3869
3870 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
3871 {
3872 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
3873 }
3874
3875 RValue<Int> operator+=(const Int &lhs, RValue<Int> rhs)
3876 {
3877 return lhs = lhs + rhs;
3878 }
3879
3880 RValue<Int> operator-=(const Int &lhs, RValue<Int> rhs)
3881 {
3882 return lhs = lhs - rhs;
3883 }
3884
3885 RValue<Int> operator*=(const Int &lhs, RValue<Int> rhs)
3886 {
3887 return lhs = lhs * rhs;
3888 }
3889
3890 RValue<Int> operator/=(const Int &lhs, RValue<Int> rhs)
3891 {
3892 return lhs = lhs / rhs;
3893 }
3894
3895 RValue<Int> operator%=(const Int &lhs, RValue<Int> rhs)
3896 {
3897 return lhs = lhs % rhs;
3898 }
3899
3900 RValue<Int> operator&=(const Int &lhs, RValue<Int> rhs)
3901 {
3902 return lhs = lhs & rhs;
3903 }
3904
3905 RValue<Int> operator|=(const Int &lhs, RValue<Int> rhs)
3906 {
3907 return lhs = lhs | rhs;
3908 }
3909
3910 RValue<Int> operator^=(const Int &lhs, RValue<Int> rhs)
3911 {
3912 return lhs = lhs ^ rhs;
3913 }
3914
3915 RValue<Int> operator<<=(const Int &lhs, RValue<Int> rhs)
3916 {
3917 return lhs = lhs << rhs;
3918 }
3919
3920 RValue<Int> operator>>=(const Int &lhs, RValue<Int> rhs)
3921 {
3922 return lhs = lhs >> rhs;
3923 }
3924
3925 RValue<Int> operator+(RValue<Int> val)
3926 {
3927 return val;
3928 }
3929
3930 RValue<Int> operator-(RValue<Int> val)
3931 {
3932 return RValue<Int>(Nucleus::createNeg(val.value));
3933 }
3934
3935 RValue<Int> operator~(RValue<Int> val)
3936 {
3937 return RValue<Int>(Nucleus::createNot(val.value));
3938 }
3939
3940 RValue<Int> operator++(const Int &val, int) // Post-increment
3941 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003942 RValue<UInt> res = val;
3943 val += 1;
3944 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003945 }
3946
3947 const Int &operator++(const Int &val) // Pre-increment
3948 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003949 val += 1;
3950 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003951 }
3952
3953 RValue<Int> operator--(const Int &val, int) // Post-decrement
3954 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003955 RValue<Int> res = val;
3956 val -= 1;
3957 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003958 }
3959
3960 const Int &operator--(const Int &val) // Pre-decrement
3961 {
Nicolas Capensd1229402016-11-07 16:05:22 -05003962 val -= 1;
3963 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003964 }
3965
3966 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
3967 {
3968 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
3969 }
3970
3971 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
3972 {
3973 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
3974 }
3975
3976 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
3977 {
3978 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
3979 }
3980
3981 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
3982 {
3983 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
3984 }
3985
3986 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
3987 {
3988 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
3989 }
3990
3991 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
3992 {
3993 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
3994 }
3995
3996 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
3997 {
3998 return IfThenElse(x > y, x, y);
3999 }
4000
4001 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4002 {
4003 return IfThenElse(x < y, x, y);
4004 }
4005
4006 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4007 {
4008 return Min(Max(x, min), max);
4009 }
4010
4011 RValue<Int> RoundInt(RValue<Float> cast)
4012 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004013 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004014 }
4015
4016 Type *Int::getType()
4017 {
4018 return T(Ice::IceType_i32);
4019 }
4020
4021 Long::Long(RValue<Int> cast)
4022 {
4023 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4024
4025 storeValue(integer);
4026 }
4027
4028 Long::Long(RValue<UInt> cast)
4029 {
4030 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4031
4032 storeValue(integer);
4033 }
4034
4035 Long::Long()
4036 {
4037 }
4038
4039 Long::Long(RValue<Long> rhs)
4040 {
4041 storeValue(rhs.value);
4042 }
4043
4044 RValue<Long> Long::operator=(int64_t rhs) const
4045 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004046 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004047 }
4048
4049 RValue<Long> Long::operator=(RValue<Long> rhs) const
4050 {
4051 storeValue(rhs.value);
4052
4053 return rhs;
4054 }
4055
4056 RValue<Long> Long::operator=(const Long &rhs) const
4057 {
4058 Value *value = rhs.loadValue();
4059 storeValue(value);
4060
4061 return RValue<Long>(value);
4062 }
4063
4064 RValue<Long> Long::operator=(const Reference<Long> &rhs) const
4065 {
4066 Value *value = rhs.loadValue();
4067 storeValue(value);
4068
4069 return RValue<Long>(value);
4070 }
4071
4072 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
4073 {
4074 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4075 }
4076
4077 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
4078 {
4079 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4080 }
4081
4082 RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs)
4083 {
4084 return lhs = lhs + rhs;
4085 }
4086
4087 RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs)
4088 {
4089 return lhs = lhs - rhs;
4090 }
4091
4092 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
4093 {
4094 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
4095 }
4096
4097 Type *Long::getType()
4098 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004099 return T(Ice::IceType_i64);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004100 }
4101
4102 Long1::Long1(const RValue<UInt> cast)
4103 {
4104 assert(false && "UNIMPLEMENTED");
4105 }
4106
4107 Long1::Long1(RValue<Long1> rhs)
4108 {
4109 storeValue(rhs.value);
4110 }
4111
4112 Type *Long1::getType()
4113 {
4114 assert(false && "UNIMPLEMENTED"); return nullptr;
4115 }
4116
Nicolas Capens598f8d82016-09-26 15:09:10 -04004117 UInt::UInt(Argument<UInt> argument)
4118 {
4119 storeValue(argument.value);
4120 }
4121
4122 UInt::UInt(RValue<UShort> cast)
4123 {
4124 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4125
4126 storeValue(integer);
4127 }
4128
4129 UInt::UInt(RValue<Long> cast)
4130 {
4131 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4132
4133 storeValue(integer);
4134 }
4135
4136 UInt::UInt(RValue<Float> cast)
4137 {
4138 assert(false && "UNIMPLEMENTED");
4139 }
4140
4141 UInt::UInt()
4142 {
4143 }
4144
4145 UInt::UInt(int x)
4146 {
4147 storeValue(Nucleus::createConstantInt(x));
4148 }
4149
4150 UInt::UInt(unsigned int x)
4151 {
4152 storeValue(Nucleus::createConstantInt(x));
4153 }
4154
4155 UInt::UInt(RValue<UInt> rhs)
4156 {
4157 storeValue(rhs.value);
4158 }
4159
4160 UInt::UInt(RValue<Int> rhs)
4161 {
4162 storeValue(rhs.value);
4163 }
4164
4165 UInt::UInt(const UInt &rhs)
4166 {
4167 Value *value = rhs.loadValue();
4168 storeValue(value);
4169 }
4170
4171 UInt::UInt(const Reference<UInt> &rhs)
4172 {
4173 Value *value = rhs.loadValue();
4174 storeValue(value);
4175 }
4176
4177 UInt::UInt(const Int &rhs)
4178 {
4179 Value *value = rhs.loadValue();
4180 storeValue(value);
4181 }
4182
4183 UInt::UInt(const Reference<Int> &rhs)
4184 {
4185 Value *value = rhs.loadValue();
4186 storeValue(value);
4187 }
4188
4189 RValue<UInt> UInt::operator=(unsigned int rhs) const
4190 {
4191 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
4192 }
4193
4194 RValue<UInt> UInt::operator=(RValue<UInt> rhs) const
4195 {
4196 storeValue(rhs.value);
4197
4198 return rhs;
4199 }
4200
4201 RValue<UInt> UInt::operator=(RValue<Int> rhs) const
4202 {
4203 storeValue(rhs.value);
4204
4205 return RValue<UInt>(rhs);
4206 }
4207
4208 RValue<UInt> UInt::operator=(const UInt &rhs) const
4209 {
4210 Value *value = rhs.loadValue();
4211 storeValue(value);
4212
4213 return RValue<UInt>(value);
4214 }
4215
4216 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const
4217 {
4218 Value *value = rhs.loadValue();
4219 storeValue(value);
4220
4221 return RValue<UInt>(value);
4222 }
4223
4224 RValue<UInt> UInt::operator=(const Int &rhs) const
4225 {
4226 Value *value = rhs.loadValue();
4227 storeValue(value);
4228
4229 return RValue<UInt>(value);
4230 }
4231
4232 RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const
4233 {
4234 Value *value = rhs.loadValue();
4235 storeValue(value);
4236
4237 return RValue<UInt>(value);
4238 }
4239
4240 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
4241 {
4242 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4243 }
4244
4245 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
4246 {
4247 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4248 }
4249
4250 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
4251 {
4252 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4253 }
4254
4255 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
4256 {
4257 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4258 }
4259
4260 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
4261 {
4262 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4263 }
4264
4265 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
4266 {
4267 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4268 }
4269
4270 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
4271 {
4272 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4273 }
4274
4275 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
4276 {
4277 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4278 }
4279
4280 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
4281 {
4282 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4283 }
4284
4285 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
4286 {
4287 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4288 }
4289
4290 RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs)
4291 {
4292 return lhs = lhs + rhs;
4293 }
4294
4295 RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs)
4296 {
4297 return lhs = lhs - rhs;
4298 }
4299
4300 RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs)
4301 {
4302 return lhs = lhs * rhs;
4303 }
4304
4305 RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs)
4306 {
4307 return lhs = lhs / rhs;
4308 }
4309
4310 RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs)
4311 {
4312 return lhs = lhs % rhs;
4313 }
4314
4315 RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs)
4316 {
4317 return lhs = lhs & rhs;
4318 }
4319
4320 RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs)
4321 {
4322 return lhs = lhs | rhs;
4323 }
4324
4325 RValue<UInt> operator^=(const UInt &lhs, RValue<UInt> rhs)
4326 {
4327 return lhs = lhs ^ rhs;
4328 }
4329
4330 RValue<UInt> operator<<=(const UInt &lhs, RValue<UInt> rhs)
4331 {
4332 return lhs = lhs << rhs;
4333 }
4334
4335 RValue<UInt> operator>>=(const UInt &lhs, RValue<UInt> rhs)
4336 {
4337 return lhs = lhs >> rhs;
4338 }
4339
4340 RValue<UInt> operator+(RValue<UInt> val)
4341 {
4342 return val;
4343 }
4344
4345 RValue<UInt> operator-(RValue<UInt> val)
4346 {
4347 return RValue<UInt>(Nucleus::createNeg(val.value));
4348 }
4349
4350 RValue<UInt> operator~(RValue<UInt> val)
4351 {
4352 return RValue<UInt>(Nucleus::createNot(val.value));
4353 }
4354
4355 RValue<UInt> operator++(const UInt &val, int) // Post-increment
4356 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004357 RValue<UInt> res = val;
4358 val += 1;
4359 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004360 }
4361
4362 const UInt &operator++(const UInt &val) // Pre-increment
4363 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004364 val += 1;
4365 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004366 }
4367
4368 RValue<UInt> operator--(const UInt &val, int) // Post-decrement
4369 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004370 RValue<UInt> res = val;
4371 val -= 1;
4372 return res;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004373 }
4374
4375 const UInt &operator--(const UInt &val) // Pre-decrement
4376 {
Nicolas Capensd1229402016-11-07 16:05:22 -05004377 val -= 1;
4378 return val;
Nicolas Capens598f8d82016-09-26 15:09:10 -04004379 }
4380
4381 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4382 {
4383 return IfThenElse(x > y, x, y);
4384 }
4385
4386 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4387 {
4388 return IfThenElse(x < y, x, y);
4389 }
4390
4391 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4392 {
4393 return Min(Max(x, min), max);
4394 }
4395
4396 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
4397 {
4398 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4399 }
4400
4401 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
4402 {
4403 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4404 }
4405
4406 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
4407 {
4408 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4409 }
4410
4411 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
4412 {
4413 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4414 }
4415
4416 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
4417 {
4418 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4419 }
4420
4421 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
4422 {
4423 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4424 }
4425
4426// RValue<UInt> RoundUInt(RValue<Float> cast)
4427// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004428// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004429// }
4430
4431 Type *UInt::getType()
4432 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004433 return T(Ice::IceType_i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004434 }
4435
4436// Int2::Int2(RValue<Int> cast)
4437// {
4438// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4439// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
4440//
4441// Constant *shuffle[2];
4442// shuffle[0] = Nucleus::createConstantInt(0);
4443// shuffle[1] = Nucleus::createConstantInt(0);
4444//
4445// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4446//
4447// storeValue(replicate);
4448// }
4449
4450 Int2::Int2(RValue<Int4> cast)
4451 {
Nicolas Capens22008782016-10-20 01:11:47 -04004452 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004453 }
4454
4455 Int2::Int2()
4456 {
4457 // xy.parent = this;
4458 }
4459
4460 Int2::Int2(int x, int y)
4461 {
4462 // xy.parent = this;
4463
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004464 int64_t constantVector[2] = {x, y};
4465 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004466 }
4467
4468 Int2::Int2(RValue<Int2> rhs)
4469 {
4470 // xy.parent = this;
4471
4472 storeValue(rhs.value);
4473 }
4474
4475 Int2::Int2(const Int2 &rhs)
4476 {
4477 // xy.parent = this;
4478
4479 Value *value = rhs.loadValue();
4480 storeValue(value);
4481 }
4482
4483 Int2::Int2(const Reference<Int2> &rhs)
4484 {
4485 // xy.parent = this;
4486
4487 Value *value = rhs.loadValue();
4488 storeValue(value);
4489 }
4490
4491 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4492 {
4493 assert(false && "UNIMPLEMENTED");
4494 }
4495
4496 RValue<Int2> Int2::operator=(RValue<Int2> rhs) const
4497 {
4498 storeValue(rhs.value);
4499
4500 return rhs;
4501 }
4502
4503 RValue<Int2> Int2::operator=(const Int2 &rhs) const
4504 {
4505 Value *value = rhs.loadValue();
4506 storeValue(value);
4507
4508 return RValue<Int2>(value);
4509 }
4510
4511 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const
4512 {
4513 Value *value = rhs.loadValue();
4514 storeValue(value);
4515
4516 return RValue<Int2>(value);
4517 }
4518
4519 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
4520 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004521 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004522 }
4523
4524 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
4525 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004526 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004527 }
4528
4529// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4530// {
4531// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4532// }
4533
4534// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4535// {
4536// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4537// }
4538
4539// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4540// {
4541// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4542// }
4543
4544 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
4545 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004546 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004547 }
4548
4549 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
4550 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004551 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004552 }
4553
4554 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
4555 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004556 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004557 }
4558
4559 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
4560 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004561 return RValue<Int2>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004562 }
4563
4564 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
4565 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004566 return RValue<Int2>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004567 }
4568
4569 RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs)
4570 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004571 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004572 }
4573
4574 RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs)
4575 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004576 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004577 }
4578
4579 RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs)
4580 {
4581 return lhs = lhs + rhs;
4582 }
4583
4584 RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs)
4585 {
4586 return lhs = lhs - rhs;
4587 }
4588
4589// RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs)
4590// {
4591// return lhs = lhs * rhs;
4592// }
4593
4594// RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs)
4595// {
4596// return lhs = lhs / rhs;
4597// }
4598
4599// RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs)
4600// {
4601// return lhs = lhs % rhs;
4602// }
4603
4604 RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs)
4605 {
4606 return lhs = lhs & rhs;
4607 }
4608
4609 RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs)
4610 {
4611 return lhs = lhs | rhs;
4612 }
4613
4614 RValue<Int2> operator^=(const Int2 &lhs, RValue<Int2> rhs)
4615 {
4616 return lhs = lhs ^ rhs;
4617 }
4618
4619 RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs)
4620 {
4621 return lhs = lhs << rhs;
4622 }
4623
4624 RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs)
4625 {
4626 return lhs = lhs >> rhs;
4627 }
4628
4629 RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs)
4630 {
4631 return lhs = lhs << rhs;
4632 }
4633
4634 RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs)
4635 {
4636 return lhs = lhs >> rhs;
4637 }
4638
4639// 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 Capensc37252c2016-09-28 16:11:54 -04004651 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004652 }
4653
4654 RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y)
4655 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004656 assert(false && "UNIMPLEMENTED"); return RValue<Long1>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004657 }
4658
4659 RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
4660 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004661 assert(false && "UNIMPLEMENTED"); return RValue<Long1>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004662 }
4663
4664 RValue<Int> Extract(RValue<Int2> val, int i)
4665 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004666 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004667 }
4668
4669 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4670 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004671 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004672 }
4673
4674 Type *Int2::getType()
4675 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004676 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004677 }
4678
4679 UInt2::UInt2()
4680 {
4681 // xy.parent = this;
4682 }
4683
4684 UInt2::UInt2(unsigned int x, unsigned int y)
4685 {
4686 // xy.parent = this;
4687
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004688 int64_t constantVector[2] = {x, y};
4689 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004690 }
4691
4692 UInt2::UInt2(RValue<UInt2> rhs)
4693 {
4694 // xy.parent = this;
4695
4696 storeValue(rhs.value);
4697 }
4698
4699 UInt2::UInt2(const UInt2 &rhs)
4700 {
4701 // xy.parent = this;
4702
4703 Value *value = rhs.loadValue();
4704 storeValue(value);
4705 }
4706
4707 UInt2::UInt2(const Reference<UInt2> &rhs)
4708 {
4709 // xy.parent = this;
4710
4711 Value *value = rhs.loadValue();
4712 storeValue(value);
4713 }
4714
4715 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const
4716 {
4717 storeValue(rhs.value);
4718
4719 return rhs;
4720 }
4721
4722 RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
4723 {
4724 Value *value = rhs.loadValue();
4725 storeValue(value);
4726
4727 return RValue<UInt2>(value);
4728 }
4729
4730 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const
4731 {
4732 Value *value = rhs.loadValue();
4733 storeValue(value);
4734
4735 return RValue<UInt2>(value);
4736 }
4737
4738 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
4739 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004740 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004741 }
4742
4743 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
4744 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004745 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004746 }
4747
4748// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4749// {
4750// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4751// }
4752
4753// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4754// {
4755// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4756// }
4757
4758// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4759// {
4760// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4761// }
4762
4763 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
4764 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004765 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004766 }
4767
4768 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
4769 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004770 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004771 }
4772
4773 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
4774 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004775 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004776 }
4777
4778 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
4779 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004780 return RValue<UInt2>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004781 }
4782
4783 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
4784 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004785 return RValue<UInt2>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004786 }
4787
4788 RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs)
4789 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004790 assert(false && "UNIMPLEMENTED"); return RValue<UInt2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004791 }
4792
4793 RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs)
4794 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004795 assert(false && "UNIMPLEMENTED"); return RValue<UInt2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004796 }
4797
4798 RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs)
4799 {
4800 return lhs = lhs + rhs;
4801 }
4802
4803 RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs)
4804 {
4805 return lhs = lhs - rhs;
4806 }
4807
4808// RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs)
4809// {
4810// return lhs = lhs * rhs;
4811// }
4812
4813// RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs)
4814// {
4815// return lhs = lhs / rhs;
4816// }
4817
4818// RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs)
4819// {
4820// return lhs = lhs % rhs;
4821// }
4822
4823 RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs)
4824 {
4825 return lhs = lhs & rhs;
4826 }
4827
4828 RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs)
4829 {
4830 return lhs = lhs | rhs;
4831 }
4832
4833 RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs)
4834 {
4835 return lhs = lhs ^ rhs;
4836 }
4837
4838 RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
4839 {
4840 return lhs = lhs << rhs;
4841 }
4842
4843 RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
4844 {
4845 return lhs = lhs >> rhs;
4846 }
4847
4848 RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs)
4849 {
4850 return lhs = lhs << rhs;
4851 }
4852
4853 RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs)
4854 {
4855 return lhs = lhs >> rhs;
4856 }
4857
4858// RValue<UInt2> operator+(RValue<UInt2> val)
4859// {
4860// return val;
4861// }
4862
4863// RValue<UInt2> operator-(RValue<UInt2> val)
4864// {
4865// return RValue<UInt2>(Nucleus::createNeg(val.value));
4866// }
4867
4868 RValue<UInt2> operator~(RValue<UInt2> val)
4869 {
4870 return RValue<UInt2>(Nucleus::createNot(val.value));
4871 }
4872
4873 Type *UInt2::getType()
4874 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004875 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004876 }
4877
4878 Int4::Int4(RValue<Byte4> cast)
4879 {
4880 assert(false && "UNIMPLEMENTED");
4881 }
4882
4883 Int4::Int4(RValue<SByte4> cast)
4884 {
4885 assert(false && "UNIMPLEMENTED");
4886 }
4887
4888 Int4::Int4(RValue<Float4> cast)
4889 {
4890 // xyzw.parent = this;
4891
4892 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
4893
4894 storeValue(xyzw);
4895 }
4896
4897 Int4::Int4(RValue<Short4> cast)
4898 {
4899 assert(false && "UNIMPLEMENTED");
4900 }
4901
4902 Int4::Int4(RValue<UShort4> cast)
4903 {
4904 assert(false && "UNIMPLEMENTED");
4905 }
4906
4907 Int4::Int4()
4908 {
4909 // xyzw.parent = this;
4910 }
4911
4912 Int4::Int4(int xyzw)
4913 {
4914 constant(xyzw, xyzw, xyzw, xyzw);
4915 }
4916
4917 Int4::Int4(int x, int yzw)
4918 {
4919 constant(x, yzw, yzw, yzw);
4920 }
4921
4922 Int4::Int4(int x, int y, int zw)
4923 {
4924 constant(x, y, zw, zw);
4925 }
4926
4927 Int4::Int4(int x, int y, int z, int w)
4928 {
4929 constant(x, y, z, w);
4930 }
4931
4932 void Int4::constant(int x, int y, int z, int w)
4933 {
4934 // xyzw.parent = this;
4935
Nicolas Capens13ac2322016-10-13 14:52:12 -04004936 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004937 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004938 }
4939
4940 Int4::Int4(RValue<Int4> rhs)
4941 {
4942 // xyzw.parent = this;
4943
4944 storeValue(rhs.value);
4945 }
4946
4947 Int4::Int4(const Int4 &rhs)
4948 {
4949 // xyzw.parent = this;
4950
4951 Value *value = rhs.loadValue();
4952 storeValue(value);
4953 }
4954
4955 Int4::Int4(const Reference<Int4> &rhs)
4956 {
4957 // xyzw.parent = this;
4958
4959 Value *value = rhs.loadValue();
4960 storeValue(value);
4961 }
4962
4963 Int4::Int4(RValue<UInt4> rhs)
4964 {
4965 // xyzw.parent = this;
4966
4967 storeValue(rhs.value);
4968 }
4969
4970 Int4::Int4(const UInt4 &rhs)
4971 {
4972 // xyzw.parent = this;
4973
4974 Value *value = rhs.loadValue();
4975 storeValue(value);
4976 }
4977
4978 Int4::Int4(const Reference<UInt4> &rhs)
4979 {
4980 // xyzw.parent = this;
4981
4982 Value *value = rhs.loadValue();
4983 storeValue(value);
4984 }
4985
4986 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
4987 {
4988 assert(false && "UNIMPLEMENTED");
4989 }
4990
4991 Int4::Int4(RValue<Int> rhs)
4992 {
4993 // xyzw.parent = this;
4994
4995 assert(false && "UNIMPLEMENTED");
4996 }
4997
4998 Int4::Int4(const Int &rhs)
4999 {
5000 // xyzw.parent = this;
5001
5002 *this = RValue<Int>(rhs.loadValue());
5003 }
5004
5005 Int4::Int4(const Reference<Int> &rhs)
5006 {
5007 // xyzw.parent = this;
5008
5009 *this = RValue<Int>(rhs.loadValue());
5010 }
5011
5012 RValue<Int4> Int4::operator=(RValue<Int4> rhs) const
5013 {
5014 storeValue(rhs.value);
5015
5016 return rhs;
5017 }
5018
5019 RValue<Int4> Int4::operator=(const Int4 &rhs) const
5020 {
5021 Value *value = rhs.loadValue();
5022 storeValue(value);
5023
5024 return RValue<Int4>(value);
5025 }
5026
5027 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const
5028 {
5029 Value *value = rhs.loadValue();
5030 storeValue(value);
5031
5032 return RValue<Int4>(value);
5033 }
5034
5035 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
5036 {
5037 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5038 }
5039
5040 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
5041 {
5042 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5043 }
5044
5045 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
5046 {
5047 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5048 }
5049
5050 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5051 {
5052 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5053 }
5054
5055 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5056 {
5057 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5058 }
5059
5060 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
5061 {
5062 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5063 }
5064
5065 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
5066 {
5067 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5068 }
5069
5070 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
5071 {
5072 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5073 }
5074
5075 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
5076 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005077 return RValue<Int4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005078 }
5079
5080 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
5081 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005082 return RValue<Int4>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005083 }
5084
5085 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5086 {
5087 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5088 }
5089
5090 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5091 {
5092 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5093 }
5094
5095 RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs)
5096 {
5097 return lhs = lhs + rhs;
5098 }
5099
5100 RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs)
5101 {
5102 return lhs = lhs - rhs;
5103 }
5104
5105 RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs)
5106 {
5107 return lhs = lhs * rhs;
5108 }
5109
5110// RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs)
5111// {
5112// return lhs = lhs / rhs;
5113// }
5114
5115// RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs)
5116// {
5117// return lhs = lhs % rhs;
5118// }
5119
5120 RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs)
5121 {
5122 return lhs = lhs & rhs;
5123 }
5124
5125 RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs)
5126 {
5127 return lhs = lhs | rhs;
5128 }
5129
5130 RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs)
5131 {
5132 return lhs = lhs ^ rhs;
5133 }
5134
5135 RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
5136 {
5137 return lhs = lhs << rhs;
5138 }
5139
5140 RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
5141 {
5142 return lhs = lhs >> rhs;
5143 }
5144
5145 RValue<Int4> operator+(RValue<Int4> val)
5146 {
5147 return val;
5148 }
5149
5150 RValue<Int4> operator-(RValue<Int4> val)
5151 {
5152 return RValue<Int4>(Nucleus::createNeg(val.value));
5153 }
5154
5155 RValue<Int4> operator~(RValue<Int4> val)
5156 {
5157 return RValue<Int4>(Nucleus::createNot(val.value));
5158 }
5159
5160 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5161 {
5162 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5163 }
5164
5165 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5166 {
5167 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
5168 }
5169
5170 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5171 {
5172 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
5173 }
5174
5175 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5176 {
5177 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5178 }
5179
5180 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5181 {
5182 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
5183 }
5184
5185 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5186 {
5187 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
5188 }
5189
5190 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5191 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005192 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5193 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
5194 ::basicBlock->appendInst(cmp);
5195
5196 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5197 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5198 ::basicBlock->appendInst(select);
5199
5200 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005201 }
5202
5203 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5204 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005205 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5206 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
5207 ::basicBlock->appendInst(cmp);
5208
5209 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5210 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5211 ::basicBlock->appendInst(select);
5212
5213 return RValue<Int4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005214 }
5215
5216 RValue<Int4> RoundInt(RValue<Float4> cast)
5217 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005218 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005219 }
5220
5221 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
5222 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005223 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5224 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5225 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5226 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5227 pack->addArg(x.value);
5228 pack->addArg(y.value);
5229 ::basicBlock->appendInst(pack);
5230
5231 return RValue<Short8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005232 }
5233
5234 RValue<Int> Extract(RValue<Int4> x, int i)
5235 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005236 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005237 }
5238
5239 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
5240 {
5241 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5242 }
5243
5244 RValue<Int> SignMask(RValue<Int4> x)
5245 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04005246 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
5247 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5248 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5249 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5250 movmsk->addArg(x.value);
5251 ::basicBlock->appendInst(movmsk);
5252
5253 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005254 }
5255
5256 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
5257 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005258 return RValue<Int4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005259 }
5260
5261 Type *Int4::getType()
5262 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04005263 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005264 }
5265
5266 UInt4::UInt4(RValue<Float4> cast)
5267 {
5268 // xyzw.parent = this;
5269
5270 assert(false && "UNIMPLEMENTED");
5271 }
5272
5273 UInt4::UInt4()
5274 {
5275 // xyzw.parent = this;
5276 }
5277
5278 UInt4::UInt4(int xyzw)
5279 {
5280 constant(xyzw, xyzw, xyzw, xyzw);
5281 }
5282
5283 UInt4::UInt4(int x, int yzw)
5284 {
5285 constant(x, yzw, yzw, yzw);
5286 }
5287
5288 UInt4::UInt4(int x, int y, int zw)
5289 {
5290 constant(x, y, zw, zw);
5291 }
5292
5293 UInt4::UInt4(int x, int y, int z, int w)
5294 {
5295 constant(x, y, z, w);
5296 }
5297
5298 void UInt4::constant(int x, int y, int z, int w)
5299 {
5300 // xyzw.parent = this;
5301
Nicolas Capens13ac2322016-10-13 14:52:12 -04005302 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005303 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005304 }
5305
5306 UInt4::UInt4(RValue<UInt4> rhs)
5307 {
5308 // xyzw.parent = this;
5309
5310 storeValue(rhs.value);
5311 }
5312
5313 UInt4::UInt4(const UInt4 &rhs)
5314 {
5315 // xyzw.parent = this;
5316
5317 Value *value = rhs.loadValue();
5318 storeValue(value);
5319 }
5320
5321 UInt4::UInt4(const Reference<UInt4> &rhs)
5322 {
5323 // xyzw.parent = this;
5324
5325 Value *value = rhs.loadValue();
5326 storeValue(value);
5327 }
5328
5329 UInt4::UInt4(RValue<Int4> rhs)
5330 {
5331 // xyzw.parent = this;
5332
5333 storeValue(rhs.value);
5334 }
5335
5336 UInt4::UInt4(const Int4 &rhs)
5337 {
5338 // xyzw.parent = this;
5339
5340 Value *value = rhs.loadValue();
5341 storeValue(value);
5342 }
5343
5344 UInt4::UInt4(const Reference<Int4> &rhs)
5345 {
5346 // xyzw.parent = this;
5347
5348 Value *value = rhs.loadValue();
5349 storeValue(value);
5350 }
5351
5352 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5353 {
5354 assert(false && "UNIMPLEMENTED");
5355 }
5356
5357 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const
5358 {
5359 storeValue(rhs.value);
5360
5361 return rhs;
5362 }
5363
5364 RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
5365 {
5366 Value *value = rhs.loadValue();
5367 storeValue(value);
5368
5369 return RValue<UInt4>(value);
5370 }
5371
5372 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const
5373 {
5374 Value *value = rhs.loadValue();
5375 storeValue(value);
5376
5377 return RValue<UInt4>(value);
5378 }
5379
5380 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
5381 {
5382 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5383 }
5384
5385 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
5386 {
5387 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5388 }
5389
5390 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
5391 {
5392 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5393 }
5394
5395 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5396 {
5397 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5398 }
5399
5400 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5401 {
5402 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5403 }
5404
5405 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
5406 {
5407 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5408 }
5409
5410 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
5411 {
5412 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5413 }
5414
5415 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
5416 {
5417 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5418 }
5419
5420 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
5421 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005422 return RValue<UInt4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005423 }
5424
5425 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
5426 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005427 return RValue<UInt4>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005428 }
5429
5430 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5431 {
5432 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5433 }
5434
5435 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5436 {
5437 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5438 }
5439
5440 RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs)
5441 {
5442 return lhs = lhs + rhs;
5443 }
5444
5445 RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs)
5446 {
5447 return lhs = lhs - rhs;
5448 }
5449
5450 RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs)
5451 {
5452 return lhs = lhs * rhs;
5453 }
5454
5455// RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs)
5456// {
5457// return lhs = lhs / rhs;
5458// }
5459
5460// RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs)
5461// {
5462// return lhs = lhs % rhs;
5463// }
5464
5465 RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs)
5466 {
5467 return lhs = lhs & rhs;
5468 }
5469
5470 RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs)
5471 {
5472 return lhs = lhs | rhs;
5473 }
5474
5475 RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs)
5476 {
5477 return lhs = lhs ^ rhs;
5478 }
5479
5480 RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
5481 {
5482 return lhs = lhs << rhs;
5483 }
5484
5485 RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
5486 {
5487 return lhs = lhs >> rhs;
5488 }
5489
5490 RValue<UInt4> operator+(RValue<UInt4> val)
5491 {
5492 return val;
5493 }
5494
5495 RValue<UInt4> operator-(RValue<UInt4> val)
5496 {
5497 return RValue<UInt4>(Nucleus::createNeg(val.value));
5498 }
5499
5500 RValue<UInt4> operator~(RValue<UInt4> val)
5501 {
5502 return RValue<UInt4>(Nucleus::createNot(val.value));
5503 }
5504
5505 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5506 {
5507 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5508 }
5509
5510 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5511 {
5512 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5513 }
5514
5515 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5516 {
5517 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5518 }
5519
5520 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5521 {
5522 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5523 }
5524
5525 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5526 {
5527 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5528 }
5529
5530 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5531 {
5532 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5533 }
5534
5535 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5536 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005537 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5538 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
5539 ::basicBlock->appendInst(cmp);
5540
5541 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5542 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5543 ::basicBlock->appendInst(select);
5544
5545 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005546 }
5547
5548 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5549 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04005550 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5551 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
5552 ::basicBlock->appendInst(cmp);
5553
5554 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5555 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5556 ::basicBlock->appendInst(select);
5557
5558 return RValue<UInt4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005559 }
5560
5561 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
5562 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005563 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5564 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5565 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5566 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5567 pack->addArg(x.value);
5568 pack->addArg(y.value);
5569 ::basicBlock->appendInst(pack);
5570
5571 return RValue<UShort8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005572 }
5573
5574 Type *UInt4::getType()
5575 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005576 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005577 }
5578
5579 Float::Float(RValue<Int> cast)
5580 {
5581 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5582
5583 storeValue(integer);
5584 }
5585
5586 Float::Float()
5587 {
5588 }
5589
5590 Float::Float(float x)
5591 {
5592 storeValue(Nucleus::createConstantFloat(x));
5593 }
5594
5595 Float::Float(RValue<Float> rhs)
5596 {
5597 storeValue(rhs.value);
5598 }
5599
5600 Float::Float(const Float &rhs)
5601 {
5602 Value *value = rhs.loadValue();
5603 storeValue(value);
5604 }
5605
5606 Float::Float(const Reference<Float> &rhs)
5607 {
5608 Value *value = rhs.loadValue();
5609 storeValue(value);
5610 }
5611
5612 RValue<Float> Float::operator=(RValue<Float> rhs) const
5613 {
5614 storeValue(rhs.value);
5615
5616 return rhs;
5617 }
5618
5619 RValue<Float> Float::operator=(const Float &rhs) const
5620 {
5621 Value *value = rhs.loadValue();
5622 storeValue(value);
5623
5624 return RValue<Float>(value);
5625 }
5626
5627 RValue<Float> Float::operator=(const Reference<Float> &rhs) const
5628 {
5629 Value *value = rhs.loadValue();
5630 storeValue(value);
5631
5632 return RValue<Float>(value);
5633 }
5634
5635 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
5636 {
5637 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5638 }
5639
5640 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
5641 {
5642 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5643 }
5644
5645 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
5646 {
5647 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5648 }
5649
5650 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
5651 {
5652 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5653 }
5654
5655 RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs)
5656 {
5657 return lhs = lhs + rhs;
5658 }
5659
5660 RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs)
5661 {
5662 return lhs = lhs - rhs;
5663 }
5664
5665 RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs)
5666 {
5667 return lhs = lhs * rhs;
5668 }
5669
5670 RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs)
5671 {
5672 return lhs = lhs / rhs;
5673 }
5674
5675 RValue<Float> operator+(RValue<Float> val)
5676 {
5677 return val;
5678 }
5679
5680 RValue<Float> operator-(RValue<Float> val)
5681 {
5682 return RValue<Float>(Nucleus::createFNeg(val.value));
5683 }
5684
5685 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
5686 {
5687 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5688 }
5689
5690 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
5691 {
5692 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5693 }
5694
5695 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
5696 {
5697 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5698 }
5699
5700 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
5701 {
5702 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5703 }
5704
5705 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
5706 {
5707 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5708 }
5709
5710 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
5711 {
5712 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5713 }
5714
5715 RValue<Float> Abs(RValue<Float> x)
5716 {
5717 return IfThenElse(x > 0.0f, x, -x);
5718 }
5719
5720 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
5721 {
5722 return IfThenElse(x > y, x, y);
5723 }
5724
5725 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
5726 {
5727 return IfThenElse(x < y, x, y);
5728 }
5729
5730 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
5731 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005732 return 1.0f / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04005733 }
5734
5735 RValue<Float> RcpSqrt_pp(RValue<Float> x)
5736 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005737 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005738 }
5739
5740 RValue<Float> Sqrt(RValue<Float> x)
5741 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04005742 Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32);
5743 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5744 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5745 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5746 sqrt->addArg(x.value);
5747 ::basicBlock->appendInst(sqrt);
5748
5749 return RValue<Float>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005750 }
5751
5752 RValue<Float> Round(RValue<Float> x)
5753 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005754 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005755 }
5756
5757 RValue<Float> Trunc(RValue<Float> x)
5758 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005759 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005760 }
5761
5762 RValue<Float> Frac(RValue<Float> x)
5763 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005764 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005765 }
5766
5767 RValue<Float> Floor(RValue<Float> x)
5768 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005769 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005770 }
5771
5772 RValue<Float> Ceil(RValue<Float> x)
5773 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005774 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005775 }
5776
5777 Type *Float::getType()
5778 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04005779 return T(Ice::IceType_f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005780 }
5781
5782 Float2::Float2(RValue<Float4> cast)
5783 {
Nicolas Capens22008782016-10-20 01:11:47 -04005784 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005785 }
5786
5787 Type *Float2::getType()
5788 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005789 return T(Type_v2f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005790 }
5791
5792 Float4::Float4(RValue<Byte4> cast)
5793 {
5794 xyzw.parent = this;
5795
5796 assert(false && "UNIMPLEMENTED");
5797 }
5798
5799 Float4::Float4(RValue<SByte4> cast)
5800 {
5801 xyzw.parent = this;
5802
5803 assert(false && "UNIMPLEMENTED");
5804 }
5805
5806 Float4::Float4(RValue<Short4> cast)
5807 {
5808 xyzw.parent = this;
5809
5810 Int4 c(cast);
5811 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5812 }
5813
5814 Float4::Float4(RValue<UShort4> cast)
5815 {
5816 xyzw.parent = this;
5817
5818 Int4 c(cast);
5819 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5820 }
5821
5822 Float4::Float4(RValue<Int4> cast)
5823 {
5824 xyzw.parent = this;
5825
5826 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
5827
5828 storeValue(xyzw);
5829 }
5830
5831 Float4::Float4(RValue<UInt4> cast)
5832 {
5833 xyzw.parent = this;
5834
5835 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
5836
5837 storeValue(xyzw);
5838 }
5839
5840 Float4::Float4()
5841 {
5842 xyzw.parent = this;
5843 }
5844
5845 Float4::Float4(float xyzw)
5846 {
5847 constant(xyzw, xyzw, xyzw, xyzw);
5848 }
5849
5850 Float4::Float4(float x, float yzw)
5851 {
5852 constant(x, yzw, yzw, yzw);
5853 }
5854
5855 Float4::Float4(float x, float y, float zw)
5856 {
5857 constant(x, y, zw, zw);
5858 }
5859
5860 Float4::Float4(float x, float y, float z, float w)
5861 {
5862 constant(x, y, z, w);
5863 }
5864
5865 void Float4::constant(float x, float y, float z, float w)
5866 {
5867 xyzw.parent = this;
5868
Nicolas Capens13ac2322016-10-13 14:52:12 -04005869 double constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005870 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005871 }
5872
5873 Float4::Float4(RValue<Float4> rhs)
5874 {
5875 xyzw.parent = this;
5876
5877 storeValue(rhs.value);
5878 }
5879
5880 Float4::Float4(const Float4 &rhs)
5881 {
5882 xyzw.parent = this;
5883
5884 Value *value = rhs.loadValue();
5885 storeValue(value);
5886 }
5887
5888 Float4::Float4(const Reference<Float4> &rhs)
5889 {
5890 xyzw.parent = this;
5891
5892 Value *value = rhs.loadValue();
5893 storeValue(value);
5894 }
5895
5896 Float4::Float4(RValue<Float> rhs)
5897 {
5898 xyzw.parent = this;
5899
5900 assert(false && "UNIMPLEMENTED");
5901 }
5902
5903 Float4::Float4(const Float &rhs)
5904 {
5905 xyzw.parent = this;
5906
5907 *this = RValue<Float>(rhs.loadValue());
5908 }
5909
5910 Float4::Float4(const Reference<Float> &rhs)
5911 {
5912 xyzw.parent = this;
5913
5914 *this = RValue<Float>(rhs.loadValue());
5915 }
5916
5917 RValue<Float4> Float4::operator=(float x) const
5918 {
5919 return *this = Float4(x, x, x, x);
5920 }
5921
5922 RValue<Float4> Float4::operator=(RValue<Float4> rhs) const
5923 {
5924 storeValue(rhs.value);
5925
5926 return rhs;
5927 }
5928
5929 RValue<Float4> Float4::operator=(const Float4 &rhs) const
5930 {
5931 Value *value = rhs.loadValue();
5932 storeValue(value);
5933
5934 return RValue<Float4>(value);
5935 }
5936
5937 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const
5938 {
5939 Value *value = rhs.loadValue();
5940 storeValue(value);
5941
5942 return RValue<Float4>(value);
5943 }
5944
5945 RValue<Float4> Float4::operator=(RValue<Float> rhs) const
5946 {
5947 return *this = Float4(rhs);
5948 }
5949
5950 RValue<Float4> Float4::operator=(const Float &rhs) const
5951 {
5952 return *this = Float4(rhs);
5953 }
5954
5955 RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const
5956 {
5957 return *this = Float4(rhs);
5958 }
5959
5960 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
5961 {
5962 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
5963 }
5964
5965 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
5966 {
5967 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
5968 }
5969
5970 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
5971 {
5972 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
5973 }
5974
5975 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
5976 {
5977 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
5978 }
5979
5980 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
5981 {
5982 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
5983 }
5984
5985 RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs)
5986 {
5987 return lhs = lhs + rhs;
5988 }
5989
5990 RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs)
5991 {
5992 return lhs = lhs - rhs;
5993 }
5994
5995 RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs)
5996 {
5997 return lhs = lhs * rhs;
5998 }
5999
6000 RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs)
6001 {
6002 return lhs = lhs / rhs;
6003 }
6004
6005 RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs)
6006 {
6007 return lhs = lhs % rhs;
6008 }
6009
6010 RValue<Float4> operator+(RValue<Float4> val)
6011 {
6012 return val;
6013 }
6014
6015 RValue<Float4> operator-(RValue<Float4> val)
6016 {
6017 return RValue<Float4>(Nucleus::createFNeg(val.value));
6018 }
6019
6020 RValue<Float4> Abs(RValue<Float4> x)
6021 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006022 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006023 }
6024
6025 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
6026 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006027 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6028 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ule, condition, x.value, y.value);
6029 ::basicBlock->appendInst(cmp);
6030
6031 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6032 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
6033 ::basicBlock->appendInst(select);
6034
6035 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006036 }
6037
6038 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
6039 {
Nicolas Capens53a8a3f2016-10-26 00:23:12 -04006040 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6041 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ugt, condition, x.value, y.value);
6042 ::basicBlock->appendInst(cmp);
6043
6044 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6045 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
6046 ::basicBlock->appendInst(select);
6047
6048 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006049 }
6050
6051 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
6052 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006053 return Float4(1.0f) / x;
Nicolas Capens598f8d82016-09-26 15:09:10 -04006054 }
6055
6056 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
6057 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006058 return Rcp_pp(Sqrt(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006059 }
6060
6061 RValue<Float4> Sqrt(RValue<Float4> x)
6062 {
Nicolas Capensd52e9362016-10-31 23:23:15 -04006063 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6064 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6065 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6066 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6067 sqrt->addArg(x.value);
6068 ::basicBlock->appendInst(sqrt);
6069
6070 return RValue<Float4>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006071 }
6072
6073 RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i)
6074 {
6075 Value *value = val.loadValue();
6076 Value *insert = Nucleus::createInsertElement(value, element.value, i);
6077
6078 val = RValue<Float4>(insert);
6079
6080 return val;
6081 }
6082
6083 RValue<Float> Extract(RValue<Float4> x, int i)
6084 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006085 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006086 }
6087
6088 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
6089 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006090 return RValue<Float4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006091 }
6092
6093 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
6094 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006095 int shuffle[4] =
6096 {
6097 ((imm >> 0) & 0x03) + 0,
6098 ((imm >> 2) & 0x03) + 0,
6099 ((imm >> 4) & 0x03) + 4,
6100 ((imm >> 6) & 0x03) + 4,
6101 };
6102
6103 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006104 }
6105
6106 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
6107 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006108 int shuffle[4] = {0, 4, 1, 5};
6109 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006110 }
6111
6112 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
6113 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006114 int shuffle[4] = {2, 6, 3, 7};
6115 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006116 }
6117
6118 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
6119 {
6120 Value *vector = lhs.loadValue();
Nicolas Capense95d5342016-09-30 11:37:28 -04006121 Value *shuffle = createMask4(vector, rhs.value, select);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006122 lhs.storeValue(shuffle);
6123
6124 return RValue<Float4>(shuffle);
6125 }
6126
6127 RValue<Int> SignMask(RValue<Float4> x)
6128 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04006129 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
6130 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6131 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6132 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6133 movmsk->addArg(x.value);
6134 ::basicBlock->appendInst(movmsk);
6135
6136 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006137 }
6138
6139 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
6140 {
6141 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
6142 }
6143
6144 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
6145 {
6146 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
6147 }
6148
6149 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
6150 {
6151 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
6152 }
6153
6154 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
6155 {
6156 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
6157 }
6158
6159 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
6160 {
6161 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
6162 }
6163
6164 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
6165 {
6166 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
6167 }
6168
6169 RValue<Float4> Round(RValue<Float4> x)
6170 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006171 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006172 }
6173
6174 RValue<Float4> Trunc(RValue<Float4> x)
6175 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006176 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006177 }
6178
6179 RValue<Float4> Frac(RValue<Float4> x)
6180 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006181 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006182 }
6183
6184 RValue<Float4> Floor(RValue<Float4> x)
6185 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006186 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006187 }
6188
6189 RValue<Float4> Ceil(RValue<Float4> x)
6190 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006191 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006192 }
6193
6194 Type *Float4::getType()
6195 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04006196 return T(Ice::IceType_v4f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006197 }
6198
6199 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
6200 {
Nicolas Capens8820f642016-09-30 04:42:43 -04006201 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006202 }
6203
6204 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6205 {
Nicolas Capens6d738712016-09-30 04:15:22 -04006206 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006207 }
6208
6209 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6210 {
Nicolas Capens6d738712016-09-30 04:15:22 -04006211 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006212 }
6213
6214 RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
6215 {
6216 return lhs = lhs + offset;
6217 }
6218
6219 RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
6220 {
6221 return lhs = lhs + offset;
6222 }
6223
6224 RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
6225 {
6226 return lhs = lhs + offset;
6227 }
6228
6229 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
6230 {
6231 return lhs + -offset;
6232 }
6233
6234 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6235 {
6236 return lhs + -offset;
6237 }
6238
6239 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6240 {
6241 return lhs + -offset;
6242 }
6243
6244 RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset)
6245 {
6246 return lhs = lhs - offset;
6247 }
6248
6249 RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
6250 {
6251 return lhs = lhs - offset;
6252 }
6253
6254 RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
6255 {
6256 return lhs = lhs - offset;
6257 }
6258
6259 void Return()
6260 {
6261 Nucleus::createRetVoid();
6262 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6263 Nucleus::createUnreachable();
6264 }
6265
6266 void Return(bool ret)
6267 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006268 Nucleus::createRet(Nucleus::createConstantInt(ret));
6269 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6270 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006271 }
6272
6273 void Return(const Int &ret)
6274 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006275 Nucleus::createRet(ret.loadValue());
6276 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6277 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006278 }
6279
Nicolas Capens598f8d82016-09-26 15:09:10 -04006280 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
6281 {
6282 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
6283 Nucleus::setInsertBlock(bodyBB);
6284
6285 return true;
6286 }
6287
Nicolas Capens9ed1a182016-10-24 09:52:23 -04006288 void endIf(BasicBlock *falseBB)
6289 {
6290 ::falseBB = falseBB;
6291 }
6292
Nicolas Capens598f8d82016-09-26 15:09:10 -04006293 bool elseBlock(BasicBlock *falseBB)
6294 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -04006295 assert(falseBB && "Else not preceded by If");
6296 falseBB->getInsts().back().setDeleted();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006297 Nucleus::setInsertBlock(falseBB);
6298
6299 return true;
6300 }
6301
Nicolas Capens9ed1a182016-10-24 09:52:23 -04006302 BasicBlock *beginElse()
6303 {
6304 BasicBlock *falseBB = ::falseBB;
6305 ::falseBB = nullptr;
6306
6307 return falseBB;
6308 }
6309
Nicolas Capens598f8d82016-09-26 15:09:10 -04006310 RValue<Long> Ticks()
6311 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006312 assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006313 }
6314}
6315