blob: c15ea8e38f391c2d17b07f9ffd6827b3b684acdc [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
248 assert(sizeof(void*) == 8 ? elfHeader->e_machine == EM_X86_64 : elfHeader->e_machine == EM_386);
249
Nicolas Capens598f8d82016-09-26 15:09:10 -0400250 SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff);
251 void *entry = nullptr;
252
253 for(int i = 0; i < elfHeader->e_shnum; i++)
254 {
Nicolas Capens66478362016-10-13 15:36:36 -0400255 if(sectionHeader[i].sh_type == SHT_PROGBITS)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400256 {
Nicolas Capens66478362016-10-13 15:36:36 -0400257 if(sectionHeader[i].sh_flags & SHF_EXECINSTR)
258 {
259 entry = elfImage + sectionHeader[i].sh_offset;
260 }
261 }
262 else if(sectionHeader[i].sh_type == SHT_REL)
263 {
264 assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code
265
266 for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
267 {
268 const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index];
269 void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]);
270 }
271 }
272 else if(sectionHeader[i].sh_type == SHT_RELA)
273 {
274 assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code
275
276 for(int index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
277 {
278 const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index];
279 void *symbol = relocateSymbol(elfHeader, relocation, sectionHeader[i]);
280 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400281 }
282 }
283
284 return entry;
285 }
286
287 template<typename T>
288 struct ExecutableAllocator
289 {
290 ExecutableAllocator() {};
291 template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {};
292
293 using value_type = T;
294 using size_type = std::size_t;
295
296 T *allocate(size_type n)
297 {
298 return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
299 }
300
301 void deallocate(T *p, size_type n)
302 {
303 VirtualFree(p, 0, MEM_RELEASE);
304 }
305 };
306
307 class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine
308 {
309 ELFMemoryStreamer(const ELFMemoryStreamer &) = delete;
310 ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete;
311
312 public:
Nicolas Capens58274b52016-10-19 23:45:19 -0400313 ELFMemoryStreamer() : Routine(), entry(nullptr)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400314 {
315 position = 0;
316 buffer.reserve(0x1000);
317 }
318
319 virtual ~ELFMemoryStreamer()
320 {
321 if(buffer.size() != 0)
322 {
323 DWORD exeProtection;
324 VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection);
325 }
326 }
327
328 void write8(uint8_t Value) override
329 {
330 if(position == (uint64_t)buffer.size())
331 {
332 buffer.push_back(Value);
333 position++;
334 }
335 else if(position < (uint64_t)buffer.size())
336 {
337 buffer[position] = Value;
338 position++;
339 }
340 else assert(false && "UNIMPLEMENTED");
341 }
342
343 void writeBytes(llvm::StringRef Bytes) override
344 {
345 std::size_t oldSize = buffer.size();
346 buffer.resize(oldSize + Bytes.size());
347 memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size());
348 position += Bytes.size();
349 }
350
351 uint64_t tell() const override { return position; }
352
353 void seek(uint64_t Off) override { position = Off; }
354
355 const void *getEntry() override
356 {
Nicolas Capens58274b52016-10-19 23:45:19 -0400357 if(!entry)
358 {
359 VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READWRITE, &oldProtection);
360 position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this
Nicolas Capens598f8d82016-09-26 15:09:10 -0400361
Nicolas Capens58274b52016-10-19 23:45:19 -0400362 entry = loadImage(&buffer[0]);
363 }
364
365 return entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400366 }
367
368 private:
Nicolas Capens58274b52016-10-19 23:45:19 -0400369 void *entry;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400370 std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer;
371 std::size_t position;
372 DWORD oldProtection;
373 };
374
375 Nucleus::Nucleus()
376 {
377 ::codegenMutex.lock(); // Reactor is currently not thread safe
378
Nicolas Capens66478362016-10-13 15:36:36 -0400379 Ice::ClFlags &Flags = Ice::ClFlags::Flags;
380 Ice::ClFlags::getParsedClFlags(Flags);
381
382 Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632);
383 Flags.setOutFileType(Ice::FT_Elf);
384 Flags.setOptLevel(Ice::Opt_2);
385 Flags.setApplicationBinaryInterface(Ice::ABI_Platform);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400386
387 std::unique_ptr<Ice::Ostream> cout(new llvm::raw_os_ostream(std::cout));
388
389 if(false) // Write out to a file
390 {
391 std::error_code errorCode;
392 ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None);
393 ::elfFile = new Ice::ELFFileStreamer(*out);
394 ::context = new Ice::GlobalContext(cout.get(), cout.get(), cout.get(), elfFile);
395 }
396 else
397 {
398 ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer();
399 ::context = new Ice::GlobalContext(cout.get(), cout.get(), cout.get(), elfMemory);
400 ::routine = elfMemory;
401 }
402 }
403
404 Nucleus::~Nucleus()
405 {
406 delete ::allocator;
407 delete ::function;
408 delete ::context;
409
410 delete ::elfFile;
411 delete ::out;
412
413 ::codegenMutex.unlock();
414 }
415
416 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
417 {
418 if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
419 {
420 createRetVoid();
421 }
422
423 std::wstring wideName(name);
424 std::string asciiName(wideName.begin(), wideName.end());
425 ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
426
427 ::function->translate();
Nicolas Capensde19f392016-10-19 10:29:49 -0400428 assert(!::function->hasError());
429
Nicolas Capens66478362016-10-13 15:36:36 -0400430 auto *globals = ::function->getGlobalInits().release();
431
432 if(globals && !globals->empty())
433 {
434 ::context->getGlobals()->merge(globals);
435 }
Nicolas Capens598f8d82016-09-26 15:09:10 -0400436
437 ::context->emitFileHeader();
438 ::function->emitIAS();
439 auto assembler = ::function->releaseAssembler();
Nicolas Capens66478362016-10-13 15:36:36 -0400440 auto objectWriter = ::context->getObjectWriter();
441 assembler->alignFunction();
442 objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
443 ::context->lowerGlobals("last");
Nicolas Capens73dd7a22016-10-20 13:20:34 -0400444 ::context->lowerConstants();
Nicolas Capens66478362016-10-13 15:36:36 -0400445 objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
446 objectWriter->writeNonUserSections();
Nicolas Capens598f8d82016-09-26 15:09:10 -0400447
448 return ::routine;
449 }
450
451 void Nucleus::optimize()
452 {
453 }
454
455 Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
456 {
457 Ice::Type type = T(t);
Nicolas Capensa8f98632016-10-20 11:25:55 -0400458 int typeSize = Ice::typeWidthInBytes(type);
459 int totalSize = typeSize * (arraySize ? arraySize : 1);
Nicolas Capense12780d2016-09-27 14:18:07 -0400460
Nicolas Capensa8f98632016-10-20 11:25:55 -0400461 auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400462 auto address = ::function->makeVariable(T(getPointerType(t)));
Nicolas Capensa8f98632016-10-20 11:25:55 -0400463 auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize);
Nicolas Capense12780d2016-09-27 14:18:07 -0400464 ::function->getEntryNode()->getInsts().push_front(alloca);
465
466 return V(address);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400467 }
468
469 BasicBlock *Nucleus::createBasicBlock()
470 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400471 return B(::function->makeNode());
Nicolas Capens598f8d82016-09-26 15:09:10 -0400472 }
473
474 BasicBlock *Nucleus::getInsertBlock()
475 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400476 return B(::basicBlock);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400477 }
478
479 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
480 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -0400481 // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator");
Nicolas Capens611642a2016-09-28 16:45:04 -0400482 ::basicBlock = basicBlock;
Nicolas Capens598f8d82016-09-26 15:09:10 -0400483 }
484
Nicolas Capens598f8d82016-09-26 15:09:10 -0400485 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
486 {
487 uint32_t sequenceNumber = 0;
488 ::function = Ice::Cfg::create(::context, sequenceNumber).release();
489 ::allocator = new Ice::CfgLocalAllocatorScope(::function);
490
491 for(Type *type : Params)
492 {
493 Ice::Variable *arg = ::function->makeVariable(T(type));
494 ::function->addArg(arg);
495 }
496
497 Ice::CfgNode *node = ::function->makeNode();
498 ::function->setEntryNode(node);
499 ::basicBlock = node;
500 }
501
502 Value *Nucleus::getArgument(unsigned int index)
503 {
504 return V(::function->getArgs()[index]);
505 }
506
507 void Nucleus::createRetVoid()
508 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400509 Ice::InstRet *ret = Ice::InstRet::create(::function);
510 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400511 }
512
513 void Nucleus::createRet(Value *v)
514 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -0400515 Ice::InstRet *ret = Ice::InstRet::create(::function, v);
516 ::basicBlock->appendInst(ret);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400517 }
518
519 void Nucleus::createBr(BasicBlock *dest)
520 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400521 auto br = Ice::InstBr::create(::function, dest);
522 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400523 }
524
525 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
526 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400527 auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse);
528 ::basicBlock->appendInst(br);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400529 }
530
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400531 static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
532 {
Nicolas Capens327f1df2016-10-21 14:26:34 -0400533 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 -0400534
535 Ice::Variable *result = ::function->makeVariable(lhs->getType());
536 Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, lhs, rhs);
537 ::basicBlock->appendInst(arithmetic);
538
539 return V(result);
540 }
541
Nicolas Capens598f8d82016-09-26 15:09:10 -0400542 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
543 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400544 return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400545 }
546
547 Value *Nucleus::createSub(Value *lhs, Value *rhs)
548 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400549 return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400550 }
551
552 Value *Nucleus::createMul(Value *lhs, Value *rhs)
553 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400554 return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400555 }
556
557 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
558 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400559 return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400560 }
561
562 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
563 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400564 return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400565 }
566
567 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
568 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400569 return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400570 }
571
572 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
573 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400574 return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400575 }
576
577 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
578 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400579 return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400580 }
581
582 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
583 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400584 return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400585 }
586
587 Value *Nucleus::createURem(Value *lhs, Value *rhs)
588 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400589 return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400590 }
591
592 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
593 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400594 return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400595 }
596
597 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
598 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400599 return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400600 }
601
602 Value *Nucleus::createShl(Value *lhs, Value *rhs)
603 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400604 return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400605 }
606
607 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
608 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400609 return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400610 }
611
612 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
613 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400614 return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400615 }
616
617 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
618 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400619 return createArithmetic(Ice::InstArithmetic::And, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400620 }
621
622 Value *Nucleus::createOr(Value *lhs, Value *rhs)
623 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400624 return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400625 }
626
627 Value *Nucleus::createXor(Value *lhs, Value *rhs)
628 {
Nicolas Capens7d9f76d2016-09-29 13:39:44 -0400629 return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400630 }
631
Nicolas Capens13ac2322016-10-13 14:52:12 -0400632 static Value *createAssign(Ice::Constant *constant)
Nicolas Capensb955d5b2016-09-28 22:36:28 -0400633 {
634 Ice::Variable *value = ::function->makeVariable(constant->getType());
635 auto assign = Ice::InstAssign::create(::function, value, constant);
636 ::basicBlock->appendInst(assign);
637
638 return V(value);
639 }
640
Nicolas Capens598f8d82016-09-26 15:09:10 -0400641 Value *Nucleus::createNeg(Value *v)
642 {
643 assert(false && "UNIMPLEMENTED"); return nullptr;
644 }
645
646 Value *Nucleus::createFNeg(Value *v)
647 {
648 assert(false && "UNIMPLEMENTED"); return nullptr;
649 }
650
651 Value *Nucleus::createNot(Value *v)
652 {
653 assert(false && "UNIMPLEMENTED"); return nullptr;
654 }
655
Nicolas Capense12780d2016-09-27 14:18:07 -0400656 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400657 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400658 int valueType = (int)reinterpret_cast<intptr_t>(type);
659 Ice::Variable *result = ::function->makeVariable(T(type));
660
661 if(valueType & EmulatedBits)
662 {
663 switch(valueType)
664 {
665 case Type_v4i8:
666 case Type_v2i16:
667 {
668 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
669 auto target = ::context->getConstantUndef(Ice::IceType_i32);
670 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
671 load->addArg(::context->getConstantInt32(4));
672 load->addArg(ptr);
673 ::basicBlock->appendInst(load);
674 }
675 break;
676 case Type_v2i32:
677 case Type_v8i8:
678 case Type_v4i16:
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400679 case Type_v2f32:
Nicolas Capens23d99a42016-09-30 14:57:16 -0400680 {
681 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
682 auto target = ::context->getConstantUndef(Ice::IceType_i32);
683 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
684 load->addArg(::context->getConstantInt32(8));
685 load->addArg(ptr);
686 ::basicBlock->appendInst(load);
687 }
688 break;
689 default: assert(false && "UNIMPLEMENTED");
690 }
691 }
692 else
693 {
694 auto load = Ice::InstLoad::create(::function, result, ptr, align);
695 ::basicBlock->appendInst(load);
696 }
697
698 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400699 }
700
Nicolas Capens6d738712016-09-30 04:15:22 -0400701 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400702 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400703 int valueType = (int)reinterpret_cast<intptr_t>(type);
704
705 if(valueType & EmulatedBits)
706 {
707 switch(valueType)
708 {
709 case Type_v4i8:
710 case Type_v2i16:
711 {
712 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
713 auto target = ::context->getConstantUndef(Ice::IceType_i32);
714 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
715 store->addArg(::context->getConstantInt32(4));
716 store->addArg(value);
717 store->addArg(ptr);
718 ::basicBlock->appendInst(store);
719 }
720 break;
721 case Type_v2i32:
722 case Type_v8i8:
723 case Type_v4i16:
Nicolas Capens4cfd4572016-10-20 01:00:19 -0400724 case Type_v2f32:
Nicolas Capens23d99a42016-09-30 14:57:16 -0400725 {
726 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
727 auto target = ::context->getConstantUndef(Ice::IceType_i32);
728 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
729 store->addArg(::context->getConstantInt32(8));
730 store->addArg(value);
731 store->addArg(ptr);
732 ::basicBlock->appendInst(store);
733 }
734 break;
735 default: assert(false && "UNIMPLEMENTED");
736 }
737 }
738 else
739 {
740 assert(T(value->getType()) == type);
741
742 auto store = Ice::InstStore::create(::function, value, ptr, align);
743 ::basicBlock->appendInst(store);
744 }
745
Nicolas Capens598f8d82016-09-26 15:09:10 -0400746 return value;
747 }
748
Nicolas Capens6d738712016-09-30 04:15:22 -0400749 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400750 {
Nicolas Capens8820f642016-09-30 04:42:43 -0400751 assert(index->getType() == Ice::IceType_i32);
752
753 if(!Ice::isByteSizedType(T(type)))
754 {
Nicolas Capens13ac2322016-10-13 14:52:12 -0400755 index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type))));
Nicolas Capens8820f642016-09-30 04:42:43 -0400756 }
757
758 if(sizeof(void*) == 8)
759 {
760 index = createSExt(index, T(Ice::IceType_i64));
761 }
762
763 return createAdd(ptr, index);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400764 }
765
766 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
767 {
768 assert(false && "UNIMPLEMENTED"); return nullptr;
769 }
770
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400771 static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType)
772 {
Nicolas Capens23d99a42016-09-30 14:57:16 -0400773 if(v->getType() == T(destType))
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400774 {
775 return v;
776 }
777
778 Ice::Variable *result = ::function->makeVariable(T(destType));
779 Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v);
780 ::basicBlock->appendInst(cast);
781
782 return V(result);
783 }
784
Nicolas Capens598f8d82016-09-26 15:09:10 -0400785 Value *Nucleus::createTrunc(Value *v, Type *destType)
786 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400787 return createCast(Ice::InstCast::Trunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400788 }
789
790 Value *Nucleus::createZExt(Value *v, Type *destType)
791 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400792 return createCast(Ice::InstCast::Zext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400793 }
794
795 Value *Nucleus::createSExt(Value *v, Type *destType)
796 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400797 return createCast(Ice::InstCast::Sext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400798 }
799
800 Value *Nucleus::createFPToSI(Value *v, Type *destType)
801 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400802 return createCast(Ice::InstCast::Fptosi, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400803 }
804
805 Value *Nucleus::createUIToFP(Value *v, Type *destType)
806 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400807 return createCast(Ice::InstCast::Uitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400808 }
809
810 Value *Nucleus::createSIToFP(Value *v, Type *destType)
811 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400812 return createCast(Ice::InstCast::Sitofp, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400813 }
814
815 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
816 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400817 return createCast(Ice::InstCast::Fptrunc, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400818 }
819
820 Value *Nucleus::createFPExt(Value *v, Type *destType)
821 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400822 return createCast(Ice::InstCast::Fpext, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400823 }
824
825 Value *Nucleus::createBitCast(Value *v, Type *destType)
826 {
Nicolas Capensa0c2fc52016-09-30 05:04:21 -0400827 return createCast(Ice::InstCast::Bitcast, v, destType);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400828 }
829
830 Value *Nucleus::createIntCast(Value *v, Type *destType, bool isSigned)
831 {
832 assert(false && "UNIMPLEMENTED"); return nullptr;
833 }
834
Nicolas Capens43dc6292016-10-20 00:01:38 -0400835 static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400836 {
Nicolas Capens611642a2016-09-28 16:45:04 -0400837 assert(lhs->getType() == rhs->getType());
838
Nicolas Capens43dc6292016-10-20 00:01:38 -0400839 auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType());
840 auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs);
Nicolas Capens611642a2016-09-28 16:45:04 -0400841 ::basicBlock->appendInst(cmp);
842
843 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400844 }
845
Nicolas Capens43dc6292016-10-20 00:01:38 -0400846 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
847 {
848 return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs);
849 }
850
851 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
852 {
853 return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs);
854 }
855
856 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
857 {
858 return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs);
859 }
860
861 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
862 {
863 return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs);
864 }
865
866 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
867 {
868 return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs);
869 }
870
871 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
872 {
873 return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs);
874 }
875
876 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
877 {
878 return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs);
879 }
880
881 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
882 {
883 return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs);
884 }
885
886 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
887 {
888 return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs);
889 }
890
Nicolas Capens598f8d82016-09-26 15:09:10 -0400891 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
892 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400893 return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs);
894 }
895
896 static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs)
897 {
898 assert(lhs->getType() == rhs->getType());
899 assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32);
900
901 auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32);
902 auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs);
903 ::basicBlock->appendInst(cmp);
904
905 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400906 }
907
908 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
909 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400910 return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400911 }
912
913 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
914 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400915 return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400916 }
917
918 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
919 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400920 return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400921 }
922
923 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
924 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400925 return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400926 }
927
928 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
929 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400930 return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400931 }
932
933 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
934 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400935 return createFloatCompare(Ice::InstFcmp::One, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400936 }
937
938 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
939 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400940 return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400941 }
942
943 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
944 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400945 return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400946 }
947
948 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
949 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400950 return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400951 }
952
953 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
954 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400955 return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400956 }
957
958 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
959 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400960 return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400961 }
962
963 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
964 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400965 return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400966 }
967
968 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
969 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400970 return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400971 }
972
973 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
974 {
Nicolas Capens43dc6292016-10-20 00:01:38 -0400975 return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400976 }
977
Nicolas Capense95d5342016-09-30 11:37:28 -0400978 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400979 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -0400980 auto result = ::function->makeVariable(T(type));
981 auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index));
982 ::basicBlock->appendInst(extract);
983
984 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400985 }
986
987 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
988 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -0400989 auto result = ::function->makeVariable(vector->getType());
990 auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index));
991 ::basicBlock->appendInst(insert);
992
993 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -0400994 }
995
Nicolas Capense89cd582016-09-30 14:23:47 -0400996 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
Nicolas Capens598f8d82016-09-26 15:09:10 -0400997 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -0400998 assert(V1->getType() == V2->getType());
999
1000 int size = Ice::typeNumElements(V1->getType());
1001 auto result = ::function->makeVariable(V1->getType());
1002 auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2);
1003
1004 for(int i = 0; i < size; i++)
1005 {
1006 shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i])));
1007 }
1008
1009 ::basicBlock->appendInst(shuffle);
1010
1011 return V(result);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001012 }
1013
1014 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
1015 {
1016 assert(false && "UNIMPLEMENTED"); return nullptr;
1017 }
1018
1019 Value *Nucleus::createSwitch(Value *v, BasicBlock *Dest, unsigned NumCases)
1020 {
1021 assert(false && "UNIMPLEMENTED"); return nullptr;
1022 }
1023
1024 void Nucleus::addSwitchCase(Value *Switch, int Case, BasicBlock *Branch)
1025 {
1026 assert(false && "UNIMPLEMENTED"); return;
1027 }
1028
1029 void Nucleus::createUnreachable()
1030 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04001031 Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function);
1032 ::basicBlock->appendInst(unreachable);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001033 }
1034
Nicolas Capense95d5342016-09-30 11:37:28 -04001035 static Value *createSwizzle4(Value *val, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001036 {
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001037 int swizzle[4] =
1038 {
1039 (select >> 0) & 0x03,
1040 (select >> 2) & 0x03,
1041 (select >> 4) & 0x03,
1042 (select >> 6) & 0x03,
1043 };
Nicolas Capens9709d4f2016-09-30 11:44:14 -04001044
Nicolas Capens619c0ab2016-09-30 14:46:24 -04001045 return Nucleus::createShuffleVector(val, val, swizzle);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001046 }
1047
Nicolas Capense95d5342016-09-30 11:37:28 -04001048 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001049 {
1050 assert(false && "UNIMPLEMENTED"); return nullptr;
1051 }
1052
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001053 Value *Nucleus::createConstantPointer(const void *address, Type *Ty, unsigned int align)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001054 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001055 if(sizeof(void*) == 8)
1056 {
1057 return createAssign(::context->getConstantInt64(reinterpret_cast<intptr_t>(address)));
1058 }
1059 else
1060 {
1061 return createAssign(::context->getConstantInt32(reinterpret_cast<intptr_t>(address)));
1062 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001063 }
1064
1065 Type *Nucleus::getPointerType(Type *ElementType)
1066 {
Nicolas Capense12780d2016-09-27 14:18:07 -04001067 if(sizeof(void*) == 8)
1068 {
1069 return T(Ice::IceType_i64);
1070 }
1071 else
1072 {
1073 return T(Ice::IceType_i32);
1074 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001075 }
1076
Nicolas Capens13ac2322016-10-13 14:52:12 -04001077 Value *Nucleus::createNullValue(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001078 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001079 if(Ice::isVectorType(T(Ty)))
1080 {
1081 int64_t c[4] = {0, 0, 0, 0};
1082 return createConstantVector(c, Ty);
1083 }
1084 else
1085 {
1086 return createAssign(::context->getConstantZero(T(Ty)));
1087 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001088 }
1089
Nicolas Capens13ac2322016-10-13 14:52:12 -04001090 Value *Nucleus::createConstantLong(int64_t i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001091 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001092 return createAssign(::context->getConstantInt64(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001093 }
1094
Nicolas Capens13ac2322016-10-13 14:52:12 -04001095 Value *Nucleus::createConstantInt(int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001096 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04001097 return createAssign(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001098 }
1099
Nicolas Capens13ac2322016-10-13 14:52:12 -04001100 Value *Nucleus::createConstantInt(unsigned int i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001101 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001102 return createAssign(::context->getConstantInt32(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001103 }
1104
Nicolas Capens13ac2322016-10-13 14:52:12 -04001105 Value *Nucleus::createConstantBool(bool b)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001106 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001107 return createAssign(::context->getConstantInt1(b));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001108 }
1109
Nicolas Capens13ac2322016-10-13 14:52:12 -04001110 Value *Nucleus::createConstantByte(signed char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001111 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001112 return createAssign(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001113 }
1114
Nicolas Capens13ac2322016-10-13 14:52:12 -04001115 Value *Nucleus::createConstantByte(unsigned char i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001116 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001117 return createAssign(::context->getConstantInt8(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001118 }
1119
Nicolas Capens13ac2322016-10-13 14:52:12 -04001120 Value *Nucleus::createConstantShort(short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001121 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001122 return createAssign(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001123 }
1124
Nicolas Capens13ac2322016-10-13 14:52:12 -04001125 Value *Nucleus::createConstantShort(unsigned short i)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001126 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001127 return createAssign(::context->getConstantInt16(i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001128 }
1129
Nicolas Capens13ac2322016-10-13 14:52:12 -04001130 Value *Nucleus::createConstantFloat(float x)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001131 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001132 return createAssign(::context->getConstantFloat(x));
Nicolas Capens598f8d82016-09-26 15:09:10 -04001133 }
1134
Nicolas Capens13ac2322016-10-13 14:52:12 -04001135 Value *Nucleus::createNullPointer(Type *Ty)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001136 {
Nicolas Capens73dd7a22016-10-20 13:20:34 -04001137 if(true)
1138 {
1139 return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
1140 }
1141 else
1142 {
1143 return createConstantPointer(nullptr, Ty);
1144 }
Nicolas Capens598f8d82016-09-26 15:09:10 -04001145 }
1146
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001147 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
Nicolas Capens13ac2322016-10-13 14:52:12 -04001148 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001149 const int vectorSize = 16;
1150 assert(Ice::typeWidthInBytes(T(type)) == vectorSize);
1151 const int alignment = vectorSize;
1152 auto globalPool = ::function->getGlobalPool();
1153
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001154 const int64_t *i = constants;
1155 const double *f = reinterpret_cast<const double*>(constants);
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001156 Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr;
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001157
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001158 switch((int)reinterpret_cast<intptr_t>(type))
1159 {
1160 case Ice::IceType_v4i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001161 {
1162 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]};
1163 static_assert(sizeof(initializer) == vectorSize, "!");
1164 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1165 }
1166 break;
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001167 case Ice::IceType_v4f32:
1168 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001169 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001170 static_assert(sizeof(initializer) == vectorSize, "!");
1171 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1172 }
1173 break;
1174 case Ice::IceType_v8i16:
1175 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001176 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 -04001177 static_assert(sizeof(initializer) == vectorSize, "!");
1178 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1179 }
1180 break;
1181 case Ice::IceType_v16i8:
1182 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001183 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 -04001184 static_assert(sizeof(initializer) == vectorSize, "!");
1185 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1186 }
1187 break;
1188 case Type_v2i32:
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001189 {
1190 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]};
1191 static_assert(sizeof(initializer) == vectorSize, "!");
1192 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1193 }
1194 break;
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001195 case Type_v2f32:
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001196 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001197 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001198 static_assert(sizeof(initializer) == vectorSize, "!");
1199 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1200 }
1201 break;
1202 case Type_v4i16:
1203 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001204 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 -04001205 static_assert(sizeof(initializer) == vectorSize, "!");
1206 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1207 }
1208 break;
1209 case Type_v8i8:
1210 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001211 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 -04001212 static_assert(sizeof(initializer) == vectorSize, "!");
1213 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1214 }
1215 break;
1216 case Type_v4i8:
1217 {
Nicolas Capens7f3f69c2016-10-20 01:29:33 -04001218 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 -04001219 static_assert(sizeof(initializer) == vectorSize, "!");
1220 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1221 }
1222 break;
1223 default:
1224 assert(false && "Unknown constant vector type" && type);
1225 }
1226
1227 auto name = Ice::GlobalString::createWithoutString(::context);
1228 auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool);
1229 variableDeclaration->setName(name);
1230 variableDeclaration->setAlignment(alignment);
1231 variableDeclaration->setIsConstant(true);
1232 variableDeclaration->addInitializer(dataInitializer);
1233
1234 ::function->addGlobal(variableDeclaration);
1235
1236 constexpr int32_t offset = 0;
1237 Ice::Operand *ptr = ::context->getConstantSym(offset, name);
1238
1239 Ice::Variable *result = ::function->makeVariable(T(type));
1240 auto load = Ice::InstLoad::create(::function, result, ptr, alignment);
1241 ::basicBlock->appendInst(load);
1242
1243 return V(result);
Nicolas Capens13ac2322016-10-13 14:52:12 -04001244 }
1245
1246 Value *Nucleus::createConstantVector(const double *constants, Type *type)
Nicolas Capens598f8d82016-09-26 15:09:10 -04001247 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04001248 return createConstantVector((const int64_t*)constants, type);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001249 }
1250
1251 Type *Void::getType()
1252 {
1253 return T(Ice::IceType_void);
1254 }
1255
Nicolas Capens598f8d82016-09-26 15:09:10 -04001256 Bool::Bool(Argument<Bool> argument)
1257 {
1258 storeValue(argument.value);
1259 }
1260
1261 Bool::Bool()
1262 {
1263 }
1264
1265 Bool::Bool(bool x)
1266 {
1267 storeValue(Nucleus::createConstantBool(x));
1268 }
1269
1270 Bool::Bool(RValue<Bool> rhs)
1271 {
1272 storeValue(rhs.value);
1273 }
1274
1275 Bool::Bool(const Bool &rhs)
1276 {
1277 Value *value = rhs.loadValue();
1278 storeValue(value);
1279 }
1280
1281 Bool::Bool(const Reference<Bool> &rhs)
1282 {
1283 Value *value = rhs.loadValue();
1284 storeValue(value);
1285 }
1286
1287 RValue<Bool> Bool::operator=(RValue<Bool> rhs) const
1288 {
1289 storeValue(rhs.value);
1290
1291 return rhs;
1292 }
1293
1294 RValue<Bool> Bool::operator=(const Bool &rhs) const
1295 {
1296 Value *value = rhs.loadValue();
1297 storeValue(value);
1298
1299 return RValue<Bool>(value);
1300 }
1301
1302 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) const
1303 {
1304 Value *value = rhs.loadValue();
1305 storeValue(value);
1306
1307 return RValue<Bool>(value);
1308 }
1309
1310 RValue<Bool> operator!(RValue<Bool> val)
1311 {
1312 return RValue<Bool>(Nucleus::createNot(val.value));
1313 }
1314
1315 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
1316 {
1317 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1318 }
1319
1320 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
1321 {
1322 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1323 }
1324
1325 Type *Bool::getType()
1326 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001327 return T(Ice::IceType_i1);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001328 }
1329
1330 Byte::Byte(Argument<Byte> argument)
1331 {
1332 storeValue(argument.value);
1333 }
1334
1335 Byte::Byte(RValue<Int> cast)
1336 {
1337 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1338
1339 storeValue(integer);
1340 }
1341
1342 Byte::Byte(RValue<UInt> cast)
1343 {
1344 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1345
1346 storeValue(integer);
1347 }
1348
1349 Byte::Byte(RValue<UShort> cast)
1350 {
1351 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1352
1353 storeValue(integer);
1354 }
1355
1356 Byte::Byte()
1357 {
1358 }
1359
1360 Byte::Byte(int x)
1361 {
1362 storeValue(Nucleus::createConstantByte((unsigned char)x));
1363 }
1364
1365 Byte::Byte(unsigned char x)
1366 {
1367 storeValue(Nucleus::createConstantByte(x));
1368 }
1369
1370 Byte::Byte(RValue<Byte> rhs)
1371 {
1372 storeValue(rhs.value);
1373 }
1374
1375 Byte::Byte(const Byte &rhs)
1376 {
1377 Value *value = rhs.loadValue();
1378 storeValue(value);
1379 }
1380
1381 Byte::Byte(const Reference<Byte> &rhs)
1382 {
1383 Value *value = rhs.loadValue();
1384 storeValue(value);
1385 }
1386
1387 RValue<Byte> Byte::operator=(RValue<Byte> rhs) const
1388 {
1389 storeValue(rhs.value);
1390
1391 return rhs;
1392 }
1393
1394 RValue<Byte> Byte::operator=(const Byte &rhs) const
1395 {
1396 Value *value = rhs.loadValue();
1397 storeValue(value);
1398
1399 return RValue<Byte>(value);
1400 }
1401
1402 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) const
1403 {
1404 Value *value = rhs.loadValue();
1405 storeValue(value);
1406
1407 return RValue<Byte>(value);
1408 }
1409
1410 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
1411 {
1412 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1413 }
1414
1415 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
1416 {
1417 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1418 }
1419
1420 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
1421 {
1422 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1423 }
1424
1425 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
1426 {
1427 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1428 }
1429
1430 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
1431 {
1432 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1433 }
1434
1435 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
1436 {
1437 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1438 }
1439
1440 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
1441 {
1442 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1443 }
1444
1445 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
1446 {
1447 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1448 }
1449
1450 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
1451 {
1452 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1453 }
1454
1455 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
1456 {
1457 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1458 }
1459
1460 RValue<Byte> operator+=(const Byte &lhs, RValue<Byte> rhs)
1461 {
1462 return lhs = lhs + rhs;
1463 }
1464
1465 RValue<Byte> operator-=(const Byte &lhs, RValue<Byte> rhs)
1466 {
1467 return lhs = lhs - rhs;
1468 }
1469
1470 RValue<Byte> operator*=(const Byte &lhs, RValue<Byte> rhs)
1471 {
1472 return lhs = lhs * rhs;
1473 }
1474
1475 RValue<Byte> operator/=(const Byte &lhs, RValue<Byte> rhs)
1476 {
1477 return lhs = lhs / rhs;
1478 }
1479
1480 RValue<Byte> operator%=(const Byte &lhs, RValue<Byte> rhs)
1481 {
1482 return lhs = lhs % rhs;
1483 }
1484
1485 RValue<Byte> operator&=(const Byte &lhs, RValue<Byte> rhs)
1486 {
1487 return lhs = lhs & rhs;
1488 }
1489
1490 RValue<Byte> operator|=(const Byte &lhs, RValue<Byte> rhs)
1491 {
1492 return lhs = lhs | rhs;
1493 }
1494
1495 RValue<Byte> operator^=(const Byte &lhs, RValue<Byte> rhs)
1496 {
1497 return lhs = lhs ^ rhs;
1498 }
1499
1500 RValue<Byte> operator<<=(const Byte &lhs, RValue<Byte> rhs)
1501 {
1502 return lhs = lhs << rhs;
1503 }
1504
1505 RValue<Byte> operator>>=(const Byte &lhs, RValue<Byte> rhs)
1506 {
1507 return lhs = lhs >> rhs;
1508 }
1509
1510 RValue<Byte> operator+(RValue<Byte> val)
1511 {
1512 return val;
1513 }
1514
1515 RValue<Byte> operator-(RValue<Byte> val)
1516 {
1517 return RValue<Byte>(Nucleus::createNeg(val.value));
1518 }
1519
1520 RValue<Byte> operator~(RValue<Byte> val)
1521 {
1522 return RValue<Byte>(Nucleus::createNot(val.value));
1523 }
1524
1525 RValue<Byte> operator++(const Byte &val, int) // Post-increment
1526 {
1527 RValue<Byte> res = val;
1528
1529 assert(false && "UNIMPLEMENTED");
1530
1531 return res;
1532 }
1533
1534 const Byte &operator++(const Byte &val) // Pre-increment
1535 {
1536 assert(false && "UNIMPLEMENTED");
1537
1538 return val;
1539 }
1540
1541 RValue<Byte> operator--(const Byte &val, int) // Post-decrement
1542 {
1543 RValue<Byte> res = val;
1544
1545 assert(false && "UNIMPLEMENTED");
1546
1547 return res;
1548 }
1549
1550 const Byte &operator--(const Byte &val) // Pre-decrement
1551 {
1552 assert(false && "UNIMPLEMENTED");
1553
1554 return val;
1555 }
1556
1557 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
1558 {
1559 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1560 }
1561
1562 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
1563 {
1564 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1565 }
1566
1567 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
1568 {
1569 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1570 }
1571
1572 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
1573 {
1574 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1575 }
1576
1577 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
1578 {
1579 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1580 }
1581
1582 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
1583 {
1584 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1585 }
1586
1587 Type *Byte::getType()
1588 {
Nicolas Capens6d738712016-09-30 04:15:22 -04001589 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001590 }
1591
1592 SByte::SByte(Argument<SByte> argument)
1593 {
1594 storeValue(argument.value);
1595 }
1596
1597 SByte::SByte(RValue<Int> cast)
1598 {
1599 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1600
1601 storeValue(integer);
1602 }
1603
1604 SByte::SByte(RValue<Short> cast)
1605 {
1606 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1607
1608 storeValue(integer);
1609 }
1610
1611 SByte::SByte()
1612 {
1613 }
1614
1615 SByte::SByte(signed char x)
1616 {
1617 storeValue(Nucleus::createConstantByte(x));
1618 }
1619
1620 SByte::SByte(RValue<SByte> rhs)
1621 {
1622 storeValue(rhs.value);
1623 }
1624
1625 SByte::SByte(const SByte &rhs)
1626 {
1627 Value *value = rhs.loadValue();
1628 storeValue(value);
1629 }
1630
1631 SByte::SByte(const Reference<SByte> &rhs)
1632 {
1633 Value *value = rhs.loadValue();
1634 storeValue(value);
1635 }
1636
1637 RValue<SByte> SByte::operator=(RValue<SByte> rhs) const
1638 {
1639 storeValue(rhs.value);
1640
1641 return rhs;
1642 }
1643
1644 RValue<SByte> SByte::operator=(const SByte &rhs) const
1645 {
1646 Value *value = rhs.loadValue();
1647 storeValue(value);
1648
1649 return RValue<SByte>(value);
1650 }
1651
1652 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) const
1653 {
1654 Value *value = rhs.loadValue();
1655 storeValue(value);
1656
1657 return RValue<SByte>(value);
1658 }
1659
1660 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
1661 {
1662 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1663 }
1664
1665 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
1666 {
1667 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1668 }
1669
1670 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
1671 {
1672 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1673 }
1674
1675 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
1676 {
1677 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1678 }
1679
1680 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
1681 {
1682 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1683 }
1684
1685 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
1686 {
1687 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1688 }
1689
1690 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
1691 {
1692 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1693 }
1694
1695 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
1696 {
1697 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1698 }
1699
1700 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
1701 {
1702 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1703 }
1704
1705 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
1706 {
1707 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1708 }
1709
1710 RValue<SByte> operator+=(const SByte &lhs, RValue<SByte> rhs)
1711 {
1712 return lhs = lhs + rhs;
1713 }
1714
1715 RValue<SByte> operator-=(const SByte &lhs, RValue<SByte> rhs)
1716 {
1717 return lhs = lhs - rhs;
1718 }
1719
1720 RValue<SByte> operator*=(const SByte &lhs, RValue<SByte> rhs)
1721 {
1722 return lhs = lhs * rhs;
1723 }
1724
1725 RValue<SByte> operator/=(const SByte &lhs, RValue<SByte> rhs)
1726 {
1727 return lhs = lhs / rhs;
1728 }
1729
1730 RValue<SByte> operator%=(const SByte &lhs, RValue<SByte> rhs)
1731 {
1732 return lhs = lhs % rhs;
1733 }
1734
1735 RValue<SByte> operator&=(const SByte &lhs, RValue<SByte> rhs)
1736 {
1737 return lhs = lhs & rhs;
1738 }
1739
1740 RValue<SByte> operator|=(const SByte &lhs, RValue<SByte> rhs)
1741 {
1742 return lhs = lhs | rhs;
1743 }
1744
1745 RValue<SByte> operator^=(const SByte &lhs, RValue<SByte> rhs)
1746 {
1747 return lhs = lhs ^ rhs;
1748 }
1749
1750 RValue<SByte> operator<<=(const SByte &lhs, RValue<SByte> rhs)
1751 {
1752 return lhs = lhs << rhs;
1753 }
1754
1755 RValue<SByte> operator>>=(const SByte &lhs, RValue<SByte> rhs)
1756 {
1757 return lhs = lhs >> rhs;
1758 }
1759
1760 RValue<SByte> operator+(RValue<SByte> val)
1761 {
1762 return val;
1763 }
1764
1765 RValue<SByte> operator-(RValue<SByte> val)
1766 {
1767 return RValue<SByte>(Nucleus::createNeg(val.value));
1768 }
1769
1770 RValue<SByte> operator~(RValue<SByte> val)
1771 {
1772 return RValue<SByte>(Nucleus::createNot(val.value));
1773 }
1774
1775 RValue<SByte> operator++(const SByte &val, int) // Post-increment
1776 {
1777 RValue<SByte> res = val;
1778
1779 assert(false && "UNIMPLEMENTED");
1780
1781 return res;
1782 }
1783
1784 const SByte &operator++(const SByte &val) // Pre-increment
1785 {
1786 assert(false && "UNIMPLEMENTED");
1787 assert(false && "UNIMPLEMENTED");
1788
1789 return val;
1790 }
1791
1792 RValue<SByte> operator--(const SByte &val, int) // Post-decrement
1793 {
1794 RValue<SByte> res = val;
1795
1796 assert(false && "UNIMPLEMENTED");
1797 assert(false && "UNIMPLEMENTED");
1798
1799 return res;
1800 }
1801
1802 const SByte &operator--(const SByte &val) // Pre-decrement
1803 {
1804 assert(false && "UNIMPLEMENTED");
1805 assert(false && "UNIMPLEMENTED");
1806
1807 return val;
1808 }
1809
1810 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
1811 {
1812 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
1813 }
1814
1815 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
1816 {
1817 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
1818 }
1819
1820 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
1821 {
1822 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
1823 }
1824
1825 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
1826 {
1827 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
1828 }
1829
1830 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
1831 {
1832 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1833 }
1834
1835 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
1836 {
1837 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1838 }
1839
1840 Type *SByte::getType()
1841 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04001842 return T(Ice::IceType_i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04001843 }
1844
1845 Short::Short(Argument<Short> argument)
1846 {
1847 storeValue(argument.value);
1848 }
1849
1850 Short::Short(RValue<Int> cast)
1851 {
1852 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
1853
1854 storeValue(integer);
1855 }
1856
1857 Short::Short()
1858 {
1859 }
1860
1861 Short::Short(short x)
1862 {
1863 storeValue(Nucleus::createConstantShort(x));
1864 }
1865
1866 Short::Short(RValue<Short> rhs)
1867 {
1868 storeValue(rhs.value);
1869 }
1870
1871 Short::Short(const Short &rhs)
1872 {
1873 Value *value = rhs.loadValue();
1874 storeValue(value);
1875 }
1876
1877 Short::Short(const Reference<Short> &rhs)
1878 {
1879 Value *value = rhs.loadValue();
1880 storeValue(value);
1881 }
1882
1883 RValue<Short> Short::operator=(RValue<Short> rhs) const
1884 {
1885 storeValue(rhs.value);
1886
1887 return rhs;
1888 }
1889
1890 RValue<Short> Short::operator=(const Short &rhs) const
1891 {
1892 Value *value = rhs.loadValue();
1893 storeValue(value);
1894
1895 return RValue<Short>(value);
1896 }
1897
1898 RValue<Short> Short::operator=(const Reference<Short> &rhs) const
1899 {
1900 Value *value = rhs.loadValue();
1901 storeValue(value);
1902
1903 return RValue<Short>(value);
1904 }
1905
1906 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
1907 {
1908 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
1909 }
1910
1911 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
1912 {
1913 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
1914 }
1915
1916 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
1917 {
1918 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
1919 }
1920
1921 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
1922 {
1923 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
1924 }
1925
1926 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
1927 {
1928 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
1929 }
1930
1931 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
1932 {
1933 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
1934 }
1935
1936 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
1937 {
1938 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
1939 }
1940
1941 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
1942 {
1943 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
1944 }
1945
1946 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
1947 {
1948 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
1949 }
1950
1951 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
1952 {
1953 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
1954 }
1955
1956 RValue<Short> operator+=(const Short &lhs, RValue<Short> rhs)
1957 {
1958 return lhs = lhs + rhs;
1959 }
1960
1961 RValue<Short> operator-=(const Short &lhs, RValue<Short> rhs)
1962 {
1963 return lhs = lhs - rhs;
1964 }
1965
1966 RValue<Short> operator*=(const Short &lhs, RValue<Short> rhs)
1967 {
1968 return lhs = lhs * rhs;
1969 }
1970
1971 RValue<Short> operator/=(const Short &lhs, RValue<Short> rhs)
1972 {
1973 return lhs = lhs / rhs;
1974 }
1975
1976 RValue<Short> operator%=(const Short &lhs, RValue<Short> rhs)
1977 {
1978 return lhs = lhs % rhs;
1979 }
1980
1981 RValue<Short> operator&=(const Short &lhs, RValue<Short> rhs)
1982 {
1983 return lhs = lhs & rhs;
1984 }
1985
1986 RValue<Short> operator|=(const Short &lhs, RValue<Short> rhs)
1987 {
1988 return lhs = lhs | rhs;
1989 }
1990
1991 RValue<Short> operator^=(const Short &lhs, RValue<Short> rhs)
1992 {
1993 return lhs = lhs ^ rhs;
1994 }
1995
1996 RValue<Short> operator<<=(const Short &lhs, RValue<Short> rhs)
1997 {
1998 return lhs = lhs << rhs;
1999 }
2000
2001 RValue<Short> operator>>=(const Short &lhs, RValue<Short> rhs)
2002 {
2003 return lhs = lhs >> rhs;
2004 }
2005
2006 RValue<Short> operator+(RValue<Short> val)
2007 {
2008 return val;
2009 }
2010
2011 RValue<Short> operator-(RValue<Short> val)
2012 {
2013 return RValue<Short>(Nucleus::createNeg(val.value));
2014 }
2015
2016 RValue<Short> operator~(RValue<Short> val)
2017 {
2018 return RValue<Short>(Nucleus::createNot(val.value));
2019 }
2020
2021 RValue<Short> operator++(const Short &val, int) // Post-increment
2022 {
2023 RValue<Short> res = val;
2024
2025 assert(false && "UNIMPLEMENTED");
2026 assert(false && "UNIMPLEMENTED");
2027
2028 return res;
2029 }
2030
2031 const Short &operator++(const Short &val) // Pre-increment
2032 {
2033 assert(false && "UNIMPLEMENTED");
2034 assert(false && "UNIMPLEMENTED");
2035
2036 return val;
2037 }
2038
2039 RValue<Short> operator--(const Short &val, int) // Post-decrement
2040 {
2041 RValue<Short> res = val;
2042
2043 assert(false && "UNIMPLEMENTED");
2044 assert(false && "UNIMPLEMENTED");
2045
2046 return res;
2047 }
2048
2049 const Short &operator--(const Short &val) // Pre-decrement
2050 {
2051 assert(false && "UNIMPLEMENTED");
2052 assert(false && "UNIMPLEMENTED");
2053
2054 return val;
2055 }
2056
2057 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
2058 {
2059 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2060 }
2061
2062 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
2063 {
2064 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2065 }
2066
2067 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
2068 {
2069 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2070 }
2071
2072 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
2073 {
2074 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2075 }
2076
2077 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
2078 {
2079 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2080 }
2081
2082 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
2083 {
2084 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2085 }
2086
2087 Type *Short::getType()
2088 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002089 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002090 }
2091
2092 UShort::UShort(Argument<UShort> argument)
2093 {
2094 storeValue(argument.value);
2095 }
2096
2097 UShort::UShort(RValue<UInt> cast)
2098 {
2099 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2100
2101 storeValue(integer);
2102 }
2103
2104 UShort::UShort(RValue<Int> cast)
2105 {
2106 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2107
2108 storeValue(integer);
2109 }
2110
2111 UShort::UShort()
2112 {
2113 }
2114
2115 UShort::UShort(unsigned short x)
2116 {
2117 storeValue(Nucleus::createConstantShort(x));
2118 }
2119
2120 UShort::UShort(RValue<UShort> rhs)
2121 {
2122 storeValue(rhs.value);
2123 }
2124
2125 UShort::UShort(const UShort &rhs)
2126 {
2127 Value *value = rhs.loadValue();
2128 storeValue(value);
2129 }
2130
2131 UShort::UShort(const Reference<UShort> &rhs)
2132 {
2133 Value *value = rhs.loadValue();
2134 storeValue(value);
2135 }
2136
2137 RValue<UShort> UShort::operator=(RValue<UShort> rhs) const
2138 {
2139 storeValue(rhs.value);
2140
2141 return rhs;
2142 }
2143
2144 RValue<UShort> UShort::operator=(const UShort &rhs) const
2145 {
2146 Value *value = rhs.loadValue();
2147 storeValue(value);
2148
2149 return RValue<UShort>(value);
2150 }
2151
2152 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) const
2153 {
2154 Value *value = rhs.loadValue();
2155 storeValue(value);
2156
2157 return RValue<UShort>(value);
2158 }
2159
2160 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
2161 {
2162 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
2163 }
2164
2165 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
2166 {
2167 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
2168 }
2169
2170 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
2171 {
2172 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
2173 }
2174
2175 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
2176 {
2177 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
2178 }
2179
2180 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
2181 {
2182 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
2183 }
2184
2185 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
2186 {
2187 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
2188 }
2189
2190 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
2191 {
2192 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
2193 }
2194
2195 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
2196 {
2197 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
2198 }
2199
2200 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
2201 {
2202 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
2203 }
2204
2205 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
2206 {
2207 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
2208 }
2209
2210 RValue<UShort> operator+=(const UShort &lhs, RValue<UShort> rhs)
2211 {
2212 return lhs = lhs + rhs;
2213 }
2214
2215 RValue<UShort> operator-=(const UShort &lhs, RValue<UShort> rhs)
2216 {
2217 return lhs = lhs - rhs;
2218 }
2219
2220 RValue<UShort> operator*=(const UShort &lhs, RValue<UShort> rhs)
2221 {
2222 return lhs = lhs * rhs;
2223 }
2224
2225 RValue<UShort> operator/=(const UShort &lhs, RValue<UShort> rhs)
2226 {
2227 return lhs = lhs / rhs;
2228 }
2229
2230 RValue<UShort> operator%=(const UShort &lhs, RValue<UShort> rhs)
2231 {
2232 return lhs = lhs % rhs;
2233 }
2234
2235 RValue<UShort> operator&=(const UShort &lhs, RValue<UShort> rhs)
2236 {
2237 return lhs = lhs & rhs;
2238 }
2239
2240 RValue<UShort> operator|=(const UShort &lhs, RValue<UShort> rhs)
2241 {
2242 return lhs = lhs | rhs;
2243 }
2244
2245 RValue<UShort> operator^=(const UShort &lhs, RValue<UShort> rhs)
2246 {
2247 return lhs = lhs ^ rhs;
2248 }
2249
2250 RValue<UShort> operator<<=(const UShort &lhs, RValue<UShort> rhs)
2251 {
2252 return lhs = lhs << rhs;
2253 }
2254
2255 RValue<UShort> operator>>=(const UShort &lhs, RValue<UShort> rhs)
2256 {
2257 return lhs = lhs >> rhs;
2258 }
2259
2260 RValue<UShort> operator+(RValue<UShort> val)
2261 {
2262 return val;
2263 }
2264
2265 RValue<UShort> operator-(RValue<UShort> val)
2266 {
2267 return RValue<UShort>(Nucleus::createNeg(val.value));
2268 }
2269
2270 RValue<UShort> operator~(RValue<UShort> val)
2271 {
2272 return RValue<UShort>(Nucleus::createNot(val.value));
2273 }
2274
2275 RValue<UShort> operator++(const UShort &val, int) // Post-increment
2276 {
2277 RValue<UShort> res = val;
2278
2279 assert(false && "UNIMPLEMENTED");
2280 assert(false && "UNIMPLEMENTED");
2281
2282 return res;
2283 }
2284
2285 const UShort &operator++(const UShort &val) // Pre-increment
2286 {
2287 assert(false && "UNIMPLEMENTED");
2288 assert(false && "UNIMPLEMENTED");
2289
2290 return val;
2291 }
2292
2293 RValue<UShort> operator--(const UShort &val, int) // Post-decrement
2294 {
2295 RValue<UShort> res = val;
2296
2297 assert(false && "UNIMPLEMENTED");
2298 assert(false && "UNIMPLEMENTED");
2299
2300 return res;
2301 }
2302
2303 const UShort &operator--(const UShort &val) // Pre-decrement
2304 {
2305 assert(false && "UNIMPLEMENTED");
2306 assert(false && "UNIMPLEMENTED");
2307
2308 return val;
2309 }
2310
2311 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
2312 {
2313 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2314 }
2315
2316 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
2317 {
2318 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2319 }
2320
2321 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
2322 {
2323 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2324 }
2325
2326 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
2327 {
2328 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2329 }
2330
2331 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
2332 {
2333 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2334 }
2335
2336 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
2337 {
2338 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2339 }
2340
2341 Type *UShort::getType()
2342 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002343 return T(Ice::IceType_i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002344 }
2345
Nicolas Capens16b5f152016-10-13 13:39:01 -04002346 Byte4::Byte4(RValue<Byte8> cast)
2347 {
2348 // xyzw.parent = this;
2349
2350 storeValue(Nucleus::createBitCast(cast.value, getType()));
2351 }
2352
2353 Byte4::Byte4(const Reference<Byte4> &rhs)
2354 {
2355 // xyzw.parent = this;
2356
2357 assert(false && "UNIMPLEMENTED");
2358 }
2359
Nicolas Capens598f8d82016-09-26 15:09:10 -04002360 Type *Byte4::getType()
2361 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002362 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002363 }
2364
2365 Type *SByte4::getType()
2366 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002367 return T(Type_v4i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002368 }
2369
2370 Byte8::Byte8()
2371 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002372 }
2373
2374 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)
2375 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002376 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
2377 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002378 }
2379
2380 Byte8::Byte8(RValue<Byte8> rhs)
2381 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002382 storeValue(rhs.value);
2383 }
2384
2385 Byte8::Byte8(const Byte8 &rhs)
2386 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002387 Value *value = rhs.loadValue();
2388 storeValue(value);
2389 }
2390
2391 Byte8::Byte8(const Reference<Byte8> &rhs)
2392 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04002393 Value *value = rhs.loadValue();
2394 storeValue(value);
2395 }
2396
2397 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) const
2398 {
2399 storeValue(rhs.value);
2400
2401 return rhs;
2402 }
2403
2404 RValue<Byte8> Byte8::operator=(const Byte8 &rhs) const
2405 {
2406 Value *value = rhs.loadValue();
2407 storeValue(value);
2408
2409 return RValue<Byte8>(value);
2410 }
2411
2412 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) const
2413 {
2414 Value *value = rhs.loadValue();
2415 storeValue(value);
2416
2417 return RValue<Byte8>(value);
2418 }
2419
2420 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
2421 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002422 return RValue<Byte8>(Nucleus::createAdd(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::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002428 }
2429
2430// RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2431// {
2432// return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2433// }
2434
2435// RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2436// {
2437// return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2438// }
2439
2440// RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2441// {
2442// return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2443// }
2444
2445 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
2446 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002447 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002448 }
2449
2450 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
2451 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002452 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002453 }
2454
2455 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
2456 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002457 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002458 }
2459
2460// RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
2461// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002462// return RValue<Byte8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002463// }
2464
2465// RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
2466// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002467// return RValue<Byte8>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002468// }
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%=(const Byte8 &lhs, RValue<Byte8> rhs)
2491// {
2492// return lhs = lhs % rhs;
2493// }
2494
2495 RValue<Byte8> operator&=(const Byte8 &lhs, RValue<Byte8> rhs)
2496 {
2497 return lhs = lhs & rhs;
2498 }
2499
2500 RValue<Byte8> operator|=(const Byte8 &lhs, RValue<Byte8> rhs)
2501 {
2502 return lhs = lhs | rhs;
2503 }
2504
2505 RValue<Byte8> operator^=(const Byte8 &lhs, RValue<Byte8> rhs)
2506 {
2507 return lhs = lhs ^ rhs;
2508 }
2509
2510// RValue<Byte8> operator<<=(const Byte8 &lhs, RValue<Byte8> rhs)
2511// {
2512// return lhs = lhs << rhs;
2513// }
2514
2515// RValue<Byte8> operator>>=(const Byte8 &lhs, RValue<Byte8> rhs)
2516// {
2517// return lhs = lhs >> rhs;
2518// }
2519
2520// RValue<Byte8> operator+(RValue<Byte8> val)
2521// {
2522// return val;
2523// }
2524
2525// RValue<Byte8> operator-(RValue<Byte8> val)
2526// {
2527// return RValue<Byte8>(Nucleus::createNeg(val.value));
2528// }
2529
2530 RValue<Byte8> operator~(RValue<Byte8> val)
2531 {
2532 return RValue<Byte8>(Nucleus::createNot(val.value));
2533 }
2534
2535 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
2536 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002537 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002538 }
2539
2540 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
2541 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002542 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002543 }
2544
2545 RValue<Short4> Unpack(RValue<Byte4> x)
2546 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002547 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2548 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002549 }
2550
2551 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2552 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002553 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2554 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002555 }
2556
2557 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
2558 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002559 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2560 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2561 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002562 }
2563
2564 RValue<Int> SignMask(RValue<Byte8> x)
2565 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002566 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002567 }
2568
2569// RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
2570// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002571// assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002572// }
2573
2574 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
2575 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002576 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002577 }
2578
2579 Type *Byte8::getType()
2580 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002581 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002582 }
2583
2584 SByte8::SByte8()
2585 {
2586 // xyzw.parent = this;
2587 }
2588
2589 SByte8::SByte8(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t x4, uint8_t x5, uint8_t x6, uint8_t x7)
2590 {
2591 // xyzw.parent = this;
2592
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002593 int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
2594 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
2595
2596 storeValue(Nucleus::createBitCast(vector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002597 }
2598
Nicolas Capens598f8d82016-09-26 15:09:10 -04002599 SByte8::SByte8(RValue<SByte8> rhs)
2600 {
2601 // xyzw.parent = this;
2602
2603 storeValue(rhs.value);
2604 }
2605
2606 SByte8::SByte8(const SByte8 &rhs)
2607 {
2608 // xyzw.parent = this;
2609
2610 Value *value = rhs.loadValue();
2611 storeValue(value);
2612 }
2613
2614 SByte8::SByte8(const Reference<SByte8> &rhs)
2615 {
2616 // xyzw.parent = this;
2617
2618 Value *value = rhs.loadValue();
2619 storeValue(value);
2620 }
2621
2622 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) const
2623 {
2624 storeValue(rhs.value);
2625
2626 return rhs;
2627 }
2628
2629 RValue<SByte8> SByte8::operator=(const SByte8 &rhs) const
2630 {
2631 Value *value = rhs.loadValue();
2632 storeValue(value);
2633
2634 return RValue<SByte8>(value);
2635 }
2636
2637 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) const
2638 {
2639 Value *value = rhs.loadValue();
2640 storeValue(value);
2641
2642 return RValue<SByte8>(value);
2643 }
2644
2645 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
2646 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002647 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002648 }
2649
2650 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
2651 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04002652 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002653 }
2654
2655// RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2656// {
2657// return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2658// }
2659
2660// RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2661// {
2662// return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2663// }
2664
2665// RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2666// {
2667// return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2668// }
2669
2670 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
2671 {
2672 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2673 }
2674
2675 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
2676 {
2677 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2678 }
2679
2680 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
2681 {
2682 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2683 }
2684
2685// RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
2686// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002687// return RValue<SByte8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002688// }
2689
2690// RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
2691// {
Nicolas Capens327f1df2016-10-21 14:26:34 -04002692// return RValue<SByte8>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002693// }
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%=(const SByte8 &lhs, RValue<SByte8> rhs)
2716// {
2717// return lhs = lhs % rhs;
2718// }
2719
2720 RValue<SByte8> operator&=(const SByte8 &lhs, RValue<SByte8> rhs)
2721 {
2722 return lhs = lhs & rhs;
2723 }
2724
2725 RValue<SByte8> operator|=(const SByte8 &lhs, RValue<SByte8> rhs)
2726 {
2727 return lhs = lhs | rhs;
2728 }
2729
2730 RValue<SByte8> operator^=(const SByte8 &lhs, RValue<SByte8> rhs)
2731 {
2732 return lhs = lhs ^ rhs;
2733 }
2734
2735// RValue<SByte8> operator<<=(const SByte8 &lhs, RValue<SByte8> rhs)
2736// {
2737// return lhs = lhs << rhs;
2738// }
2739
2740// RValue<SByte8> operator>>=(const SByte8 &lhs, RValue<SByte8> rhs)
2741// {
2742// return lhs = lhs >> rhs;
2743// }
2744
2745// RValue<SByte8> operator+(RValue<SByte8> val)
2746// {
2747// return val;
2748// }
2749
2750// RValue<SByte8> operator-(RValue<SByte8> val)
2751// {
2752// return RValue<SByte8>(Nucleus::createNeg(val.value));
2753// }
2754
2755 RValue<SByte8> operator~(RValue<SByte8> val)
2756 {
2757 return RValue<SByte8>(Nucleus::createNot(val.value));
2758 }
2759
2760 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
2761 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002762 assert(false && "UNIMPLEMENTED"); return RValue<SByte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002763 }
2764
2765 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
2766 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002767 assert(false && "UNIMPLEMENTED"); return RValue<SByte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002768 }
2769
2770 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
2771 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04002772 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2773 return RValue<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002774 }
2775
2776 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
2777 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04002778 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2779 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2780 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002781 }
2782
2783 RValue<Int> SignMask(RValue<SByte8> x)
2784 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04002785 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2786 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2787 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2788 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2789 movmsk->addArg(x.value);
2790 ::basicBlock->appendInst(movmsk);
2791
2792 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002793 }
2794
2795 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
2796 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002797 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002798 }
2799
2800 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
2801 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04002802 assert(false && "UNIMPLEMENTED"); return RValue<Byte8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002803 }
2804
2805 Type *SByte8::getType()
2806 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04002807 return T(Type_v8i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002808 }
2809
2810 Byte16::Byte16(RValue<Byte16> rhs)
2811 {
2812 // xyzw.parent = this;
2813
2814 storeValue(rhs.value);
2815 }
2816
2817 Byte16::Byte16(const Byte16 &rhs)
2818 {
2819 // xyzw.parent = this;
2820
2821 Value *value = rhs.loadValue();
2822 storeValue(value);
2823 }
2824
2825 Byte16::Byte16(const Reference<Byte16> &rhs)
2826 {
2827 // xyzw.parent = this;
2828
2829 Value *value = rhs.loadValue();
2830 storeValue(value);
2831 }
2832
2833 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) const
2834 {
2835 storeValue(rhs.value);
2836
2837 return rhs;
2838 }
2839
2840 RValue<Byte16> Byte16::operator=(const Byte16 &rhs) const
2841 {
2842 Value *value = rhs.loadValue();
2843 storeValue(value);
2844
2845 return RValue<Byte16>(value);
2846 }
2847
2848 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) const
2849 {
2850 Value *value = rhs.loadValue();
2851 storeValue(value);
2852
2853 return RValue<Byte16>(value);
2854 }
2855
2856 Type *Byte16::getType()
2857 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002858 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002859 }
2860
2861 Type *SByte16::getType()
2862 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002863 return T(Ice::IceType_v16i8);
Nicolas Capens598f8d82016-09-26 15:09:10 -04002864 }
2865
Nicolas Capens16b5f152016-10-13 13:39:01 -04002866 Short2::Short2(RValue<Short4> cast)
2867 {
2868 assert(false && "UNIMPLEMENTED");
2869 }
2870
2871 Type *Short2::getType()
2872 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002873 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002874 }
2875
2876 UShort2::UShort2(RValue<UShort4> cast)
2877 {
2878 assert(false && "UNIMPLEMENTED");
2879 }
2880
2881 Type *UShort2::getType()
2882 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04002883 return T(Type_v2i16);
Nicolas Capens16b5f152016-10-13 13:39:01 -04002884 }
2885
Nicolas Capens598f8d82016-09-26 15:09:10 -04002886 Short4::Short4(RValue<Int> cast)
2887 {
2888 Value *extend = Nucleus::createZExt(cast.value, Long::getType());
2889 Value *swizzle = Swizzle(RValue<Short4>(extend), 0x00).value;
2890
2891 storeValue(swizzle);
2892 }
2893
2894 Short4::Short4(RValue<Int4> cast)
2895 {
2896 assert(false && "UNIMPLEMENTED");
2897 }
2898
2899// Short4::Short4(RValue<Float> cast)
2900// {
2901// }
2902
2903 Short4::Short4(RValue<Float4> cast)
2904 {
2905 assert(false && "UNIMPLEMENTED");
2906 }
2907
2908 Short4::Short4()
2909 {
2910 // xyzw.parent = this;
2911 }
2912
2913 Short4::Short4(short xyzw)
2914 {
2915 // xyzw.parent = this;
2916
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002917 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
2918 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002919 }
2920
2921 Short4::Short4(short x, short y, short z, short w)
2922 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002923 // xyzw.parent = this;
Nicolas Capens598f8d82016-09-26 15:09:10 -04002924
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04002925 int64_t constantVector[4] = {x, y, z, w};
2926 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04002927 }
2928
2929 Short4::Short4(RValue<Short4> rhs)
2930 {
2931 // xyzw.parent = this;
2932
2933 storeValue(rhs.value);
2934 }
2935
2936 Short4::Short4(const Short4 &rhs)
2937 {
2938 // xyzw.parent = this;
2939
2940 Value *value = rhs.loadValue();
2941 storeValue(value);
2942 }
2943
2944 Short4::Short4(const Reference<Short4> &rhs)
2945 {
2946 // xyzw.parent = this;
2947
2948 Value *value = rhs.loadValue();
2949 storeValue(value);
2950 }
2951
2952 Short4::Short4(RValue<UShort4> rhs)
2953 {
2954 // xyzw.parent = this;
2955
2956 storeValue(rhs.value);
2957 }
2958
2959 Short4::Short4(const UShort4 &rhs)
2960 {
2961 // xyzw.parent = this;
2962
2963 storeValue(rhs.loadValue());
2964 }
2965
2966 Short4::Short4(const Reference<UShort4> &rhs)
2967 {
2968 // xyzw.parent = this;
2969
2970 storeValue(rhs.loadValue());
2971 }
2972
2973 RValue<Short4> Short4::operator=(RValue<Short4> rhs) const
2974 {
2975 storeValue(rhs.value);
2976
2977 return rhs;
2978 }
2979
2980 RValue<Short4> Short4::operator=(const Short4 &rhs) const
2981 {
2982 Value *value = rhs.loadValue();
2983 storeValue(value);
2984
2985 return RValue<Short4>(value);
2986 }
2987
2988 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) const
2989 {
2990 Value *value = rhs.loadValue();
2991 storeValue(value);
2992
2993 return RValue<Short4>(value);
2994 }
2995
2996 RValue<Short4> Short4::operator=(RValue<UShort4> rhs) const
2997 {
2998 storeValue(rhs.value);
2999
3000 return RValue<Short4>(rhs);
3001 }
3002
3003 RValue<Short4> Short4::operator=(const UShort4 &rhs) const
3004 {
3005 Value *value = rhs.loadValue();
3006 storeValue(value);
3007
3008 return RValue<Short4>(value);
3009 }
3010
3011 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) const
3012 {
3013 Value *value = rhs.loadValue();
3014 storeValue(value);
3015
3016 return RValue<Short4>(value);
3017 }
3018
3019 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
3020 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003021 return RValue<Short4>(Nucleus::createAdd(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::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003027 }
3028
3029 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
3030 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003031 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003032 }
3033
3034// RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
3035// {
3036// return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
3037// }
3038
3039// RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
3040// {
3041// return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
3042// }
3043
3044 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
3045 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003046 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003047 }
3048
3049 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
3050 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003051 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003052 }
3053
3054 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
3055 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003056 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003057 }
3058
3059 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
3060 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003061 return RValue<Short4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003062 }
3063
3064 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
3065 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003066 return RValue<Short4>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003067 }
3068
3069 RValue<Short4> operator<<(RValue<Short4> lhs, RValue<Long1> rhs)
3070 {
3071 // return RValue<Short4>(Nucleus::createShl(lhs.value, rhs.value));
3072
Nicolas Capensc37252c2016-09-28 16:11:54 -04003073 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003074 }
3075
3076 RValue<Short4> operator>>(RValue<Short4> lhs, RValue<Long1> rhs)
3077 {
3078 // return RValue<Short4>(Nucleus::createAShr(lhs.value, rhs.value));
3079
Nicolas Capensc37252c2016-09-28 16:11:54 -04003080 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003081 }
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, RValue<Short4> rhs)
3094 {
3095 return lhs = lhs * rhs;
3096 }
3097
3098// RValue<Short4> operator/=(const Short4 &lhs, RValue<Short4> rhs)
3099// {
3100// return lhs = lhs / rhs;
3101// }
3102
3103// RValue<Short4> operator%=(const Short4 &lhs, RValue<Short4> rhs)
3104// {
3105// return lhs = lhs % rhs;
3106// }
3107
3108 RValue<Short4> operator&=(const Short4 &lhs, RValue<Short4> rhs)
3109 {
3110 return lhs = lhs & rhs;
3111 }
3112
3113 RValue<Short4> operator|=(const Short4 &lhs, RValue<Short4> rhs)
3114 {
3115 return lhs = lhs | rhs;
3116 }
3117
3118 RValue<Short4> operator^=(const Short4 &lhs, RValue<Short4> rhs)
3119 {
3120 return lhs = lhs ^ rhs;
3121 }
3122
3123 RValue<Short4> operator<<=(const Short4 &lhs, unsigned char rhs)
3124 {
3125 return lhs = lhs << rhs;
3126 }
3127
3128 RValue<Short4> operator>>=(const Short4 &lhs, unsigned char rhs)
3129 {
3130 return lhs = lhs >> rhs;
3131 }
3132
3133 RValue<Short4> operator<<=(const Short4 &lhs, RValue<Long1> rhs)
3134 {
3135 return lhs = lhs << rhs;
3136 }
3137
3138 RValue<Short4> operator>>=(const Short4 &lhs, RValue<Long1> rhs)
3139 {
3140 return lhs = lhs >> rhs;
3141 }
3142
3143// RValue<Short4> operator+(RValue<Short4> val)
3144// {
3145// return val;
3146// }
3147
3148 RValue<Short4> operator-(RValue<Short4> val)
3149 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003150 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003151 }
3152
3153 RValue<Short4> operator~(RValue<Short4> val)
3154 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003155 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003156 }
3157
3158 RValue<Short4> RoundShort4(RValue<Float4> cast)
3159 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003160 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003161 }
3162
3163 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
3164 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003165 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003166 }
3167
3168 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
3169 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003170 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003171 }
3172
3173 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
3174 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003175 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003176 }
3177
3178 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
3179 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003180 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003181 }
3182
3183 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
3184 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003185 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003186 }
3187
3188 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
3189 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003190 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003191 }
3192
3193 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
3194 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003195 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3196 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3197 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3198 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3199 pack->addArg(x.value);
3200 pack->addArg(y.value);
3201 ::basicBlock->appendInst(pack);
3202
3203 return RValue<SByte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003204 }
3205
3206 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
3207 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003208 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3209 return RValue<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003210 }
3211
3212 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
3213 {
Nicolas Capens20e22c42016-10-25 17:32:37 -04003214 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3215 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3216 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003217 }
3218
3219 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
3220 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04003221 // Real type is v8i16
3222 int shuffle[8] =
3223 {
3224 (select >> 0) & 0x03,
3225 (select >> 2) & 0x03,
3226 (select >> 4) & 0x03,
3227 (select >> 6) & 0x03,
3228 (select >> 0) & 0x03,
3229 (select >> 2) & 0x03,
3230 (select >> 4) & 0x03,
3231 (select >> 6) & 0x03,
3232 };
3233
3234 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003235 }
3236
3237 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
3238 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003239 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003240 }
3241
3242 RValue<Short> Extract(RValue<Short4> val, int i)
3243 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003244 assert(false && "UNIMPLEMENTED"); return RValue<Short>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003245 }
3246
3247 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
3248 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003249 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003250 }
3251
3252 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
3253 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003254 assert(false && "UNIMPLEMENTED"); return RValue<Short4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003255 }
3256
3257 Type *Short4::getType()
3258 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003259 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003260 }
3261
3262 UShort4::UShort4(RValue<Int4> cast)
3263 {
3264 *this = Short4(cast);
3265 }
3266
3267 UShort4::UShort4(RValue<Float4> cast, bool saturate)
3268 {
3269 assert(false && "UNIMPLEMENTED");
3270 }
3271
3272 UShort4::UShort4()
3273 {
3274 // xyzw.parent = this;
3275 }
3276
3277 UShort4::UShort4(unsigned short xyzw)
3278 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003279 // xyzw.parent = this;
Nicolas Capens598f8d82016-09-26 15:09:10 -04003280
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003281 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3282 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003283 }
3284
3285 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3286 {
3287 // xyzw.parent = this;
3288
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003289 int64_t constantVector[4] = {x, y, z, w};
3290 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003291 }
3292
3293 UShort4::UShort4(RValue<UShort4> rhs)
3294 {
3295 // xyzw.parent = this;
3296
3297 storeValue(rhs.value);
3298 }
3299
3300 UShort4::UShort4(const UShort4 &rhs)
3301 {
3302 // xyzw.parent = this;
3303
3304 Value *value = rhs.loadValue();
3305 storeValue(value);
3306 }
3307
3308 UShort4::UShort4(const Reference<UShort4> &rhs)
3309 {
3310 // xyzw.parent = this;
3311
3312 Value *value = rhs.loadValue();
3313 storeValue(value);
3314 }
3315
3316 UShort4::UShort4(RValue<Short4> rhs)
3317 {
3318 // xyzw.parent = this;
3319
3320 storeValue(rhs.value);
3321 }
3322
3323 UShort4::UShort4(const Short4 &rhs)
3324 {
3325 // xyzw.parent = this;
3326
3327 Value *value = rhs.loadValue();
3328 storeValue(value);
3329 }
3330
3331 UShort4::UShort4(const Reference<Short4> &rhs)
3332 {
3333 // xyzw.parent = this;
3334
3335 Value *value = rhs.loadValue();
3336 storeValue(value);
3337 }
3338
3339 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) const
3340 {
3341 storeValue(rhs.value);
3342
3343 return rhs;
3344 }
3345
3346 RValue<UShort4> UShort4::operator=(const UShort4 &rhs) const
3347 {
3348 Value *value = rhs.loadValue();
3349 storeValue(value);
3350
3351 return RValue<UShort4>(value);
3352 }
3353
3354 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) const
3355 {
3356 Value *value = rhs.loadValue();
3357 storeValue(value);
3358
3359 return RValue<UShort4>(value);
3360 }
3361
3362 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) const
3363 {
3364 storeValue(rhs.value);
3365
3366 return RValue<UShort4>(rhs);
3367 }
3368
3369 RValue<UShort4> UShort4::operator=(const Short4 &rhs) const
3370 {
3371 Value *value = rhs.loadValue();
3372 storeValue(value);
3373
3374 return RValue<UShort4>(value);
3375 }
3376
3377 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) const
3378 {
3379 Value *value = rhs.loadValue();
3380 storeValue(value);
3381
3382 return RValue<UShort4>(value);
3383 }
3384
3385 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
3386 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003387 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003388 }
3389
3390 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
3391 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003392 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003393 }
3394
3395 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
3396 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003397 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003398 }
3399
Nicolas Capens16b5f152016-10-13 13:39:01 -04003400 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3401 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003402 return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003403 }
3404
3405 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
3406 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003407 return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003408 }
3409
3410 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3411 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04003412 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens16b5f152016-10-13 13:39:01 -04003413 }
3414
Nicolas Capens598f8d82016-09-26 15:09:10 -04003415 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
3416 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003417 return RValue<UShort4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003418 }
3419
3420 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
3421 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003422 return RValue<UShort4>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003423 }
3424
3425 RValue<UShort4> operator<<(RValue<UShort4> lhs, RValue<Long1> rhs)
3426 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003427 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003428 }
3429
3430 RValue<UShort4> operator>>(RValue<UShort4> lhs, RValue<Long1> rhs)
3431 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003432 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003433 }
3434
3435 RValue<UShort4> operator<<=(const UShort4 &lhs, unsigned char rhs)
3436 {
3437 return lhs = lhs << rhs;
3438 }
3439
3440 RValue<UShort4> operator>>=(const UShort4 &lhs, unsigned char rhs)
3441 {
3442 return lhs = lhs >> rhs;
3443 }
3444
3445 RValue<UShort4> operator<<=(const UShort4 &lhs, RValue<Long1> rhs)
3446 {
3447 return lhs = lhs << rhs;
3448 }
3449
3450 RValue<UShort4> operator>>=(const UShort4 &lhs, RValue<Long1> rhs)
3451 {
3452 return lhs = lhs >> rhs;
3453 }
3454
3455 RValue<UShort4> operator~(RValue<UShort4> val)
3456 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003457 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003458 }
3459
3460 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
3461 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003462 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003463 }
3464
3465 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
3466 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003467 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003468 }
3469
3470 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
3471 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003472 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003473 }
3474
3475 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
3476 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003477 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003478 }
3479
3480 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
3481 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003482 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003483 }
3484
3485 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
3486 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003487 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003488 }
3489
3490 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
3491 {
Nicolas Capensec54a172016-10-25 17:32:37 -04003492 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3493 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3494 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3495 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3496 pack->addArg(x.value);
3497 pack->addArg(y.value);
3498 ::basicBlock->appendInst(pack);
3499
3500 return RValue<Byte8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003501 }
3502
3503 Type *UShort4::getType()
3504 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04003505 return T(Type_v4i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003506 }
3507
3508 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3509 {
3510 // xyzw.parent = this;
3511
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003512 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3513 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003514 }
3515
3516 Short8::Short8(RValue<Short8> rhs)
3517 {
3518 // xyzw.parent = this;
3519
3520 storeValue(rhs.value);
3521 }
3522
3523 Short8::Short8(const Reference<Short8> &rhs)
3524 {
3525 // xyzw.parent = this;
3526
3527 Value *value = rhs.loadValue();
3528 storeValue(value);
3529 }
3530
3531 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3532 {
3533 assert(false && "UNIMPLEMENTED");
3534 }
3535
3536 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
3537 {
3538 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3539 }
3540
3541 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
3542 {
3543 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3544 }
3545
3546 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
3547 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003548 return RValue<Short8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003549 }
3550
3551 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
3552 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003553 return RValue<Short8>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003554 }
3555
3556 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
3557 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003558 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003559 }
3560
3561 RValue<Int4> Abs(RValue<Int4> x)
3562 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003563 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003564 }
3565
3566 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
3567 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003568 assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003569 }
3570
3571 Type *Short8::getType()
3572 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003573 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003574 }
3575
3576 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)
3577 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04003578 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3579 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003580 }
3581
3582 UShort8::UShort8(RValue<UShort8> rhs)
3583 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003584 storeValue(rhs.value);
3585 }
3586
3587 UShort8::UShort8(const Reference<UShort8> &rhs)
3588 {
Nicolas Capens598f8d82016-09-26 15:09:10 -04003589 Value *value = rhs.loadValue();
3590 storeValue(value);
3591 }
3592
3593 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3594 {
3595 assert(false && "UNIMPLEMENTED");
3596 }
3597
3598 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) const
3599 {
3600 storeValue(rhs.value);
3601
3602 return rhs;
3603 }
3604
3605 RValue<UShort8> UShort8::operator=(const UShort8 &rhs) const
3606 {
3607 Value *value = rhs.loadValue();
3608 storeValue(value);
3609
3610 return RValue<UShort8>(value);
3611 }
3612
3613 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) const
3614 {
3615 Value *value = rhs.loadValue();
3616 storeValue(value);
3617
3618 return RValue<UShort8>(value);
3619 }
3620
3621 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
3622 {
3623 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3624 }
3625
3626 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
3627 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003628 return RValue<UShort8>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003629 }
3630
3631 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
3632 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04003633 return RValue<UShort8>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003634 }
3635
3636 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
3637 {
3638 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
3639 }
3640
3641 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
3642 {
3643 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
3644 }
3645
3646 RValue<UShort8> operator+=(const UShort8 &lhs, RValue<UShort8> rhs)
3647 {
3648 return lhs = lhs + rhs;
3649 }
3650
3651 RValue<UShort8> operator~(RValue<UShort8> val)
3652 {
3653 return RValue<UShort8>(Nucleus::createNot(val.value));
3654 }
3655
3656 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
3657 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003658 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003659 }
3660
3661 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
3662 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003663 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003664 }
3665
3666 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
3667// RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
3668// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003669// assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003670// }
3671
3672 Type *UShort8::getType()
3673 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04003674 return T(Ice::IceType_v8i16);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003675 }
3676
3677 Int::Int(Argument<Int> argument)
3678 {
3679 storeValue(argument.value);
3680 }
3681
3682 Int::Int(RValue<Byte> cast)
3683 {
3684 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3685
3686 storeValue(integer);
3687 }
3688
3689 Int::Int(RValue<SByte> cast)
3690 {
3691 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3692
3693 storeValue(integer);
3694 }
3695
3696 Int::Int(RValue<Short> cast)
3697 {
3698 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
3699
3700 storeValue(integer);
3701 }
3702
3703 Int::Int(RValue<UShort> cast)
3704 {
3705 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
3706
3707 storeValue(integer);
3708 }
3709
3710 Int::Int(RValue<Int2> cast)
3711 {
3712 *this = Extract(cast, 0);
3713 }
3714
3715 Int::Int(RValue<Long> cast)
3716 {
3717 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
3718
3719 storeValue(integer);
3720 }
3721
3722 Int::Int(RValue<Float> cast)
3723 {
3724 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
3725
3726 storeValue(integer);
3727 }
3728
3729 Int::Int()
3730 {
3731 }
3732
3733 Int::Int(int x)
3734 {
3735 storeValue(Nucleus::createConstantInt(x));
3736 }
3737
3738 Int::Int(RValue<Int> rhs)
3739 {
3740 storeValue(rhs.value);
3741 }
3742
3743 Int::Int(RValue<UInt> rhs)
3744 {
3745 storeValue(rhs.value);
3746 }
3747
3748 Int::Int(const Int &rhs)
3749 {
3750 Value *value = rhs.loadValue();
3751 storeValue(value);
3752 }
3753
3754 Int::Int(const Reference<Int> &rhs)
3755 {
3756 Value *value = rhs.loadValue();
3757 storeValue(value);
3758 }
3759
3760 Int::Int(const UInt &rhs)
3761 {
3762 Value *value = rhs.loadValue();
3763 storeValue(value);
3764 }
3765
3766 Int::Int(const Reference<UInt> &rhs)
3767 {
3768 Value *value = rhs.loadValue();
3769 storeValue(value);
3770 }
3771
3772 RValue<Int> Int::operator=(int rhs) const
3773 {
3774 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
3775 }
3776
3777 RValue<Int> Int::operator=(RValue<Int> rhs) const
3778 {
3779 storeValue(rhs.value);
3780
3781 return rhs;
3782 }
3783
3784 RValue<Int> Int::operator=(RValue<UInt> rhs) const
3785 {
3786 storeValue(rhs.value);
3787
3788 return RValue<Int>(rhs);
3789 }
3790
3791 RValue<Int> Int::operator=(const Int &rhs) const
3792 {
3793 Value *value = rhs.loadValue();
3794 storeValue(value);
3795
3796 return RValue<Int>(value);
3797 }
3798
3799 RValue<Int> Int::operator=(const Reference<Int> &rhs) const
3800 {
3801 Value *value = rhs.loadValue();
3802 storeValue(value);
3803
3804 return RValue<Int>(value);
3805 }
3806
3807 RValue<Int> Int::operator=(const UInt &rhs) const
3808 {
3809 Value *value = rhs.loadValue();
3810 storeValue(value);
3811
3812 return RValue<Int>(value);
3813 }
3814
3815 RValue<Int> Int::operator=(const Reference<UInt> &rhs) const
3816 {
3817 Value *value = rhs.loadValue();
3818 storeValue(value);
3819
3820 return RValue<Int>(value);
3821 }
3822
3823 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
3824 {
3825 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
3826 }
3827
3828 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
3829 {
3830 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
3831 }
3832
3833 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
3834 {
3835 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
3836 }
3837
3838 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
3839 {
3840 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
3841 }
3842
3843 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
3844 {
3845 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
3846 }
3847
3848 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
3849 {
3850 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
3851 }
3852
3853 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
3854 {
3855 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
3856 }
3857
3858 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
3859 {
3860 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
3861 }
3862
3863 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
3864 {
3865 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
3866 }
3867
3868 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
3869 {
3870 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
3871 }
3872
3873 RValue<Int> operator+=(const Int &lhs, RValue<Int> rhs)
3874 {
3875 return lhs = lhs + rhs;
3876 }
3877
3878 RValue<Int> operator-=(const Int &lhs, RValue<Int> rhs)
3879 {
3880 return lhs = lhs - rhs;
3881 }
3882
3883 RValue<Int> operator*=(const Int &lhs, RValue<Int> rhs)
3884 {
3885 return lhs = lhs * rhs;
3886 }
3887
3888 RValue<Int> operator/=(const Int &lhs, RValue<Int> rhs)
3889 {
3890 return lhs = lhs / rhs;
3891 }
3892
3893 RValue<Int> operator%=(const Int &lhs, RValue<Int> rhs)
3894 {
3895 return lhs = lhs % rhs;
3896 }
3897
3898 RValue<Int> operator&=(const Int &lhs, RValue<Int> rhs)
3899 {
3900 return lhs = lhs & rhs;
3901 }
3902
3903 RValue<Int> operator|=(const Int &lhs, RValue<Int> rhs)
3904 {
3905 return lhs = lhs | rhs;
3906 }
3907
3908 RValue<Int> operator^=(const Int &lhs, RValue<Int> rhs)
3909 {
3910 return lhs = lhs ^ rhs;
3911 }
3912
3913 RValue<Int> operator<<=(const Int &lhs, RValue<Int> rhs)
3914 {
3915 return lhs = lhs << rhs;
3916 }
3917
3918 RValue<Int> operator>>=(const Int &lhs, RValue<Int> rhs)
3919 {
3920 return lhs = lhs >> rhs;
3921 }
3922
3923 RValue<Int> operator+(RValue<Int> val)
3924 {
3925 return val;
3926 }
3927
3928 RValue<Int> operator-(RValue<Int> val)
3929 {
3930 return RValue<Int>(Nucleus::createNeg(val.value));
3931 }
3932
3933 RValue<Int> operator~(RValue<Int> val)
3934 {
3935 return RValue<Int>(Nucleus::createNot(val.value));
3936 }
3937
3938 RValue<Int> operator++(const Int &val, int) // Post-increment
3939 {
Nicolas Capens611642a2016-09-28 16:45:04 -04003940 auto oldValue = val.loadValue();
3941 auto newValue = ::function->makeVariable(Ice::IceType_i32);
3942 auto inc = Ice::InstArithmetic::create(::function, Ice::InstArithmetic::Add, newValue, oldValue, ::context->getConstantInt32(1));
3943 ::basicBlock->appendInst(inc);
3944 val.storeValue(V(newValue));
3945
3946 return RValue<Int>(oldValue);
Nicolas Capens598f8d82016-09-26 15:09:10 -04003947 }
3948
3949 const Int &operator++(const Int &val) // Pre-increment
3950 {
3951 assert(false && "UNIMPLEMENTED"); return val;
3952 }
3953
3954 RValue<Int> operator--(const Int &val, int) // Post-decrement
3955 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04003956 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04003957 }
3958
3959 const Int &operator--(const Int &val) // Pre-decrement
3960 {
3961 assert(false && "UNIMPLEMENTED"); return val;
3962 }
3963
3964 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
3965 {
3966 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
3967 }
3968
3969 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
3970 {
3971 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
3972 }
3973
3974 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
3975 {
3976 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
3977 }
3978
3979 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
3980 {
3981 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
3982 }
3983
3984 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
3985 {
3986 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
3987 }
3988
3989 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
3990 {
3991 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
3992 }
3993
3994 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
3995 {
3996 return IfThenElse(x > y, x, y);
3997 }
3998
3999 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4000 {
4001 return IfThenElse(x < y, x, y);
4002 }
4003
4004 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4005 {
4006 return Min(Max(x, min), max);
4007 }
4008
4009 RValue<Int> RoundInt(RValue<Float> cast)
4010 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004011 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004012 }
4013
4014 Type *Int::getType()
4015 {
4016 return T(Ice::IceType_i32);
4017 }
4018
4019 Long::Long(RValue<Int> cast)
4020 {
4021 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4022
4023 storeValue(integer);
4024 }
4025
4026 Long::Long(RValue<UInt> cast)
4027 {
4028 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4029
4030 storeValue(integer);
4031 }
4032
4033 Long::Long()
4034 {
4035 }
4036
4037 Long::Long(RValue<Long> rhs)
4038 {
4039 storeValue(rhs.value);
4040 }
4041
4042 RValue<Long> Long::operator=(int64_t rhs) const
4043 {
Nicolas Capens13ac2322016-10-13 14:52:12 -04004044 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004045 }
4046
4047 RValue<Long> Long::operator=(RValue<Long> rhs) const
4048 {
4049 storeValue(rhs.value);
4050
4051 return rhs;
4052 }
4053
4054 RValue<Long> Long::operator=(const Long &rhs) const
4055 {
4056 Value *value = rhs.loadValue();
4057 storeValue(value);
4058
4059 return RValue<Long>(value);
4060 }
4061
4062 RValue<Long> Long::operator=(const Reference<Long> &rhs) const
4063 {
4064 Value *value = rhs.loadValue();
4065 storeValue(value);
4066
4067 return RValue<Long>(value);
4068 }
4069
4070 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
4071 {
4072 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4073 }
4074
4075 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
4076 {
4077 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4078 }
4079
4080 RValue<Long> operator+=(const Long &lhs, RValue<Long> rhs)
4081 {
4082 return lhs = lhs + rhs;
4083 }
4084
4085 RValue<Long> operator-=(const Long &lhs, RValue<Long> rhs)
4086 {
4087 return lhs = lhs - rhs;
4088 }
4089
4090 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
4091 {
4092 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
4093 }
4094
4095 Type *Long::getType()
4096 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004097 return T(Ice::IceType_i64);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004098 }
4099
4100 Long1::Long1(const RValue<UInt> cast)
4101 {
4102 assert(false && "UNIMPLEMENTED");
4103 }
4104
4105 Long1::Long1(RValue<Long1> rhs)
4106 {
4107 storeValue(rhs.value);
4108 }
4109
4110 Type *Long1::getType()
4111 {
4112 assert(false && "UNIMPLEMENTED"); return nullptr;
4113 }
4114
Nicolas Capens598f8d82016-09-26 15:09:10 -04004115 UInt::UInt(Argument<UInt> argument)
4116 {
4117 storeValue(argument.value);
4118 }
4119
4120 UInt::UInt(RValue<UShort> cast)
4121 {
4122 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4123
4124 storeValue(integer);
4125 }
4126
4127 UInt::UInt(RValue<Long> cast)
4128 {
4129 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4130
4131 storeValue(integer);
4132 }
4133
4134 UInt::UInt(RValue<Float> cast)
4135 {
4136 assert(false && "UNIMPLEMENTED");
4137 }
4138
4139 UInt::UInt()
4140 {
4141 }
4142
4143 UInt::UInt(int x)
4144 {
4145 storeValue(Nucleus::createConstantInt(x));
4146 }
4147
4148 UInt::UInt(unsigned int x)
4149 {
4150 storeValue(Nucleus::createConstantInt(x));
4151 }
4152
4153 UInt::UInt(RValue<UInt> rhs)
4154 {
4155 storeValue(rhs.value);
4156 }
4157
4158 UInt::UInt(RValue<Int> rhs)
4159 {
4160 storeValue(rhs.value);
4161 }
4162
4163 UInt::UInt(const UInt &rhs)
4164 {
4165 Value *value = rhs.loadValue();
4166 storeValue(value);
4167 }
4168
4169 UInt::UInt(const Reference<UInt> &rhs)
4170 {
4171 Value *value = rhs.loadValue();
4172 storeValue(value);
4173 }
4174
4175 UInt::UInt(const Int &rhs)
4176 {
4177 Value *value = rhs.loadValue();
4178 storeValue(value);
4179 }
4180
4181 UInt::UInt(const Reference<Int> &rhs)
4182 {
4183 Value *value = rhs.loadValue();
4184 storeValue(value);
4185 }
4186
4187 RValue<UInt> UInt::operator=(unsigned int rhs) const
4188 {
4189 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
4190 }
4191
4192 RValue<UInt> UInt::operator=(RValue<UInt> rhs) const
4193 {
4194 storeValue(rhs.value);
4195
4196 return rhs;
4197 }
4198
4199 RValue<UInt> UInt::operator=(RValue<Int> rhs) const
4200 {
4201 storeValue(rhs.value);
4202
4203 return RValue<UInt>(rhs);
4204 }
4205
4206 RValue<UInt> UInt::operator=(const UInt &rhs) const
4207 {
4208 Value *value = rhs.loadValue();
4209 storeValue(value);
4210
4211 return RValue<UInt>(value);
4212 }
4213
4214 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) const
4215 {
4216 Value *value = rhs.loadValue();
4217 storeValue(value);
4218
4219 return RValue<UInt>(value);
4220 }
4221
4222 RValue<UInt> UInt::operator=(const Int &rhs) const
4223 {
4224 Value *value = rhs.loadValue();
4225 storeValue(value);
4226
4227 return RValue<UInt>(value);
4228 }
4229
4230 RValue<UInt> UInt::operator=(const Reference<Int> &rhs) const
4231 {
4232 Value *value = rhs.loadValue();
4233 storeValue(value);
4234
4235 return RValue<UInt>(value);
4236 }
4237
4238 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
4239 {
4240 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4241 }
4242
4243 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
4244 {
4245 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4246 }
4247
4248 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
4249 {
4250 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4251 }
4252
4253 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
4254 {
4255 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4256 }
4257
4258 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
4259 {
4260 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4261 }
4262
4263 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
4264 {
4265 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4266 }
4267
4268 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
4269 {
4270 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4271 }
4272
4273 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
4274 {
4275 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4276 }
4277
4278 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
4279 {
4280 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4281 }
4282
4283 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
4284 {
4285 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4286 }
4287
4288 RValue<UInt> operator+=(const UInt &lhs, RValue<UInt> rhs)
4289 {
4290 return lhs = lhs + rhs;
4291 }
4292
4293 RValue<UInt> operator-=(const UInt &lhs, RValue<UInt> rhs)
4294 {
4295 return lhs = lhs - rhs;
4296 }
4297
4298 RValue<UInt> operator*=(const UInt &lhs, RValue<UInt> rhs)
4299 {
4300 return lhs = lhs * rhs;
4301 }
4302
4303 RValue<UInt> operator/=(const UInt &lhs, RValue<UInt> rhs)
4304 {
4305 return lhs = lhs / rhs;
4306 }
4307
4308 RValue<UInt> operator%=(const UInt &lhs, RValue<UInt> rhs)
4309 {
4310 return lhs = lhs % rhs;
4311 }
4312
4313 RValue<UInt> operator&=(const UInt &lhs, RValue<UInt> rhs)
4314 {
4315 return lhs = lhs & rhs;
4316 }
4317
4318 RValue<UInt> operator|=(const UInt &lhs, RValue<UInt> rhs)
4319 {
4320 return lhs = lhs | rhs;
4321 }
4322
4323 RValue<UInt> operator^=(const UInt &lhs, RValue<UInt> rhs)
4324 {
4325 return lhs = lhs ^ rhs;
4326 }
4327
4328 RValue<UInt> operator<<=(const UInt &lhs, RValue<UInt> rhs)
4329 {
4330 return lhs = lhs << rhs;
4331 }
4332
4333 RValue<UInt> operator>>=(const UInt &lhs, RValue<UInt> rhs)
4334 {
4335 return lhs = lhs >> rhs;
4336 }
4337
4338 RValue<UInt> operator+(RValue<UInt> val)
4339 {
4340 return val;
4341 }
4342
4343 RValue<UInt> operator-(RValue<UInt> val)
4344 {
4345 return RValue<UInt>(Nucleus::createNeg(val.value));
4346 }
4347
4348 RValue<UInt> operator~(RValue<UInt> val)
4349 {
4350 return RValue<UInt>(Nucleus::createNot(val.value));
4351 }
4352
4353 RValue<UInt> operator++(const UInt &val, int) // Post-increment
4354 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004355 assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004356 }
4357
4358 const UInt &operator++(const UInt &val) // Pre-increment
4359 {
4360 assert(false && "UNIMPLEMENTED"); return val;
4361 }
4362
4363 RValue<UInt> operator--(const UInt &val, int) // Post-decrement
4364 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004365 assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004366 }
4367
4368 const UInt &operator--(const UInt &val) // Pre-decrement
4369 {
4370 assert(false && "UNIMPLEMENTED"); return val;
4371 }
4372
4373 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4374 {
4375 return IfThenElse(x > y, x, y);
4376 }
4377
4378 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4379 {
4380 return IfThenElse(x < y, x, y);
4381 }
4382
4383 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4384 {
4385 return Min(Max(x, min), max);
4386 }
4387
4388 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
4389 {
4390 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4391 }
4392
4393 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
4394 {
4395 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4396 }
4397
4398 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
4399 {
4400 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4401 }
4402
4403 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
4404 {
4405 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4406 }
4407
4408 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
4409 {
4410 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4411 }
4412
4413 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
4414 {
4415 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4416 }
4417
4418// RValue<UInt> RoundUInt(RValue<Float> cast)
4419// {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004420// assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004421// }
4422
4423 Type *UInt::getType()
4424 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004425 return T(Ice::IceType_i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004426 }
4427
4428// Int2::Int2(RValue<Int> cast)
4429// {
4430// Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4431// Value *vector = Nucleus::createBitCast(extend, Int2::getType());
4432//
4433// Constant *shuffle[2];
4434// shuffle[0] = Nucleus::createConstantInt(0);
4435// shuffle[1] = Nucleus::createConstantInt(0);
4436//
4437// Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4438//
4439// storeValue(replicate);
4440// }
4441
4442 Int2::Int2(RValue<Int4> cast)
4443 {
Nicolas Capens22008782016-10-20 01:11:47 -04004444 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004445 }
4446
4447 Int2::Int2()
4448 {
4449 // xy.parent = this;
4450 }
4451
4452 Int2::Int2(int x, int y)
4453 {
4454 // xy.parent = this;
4455
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004456 int64_t constantVector[2] = {x, y};
4457 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004458 }
4459
4460 Int2::Int2(RValue<Int2> rhs)
4461 {
4462 // xy.parent = this;
4463
4464 storeValue(rhs.value);
4465 }
4466
4467 Int2::Int2(const Int2 &rhs)
4468 {
4469 // xy.parent = this;
4470
4471 Value *value = rhs.loadValue();
4472 storeValue(value);
4473 }
4474
4475 Int2::Int2(const Reference<Int2> &rhs)
4476 {
4477 // xy.parent = this;
4478
4479 Value *value = rhs.loadValue();
4480 storeValue(value);
4481 }
4482
4483 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4484 {
4485 assert(false && "UNIMPLEMENTED");
4486 }
4487
4488 RValue<Int2> Int2::operator=(RValue<Int2> rhs) const
4489 {
4490 storeValue(rhs.value);
4491
4492 return rhs;
4493 }
4494
4495 RValue<Int2> Int2::operator=(const Int2 &rhs) const
4496 {
4497 Value *value = rhs.loadValue();
4498 storeValue(value);
4499
4500 return RValue<Int2>(value);
4501 }
4502
4503 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs) const
4504 {
4505 Value *value = rhs.loadValue();
4506 storeValue(value);
4507
4508 return RValue<Int2>(value);
4509 }
4510
4511 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
4512 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004513 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004514 }
4515
4516 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
4517 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004518 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004519 }
4520
4521// RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4522// {
4523// return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4524// }
4525
4526// RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4527// {
4528// return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4529// }
4530
4531// RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4532// {
4533// return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4534// }
4535
4536 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
4537 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004538 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004539 }
4540
4541 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
4542 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004543 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004544 }
4545
4546 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
4547 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004548 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004549 }
4550
4551 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
4552 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004553 return RValue<Int2>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004554 }
4555
4556 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
4557 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004558 return RValue<Int2>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004559 }
4560
4561 RValue<Int2> operator<<(RValue<Int2> lhs, RValue<Long1> rhs)
4562 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004563 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004564 }
4565
4566 RValue<Int2> operator>>(RValue<Int2> lhs, RValue<Long1> rhs)
4567 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004568 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004569 }
4570
4571 RValue<Int2> operator+=(const Int2 &lhs, RValue<Int2> rhs)
4572 {
4573 return lhs = lhs + rhs;
4574 }
4575
4576 RValue<Int2> operator-=(const Int2 &lhs, RValue<Int2> rhs)
4577 {
4578 return lhs = lhs - rhs;
4579 }
4580
4581// RValue<Int2> operator*=(const Int2 &lhs, RValue<Int2> rhs)
4582// {
4583// return lhs = lhs * rhs;
4584// }
4585
4586// RValue<Int2> operator/=(const Int2 &lhs, RValue<Int2> rhs)
4587// {
4588// return lhs = lhs / rhs;
4589// }
4590
4591// RValue<Int2> operator%=(const Int2 &lhs, RValue<Int2> rhs)
4592// {
4593// return lhs = lhs % rhs;
4594// }
4595
4596 RValue<Int2> operator&=(const Int2 &lhs, RValue<Int2> rhs)
4597 {
4598 return lhs = lhs & rhs;
4599 }
4600
4601 RValue<Int2> operator|=(const Int2 &lhs, RValue<Int2> rhs)
4602 {
4603 return lhs = lhs | rhs;
4604 }
4605
4606 RValue<Int2> operator^=(const Int2 &lhs, RValue<Int2> rhs)
4607 {
4608 return lhs = lhs ^ rhs;
4609 }
4610
4611 RValue<Int2> operator<<=(const Int2 &lhs, unsigned char rhs)
4612 {
4613 return lhs = lhs << rhs;
4614 }
4615
4616 RValue<Int2> operator>>=(const Int2 &lhs, unsigned char rhs)
4617 {
4618 return lhs = lhs >> rhs;
4619 }
4620
4621 RValue<Int2> operator<<=(const Int2 &lhs, RValue<Long1> rhs)
4622 {
4623 return lhs = lhs << rhs;
4624 }
4625
4626 RValue<Int2> operator>>=(const Int2 &lhs, RValue<Long1> rhs)
4627 {
4628 return lhs = lhs >> rhs;
4629 }
4630
4631// RValue<Int2> operator+(RValue<Int2> val)
4632// {
4633// return val;
4634// }
4635
4636// RValue<Int2> operator-(RValue<Int2> val)
4637// {
4638// return RValue<Int2>(Nucleus::createNeg(val.value));
4639// }
4640
4641 RValue<Int2> operator~(RValue<Int2> val)
4642 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004643 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004644 }
4645
4646 RValue<Long1> UnpackLow(RValue<Int2> x, RValue<Int2> y)
4647 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004648 assert(false && "UNIMPLEMENTED"); return RValue<Long1>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004649 }
4650
4651 RValue<Long1> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
4652 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004653 assert(false && "UNIMPLEMENTED"); return RValue<Long1>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004654 }
4655
4656 RValue<Int> Extract(RValue<Int2> val, int i)
4657 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004658 assert(false && "UNIMPLEMENTED"); return RValue<Int>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004659 }
4660
4661 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
4662 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004663 assert(false && "UNIMPLEMENTED"); return RValue<Int2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004664 }
4665
4666 Type *Int2::getType()
4667 {
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004668 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004669 }
4670
4671 UInt2::UInt2()
4672 {
4673 // xy.parent = this;
4674 }
4675
4676 UInt2::UInt2(unsigned int x, unsigned int y)
4677 {
4678 // xy.parent = this;
4679
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004680 int64_t constantVector[2] = {x, y};
4681 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004682 }
4683
4684 UInt2::UInt2(RValue<UInt2> rhs)
4685 {
4686 // xy.parent = this;
4687
4688 storeValue(rhs.value);
4689 }
4690
4691 UInt2::UInt2(const UInt2 &rhs)
4692 {
4693 // xy.parent = this;
4694
4695 Value *value = rhs.loadValue();
4696 storeValue(value);
4697 }
4698
4699 UInt2::UInt2(const Reference<UInt2> &rhs)
4700 {
4701 // xy.parent = this;
4702
4703 Value *value = rhs.loadValue();
4704 storeValue(value);
4705 }
4706
4707 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs) const
4708 {
4709 storeValue(rhs.value);
4710
4711 return rhs;
4712 }
4713
4714 RValue<UInt2> UInt2::operator=(const UInt2 &rhs) const
4715 {
4716 Value *value = rhs.loadValue();
4717 storeValue(value);
4718
4719 return RValue<UInt2>(value);
4720 }
4721
4722 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs) const
4723 {
4724 Value *value = rhs.loadValue();
4725 storeValue(value);
4726
4727 return RValue<UInt2>(value);
4728 }
4729
4730 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
4731 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004732 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004733 }
4734
4735 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
4736 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004737 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004738 }
4739
4740// RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
4741// {
4742// return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
4743// }
4744
4745// RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
4746// {
4747// return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
4748// }
4749
4750// RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
4751// {
4752// return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
4753// }
4754
4755 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
4756 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004757 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004758 }
4759
4760 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
4761 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004762 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004763 }
4764
4765 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
4766 {
Nicolas Capensc4c431d2016-10-21 15:30:29 -04004767 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004768 }
4769
4770 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
4771 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004772 return RValue<UInt2>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004773 }
4774
4775 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
4776 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04004777 return RValue<UInt2>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004778 }
4779
4780 RValue<UInt2> operator<<(RValue<UInt2> lhs, RValue<Long1> rhs)
4781 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004782 assert(false && "UNIMPLEMENTED"); return RValue<UInt2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004783 }
4784
4785 RValue<UInt2> operator>>(RValue<UInt2> lhs, RValue<Long1> rhs)
4786 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04004787 assert(false && "UNIMPLEMENTED"); return RValue<UInt2>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004788 }
4789
4790 RValue<UInt2> operator+=(const UInt2 &lhs, RValue<UInt2> rhs)
4791 {
4792 return lhs = lhs + rhs;
4793 }
4794
4795 RValue<UInt2> operator-=(const UInt2 &lhs, RValue<UInt2> rhs)
4796 {
4797 return lhs = lhs - rhs;
4798 }
4799
4800// RValue<UInt2> operator*=(const UInt2 &lhs, RValue<UInt2> rhs)
4801// {
4802// return lhs = lhs * rhs;
4803// }
4804
4805// RValue<UInt2> operator/=(const UInt2 &lhs, RValue<UInt2> rhs)
4806// {
4807// return lhs = lhs / rhs;
4808// }
4809
4810// RValue<UInt2> operator%=(const UInt2 &lhs, RValue<UInt2> rhs)
4811// {
4812// return lhs = lhs % rhs;
4813// }
4814
4815 RValue<UInt2> operator&=(const UInt2 &lhs, RValue<UInt2> rhs)
4816 {
4817 return lhs = lhs & rhs;
4818 }
4819
4820 RValue<UInt2> operator|=(const UInt2 &lhs, RValue<UInt2> rhs)
4821 {
4822 return lhs = lhs | rhs;
4823 }
4824
4825 RValue<UInt2> operator^=(const UInt2 &lhs, RValue<UInt2> rhs)
4826 {
4827 return lhs = lhs ^ rhs;
4828 }
4829
4830 RValue<UInt2> operator<<=(const UInt2 &lhs, unsigned char rhs)
4831 {
4832 return lhs = lhs << rhs;
4833 }
4834
4835 RValue<UInt2> operator>>=(const UInt2 &lhs, unsigned char rhs)
4836 {
4837 return lhs = lhs >> rhs;
4838 }
4839
4840 RValue<UInt2> operator<<=(const UInt2 &lhs, RValue<Long1> rhs)
4841 {
4842 return lhs = lhs << rhs;
4843 }
4844
4845 RValue<UInt2> operator>>=(const UInt2 &lhs, RValue<Long1> rhs)
4846 {
4847 return lhs = lhs >> rhs;
4848 }
4849
4850// RValue<UInt2> operator+(RValue<UInt2> val)
4851// {
4852// return val;
4853// }
4854
4855// RValue<UInt2> operator-(RValue<UInt2> val)
4856// {
4857// return RValue<UInt2>(Nucleus::createNeg(val.value));
4858// }
4859
4860 RValue<UInt2> operator~(RValue<UInt2> val)
4861 {
4862 return RValue<UInt2>(Nucleus::createNot(val.value));
4863 }
4864
4865 Type *UInt2::getType()
4866 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04004867 return T(Type_v2i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04004868 }
4869
4870 Int4::Int4(RValue<Byte4> cast)
4871 {
4872 assert(false && "UNIMPLEMENTED");
4873 }
4874
4875 Int4::Int4(RValue<SByte4> cast)
4876 {
4877 assert(false && "UNIMPLEMENTED");
4878 }
4879
4880 Int4::Int4(RValue<Float4> cast)
4881 {
4882 // xyzw.parent = this;
4883
4884 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
4885
4886 storeValue(xyzw);
4887 }
4888
4889 Int4::Int4(RValue<Short4> cast)
4890 {
4891 assert(false && "UNIMPLEMENTED");
4892 }
4893
4894 Int4::Int4(RValue<UShort4> cast)
4895 {
4896 assert(false && "UNIMPLEMENTED");
4897 }
4898
4899 Int4::Int4()
4900 {
4901 // xyzw.parent = this;
4902 }
4903
4904 Int4::Int4(int xyzw)
4905 {
4906 constant(xyzw, xyzw, xyzw, xyzw);
4907 }
4908
4909 Int4::Int4(int x, int yzw)
4910 {
4911 constant(x, yzw, yzw, yzw);
4912 }
4913
4914 Int4::Int4(int x, int y, int zw)
4915 {
4916 constant(x, y, zw, zw);
4917 }
4918
4919 Int4::Int4(int x, int y, int z, int w)
4920 {
4921 constant(x, y, z, w);
4922 }
4923
4924 void Int4::constant(int x, int y, int z, int w)
4925 {
4926 // xyzw.parent = this;
4927
Nicolas Capens13ac2322016-10-13 14:52:12 -04004928 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04004929 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04004930 }
4931
4932 Int4::Int4(RValue<Int4> rhs)
4933 {
4934 // xyzw.parent = this;
4935
4936 storeValue(rhs.value);
4937 }
4938
4939 Int4::Int4(const Int4 &rhs)
4940 {
4941 // xyzw.parent = this;
4942
4943 Value *value = rhs.loadValue();
4944 storeValue(value);
4945 }
4946
4947 Int4::Int4(const Reference<Int4> &rhs)
4948 {
4949 // xyzw.parent = this;
4950
4951 Value *value = rhs.loadValue();
4952 storeValue(value);
4953 }
4954
4955 Int4::Int4(RValue<UInt4> rhs)
4956 {
4957 // xyzw.parent = this;
4958
4959 storeValue(rhs.value);
4960 }
4961
4962 Int4::Int4(const UInt4 &rhs)
4963 {
4964 // xyzw.parent = this;
4965
4966 Value *value = rhs.loadValue();
4967 storeValue(value);
4968 }
4969
4970 Int4::Int4(const Reference<UInt4> &rhs)
4971 {
4972 // xyzw.parent = this;
4973
4974 Value *value = rhs.loadValue();
4975 storeValue(value);
4976 }
4977
4978 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
4979 {
4980 assert(false && "UNIMPLEMENTED");
4981 }
4982
4983 Int4::Int4(RValue<Int> rhs)
4984 {
4985 // xyzw.parent = this;
4986
4987 assert(false && "UNIMPLEMENTED");
4988 }
4989
4990 Int4::Int4(const Int &rhs)
4991 {
4992 // xyzw.parent = this;
4993
4994 *this = RValue<Int>(rhs.loadValue());
4995 }
4996
4997 Int4::Int4(const Reference<Int> &rhs)
4998 {
4999 // xyzw.parent = this;
5000
5001 *this = RValue<Int>(rhs.loadValue());
5002 }
5003
5004 RValue<Int4> Int4::operator=(RValue<Int4> rhs) const
5005 {
5006 storeValue(rhs.value);
5007
5008 return rhs;
5009 }
5010
5011 RValue<Int4> Int4::operator=(const Int4 &rhs) const
5012 {
5013 Value *value = rhs.loadValue();
5014 storeValue(value);
5015
5016 return RValue<Int4>(value);
5017 }
5018
5019 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs) const
5020 {
5021 Value *value = rhs.loadValue();
5022 storeValue(value);
5023
5024 return RValue<Int4>(value);
5025 }
5026
5027 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
5028 {
5029 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5030 }
5031
5032 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
5033 {
5034 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5035 }
5036
5037 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
5038 {
5039 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5040 }
5041
5042 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5043 {
5044 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5045 }
5046
5047 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5048 {
5049 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5050 }
5051
5052 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
5053 {
5054 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5055 }
5056
5057 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
5058 {
5059 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5060 }
5061
5062 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
5063 {
5064 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5065 }
5066
5067 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
5068 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005069 return RValue<Int4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005070 }
5071
5072 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
5073 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005074 return RValue<Int4>(Nucleus::createAShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005075 }
5076
5077 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5078 {
5079 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5080 }
5081
5082 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5083 {
5084 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5085 }
5086
5087 RValue<Int4> operator+=(const Int4 &lhs, RValue<Int4> rhs)
5088 {
5089 return lhs = lhs + rhs;
5090 }
5091
5092 RValue<Int4> operator-=(const Int4 &lhs, RValue<Int4> rhs)
5093 {
5094 return lhs = lhs - rhs;
5095 }
5096
5097 RValue<Int4> operator*=(const Int4 &lhs, RValue<Int4> rhs)
5098 {
5099 return lhs = lhs * rhs;
5100 }
5101
5102// RValue<Int4> operator/=(const Int4 &lhs, RValue<Int4> rhs)
5103// {
5104// return lhs = lhs / rhs;
5105// }
5106
5107// RValue<Int4> operator%=(const Int4 &lhs, RValue<Int4> rhs)
5108// {
5109// return lhs = lhs % rhs;
5110// }
5111
5112 RValue<Int4> operator&=(const Int4 &lhs, RValue<Int4> rhs)
5113 {
5114 return lhs = lhs & rhs;
5115 }
5116
5117 RValue<Int4> operator|=(const Int4 &lhs, RValue<Int4> rhs)
5118 {
5119 return lhs = lhs | rhs;
5120 }
5121
5122 RValue<Int4> operator^=(const Int4 &lhs, RValue<Int4> rhs)
5123 {
5124 return lhs = lhs ^ rhs;
5125 }
5126
5127 RValue<Int4> operator<<=(const Int4 &lhs, unsigned char rhs)
5128 {
5129 return lhs = lhs << rhs;
5130 }
5131
5132 RValue<Int4> operator>>=(const Int4 &lhs, unsigned char rhs)
5133 {
5134 return lhs = lhs >> rhs;
5135 }
5136
5137 RValue<Int4> operator+(RValue<Int4> val)
5138 {
5139 return val;
5140 }
5141
5142 RValue<Int4> operator-(RValue<Int4> val)
5143 {
5144 return RValue<Int4>(Nucleus::createNeg(val.value));
5145 }
5146
5147 RValue<Int4> operator~(RValue<Int4> val)
5148 {
5149 return RValue<Int4>(Nucleus::createNot(val.value));
5150 }
5151
5152 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5153 {
5154 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5155 }
5156
5157 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5158 {
5159 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLT(x.value, y.value), Int4::getType()));
5160 }
5161
5162 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5163 {
5164 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSLE(x.value, y.value), Int4::getType()));
5165 }
5166
5167 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5168 {
5169 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5170 }
5171
5172 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5173 {
5174 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGE(x.value, y.value), Int4::getType()));
5175 }
5176
5177 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5178 {
5179 return RValue<Int4>(Nucleus::createSExt(Nucleus::createICmpSGT(x.value, y.value), Int4::getType()));
5180 }
5181
5182 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5183 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005184 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005185 }
5186
5187 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5188 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005189 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005190 }
5191
5192 RValue<Int4> RoundInt(RValue<Float4> cast)
5193 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005194 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005195 }
5196
5197 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
5198 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005199 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5200 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5201 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5202 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5203 pack->addArg(x.value);
5204 pack->addArg(y.value);
5205 ::basicBlock->appendInst(pack);
5206
5207 return RValue<Short8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005208 }
5209
5210 RValue<Int> Extract(RValue<Int4> x, int i)
5211 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005212 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005213 }
5214
5215 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
5216 {
5217 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5218 }
5219
5220 RValue<Int> SignMask(RValue<Int4> x)
5221 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04005222 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
5223 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5224 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5225 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5226 movmsk->addArg(x.value);
5227 ::basicBlock->appendInst(movmsk);
5228
5229 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005230 }
5231
5232 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
5233 {
Nicolas Capense95d5342016-09-30 11:37:28 -04005234 return RValue<Int4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005235 }
5236
5237 Type *Int4::getType()
5238 {
Nicolas Capens23d99a42016-09-30 14:57:16 -04005239 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005240 }
5241
5242 UInt4::UInt4(RValue<Float4> cast)
5243 {
5244 // xyzw.parent = this;
5245
5246 assert(false && "UNIMPLEMENTED");
5247 }
5248
5249 UInt4::UInt4()
5250 {
5251 // xyzw.parent = this;
5252 }
5253
5254 UInt4::UInt4(int xyzw)
5255 {
5256 constant(xyzw, xyzw, xyzw, xyzw);
5257 }
5258
5259 UInt4::UInt4(int x, int yzw)
5260 {
5261 constant(x, yzw, yzw, yzw);
5262 }
5263
5264 UInt4::UInt4(int x, int y, int zw)
5265 {
5266 constant(x, y, zw, zw);
5267 }
5268
5269 UInt4::UInt4(int x, int y, int z, int w)
5270 {
5271 constant(x, y, z, w);
5272 }
5273
5274 void UInt4::constant(int x, int y, int z, int w)
5275 {
5276 // xyzw.parent = this;
5277
Nicolas Capens13ac2322016-10-13 14:52:12 -04005278 int64_t constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005279 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005280 }
5281
5282 UInt4::UInt4(RValue<UInt4> rhs)
5283 {
5284 // xyzw.parent = this;
5285
5286 storeValue(rhs.value);
5287 }
5288
5289 UInt4::UInt4(const UInt4 &rhs)
5290 {
5291 // xyzw.parent = this;
5292
5293 Value *value = rhs.loadValue();
5294 storeValue(value);
5295 }
5296
5297 UInt4::UInt4(const Reference<UInt4> &rhs)
5298 {
5299 // xyzw.parent = this;
5300
5301 Value *value = rhs.loadValue();
5302 storeValue(value);
5303 }
5304
5305 UInt4::UInt4(RValue<Int4> rhs)
5306 {
5307 // xyzw.parent = this;
5308
5309 storeValue(rhs.value);
5310 }
5311
5312 UInt4::UInt4(const Int4 &rhs)
5313 {
5314 // xyzw.parent = this;
5315
5316 Value *value = rhs.loadValue();
5317 storeValue(value);
5318 }
5319
5320 UInt4::UInt4(const Reference<Int4> &rhs)
5321 {
5322 // xyzw.parent = this;
5323
5324 Value *value = rhs.loadValue();
5325 storeValue(value);
5326 }
5327
5328 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5329 {
5330 assert(false && "UNIMPLEMENTED");
5331 }
5332
5333 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs) const
5334 {
5335 storeValue(rhs.value);
5336
5337 return rhs;
5338 }
5339
5340 RValue<UInt4> UInt4::operator=(const UInt4 &rhs) const
5341 {
5342 Value *value = rhs.loadValue();
5343 storeValue(value);
5344
5345 return RValue<UInt4>(value);
5346 }
5347
5348 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs) const
5349 {
5350 Value *value = rhs.loadValue();
5351 storeValue(value);
5352
5353 return RValue<UInt4>(value);
5354 }
5355
5356 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
5357 {
5358 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5359 }
5360
5361 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
5362 {
5363 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5364 }
5365
5366 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
5367 {
5368 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5369 }
5370
5371 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5372 {
5373 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5374 }
5375
5376 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5377 {
5378 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5379 }
5380
5381 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
5382 {
5383 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5384 }
5385
5386 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
5387 {
5388 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5389 }
5390
5391 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
5392 {
5393 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5394 }
5395
5396 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
5397 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005398 return RValue<UInt4>(Nucleus::createShl(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005399 }
5400
5401 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
5402 {
Nicolas Capens327f1df2016-10-21 14:26:34 -04005403 return RValue<UInt4>(Nucleus::createLShr(lhs.value, C(::context->getConstantInt32(rhs))));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005404 }
5405
5406 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5407 {
5408 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5409 }
5410
5411 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5412 {
5413 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5414 }
5415
5416 RValue<UInt4> operator+=(const UInt4 &lhs, RValue<UInt4> rhs)
5417 {
5418 return lhs = lhs + rhs;
5419 }
5420
5421 RValue<UInt4> operator-=(const UInt4 &lhs, RValue<UInt4> rhs)
5422 {
5423 return lhs = lhs - rhs;
5424 }
5425
5426 RValue<UInt4> operator*=(const UInt4 &lhs, RValue<UInt4> rhs)
5427 {
5428 return lhs = lhs * rhs;
5429 }
5430
5431// RValue<UInt4> operator/=(const UInt4 &lhs, RValue<UInt4> rhs)
5432// {
5433// return lhs = lhs / rhs;
5434// }
5435
5436// RValue<UInt4> operator%=(const UInt4 &lhs, RValue<UInt4> rhs)
5437// {
5438// return lhs = lhs % rhs;
5439// }
5440
5441 RValue<UInt4> operator&=(const UInt4 &lhs, RValue<UInt4> rhs)
5442 {
5443 return lhs = lhs & rhs;
5444 }
5445
5446 RValue<UInt4> operator|=(const UInt4 &lhs, RValue<UInt4> rhs)
5447 {
5448 return lhs = lhs | rhs;
5449 }
5450
5451 RValue<UInt4> operator^=(const UInt4 &lhs, RValue<UInt4> rhs)
5452 {
5453 return lhs = lhs ^ rhs;
5454 }
5455
5456 RValue<UInt4> operator<<=(const UInt4 &lhs, unsigned char rhs)
5457 {
5458 return lhs = lhs << rhs;
5459 }
5460
5461 RValue<UInt4> operator>>=(const UInt4 &lhs, unsigned char rhs)
5462 {
5463 return lhs = lhs >> rhs;
5464 }
5465
5466 RValue<UInt4> operator+(RValue<UInt4> val)
5467 {
5468 return val;
5469 }
5470
5471 RValue<UInt4> operator-(RValue<UInt4> val)
5472 {
5473 return RValue<UInt4>(Nucleus::createNeg(val.value));
5474 }
5475
5476 RValue<UInt4> operator~(RValue<UInt4> val)
5477 {
5478 return RValue<UInt4>(Nucleus::createNot(val.value));
5479 }
5480
5481 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5482 {
5483 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpEQ(x.value, y.value), Int4::getType()));
5484 }
5485
5486 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5487 {
5488 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULT(x.value, y.value), Int4::getType()));
5489 }
5490
5491 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5492 {
5493 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpULE(x.value, y.value), Int4::getType()));
5494 }
5495
5496 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5497 {
5498 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpNE(x.value, y.value), Int4::getType()));
5499 }
5500
5501 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5502 {
5503 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGE(x.value, y.value), Int4::getType()));
5504 }
5505
5506 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5507 {
5508 return RValue<UInt4>(Nucleus::createSExt(Nucleus::createICmpUGT(x.value, y.value), Int4::getType()));
5509 }
5510
5511 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
5512 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005513 assert(false && "UNIMPLEMENTED"); return RValue<UInt4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005514 }
5515
5516 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
5517 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005518 assert(false && "UNIMPLEMENTED"); return RValue<UInt4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005519 }
5520
5521 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
5522 {
Nicolas Capensec54a172016-10-25 17:32:37 -04005523 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5524 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5525 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5526 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5527 pack->addArg(x.value);
5528 pack->addArg(y.value);
5529 ::basicBlock->appendInst(pack);
5530
5531 return RValue<UShort8>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005532 }
5533
5534 Type *UInt4::getType()
5535 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005536 return T(Ice::IceType_v4i32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005537 }
5538
5539 Float::Float(RValue<Int> cast)
5540 {
5541 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
5542
5543 storeValue(integer);
5544 }
5545
5546 Float::Float()
5547 {
5548 }
5549
5550 Float::Float(float x)
5551 {
5552 storeValue(Nucleus::createConstantFloat(x));
5553 }
5554
5555 Float::Float(RValue<Float> rhs)
5556 {
5557 storeValue(rhs.value);
5558 }
5559
5560 Float::Float(const Float &rhs)
5561 {
5562 Value *value = rhs.loadValue();
5563 storeValue(value);
5564 }
5565
5566 Float::Float(const Reference<Float> &rhs)
5567 {
5568 Value *value = rhs.loadValue();
5569 storeValue(value);
5570 }
5571
5572 RValue<Float> Float::operator=(RValue<Float> rhs) const
5573 {
5574 storeValue(rhs.value);
5575
5576 return rhs;
5577 }
5578
5579 RValue<Float> Float::operator=(const Float &rhs) const
5580 {
5581 Value *value = rhs.loadValue();
5582 storeValue(value);
5583
5584 return RValue<Float>(value);
5585 }
5586
5587 RValue<Float> Float::operator=(const Reference<Float> &rhs) const
5588 {
5589 Value *value = rhs.loadValue();
5590 storeValue(value);
5591
5592 return RValue<Float>(value);
5593 }
5594
5595 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
5596 {
5597 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
5598 }
5599
5600 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
5601 {
5602 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
5603 }
5604
5605 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
5606 {
5607 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
5608 }
5609
5610 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
5611 {
5612 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
5613 }
5614
5615 RValue<Float> operator+=(const Float &lhs, RValue<Float> rhs)
5616 {
5617 return lhs = lhs + rhs;
5618 }
5619
5620 RValue<Float> operator-=(const Float &lhs, RValue<Float> rhs)
5621 {
5622 return lhs = lhs - rhs;
5623 }
5624
5625 RValue<Float> operator*=(const Float &lhs, RValue<Float> rhs)
5626 {
5627 return lhs = lhs * rhs;
5628 }
5629
5630 RValue<Float> operator/=(const Float &lhs, RValue<Float> rhs)
5631 {
5632 return lhs = lhs / rhs;
5633 }
5634
5635 RValue<Float> operator+(RValue<Float> val)
5636 {
5637 return val;
5638 }
5639
5640 RValue<Float> operator-(RValue<Float> val)
5641 {
5642 return RValue<Float>(Nucleus::createFNeg(val.value));
5643 }
5644
5645 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
5646 {
5647 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
5648 }
5649
5650 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
5651 {
5652 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
5653 }
5654
5655 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
5656 {
5657 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
5658 }
5659
5660 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
5661 {
5662 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
5663 }
5664
5665 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
5666 {
5667 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
5668 }
5669
5670 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
5671 {
5672 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
5673 }
5674
5675 RValue<Float> Abs(RValue<Float> x)
5676 {
5677 return IfThenElse(x > 0.0f, x, -x);
5678 }
5679
5680 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
5681 {
5682 return IfThenElse(x > y, x, y);
5683 }
5684
5685 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
5686 {
5687 return IfThenElse(x < y, x, y);
5688 }
5689
5690 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
5691 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005692 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005693 }
5694
5695 RValue<Float> RcpSqrt_pp(RValue<Float> x)
5696 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005697 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005698 }
5699
5700 RValue<Float> Sqrt(RValue<Float> x)
5701 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005702 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005703 }
5704
5705 RValue<Float> Round(RValue<Float> x)
5706 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005707 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005708 }
5709
5710 RValue<Float> Trunc(RValue<Float> x)
5711 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005712 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005713 }
5714
5715 RValue<Float> Frac(RValue<Float> x)
5716 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005717 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005718 }
5719
5720 RValue<Float> Floor(RValue<Float> x)
5721 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005722 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005723 }
5724
5725 RValue<Float> Ceil(RValue<Float> x)
5726 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005727 assert(false && "UNIMPLEMENTED"); return RValue<Float>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005728 }
5729
5730 Type *Float::getType()
5731 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04005732 return T(Ice::IceType_f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005733 }
5734
5735 Float2::Float2(RValue<Float4> cast)
5736 {
Nicolas Capens22008782016-10-20 01:11:47 -04005737 storeValue(Nucleus::createBitCast(cast.value, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005738 }
5739
5740 Type *Float2::getType()
5741 {
Nicolas Capens4cfd4572016-10-20 01:00:19 -04005742 return T(Type_v2f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04005743 }
5744
5745 Float4::Float4(RValue<Byte4> cast)
5746 {
5747 xyzw.parent = this;
5748
5749 assert(false && "UNIMPLEMENTED");
5750 }
5751
5752 Float4::Float4(RValue<SByte4> cast)
5753 {
5754 xyzw.parent = this;
5755
5756 assert(false && "UNIMPLEMENTED");
5757 }
5758
5759 Float4::Float4(RValue<Short4> cast)
5760 {
5761 xyzw.parent = this;
5762
5763 Int4 c(cast);
5764 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5765 }
5766
5767 Float4::Float4(RValue<UShort4> cast)
5768 {
5769 xyzw.parent = this;
5770
5771 Int4 c(cast);
5772 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
5773 }
5774
5775 Float4::Float4(RValue<Int4> cast)
5776 {
5777 xyzw.parent = this;
5778
5779 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
5780
5781 storeValue(xyzw);
5782 }
5783
5784 Float4::Float4(RValue<UInt4> cast)
5785 {
5786 xyzw.parent = this;
5787
5788 Value *xyzw = Nucleus::createUIToFP(cast.value, Float4::getType());
5789
5790 storeValue(xyzw);
5791 }
5792
5793 Float4::Float4()
5794 {
5795 xyzw.parent = this;
5796 }
5797
5798 Float4::Float4(float xyzw)
5799 {
5800 constant(xyzw, xyzw, xyzw, xyzw);
5801 }
5802
5803 Float4::Float4(float x, float yzw)
5804 {
5805 constant(x, yzw, yzw, yzw);
5806 }
5807
5808 Float4::Float4(float x, float y, float zw)
5809 {
5810 constant(x, y, zw, zw);
5811 }
5812
5813 Float4::Float4(float x, float y, float z, float w)
5814 {
5815 constant(x, y, z, w);
5816 }
5817
5818 void Float4::constant(float x, float y, float z, float w)
5819 {
5820 xyzw.parent = this;
5821
Nicolas Capens13ac2322016-10-13 14:52:12 -04005822 double constantVector[4] = {x, y, z, w};
Nicolas Capens8dfd9a72016-10-13 17:44:51 -04005823 storeValue(Nucleus::createConstantVector(constantVector, getType()));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005824 }
5825
5826 Float4::Float4(RValue<Float4> rhs)
5827 {
5828 xyzw.parent = this;
5829
5830 storeValue(rhs.value);
5831 }
5832
5833 Float4::Float4(const Float4 &rhs)
5834 {
5835 xyzw.parent = this;
5836
5837 Value *value = rhs.loadValue();
5838 storeValue(value);
5839 }
5840
5841 Float4::Float4(const Reference<Float4> &rhs)
5842 {
5843 xyzw.parent = this;
5844
5845 Value *value = rhs.loadValue();
5846 storeValue(value);
5847 }
5848
5849 Float4::Float4(RValue<Float> rhs)
5850 {
5851 xyzw.parent = this;
5852
5853 assert(false && "UNIMPLEMENTED");
5854 }
5855
5856 Float4::Float4(const Float &rhs)
5857 {
5858 xyzw.parent = this;
5859
5860 *this = RValue<Float>(rhs.loadValue());
5861 }
5862
5863 Float4::Float4(const Reference<Float> &rhs)
5864 {
5865 xyzw.parent = this;
5866
5867 *this = RValue<Float>(rhs.loadValue());
5868 }
5869
5870 RValue<Float4> Float4::operator=(float x) const
5871 {
5872 return *this = Float4(x, x, x, x);
5873 }
5874
5875 RValue<Float4> Float4::operator=(RValue<Float4> rhs) const
5876 {
5877 storeValue(rhs.value);
5878
5879 return rhs;
5880 }
5881
5882 RValue<Float4> Float4::operator=(const Float4 &rhs) const
5883 {
5884 Value *value = rhs.loadValue();
5885 storeValue(value);
5886
5887 return RValue<Float4>(value);
5888 }
5889
5890 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs) const
5891 {
5892 Value *value = rhs.loadValue();
5893 storeValue(value);
5894
5895 return RValue<Float4>(value);
5896 }
5897
5898 RValue<Float4> Float4::operator=(RValue<Float> rhs) const
5899 {
5900 return *this = Float4(rhs);
5901 }
5902
5903 RValue<Float4> Float4::operator=(const Float &rhs) const
5904 {
5905 return *this = Float4(rhs);
5906 }
5907
5908 RValue<Float4> Float4::operator=(const Reference<Float> &rhs) const
5909 {
5910 return *this = Float4(rhs);
5911 }
5912
5913 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
5914 {
5915 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
5916 }
5917
5918 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
5919 {
5920 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
5921 }
5922
5923 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
5924 {
5925 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
5926 }
5927
5928 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
5929 {
5930 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
5931 }
5932
5933 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
5934 {
5935 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
5936 }
5937
5938 RValue<Float4> operator+=(const Float4 &lhs, RValue<Float4> rhs)
5939 {
5940 return lhs = lhs + rhs;
5941 }
5942
5943 RValue<Float4> operator-=(const Float4 &lhs, RValue<Float4> rhs)
5944 {
5945 return lhs = lhs - rhs;
5946 }
5947
5948 RValue<Float4> operator*=(const Float4 &lhs, RValue<Float4> rhs)
5949 {
5950 return lhs = lhs * rhs;
5951 }
5952
5953 RValue<Float4> operator/=(const Float4 &lhs, RValue<Float4> rhs)
5954 {
5955 return lhs = lhs / rhs;
5956 }
5957
5958 RValue<Float4> operator%=(const Float4 &lhs, RValue<Float4> rhs)
5959 {
5960 return lhs = lhs % rhs;
5961 }
5962
5963 RValue<Float4> operator+(RValue<Float4> val)
5964 {
5965 return val;
5966 }
5967
5968 RValue<Float4> operator-(RValue<Float4> val)
5969 {
5970 return RValue<Float4>(Nucleus::createFNeg(val.value));
5971 }
5972
5973 RValue<Float4> Abs(RValue<Float4> x)
5974 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005975 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005976 }
5977
5978 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
5979 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005980 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005981 }
5982
5983 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
5984 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005985 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005986 }
5987
5988 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
5989 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005990 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005991 }
5992
5993 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
5994 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04005995 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04005996 }
5997
5998 RValue<Float4> Sqrt(RValue<Float4> x)
5999 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006000 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006001 }
6002
6003 RValue<Float4> Insert(const Float4 &val, RValue<Float> element, int i)
6004 {
6005 Value *value = val.loadValue();
6006 Value *insert = Nucleus::createInsertElement(value, element.value, i);
6007
6008 val = RValue<Float4>(insert);
6009
6010 return val;
6011 }
6012
6013 RValue<Float> Extract(RValue<Float4> x, int i)
6014 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006015 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006016 }
6017
6018 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
6019 {
Nicolas Capense95d5342016-09-30 11:37:28 -04006020 return RValue<Float4>(createSwizzle4(x.value, select));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006021 }
6022
6023 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
6024 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006025 int shuffle[4] =
6026 {
6027 ((imm >> 0) & 0x03) + 0,
6028 ((imm >> 2) & 0x03) + 0,
6029 ((imm >> 4) & 0x03) + 4,
6030 ((imm >> 6) & 0x03) + 4,
6031 };
6032
6033 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006034 }
6035
6036 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
6037 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006038 int shuffle[4] = {0, 4, 1, 5};
6039 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006040 }
6041
6042 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
6043 {
Nicolas Capens37fbece2016-10-21 15:08:56 -04006044 int shuffle[4] = {2, 6, 3, 7};
6045 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006046 }
6047
6048 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
6049 {
6050 Value *vector = lhs.loadValue();
Nicolas Capense95d5342016-09-30 11:37:28 -04006051 Value *shuffle = createMask4(vector, rhs.value, select);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006052 lhs.storeValue(shuffle);
6053
6054 return RValue<Float4>(shuffle);
6055 }
6056
6057 RValue<Int> SignMask(RValue<Float4> x)
6058 {
Nicolas Capensf2cb9df2016-10-21 17:26:13 -04006059 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
6060 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6061 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6062 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6063 movmsk->addArg(x.value);
6064 ::basicBlock->appendInst(movmsk);
6065
6066 return RValue<Int>(V(result));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006067 }
6068
6069 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
6070 {
6071 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOEQ(x.value, y.value), Int4::getType()));
6072 }
6073
6074 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
6075 {
6076 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLT(x.value, y.value), Int4::getType()));
6077 }
6078
6079 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
6080 {
6081 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOLE(x.value, y.value), Int4::getType()));
6082 }
6083
6084 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
6085 {
6086 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpONE(x.value, y.value), Int4::getType()));
6087 }
6088
6089 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
6090 {
6091 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGE(x.value, y.value), Int4::getType()));
6092 }
6093
6094 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
6095 {
6096 return RValue<Int4>(Nucleus::createSExt(Nucleus::createFCmpOGT(x.value, y.value), Int4::getType()));
6097 }
6098
6099 RValue<Float4> Round(RValue<Float4> x)
6100 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006101 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006102 }
6103
6104 RValue<Float4> Trunc(RValue<Float4> x)
6105 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006106 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006107 }
6108
6109 RValue<Float4> Frac(RValue<Float4> x)
6110 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006111 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006112 }
6113
6114 RValue<Float4> Floor(RValue<Float4> x)
6115 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006116 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006117 }
6118
6119 RValue<Float4> Ceil(RValue<Float4> x)
6120 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006121 assert(false && "UNIMPLEMENTED"); return RValue<Float4>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006122 }
6123
6124 Type *Float4::getType()
6125 {
Nicolas Capens9709d4f2016-09-30 11:44:14 -04006126 return T(Ice::IceType_v4f32);
Nicolas Capens598f8d82016-09-26 15:09:10 -04006127 }
6128
6129 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
6130 {
Nicolas Capens8820f642016-09-30 04:42:43 -04006131 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006132 }
6133
6134 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6135 {
Nicolas Capens6d738712016-09-30 04:15:22 -04006136 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006137 }
6138
6139 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6140 {
Nicolas Capens6d738712016-09-30 04:15:22 -04006141 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006142 }
6143
6144 RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
6145 {
6146 return lhs = lhs + offset;
6147 }
6148
6149 RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
6150 {
6151 return lhs = lhs + offset;
6152 }
6153
6154 RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
6155 {
6156 return lhs = lhs + offset;
6157 }
6158
6159 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
6160 {
6161 return lhs + -offset;
6162 }
6163
6164 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6165 {
6166 return lhs + -offset;
6167 }
6168
6169 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6170 {
6171 return lhs + -offset;
6172 }
6173
6174 RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset)
6175 {
6176 return lhs = lhs - offset;
6177 }
6178
6179 RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
6180 {
6181 return lhs = lhs - offset;
6182 }
6183
6184 RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
6185 {
6186 return lhs = lhs - offset;
6187 }
6188
6189 void Return()
6190 {
6191 Nucleus::createRetVoid();
6192 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6193 Nucleus::createUnreachable();
6194 }
6195
6196 void Return(bool ret)
6197 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006198 Nucleus::createRet(Nucleus::createConstantInt(ret));
6199 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6200 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006201 }
6202
6203 void Return(const Int &ret)
6204 {
Nicolas Capensfdcca2d2016-10-20 11:31:36 -04006205 Nucleus::createRet(ret.loadValue());
6206 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6207 Nucleus::createUnreachable();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006208 }
6209
Nicolas Capens598f8d82016-09-26 15:09:10 -04006210 bool branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
6211 {
6212 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
6213 Nucleus::setInsertBlock(bodyBB);
6214
6215 return true;
6216 }
6217
Nicolas Capens9ed1a182016-10-24 09:52:23 -04006218 void endIf(BasicBlock *falseBB)
6219 {
6220 ::falseBB = falseBB;
6221 }
6222
Nicolas Capens598f8d82016-09-26 15:09:10 -04006223 bool elseBlock(BasicBlock *falseBB)
6224 {
Nicolas Capens9ed1a182016-10-24 09:52:23 -04006225 assert(falseBB && "Else not preceded by If");
6226 falseBB->getInsts().back().setDeleted();
Nicolas Capens598f8d82016-09-26 15:09:10 -04006227 Nucleus::setInsertBlock(falseBB);
6228
6229 return true;
6230 }
6231
Nicolas Capens9ed1a182016-10-24 09:52:23 -04006232 BasicBlock *beginElse()
6233 {
6234 BasicBlock *falseBB = ::falseBB;
6235 ::falseBB = nullptr;
6236
6237 return falseBB;
6238 }
6239
Nicolas Capens598f8d82016-09-26 15:09:10 -04006240 RValue<Long> Ticks()
6241 {
Nicolas Capensc37252c2016-09-28 16:11:54 -04006242 assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));
Nicolas Capens598f8d82016-09-26 15:09:10 -04006243 }
6244}
6245