1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include "Nucleus.hpp"
17 #include "Reactor.hpp"
18 #include "Routine.hpp"
20 #include "Optimizer.hpp"
22 #include "src/IceTypes.h"
23 #include "src/IceCfg.h"
24 #include "src/IceELFStreamer.h"
25 #include "src/IceGlobalContext.h"
26 #include "src/IceCfgNode.h"
27 #include "src/IceELFObjectWriter.h"
28 #include "src/IceGlobalInits.h"
30 #include "llvm/Support/FileSystem.h"
31 #include "llvm/Support/raw_os_ostream.h"
34 #ifndef WIN32_LEAN_AND_MEAN
35 #define WIN32_LEAN_AND_MEAN
36 #endif // !WIN32_LEAN_AND_MEAN
43 #if !defined(MAP_ANONYMOUS)
44 #define MAP_ANONYMOUS MAP_ANON
55 Ice::GlobalContext *context = nullptr;
56 Ice::Cfg *function = nullptr;
57 Ice::CfgNode *basicBlock = nullptr;
58 Ice::CfgLocalAllocatorScope *allocator = nullptr;
59 sw::Routine *routine = nullptr;
61 std::mutex codegenMutex;
63 Ice::ELFFileStreamer *elfFile = nullptr;
64 Ice::Fdstream *out = nullptr;
69 #if !defined(__i386__) && defined(_M_IX86)
73 #if !defined(__x86_64__) && (defined(_M_AMD64) || defined (_M_X64))
80 const static bool ARM;
81 const static bool SSE4_1;
84 static void cpuid(int registers[4], int info)
86 #if defined(__i386__) || defined(__x86_64__)
88 __cpuid(registers, info);
90 __asm volatile("cpuid": "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3]): "a" (info));
100 static bool detectARM()
104 #elif defined(__i386__) || defined(__x86_64__)
107 #error "Unknown architecture"
111 static bool detectSSE4_1()
113 #if defined(__i386__) || defined(__x86_64__)
116 return (registers[2] & 0x00080000) != 0;
123 const bool CPUID::ARM = CPUID::detectARM();
124 const bool CPUID::SSE4_1 = CPUID::detectSSE4_1();
125 const bool emulateIntrinsics = CPUID::ARM;
126 const bool emulateMismatchedBitCast = CPUID::ARM;
134 EmulatedV2 = 2 << EmulatedShift,
135 EmulatedV4 = 4 << EmulatedShift,
136 EmulatedV8 = 8 << EmulatedShift,
137 EmulatedBits = EmulatedV2 | EmulatedV4 | EmulatedV8,
139 Type_v2i32 = Ice::IceType_v4i32 | EmulatedV2,
140 Type_v4i16 = Ice::IceType_v8i16 | EmulatedV4,
141 Type_v2i16 = Ice::IceType_v8i16 | EmulatedV2,
142 Type_v8i8 = Ice::IceType_v16i8 | EmulatedV8,
143 Type_v4i8 = Ice::IceType_v16i8 | EmulatedV4,
144 Type_v2f32 = Ice::IceType_v4f32 | EmulatedV2,
147 class Value : public Ice::Operand {};
148 class SwitchCases : public Ice::InstSwitch {};
149 class BasicBlock : public Ice::CfgNode {};
153 static_assert(static_cast<unsigned int>(Ice::IceType_NUM) < static_cast<unsigned int>(EmulatedBits), "Ice::Type overlaps with our emulated types!");
154 return (Ice::Type)(reinterpret_cast<std::intptr_t>(t) & ~EmulatedBits);
159 return reinterpret_cast<Type*>(t);
162 Type *T(EmulatedType t)
164 return reinterpret_cast<Type*>(t);
167 Value *V(Ice::Operand *v)
169 return reinterpret_cast<Value*>(v);
172 BasicBlock *B(Ice::CfgNode *b)
174 return reinterpret_cast<BasicBlock*>(b);
177 static size_t typeSize(Type *type)
179 if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits)
181 switch(reinterpret_cast<std::intptr_t>(type))
183 case Type_v2i32: return 8;
184 case Type_v4i16: return 8;
185 case Type_v2i16: return 4;
186 case Type_v8i8: return 8;
187 case Type_v4i8: return 4;
188 case Type_v2f32: return 8;
189 default: assert(false);
193 return Ice::typeWidthInBytes(T(type));
196 Optimization optimization[10] = {InstructionCombining, Disabled};
198 using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type;
199 using SectionHeader = std::conditional<sizeof(void*) == 8, Elf64_Shdr, Elf32_Shdr>::type;
201 inline const SectionHeader *sectionHeader(const ElfHeader *elfHeader)
203 return reinterpret_cast<const SectionHeader*>((intptr_t)elfHeader + elfHeader->e_shoff);
206 inline const SectionHeader *elfSection(const ElfHeader *elfHeader, int index)
208 return §ionHeader(elfHeader)[index];
211 static void *relocateSymbol(const ElfHeader *elfHeader, const Elf32_Rel &relocation, const SectionHeader &relocationTable)
213 const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info);
215 intptr_t address = (intptr_t)elfHeader + target->sh_offset;
216 int32_t *patchSite = (int*)(address + relocation.r_offset);
217 uint32_t index = relocation.getSymbol();
218 int table = relocationTable.sh_link;
219 void *symbolValue = nullptr;
221 if(index != SHN_UNDEF)
223 if(table == SHN_UNDEF) return nullptr;
224 const SectionHeader *symbolTable = elfSection(elfHeader, table);
226 uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize;
227 if(index >= symtab_entries)
229 assert(index < symtab_entries && "Symbol Index out of range");
233 intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset;
234 Elf32_Sym &symbol = ((Elf32_Sym*)symbolAddress)[index];
235 uint16_t section = symbol.st_shndx;
237 if(section != SHN_UNDEF && section < SHN_LORESERVE)
239 const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx);
240 symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset);
250 switch(relocation.getType())
255 case R_ARM_MOVW_ABS_NC:
257 uint32_t thumb = 0; // Calls to Thumb code not supported.
258 uint32_t lo = (uint32_t)(intptr_t)symbolValue | thumb;
259 *patchSite = (*patchSite & 0xFFF0F000) | ((lo & 0xF000) << 4) | (lo & 0x0FFF);
264 uint32_t hi = (uint32_t)(intptr_t)(symbolValue) >> 16;
265 *patchSite = (*patchSite & 0xFFF0F000) | ((hi & 0xF000) << 4) | (hi & 0x0FFF);
269 assert(false && "Unsupported relocation type");
275 switch(relocation.getType())
281 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite);
284 // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite);
287 assert(false && "Unsupported relocation type");
296 static void *relocateSymbol(const ElfHeader *elfHeader, const Elf64_Rela &relocation, const SectionHeader &relocationTable)
298 const SectionHeader *target = elfSection(elfHeader, relocationTable.sh_info);
300 intptr_t address = (intptr_t)elfHeader + target->sh_offset;
301 int32_t *patchSite = (int*)(address + relocation.r_offset);
302 uint32_t index = relocation.getSymbol();
303 int table = relocationTable.sh_link;
304 void *symbolValue = nullptr;
306 if(index != SHN_UNDEF)
308 if(table == SHN_UNDEF) return nullptr;
309 const SectionHeader *symbolTable = elfSection(elfHeader, table);
311 uint32_t symtab_entries = symbolTable->sh_size / symbolTable->sh_entsize;
312 if(index >= symtab_entries)
314 assert(index < symtab_entries && "Symbol Index out of range");
318 intptr_t symbolAddress = (intptr_t)elfHeader + symbolTable->sh_offset;
319 Elf64_Sym &symbol = ((Elf64_Sym*)symbolAddress)[index];
320 uint16_t section = symbol.st_shndx;
322 if(section != SHN_UNDEF && section < SHN_LORESERVE)
324 const SectionHeader *target = elfSection(elfHeader, symbol.st_shndx);
325 symbolValue = reinterpret_cast<void*>((intptr_t)elfHeader + symbol.st_value + target->sh_offset);
333 switch(relocation.getType())
339 *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend;
342 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend;
345 *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend;
348 assert(false && "Unsupported relocation type");
355 void *loadImage(uint8_t *const elfImage, size_t &codeSize)
357 ElfHeader *elfHeader = (ElfHeader*)elfImage;
359 if(!elfHeader->checkMagic())
364 // Expect ELF bitness to match platform
365 assert(sizeof(void*) == 8 ? elfHeader->getFileClass() == ELFCLASS64 : elfHeader->getFileClass() == ELFCLASS32);
366 #if defined(__i386__)
367 assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_386);
368 #elif defined(__x86_64__)
369 assert(sizeof(void*) == 8 && elfHeader->e_machine == EM_X86_64);
370 #elif defined(__arm__)
371 assert(sizeof(void*) == 4 && elfHeader->e_machine == EM_ARM);
373 #error "Unsupported platform"
376 SectionHeader *sectionHeader = (SectionHeader*)(elfImage + elfHeader->e_shoff);
377 void *entry = nullptr;
379 for(int i = 0; i < elfHeader->e_shnum; i++)
381 if(sectionHeader[i].sh_type == SHT_PROGBITS)
383 if(sectionHeader[i].sh_flags & SHF_EXECINSTR)
385 entry = elfImage + sectionHeader[i].sh_offset;
386 codeSize = sectionHeader[i].sh_size;
389 else if(sectionHeader[i].sh_type == SHT_REL)
391 assert(sizeof(void*) == 4 && "UNIMPLEMENTED"); // Only expected/implemented for 32-bit code
393 for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
395 const Elf32_Rel &relocation = ((const Elf32_Rel*)(elfImage + sectionHeader[i].sh_offset))[index];
396 relocateSymbol(elfHeader, relocation, sectionHeader[i]);
399 else if(sectionHeader[i].sh_type == SHT_RELA)
401 assert(sizeof(void*) == 8 && "UNIMPLEMENTED"); // Only expected/implemented for 64-bit code
403 for(Elf32_Word index = 0; index < sectionHeader[i].sh_size / sectionHeader[i].sh_entsize; index++)
405 const Elf64_Rela &relocation = ((const Elf64_Rela*)(elfImage + sectionHeader[i].sh_offset))[index];
406 relocateSymbol(elfHeader, relocation, sectionHeader[i]);
415 struct ExecutableAllocator
417 ExecutableAllocator() {};
418 template<class U> ExecutableAllocator(const ExecutableAllocator<U> &other) {};
420 using value_type = T;
421 using size_type = std::size_t;
423 T *allocate(size_type n)
426 return (T*)VirtualAlloc(NULL, sizeof(T) * n, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
428 return (T*)mmap(nullptr, sizeof(T) * n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
432 void deallocate(T *p, size_type n)
435 VirtualFree(p, 0, MEM_RELEASE);
437 munmap(p, sizeof(T) * n);
442 class ELFMemoryStreamer : public Ice::ELFStreamer, public Routine
444 ELFMemoryStreamer(const ELFMemoryStreamer &) = delete;
445 ELFMemoryStreamer &operator=(const ELFMemoryStreamer &) = delete;
448 ELFMemoryStreamer() : Routine(), entry(nullptr)
451 buffer.reserve(0x1000);
454 ~ELFMemoryStreamer() override
457 if(buffer.size() != 0)
460 VirtualProtect(&buffer[0], buffer.size(), oldProtection, &exeProtection);
465 void write8(uint8_t Value) override
467 if(position == (uint64_t)buffer.size())
469 buffer.push_back(Value);
472 else if(position < (uint64_t)buffer.size())
474 buffer[position] = Value;
477 else assert(false && "UNIMPLEMENTED");
480 void writeBytes(llvm::StringRef Bytes) override
482 std::size_t oldSize = buffer.size();
483 buffer.resize(oldSize + Bytes.size());
484 memcpy(&buffer[oldSize], Bytes.begin(), Bytes.size());
485 position += Bytes.size();
488 uint64_t tell() const override { return position; }
490 void seek(uint64_t Off) override { position = Off; }
492 const void *getEntry() override
496 position = std::numeric_limits<std::size_t>::max(); // Can't stream more data after this
499 entry = loadImage(&buffer[0], codeSize);
502 VirtualProtect(&buffer[0], buffer.size(), PAGE_EXECUTE_READ, &oldProtection);
503 FlushInstructionCache(GetCurrentProcess(), NULL, 0);
505 mprotect(&buffer[0], buffer.size(), PROT_READ | PROT_EXEC);
506 __builtin___clear_cache((char*)entry, (char*)entry + codeSize);
515 std::vector<uint8_t, ExecutableAllocator<uint8_t>> buffer;
516 std::size_t position;
525 ::codegenMutex.lock(); // Reactor is currently not thread safe
527 Ice::ClFlags &Flags = Ice::ClFlags::Flags;
528 Ice::ClFlags::getParsedClFlags(Flags);
531 Flags.setTargetArch(Ice::Target_ARM32);
532 Flags.setTargetInstructionSet(Ice::ARM32InstructionSet_HWDivArm);
534 Flags.setTargetArch(sizeof(void*) == 8 ? Ice::Target_X8664 : Ice::Target_X8632);
535 Flags.setTargetInstructionSet(CPUID::SSE4_1 ? Ice::X86InstructionSet_SSE4_1 : Ice::X86InstructionSet_SSE2);
537 Flags.setOutFileType(Ice::FT_Elf);
538 Flags.setOptLevel(Ice::Opt_2);
539 Flags.setApplicationBinaryInterface(Ice::ABI_Platform);
540 Flags.setVerbose(false ? Ice::IceV_Most : Ice::IceV_None);
541 Flags.setDisableHybridAssembly(true);
543 static llvm::raw_os_ostream cout(std::cout);
544 static llvm::raw_os_ostream cerr(std::cerr);
546 if(false) // Write out to a file
548 std::error_code errorCode;
549 ::out = new Ice::Fdstream("out.o", errorCode, llvm::sys::fs::F_None);
550 ::elfFile = new Ice::ELFFileStreamer(*out);
551 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfFile);
555 ELFMemoryStreamer *elfMemory = new ELFMemoryStreamer();
556 ::context = new Ice::GlobalContext(&cout, &cout, &cerr, elfMemory);
557 ::routine = elfMemory;
572 ::codegenMutex.unlock();
575 Routine *Nucleus::acquireRoutine(const wchar_t *name, bool runOptimizations)
577 if(basicBlock->getInsts().empty() || basicBlock->getInsts().back().getKind() != Ice::Inst::Ret)
582 std::wstring wideName(name);
583 std::string asciiName(wideName.begin(), wideName.end());
584 ::function->setFunctionName(Ice::GlobalString::createWithString(::context, asciiName));
588 ::function->translate();
589 assert(!::function->hasError());
591 auto globals = ::function->getGlobalInits();
593 if(globals && !globals->empty())
595 ::context->getGlobals()->merge(globals.get());
598 ::context->emitFileHeader();
599 ::function->emitIAS();
600 auto assembler = ::function->releaseAssembler();
601 auto objectWriter = ::context->getObjectWriter();
602 assembler->alignFunction();
603 objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
604 ::context->lowerGlobals("last");
605 ::context->lowerConstants();
606 ::context->lowerJumpTables();
607 objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
608 objectWriter->writeNonUserSections();
610 Routine *handoffRoutine = ::routine;
613 return handoffRoutine;
616 void Nucleus::optimize()
618 sw::optimize(::function);
621 Value *Nucleus::allocateStackVariable(Type *t, int arraySize)
623 Ice::Type type = T(t);
624 int typeSize = Ice::typeWidthInBytes(type);
625 int totalSize = typeSize * (arraySize ? arraySize : 1);
627 auto bytes = Ice::ConstantInteger32::create(::context, type, totalSize);
628 auto address = ::function->makeVariable(T(getPointerType(t)));
629 auto alloca = Ice::InstAlloca::create(::function, address, bytes, typeSize);
630 ::function->getEntryNode()->getInsts().push_front(alloca);
635 BasicBlock *Nucleus::createBasicBlock()
637 return B(::function->makeNode());
640 BasicBlock *Nucleus::getInsertBlock()
642 return B(::basicBlock);
645 void Nucleus::setInsertBlock(BasicBlock *basicBlock)
647 // assert(::basicBlock->getInsts().back().getTerminatorEdges().size() >= 0 && "Previous basic block must have a terminator");
648 ::basicBlock = basicBlock;
651 void Nucleus::createFunction(Type *ReturnType, std::vector<Type*> &Params)
653 uint32_t sequenceNumber = 0;
654 ::function = Ice::Cfg::create(::context, sequenceNumber).release();
655 ::allocator = new Ice::CfgLocalAllocatorScope(::function);
657 for(Type *type : Params)
659 Ice::Variable *arg = ::function->makeVariable(T(type));
660 ::function->addArg(arg);
663 Ice::CfgNode *node = ::function->makeNode();
664 ::function->setEntryNode(node);
668 Value *Nucleus::getArgument(unsigned int index)
670 return V(::function->getArgs()[index]);
673 void Nucleus::createRetVoid()
675 Ice::InstRet *ret = Ice::InstRet::create(::function);
676 ::basicBlock->appendInst(ret);
679 void Nucleus::createRet(Value *v)
681 Ice::InstRet *ret = Ice::InstRet::create(::function, v);
682 ::basicBlock->appendInst(ret);
685 void Nucleus::createBr(BasicBlock *dest)
687 auto br = Ice::InstBr::create(::function, dest);
688 ::basicBlock->appendInst(br);
691 void Nucleus::createCondBr(Value *cond, BasicBlock *ifTrue, BasicBlock *ifFalse)
693 auto br = Ice::InstBr::create(::function, cond, ifTrue, ifFalse);
694 ::basicBlock->appendInst(br);
697 static bool isCommutative(Ice::InstArithmetic::OpKind op)
701 case Ice::InstArithmetic::Add:
702 case Ice::InstArithmetic::Fadd:
703 case Ice::InstArithmetic::Mul:
704 case Ice::InstArithmetic::Fmul:
705 case Ice::InstArithmetic::And:
706 case Ice::InstArithmetic::Or:
707 case Ice::InstArithmetic::Xor:
714 static Value *createArithmetic(Ice::InstArithmetic::OpKind op, Value *lhs, Value *rhs)
716 assert(lhs->getType() == rhs->getType() || (llvm::isa<Ice::Constant>(rhs) && (op == Ice::InstArithmetic::Shl || Ice::InstArithmetic::Lshr || Ice::InstArithmetic::Ashr)));
718 bool swapOperands = llvm::isa<Ice::Constant>(lhs) && isCommutative(op);
720 Ice::Variable *result = ::function->makeVariable(lhs->getType());
721 Ice::InstArithmetic *arithmetic = Ice::InstArithmetic::create(::function, op, result, swapOperands ? rhs : lhs, swapOperands ? lhs : rhs);
722 ::basicBlock->appendInst(arithmetic);
727 Value *Nucleus::createAdd(Value *lhs, Value *rhs)
729 return createArithmetic(Ice::InstArithmetic::Add, lhs, rhs);
732 Value *Nucleus::createSub(Value *lhs, Value *rhs)
734 return createArithmetic(Ice::InstArithmetic::Sub, lhs, rhs);
737 Value *Nucleus::createMul(Value *lhs, Value *rhs)
739 return createArithmetic(Ice::InstArithmetic::Mul, lhs, rhs);
742 Value *Nucleus::createUDiv(Value *lhs, Value *rhs)
744 return createArithmetic(Ice::InstArithmetic::Udiv, lhs, rhs);
747 Value *Nucleus::createSDiv(Value *lhs, Value *rhs)
749 return createArithmetic(Ice::InstArithmetic::Sdiv, lhs, rhs);
752 Value *Nucleus::createFAdd(Value *lhs, Value *rhs)
754 return createArithmetic(Ice::InstArithmetic::Fadd, lhs, rhs);
757 Value *Nucleus::createFSub(Value *lhs, Value *rhs)
759 return createArithmetic(Ice::InstArithmetic::Fsub, lhs, rhs);
762 Value *Nucleus::createFMul(Value *lhs, Value *rhs)
764 return createArithmetic(Ice::InstArithmetic::Fmul, lhs, rhs);
767 Value *Nucleus::createFDiv(Value *lhs, Value *rhs)
769 return createArithmetic(Ice::InstArithmetic::Fdiv, lhs, rhs);
772 Value *Nucleus::createURem(Value *lhs, Value *rhs)
774 return createArithmetic(Ice::InstArithmetic::Urem, lhs, rhs);
777 Value *Nucleus::createSRem(Value *lhs, Value *rhs)
779 return createArithmetic(Ice::InstArithmetic::Srem, lhs, rhs);
782 Value *Nucleus::createFRem(Value *lhs, Value *rhs)
784 return createArithmetic(Ice::InstArithmetic::Frem, lhs, rhs);
787 Value *Nucleus::createShl(Value *lhs, Value *rhs)
789 return createArithmetic(Ice::InstArithmetic::Shl, lhs, rhs);
792 Value *Nucleus::createLShr(Value *lhs, Value *rhs)
794 return createArithmetic(Ice::InstArithmetic::Lshr, lhs, rhs);
797 Value *Nucleus::createAShr(Value *lhs, Value *rhs)
799 return createArithmetic(Ice::InstArithmetic::Ashr, lhs, rhs);
802 Value *Nucleus::createAnd(Value *lhs, Value *rhs)
804 return createArithmetic(Ice::InstArithmetic::And, lhs, rhs);
807 Value *Nucleus::createOr(Value *lhs, Value *rhs)
809 return createArithmetic(Ice::InstArithmetic::Or, lhs, rhs);
812 Value *Nucleus::createXor(Value *lhs, Value *rhs)
814 return createArithmetic(Ice::InstArithmetic::Xor, lhs, rhs);
817 Value *Nucleus::createNeg(Value *v)
819 return createSub(createNullValue(T(v->getType())), v);
822 Value *Nucleus::createFNeg(Value *v)
824 double c[4] = {-0.0, -0.0, -0.0, -0.0};
825 Value *negativeZero = Ice::isVectorType(v->getType()) ?
826 createConstantVector(c, T(v->getType())) :
827 V(::context->getConstantFloat(-0.0f));
829 return createFSub(negativeZero, v);
832 Value *Nucleus::createNot(Value *v)
834 if(Ice::isScalarIntegerType(v->getType()))
836 return createXor(v, V(::context->getConstantInt(v->getType(), -1)));
840 int64_t c[16] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
841 return createXor(v, createConstantVector(c, T(v->getType())));
845 Value *Nucleus::createLoad(Value *ptr, Type *type, bool isVolatile, unsigned int align)
847 int valueType = (int)reinterpret_cast<intptr_t>(type);
848 Ice::Variable *result = ::function->makeVariable(T(type));
850 if(valueType & EmulatedBits)
852 if(emulateIntrinsics)
854 if(typeSize(type) == 4)
856 auto pointer = RValue<Pointer<Byte>>(ptr);
857 Int x = *Pointer<Int>(pointer +1-1);
860 vector = Insert(vector, x, 0);
862 auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue());
863 ::basicBlock->appendInst(bitcast);
865 else if(typeSize(type) == 8)
867 auto pointer = RValue<Pointer<Byte>>(ptr);
868 Int x = *Pointer<Int>(pointer +1-1);
869 Int y = *Pointer<Int>(pointer + 4);
872 vector = Insert(vector, x, 0);
873 vector = Insert(vector, y, 1);
875 auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, result, vector.loadValue());
876 ::basicBlock->appendInst(bitcast);
882 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
883 auto target = ::context->getConstantUndef(Ice::IceType_i32);
884 auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
886 load->addArg(::context->getConstantInt32(typeSize(type)));
887 ::basicBlock->appendInst(load);
892 auto load = Ice::InstLoad::create(::function, result, ptr, align);
893 ::basicBlock->appendInst(load);
899 Value *Nucleus::createStore(Value *value, Value *ptr, Type *type, bool isVolatile, unsigned int align)
901 int valueType = (int)reinterpret_cast<intptr_t>(type);
903 if(valueType & EmulatedBits)
905 if(emulateIntrinsics)
907 if(typeSize(type) == 4)
909 Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32);
910 auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value);
911 ::basicBlock->appendInst(bitcast);
913 RValue<Int4> v(V(vector));
915 auto pointer = RValue<Pointer<Byte>>(ptr);
916 Int x = Extract(v, 0);
917 *Pointer<Int>(pointer) = x;
919 else if(typeSize(type) == 8)
921 Ice::Variable *vector = ::function->makeVariable(Ice::IceType_v4i32);
922 auto bitcast = Ice::InstCast::create(::function, Ice::InstCast::Bitcast, vector, value);
923 ::basicBlock->appendInst(bitcast);
925 RValue<Int4> v(V(vector));
927 auto pointer = RValue<Pointer<Byte>>(ptr);
928 Int x = Extract(v, 0);
929 *Pointer<Int>(pointer) = x;
930 Int y = Extract(v, 1);
931 *Pointer<Int>(pointer + 4) = y;
937 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
938 auto target = ::context->getConstantUndef(Ice::IceType_i32);
939 auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
940 store->addArg(value);
942 store->addArg(::context->getConstantInt32(typeSize(type)));
943 ::basicBlock->appendInst(store);
948 assert(T(value->getType()) == type);
950 auto store = Ice::InstStore::create(::function, value, ptr, align);
951 ::basicBlock->appendInst(store);
957 Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index, bool unsignedIndex)
959 assert(index->getType() == Ice::IceType_i32);
961 if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index))
963 int32_t offset = constant->getValue() * (int)typeSize(type);
970 return createAdd(ptr, createConstantInt(offset));
973 if(!Ice::isByteSizedType(T(type)))
975 index = createMul(index, createConstantInt((int)typeSize(type)));
978 if(sizeof(void*) == 8)
982 index = createZExt(index, T(Ice::IceType_i64));
986 index = createSExt(index, T(Ice::IceType_i64));
990 return createAdd(ptr, index);
993 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
995 assert(false && "UNIMPLEMENTED"); return nullptr;
998 static Value *createCast(Ice::InstCast::OpKind op, Value *v, Type *destType)
1000 if(v->getType() == T(destType))
1005 Ice::Variable *result = ::function->makeVariable(T(destType));
1006 Ice::InstCast *cast = Ice::InstCast::create(::function, op, result, v);
1007 ::basicBlock->appendInst(cast);
1012 Value *Nucleus::createTrunc(Value *v, Type *destType)
1014 return createCast(Ice::InstCast::Trunc, v, destType);
1017 Value *Nucleus::createZExt(Value *v, Type *destType)
1019 return createCast(Ice::InstCast::Zext, v, destType);
1022 Value *Nucleus::createSExt(Value *v, Type *destType)
1024 return createCast(Ice::InstCast::Sext, v, destType);
1027 Value *Nucleus::createFPToSI(Value *v, Type *destType)
1029 return createCast(Ice::InstCast::Fptosi, v, destType);
1032 Value *Nucleus::createSIToFP(Value *v, Type *destType)
1034 return createCast(Ice::InstCast::Sitofp, v, destType);
1037 Value *Nucleus::createFPTrunc(Value *v, Type *destType)
1039 return createCast(Ice::InstCast::Fptrunc, v, destType);
1042 Value *Nucleus::createFPExt(Value *v, Type *destType)
1044 return createCast(Ice::InstCast::Fpext, v, destType);
1047 Value *Nucleus::createBitCast(Value *v, Type *destType)
1049 // Bitcasts must be between types of the same logical size. But with emulated narrow vectors we need
1050 // support for casting between scalars and wide vectors. For platforms where this is not supported,
1051 // emulate them by writing to the stack and reading back as the destination type.
1052 if(emulateMismatchedBitCast)
1054 if(!Ice::isVectorType(v->getType()) && Ice::isVectorType(T(destType)))
1056 Value *address = allocateStackVariable(destType);
1057 createStore(v, address, T(v->getType()));
1058 return createLoad(address, destType);
1060 else if(Ice::isVectorType(v->getType()) && !Ice::isVectorType(T(destType)))
1062 Value *address = allocateStackVariable(T(v->getType()));
1063 createStore(v, address, T(v->getType()));
1064 return createLoad(address, destType);
1068 return createCast(Ice::InstCast::Bitcast, v, destType);
1071 static Value *createIntCompare(Ice::InstIcmp::ICond condition, Value *lhs, Value *rhs)
1073 assert(lhs->getType() == rhs->getType());
1075 auto result = ::function->makeVariable(Ice::isScalarIntegerType(lhs->getType()) ? Ice::IceType_i1 : lhs->getType());
1076 auto cmp = Ice::InstIcmp::create(::function, condition, result, lhs, rhs);
1077 ::basicBlock->appendInst(cmp);
1082 Value *Nucleus::createICmpEQ(Value *lhs, Value *rhs)
1084 return createIntCompare(Ice::InstIcmp::Eq, lhs, rhs);
1087 Value *Nucleus::createICmpNE(Value *lhs, Value *rhs)
1089 return createIntCompare(Ice::InstIcmp::Ne, lhs, rhs);
1092 Value *Nucleus::createICmpUGT(Value *lhs, Value *rhs)
1094 return createIntCompare(Ice::InstIcmp::Ugt, lhs, rhs);
1097 Value *Nucleus::createICmpUGE(Value *lhs, Value *rhs)
1099 return createIntCompare(Ice::InstIcmp::Uge, lhs, rhs);
1102 Value *Nucleus::createICmpULT(Value *lhs, Value *rhs)
1104 return createIntCompare(Ice::InstIcmp::Ult, lhs, rhs);
1107 Value *Nucleus::createICmpULE(Value *lhs, Value *rhs)
1109 return createIntCompare(Ice::InstIcmp::Ule, lhs, rhs);
1112 Value *Nucleus::createICmpSGT(Value *lhs, Value *rhs)
1114 return createIntCompare(Ice::InstIcmp::Sgt, lhs, rhs);
1117 Value *Nucleus::createICmpSGE(Value *lhs, Value *rhs)
1119 return createIntCompare(Ice::InstIcmp::Sge, lhs, rhs);
1122 Value *Nucleus::createICmpSLT(Value *lhs, Value *rhs)
1124 return createIntCompare(Ice::InstIcmp::Slt, lhs, rhs);
1127 Value *Nucleus::createICmpSLE(Value *lhs, Value *rhs)
1129 return createIntCompare(Ice::InstIcmp::Sle, lhs, rhs);
1132 static Value *createFloatCompare(Ice::InstFcmp::FCond condition, Value *lhs, Value *rhs)
1134 assert(lhs->getType() == rhs->getType());
1135 assert(Ice::isScalarFloatingType(lhs->getType()) || lhs->getType() == Ice::IceType_v4f32);
1137 auto result = ::function->makeVariable(Ice::isScalarFloatingType(lhs->getType()) ? Ice::IceType_i1 : Ice::IceType_v4i32);
1138 auto cmp = Ice::InstFcmp::create(::function, condition, result, lhs, rhs);
1139 ::basicBlock->appendInst(cmp);
1144 Value *Nucleus::createFCmpOEQ(Value *lhs, Value *rhs)
1146 return createFloatCompare(Ice::InstFcmp::Oeq, lhs, rhs);
1149 Value *Nucleus::createFCmpOGT(Value *lhs, Value *rhs)
1151 return createFloatCompare(Ice::InstFcmp::Ogt, lhs, rhs);
1154 Value *Nucleus::createFCmpOGE(Value *lhs, Value *rhs)
1156 return createFloatCompare(Ice::InstFcmp::Oge, lhs, rhs);
1159 Value *Nucleus::createFCmpOLT(Value *lhs, Value *rhs)
1161 return createFloatCompare(Ice::InstFcmp::Olt, lhs, rhs);
1164 Value *Nucleus::createFCmpOLE(Value *lhs, Value *rhs)
1166 return createFloatCompare(Ice::InstFcmp::Ole, lhs, rhs);
1169 Value *Nucleus::createFCmpONE(Value *lhs, Value *rhs)
1171 return createFloatCompare(Ice::InstFcmp::One, lhs, rhs);
1174 Value *Nucleus::createFCmpORD(Value *lhs, Value *rhs)
1176 return createFloatCompare(Ice::InstFcmp::Ord, lhs, rhs);
1179 Value *Nucleus::createFCmpUNO(Value *lhs, Value *rhs)
1181 return createFloatCompare(Ice::InstFcmp::Uno, lhs, rhs);
1184 Value *Nucleus::createFCmpUEQ(Value *lhs, Value *rhs)
1186 return createFloatCompare(Ice::InstFcmp::Ueq, lhs, rhs);
1189 Value *Nucleus::createFCmpUGT(Value *lhs, Value *rhs)
1191 return createFloatCompare(Ice::InstFcmp::Ugt, lhs, rhs);
1194 Value *Nucleus::createFCmpUGE(Value *lhs, Value *rhs)
1196 return createFloatCompare(Ice::InstFcmp::Uge, lhs, rhs);
1199 Value *Nucleus::createFCmpULT(Value *lhs, Value *rhs)
1201 return createFloatCompare(Ice::InstFcmp::Ult, lhs, rhs);
1204 Value *Nucleus::createFCmpULE(Value *lhs, Value *rhs)
1206 return createFloatCompare(Ice::InstFcmp::Ule, lhs, rhs);
1209 Value *Nucleus::createFCmpUNE(Value *lhs, Value *rhs)
1211 return createFloatCompare(Ice::InstFcmp::Une, lhs, rhs);
1214 Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
1216 auto result = ::function->makeVariable(T(type));
1217 auto extract = Ice::InstExtractElement::create(::function, result, vector, ::context->getConstantInt32(index));
1218 ::basicBlock->appendInst(extract);
1223 Value *Nucleus::createInsertElement(Value *vector, Value *element, int index)
1225 auto result = ::function->makeVariable(vector->getType());
1226 auto insert = Ice::InstInsertElement::create(::function, result, vector, element, ::context->getConstantInt32(index));
1227 ::basicBlock->appendInst(insert);
1232 Value *Nucleus::createShuffleVector(Value *V1, Value *V2, const int *select)
1234 assert(V1->getType() == V2->getType());
1236 int size = Ice::typeNumElements(V1->getType());
1237 auto result = ::function->makeVariable(V1->getType());
1238 auto shuffle = Ice::InstShuffleVector::create(::function, result, V1, V2);
1240 for(int i = 0; i < size; i++)
1242 shuffle->addIndex(llvm::cast<Ice::ConstantInteger32>(::context->getConstantInt32(select[i])));
1245 ::basicBlock->appendInst(shuffle);
1250 Value *Nucleus::createSelect(Value *C, Value *ifTrue, Value *ifFalse)
1252 assert(ifTrue->getType() == ifFalse->getType());
1254 auto result = ::function->makeVariable(ifTrue->getType());
1255 auto *select = Ice::InstSelect::create(::function, result, C, ifTrue, ifFalse);
1256 ::basicBlock->appendInst(select);
1261 SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases)
1263 auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch);
1264 ::basicBlock->appendInst(switchInst);
1266 return reinterpret_cast<SwitchCases*>(switchInst);
1269 void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch)
1271 switchCases->addBranch(label, label, branch);
1274 void Nucleus::createUnreachable()
1276 Ice::InstUnreachable *unreachable = Ice::InstUnreachable::create(::function);
1277 ::basicBlock->appendInst(unreachable);
1280 static Value *createSwizzle4(Value *val, unsigned char select)
1284 (select >> 0) & 0x03,
1285 (select >> 2) & 0x03,
1286 (select >> 4) & 0x03,
1287 (select >> 6) & 0x03,
1290 return Nucleus::createShuffleVector(val, val, swizzle);
1293 static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
1295 int64_t mask[4] = {0, 0, 0, 0};
1297 mask[(select >> 0) & 0x03] = -1;
1298 mask[(select >> 2) & 0x03] = -1;
1299 mask[(select >> 4) & 0x03] = -1;
1300 mask[(select >> 6) & 0x03] = -1;
1302 Value *condition = Nucleus::createConstantVector(mask, T(Ice::IceType_v4i1));
1303 Value *result = Nucleus::createSelect(condition, rhs, lhs);
1308 Type *Nucleus::getPointerType(Type *ElementType)
1310 if(sizeof(void*) == 8)
1312 return T(Ice::IceType_i64);
1316 return T(Ice::IceType_i32);
1320 Value *Nucleus::createNullValue(Type *Ty)
1322 if(Ice::isVectorType(T(Ty)))
1324 assert(Ice::typeNumElements(T(Ty)) <= 16);
1325 int64_t c[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1326 return createConstantVector(c, Ty);
1330 return V(::context->getConstantZero(T(Ty)));
1334 Value *Nucleus::createConstantLong(int64_t i)
1336 return V(::context->getConstantInt64(i));
1339 Value *Nucleus::createConstantInt(int i)
1341 return V(::context->getConstantInt32(i));
1344 Value *Nucleus::createConstantInt(unsigned int i)
1346 return V(::context->getConstantInt32(i));
1349 Value *Nucleus::createConstantBool(bool b)
1351 return V(::context->getConstantInt1(b));
1354 Value *Nucleus::createConstantByte(signed char i)
1356 return V(::context->getConstantInt8(i));
1359 Value *Nucleus::createConstantByte(unsigned char i)
1361 return V(::context->getConstantInt8(i));
1364 Value *Nucleus::createConstantShort(short i)
1366 return V(::context->getConstantInt16(i));
1369 Value *Nucleus::createConstantShort(unsigned short i)
1371 return V(::context->getConstantInt16(i));
1374 Value *Nucleus::createConstantFloat(float x)
1376 return V(::context->getConstantFloat(x));
1379 Value *Nucleus::createNullPointer(Type *Ty)
1381 return createNullValue(T(sizeof(void*) == 8 ? Ice::IceType_i64 : Ice::IceType_i32));
1384 Value *Nucleus::createConstantVector(const int64_t *constants, Type *type)
1386 const int vectorSize = 16;
1387 assert(Ice::typeWidthInBytes(T(type)) == vectorSize);
1388 const int alignment = vectorSize;
1389 auto globalPool = ::function->getGlobalPool();
1391 const int64_t *i = constants;
1392 const double *f = reinterpret_cast<const double*>(constants);
1393 Ice::VariableDeclaration::DataInitializer *dataInitializer = nullptr;
1395 switch((int)reinterpret_cast<intptr_t>(type))
1397 case Ice::IceType_v4i32:
1398 case Ice::IceType_v4i1:
1400 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[2], (int)i[3]};
1401 static_assert(sizeof(initializer) == vectorSize, "!");
1402 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1405 case Ice::IceType_v4f32:
1407 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[2], (float)f[3]};
1408 static_assert(sizeof(initializer) == vectorSize, "!");
1409 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1412 case Ice::IceType_v8i16:
1413 case Ice::IceType_v8i1:
1415 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]};
1416 static_assert(sizeof(initializer) == vectorSize, "!");
1417 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1420 case Ice::IceType_v16i8:
1421 case Ice::IceType_v16i1:
1423 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]};
1424 static_assert(sizeof(initializer) == vectorSize, "!");
1425 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1430 const int initializer[4] = {(int)i[0], (int)i[1], (int)i[0], (int)i[1]};
1431 static_assert(sizeof(initializer) == vectorSize, "!");
1432 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1437 const float initializer[4] = {(float)f[0], (float)f[1], (float)f[0], (float)f[1]};
1438 static_assert(sizeof(initializer) == vectorSize, "!");
1439 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1444 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]};
1445 static_assert(sizeof(initializer) == vectorSize, "!");
1446 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1451 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]};
1452 static_assert(sizeof(initializer) == vectorSize, "!");
1453 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1458 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]};
1459 static_assert(sizeof(initializer) == vectorSize, "!");
1460 dataInitializer = Ice::VariableDeclaration::DataInitializer::create(globalPool, (const char*)initializer, vectorSize);
1464 assert(false && "Unknown constant vector type" && type);
1467 auto name = Ice::GlobalString::createWithoutString(::context);
1468 auto *variableDeclaration = Ice::VariableDeclaration::create(globalPool);
1469 variableDeclaration->setName(name);
1470 variableDeclaration->setAlignment(alignment);
1471 variableDeclaration->setIsConstant(true);
1472 variableDeclaration->addInitializer(dataInitializer);
1474 ::function->addGlobal(variableDeclaration);
1476 constexpr int32_t offset = 0;
1477 Ice::Operand *ptr = ::context->getConstantSym(offset, name);
1479 Ice::Variable *result = ::function->makeVariable(T(type));
1480 auto load = Ice::InstLoad::create(::function, result, ptr, alignment);
1481 ::basicBlock->appendInst(load);
1486 Value *Nucleus::createConstantVector(const double *constants, Type *type)
1488 return createConstantVector((const int64_t*)constants, type);
1491 Type *Void::getType()
1493 return T(Ice::IceType_void);
1496 Bool::Bool(Argument<Bool> argument)
1498 storeValue(argument.value);
1503 storeValue(Nucleus::createConstantBool(x));
1506 Bool::Bool(RValue<Bool> rhs)
1508 storeValue(rhs.value);
1511 Bool::Bool(const Bool &rhs)
1513 Value *value = rhs.loadValue();
1517 Bool::Bool(const Reference<Bool> &rhs)
1519 Value *value = rhs.loadValue();
1523 RValue<Bool> Bool::operator=(RValue<Bool> rhs)
1525 storeValue(rhs.value);
1530 RValue<Bool> Bool::operator=(const Bool &rhs)
1532 Value *value = rhs.loadValue();
1535 return RValue<Bool>(value);
1538 RValue<Bool> Bool::operator=(const Reference<Bool> &rhs)
1540 Value *value = rhs.loadValue();
1543 return RValue<Bool>(value);
1546 RValue<Bool> operator!(RValue<Bool> val)
1548 return RValue<Bool>(Nucleus::createNot(val.value));
1551 RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs)
1553 return RValue<Bool>(Nucleus::createAnd(lhs.value, rhs.value));
1556 RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs)
1558 return RValue<Bool>(Nucleus::createOr(lhs.value, rhs.value));
1561 Type *Bool::getType()
1563 return T(Ice::IceType_i1);
1566 Byte::Byte(Argument<Byte> argument)
1568 storeValue(argument.value);
1571 Byte::Byte(RValue<Int> cast)
1573 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1575 storeValue(integer);
1578 Byte::Byte(RValue<UInt> cast)
1580 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1582 storeValue(integer);
1585 Byte::Byte(RValue<UShort> cast)
1587 Value *integer = Nucleus::createTrunc(cast.value, Byte::getType());
1589 storeValue(integer);
1594 storeValue(Nucleus::createConstantByte((unsigned char)x));
1597 Byte::Byte(unsigned char x)
1599 storeValue(Nucleus::createConstantByte(x));
1602 Byte::Byte(RValue<Byte> rhs)
1604 storeValue(rhs.value);
1607 Byte::Byte(const Byte &rhs)
1609 Value *value = rhs.loadValue();
1613 Byte::Byte(const Reference<Byte> &rhs)
1615 Value *value = rhs.loadValue();
1619 RValue<Byte> Byte::operator=(RValue<Byte> rhs)
1621 storeValue(rhs.value);
1626 RValue<Byte> Byte::operator=(const Byte &rhs)
1628 Value *value = rhs.loadValue();
1631 return RValue<Byte>(value);
1634 RValue<Byte> Byte::operator=(const Reference<Byte> &rhs)
1636 Value *value = rhs.loadValue();
1639 return RValue<Byte>(value);
1642 RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs)
1644 return RValue<Byte>(Nucleus::createAdd(lhs.value, rhs.value));
1647 RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs)
1649 return RValue<Byte>(Nucleus::createSub(lhs.value, rhs.value));
1652 RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs)
1654 return RValue<Byte>(Nucleus::createMul(lhs.value, rhs.value));
1657 RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs)
1659 return RValue<Byte>(Nucleus::createUDiv(lhs.value, rhs.value));
1662 RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs)
1664 return RValue<Byte>(Nucleus::createURem(lhs.value, rhs.value));
1667 RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs)
1669 return RValue<Byte>(Nucleus::createAnd(lhs.value, rhs.value));
1672 RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs)
1674 return RValue<Byte>(Nucleus::createOr(lhs.value, rhs.value));
1677 RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs)
1679 return RValue<Byte>(Nucleus::createXor(lhs.value, rhs.value));
1682 RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs)
1684 return RValue<Byte>(Nucleus::createShl(lhs.value, rhs.value));
1687 RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs)
1689 return RValue<Byte>(Nucleus::createLShr(lhs.value, rhs.value));
1692 RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs)
1694 return lhs = lhs + rhs;
1697 RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs)
1699 return lhs = lhs - rhs;
1702 RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs)
1704 return lhs = lhs * rhs;
1707 RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs)
1709 return lhs = lhs / rhs;
1712 RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs)
1714 return lhs = lhs % rhs;
1717 RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs)
1719 return lhs = lhs & rhs;
1722 RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs)
1724 return lhs = lhs | rhs;
1727 RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs)
1729 return lhs = lhs ^ rhs;
1732 RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs)
1734 return lhs = lhs << rhs;
1737 RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs)
1739 return lhs = lhs >> rhs;
1742 RValue<Byte> operator+(RValue<Byte> val)
1747 RValue<Byte> operator-(RValue<Byte> val)
1749 return RValue<Byte>(Nucleus::createNeg(val.value));
1752 RValue<Byte> operator~(RValue<Byte> val)
1754 return RValue<Byte>(Nucleus::createNot(val.value));
1757 RValue<Byte> operator++(Byte &val, int) // Post-increment
1759 RValue<Byte> res = val;
1764 const Byte &operator++(Byte &val) // Pre-increment
1770 RValue<Byte> operator--(Byte &val, int) // Post-decrement
1772 RValue<Byte> res = val;
1777 const Byte &operator--(Byte &val) // Pre-decrement
1783 RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs)
1785 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
1788 RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs)
1790 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
1793 RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs)
1795 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
1798 RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs)
1800 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
1803 RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs)
1805 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
1808 RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs)
1810 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
1813 Type *Byte::getType()
1815 return T(Ice::IceType_i8);
1818 SByte::SByte(Argument<SByte> argument)
1820 storeValue(argument.value);
1823 SByte::SByte(RValue<Int> cast)
1825 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1827 storeValue(integer);
1830 SByte::SByte(RValue<Short> cast)
1832 Value *integer = Nucleus::createTrunc(cast.value, SByte::getType());
1834 storeValue(integer);
1837 SByte::SByte(signed char x)
1839 storeValue(Nucleus::createConstantByte(x));
1842 SByte::SByte(RValue<SByte> rhs)
1844 storeValue(rhs.value);
1847 SByte::SByte(const SByte &rhs)
1849 Value *value = rhs.loadValue();
1853 SByte::SByte(const Reference<SByte> &rhs)
1855 Value *value = rhs.loadValue();
1859 RValue<SByte> SByte::operator=(RValue<SByte> rhs)
1861 storeValue(rhs.value);
1866 RValue<SByte> SByte::operator=(const SByte &rhs)
1868 Value *value = rhs.loadValue();
1871 return RValue<SByte>(value);
1874 RValue<SByte> SByte::operator=(const Reference<SByte> &rhs)
1876 Value *value = rhs.loadValue();
1879 return RValue<SByte>(value);
1882 RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs)
1884 return RValue<SByte>(Nucleus::createAdd(lhs.value, rhs.value));
1887 RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs)
1889 return RValue<SByte>(Nucleus::createSub(lhs.value, rhs.value));
1892 RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs)
1894 return RValue<SByte>(Nucleus::createMul(lhs.value, rhs.value));
1897 RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs)
1899 return RValue<SByte>(Nucleus::createSDiv(lhs.value, rhs.value));
1902 RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs)
1904 return RValue<SByte>(Nucleus::createSRem(lhs.value, rhs.value));
1907 RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs)
1909 return RValue<SByte>(Nucleus::createAnd(lhs.value, rhs.value));
1912 RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs)
1914 return RValue<SByte>(Nucleus::createOr(lhs.value, rhs.value));
1917 RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs)
1919 return RValue<SByte>(Nucleus::createXor(lhs.value, rhs.value));
1922 RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs)
1924 return RValue<SByte>(Nucleus::createShl(lhs.value, rhs.value));
1927 RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs)
1929 return RValue<SByte>(Nucleus::createAShr(lhs.value, rhs.value));
1932 RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs)
1934 return lhs = lhs + rhs;
1937 RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs)
1939 return lhs = lhs - rhs;
1942 RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs)
1944 return lhs = lhs * rhs;
1947 RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs)
1949 return lhs = lhs / rhs;
1952 RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs)
1954 return lhs = lhs % rhs;
1957 RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs)
1959 return lhs = lhs & rhs;
1962 RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs)
1964 return lhs = lhs | rhs;
1967 RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs)
1969 return lhs = lhs ^ rhs;
1972 RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs)
1974 return lhs = lhs << rhs;
1977 RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs)
1979 return lhs = lhs >> rhs;
1982 RValue<SByte> operator+(RValue<SByte> val)
1987 RValue<SByte> operator-(RValue<SByte> val)
1989 return RValue<SByte>(Nucleus::createNeg(val.value));
1992 RValue<SByte> operator~(RValue<SByte> val)
1994 return RValue<SByte>(Nucleus::createNot(val.value));
1997 RValue<SByte> operator++(SByte &val, int) // Post-increment
1999 RValue<SByte> res = val;
2004 const SByte &operator++(SByte &val) // Pre-increment
2010 RValue<SByte> operator--(SByte &val, int) // Post-decrement
2012 RValue<SByte> res = val;
2017 const SByte &operator--(SByte &val) // Pre-decrement
2023 RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs)
2025 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2028 RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs)
2030 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2033 RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs)
2035 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2038 RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs)
2040 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2043 RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs)
2045 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2048 RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs)
2050 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2053 Type *SByte::getType()
2055 return T(Ice::IceType_i8);
2058 Short::Short(Argument<Short> argument)
2060 storeValue(argument.value);
2063 Short::Short(RValue<Int> cast)
2065 Value *integer = Nucleus::createTrunc(cast.value, Short::getType());
2067 storeValue(integer);
2070 Short::Short(short x)
2072 storeValue(Nucleus::createConstantShort(x));
2075 Short::Short(RValue<Short> rhs)
2077 storeValue(rhs.value);
2080 Short::Short(const Short &rhs)
2082 Value *value = rhs.loadValue();
2086 Short::Short(const Reference<Short> &rhs)
2088 Value *value = rhs.loadValue();
2092 RValue<Short> Short::operator=(RValue<Short> rhs)
2094 storeValue(rhs.value);
2099 RValue<Short> Short::operator=(const Short &rhs)
2101 Value *value = rhs.loadValue();
2104 return RValue<Short>(value);
2107 RValue<Short> Short::operator=(const Reference<Short> &rhs)
2109 Value *value = rhs.loadValue();
2112 return RValue<Short>(value);
2115 RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs)
2117 return RValue<Short>(Nucleus::createAdd(lhs.value, rhs.value));
2120 RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs)
2122 return RValue<Short>(Nucleus::createSub(lhs.value, rhs.value));
2125 RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs)
2127 return RValue<Short>(Nucleus::createMul(lhs.value, rhs.value));
2130 RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs)
2132 return RValue<Short>(Nucleus::createSDiv(lhs.value, rhs.value));
2135 RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs)
2137 return RValue<Short>(Nucleus::createSRem(lhs.value, rhs.value));
2140 RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs)
2142 return RValue<Short>(Nucleus::createAnd(lhs.value, rhs.value));
2145 RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs)
2147 return RValue<Short>(Nucleus::createOr(lhs.value, rhs.value));
2150 RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs)
2152 return RValue<Short>(Nucleus::createXor(lhs.value, rhs.value));
2155 RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs)
2157 return RValue<Short>(Nucleus::createShl(lhs.value, rhs.value));
2160 RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs)
2162 return RValue<Short>(Nucleus::createAShr(lhs.value, rhs.value));
2165 RValue<Short> operator+=(Short &lhs, RValue<Short> rhs)
2167 return lhs = lhs + rhs;
2170 RValue<Short> operator-=(Short &lhs, RValue<Short> rhs)
2172 return lhs = lhs - rhs;
2175 RValue<Short> operator*=(Short &lhs, RValue<Short> rhs)
2177 return lhs = lhs * rhs;
2180 RValue<Short> operator/=(Short &lhs, RValue<Short> rhs)
2182 return lhs = lhs / rhs;
2185 RValue<Short> operator%=(Short &lhs, RValue<Short> rhs)
2187 return lhs = lhs % rhs;
2190 RValue<Short> operator&=(Short &lhs, RValue<Short> rhs)
2192 return lhs = lhs & rhs;
2195 RValue<Short> operator|=(Short &lhs, RValue<Short> rhs)
2197 return lhs = lhs | rhs;
2200 RValue<Short> operator^=(Short &lhs, RValue<Short> rhs)
2202 return lhs = lhs ^ rhs;
2205 RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs)
2207 return lhs = lhs << rhs;
2210 RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs)
2212 return lhs = lhs >> rhs;
2215 RValue<Short> operator+(RValue<Short> val)
2220 RValue<Short> operator-(RValue<Short> val)
2222 return RValue<Short>(Nucleus::createNeg(val.value));
2225 RValue<Short> operator~(RValue<Short> val)
2227 return RValue<Short>(Nucleus::createNot(val.value));
2230 RValue<Short> operator++(Short &val, int) // Post-increment
2232 RValue<Short> res = val;
2237 const Short &operator++(Short &val) // Pre-increment
2243 RValue<Short> operator--(Short &val, int) // Post-decrement
2245 RValue<Short> res = val;
2250 const Short &operator--(Short &val) // Pre-decrement
2256 RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs)
2258 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
2261 RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs)
2263 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
2266 RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs)
2268 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
2271 RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs)
2273 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
2276 RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs)
2278 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2281 RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs)
2283 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2286 Type *Short::getType()
2288 return T(Ice::IceType_i16);
2291 UShort::UShort(Argument<UShort> argument)
2293 storeValue(argument.value);
2296 UShort::UShort(RValue<UInt> cast)
2298 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2300 storeValue(integer);
2303 UShort::UShort(RValue<Int> cast)
2305 Value *integer = Nucleus::createTrunc(cast.value, UShort::getType());
2307 storeValue(integer);
2310 UShort::UShort(unsigned short x)
2312 storeValue(Nucleus::createConstantShort(x));
2315 UShort::UShort(RValue<UShort> rhs)
2317 storeValue(rhs.value);
2320 UShort::UShort(const UShort &rhs)
2322 Value *value = rhs.loadValue();
2326 UShort::UShort(const Reference<UShort> &rhs)
2328 Value *value = rhs.loadValue();
2332 RValue<UShort> UShort::operator=(RValue<UShort> rhs)
2334 storeValue(rhs.value);
2339 RValue<UShort> UShort::operator=(const UShort &rhs)
2341 Value *value = rhs.loadValue();
2344 return RValue<UShort>(value);
2347 RValue<UShort> UShort::operator=(const Reference<UShort> &rhs)
2349 Value *value = rhs.loadValue();
2352 return RValue<UShort>(value);
2355 RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs)
2357 return RValue<UShort>(Nucleus::createAdd(lhs.value, rhs.value));
2360 RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs)
2362 return RValue<UShort>(Nucleus::createSub(lhs.value, rhs.value));
2365 RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs)
2367 return RValue<UShort>(Nucleus::createMul(lhs.value, rhs.value));
2370 RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs)
2372 return RValue<UShort>(Nucleus::createUDiv(lhs.value, rhs.value));
2375 RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs)
2377 return RValue<UShort>(Nucleus::createURem(lhs.value, rhs.value));
2380 RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs)
2382 return RValue<UShort>(Nucleus::createAnd(lhs.value, rhs.value));
2385 RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs)
2387 return RValue<UShort>(Nucleus::createOr(lhs.value, rhs.value));
2390 RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs)
2392 return RValue<UShort>(Nucleus::createXor(lhs.value, rhs.value));
2395 RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs)
2397 return RValue<UShort>(Nucleus::createShl(lhs.value, rhs.value));
2400 RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs)
2402 return RValue<UShort>(Nucleus::createLShr(lhs.value, rhs.value));
2405 RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs)
2407 return lhs = lhs + rhs;
2410 RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs)
2412 return lhs = lhs - rhs;
2415 RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs)
2417 return lhs = lhs * rhs;
2420 RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs)
2422 return lhs = lhs / rhs;
2425 RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs)
2427 return lhs = lhs % rhs;
2430 RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs)
2432 return lhs = lhs & rhs;
2435 RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs)
2437 return lhs = lhs | rhs;
2440 RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs)
2442 return lhs = lhs ^ rhs;
2445 RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs)
2447 return lhs = lhs << rhs;
2450 RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs)
2452 return lhs = lhs >> rhs;
2455 RValue<UShort> operator+(RValue<UShort> val)
2460 RValue<UShort> operator-(RValue<UShort> val)
2462 return RValue<UShort>(Nucleus::createNeg(val.value));
2465 RValue<UShort> operator~(RValue<UShort> val)
2467 return RValue<UShort>(Nucleus::createNot(val.value));
2470 RValue<UShort> operator++(UShort &val, int) // Post-increment
2472 RValue<UShort> res = val;
2477 const UShort &operator++(UShort &val) // Pre-increment
2483 RValue<UShort> operator--(UShort &val, int) // Post-decrement
2485 RValue<UShort> res = val;
2490 const UShort &operator--(UShort &val) // Pre-decrement
2496 RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs)
2498 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
2501 RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs)
2503 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
2506 RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs)
2508 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
2511 RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs)
2513 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
2516 RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs)
2518 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
2521 RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs)
2523 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
2526 Type *UShort::getType()
2528 return T(Ice::IceType_i16);
2531 Byte4::Byte4(RValue<Byte8> cast)
2533 storeValue(Nucleus::createBitCast(cast.value, getType()));
2536 Byte4::Byte4(const Reference<Byte4> &rhs)
2538 Value *value = rhs.loadValue();
2542 Type *Byte4::getType()
2544 return T(Type_v4i8);
2547 Type *SByte4::getType()
2549 return T(Type_v4i8);
2552 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)
2554 int64_t constantVector[8] = {x0, x1, x2, x3, x4, x5, x6, x7};
2555 storeValue(Nucleus::createConstantVector(constantVector, getType()));
2558 Byte8::Byte8(RValue<Byte8> rhs)
2560 storeValue(rhs.value);
2563 Byte8::Byte8(const Byte8 &rhs)
2565 Value *value = rhs.loadValue();
2569 Byte8::Byte8(const Reference<Byte8> &rhs)
2571 Value *value = rhs.loadValue();
2575 RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs)
2577 storeValue(rhs.value);
2582 RValue<Byte8> Byte8::operator=(const Byte8 &rhs)
2584 Value *value = rhs.loadValue();
2587 return RValue<Byte8>(value);
2590 RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs)
2592 Value *value = rhs.loadValue();
2595 return RValue<Byte8>(value);
2598 RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs)
2600 return RValue<Byte8>(Nucleus::createAdd(lhs.value, rhs.value));
2603 RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs)
2605 return RValue<Byte8>(Nucleus::createSub(lhs.value, rhs.value));
2608 // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs)
2610 // return RValue<Byte8>(Nucleus::createMul(lhs.value, rhs.value));
2613 // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs)
2615 // return RValue<Byte8>(Nucleus::createUDiv(lhs.value, rhs.value));
2618 // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs)
2620 // return RValue<Byte8>(Nucleus::createURem(lhs.value, rhs.value));
2623 RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs)
2625 return RValue<Byte8>(Nucleus::createAnd(lhs.value, rhs.value));
2628 RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs)
2630 return RValue<Byte8>(Nucleus::createOr(lhs.value, rhs.value));
2633 RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs)
2635 return RValue<Byte8>(Nucleus::createXor(lhs.value, rhs.value));
2638 // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs)
2640 // return RValue<Byte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
2643 // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs)
2645 // return RValue<Byte8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
2648 RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs)
2650 return lhs = lhs + rhs;
2653 RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs)
2655 return lhs = lhs - rhs;
2658 // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs)
2660 // return lhs = lhs * rhs;
2663 // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs)
2665 // return lhs = lhs / rhs;
2668 // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs)
2670 // return lhs = lhs % rhs;
2673 RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs)
2675 return lhs = lhs & rhs;
2678 RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs)
2680 return lhs = lhs | rhs;
2683 RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs)
2685 return lhs = lhs ^ rhs;
2688 // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs)
2690 // return lhs = lhs << rhs;
2693 // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs)
2695 // return lhs = lhs >> rhs;
2698 // RValue<Byte8> operator+(RValue<Byte8> val)
2703 // RValue<Byte8> operator-(RValue<Byte8> val)
2705 // return RValue<Byte8>(Nucleus::createNeg(val.value));
2708 RValue<Byte8> operator~(RValue<Byte8> val)
2710 return RValue<Byte8>(Nucleus::createNot(val.value));
2713 RValue<Byte8> AddSat(RValue<Byte8> x, RValue<Byte8> y)
2715 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2716 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2717 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2718 auto paddusb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2719 paddusb->addArg(x.value);
2720 paddusb->addArg(y.value);
2721 ::basicBlock->appendInst(paddusb);
2723 return RValue<Byte8>(V(result));
2726 RValue<Byte8> SubSat(RValue<Byte8> x, RValue<Byte8> y)
2728 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2729 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2730 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2731 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2732 psubusw->addArg(x.value);
2733 psubusw->addArg(y.value);
2734 ::basicBlock->appendInst(psubusw);
2736 return RValue<Byte8>(V(result));
2739 RValue<Short4> Unpack(RValue<Byte4> x)
2741 int shuffle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7}; // Real type is v16i8
2742 return As<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
2745 RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y)
2747 return UnpackLow(As<Byte8>(x), As<Byte8>(y));
2750 RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y)
2752 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2753 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2756 RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y)
2758 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2759 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2760 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
2763 RValue<Int> SignMask(RValue<Byte8> x)
2765 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2766 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2767 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2768 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2769 movmsk->addArg(x.value);
2770 ::basicBlock->appendInst(movmsk);
2772 return RValue<Int>(V(result));
2775 // RValue<Byte8> CmpGT(RValue<Byte8> x, RValue<Byte8> y)
2777 // return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Ugt, x.value, y.value));
2780 RValue<Byte8> CmpEQ(RValue<Byte8> x, RValue<Byte8> y)
2782 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
2785 Type *Byte8::getType()
2787 return T(Type_v8i8);
2790 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)
2792 int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 };
2793 Value *vector = V(Nucleus::createConstantVector(constantVector, getType()));
2795 storeValue(Nucleus::createBitCast(vector, getType()));
2798 SByte8::SByte8(RValue<SByte8> rhs)
2800 storeValue(rhs.value);
2803 SByte8::SByte8(const SByte8 &rhs)
2805 Value *value = rhs.loadValue();
2809 SByte8::SByte8(const Reference<SByte8> &rhs)
2811 Value *value = rhs.loadValue();
2815 RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs)
2817 storeValue(rhs.value);
2822 RValue<SByte8> SByte8::operator=(const SByte8 &rhs)
2824 Value *value = rhs.loadValue();
2827 return RValue<SByte8>(value);
2830 RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs)
2832 Value *value = rhs.loadValue();
2835 return RValue<SByte8>(value);
2838 RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs)
2840 return RValue<SByte8>(Nucleus::createAdd(lhs.value, rhs.value));
2843 RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs)
2845 return RValue<SByte8>(Nucleus::createSub(lhs.value, rhs.value));
2848 // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs)
2850 // return RValue<SByte8>(Nucleus::createMul(lhs.value, rhs.value));
2853 // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs)
2855 // return RValue<SByte8>(Nucleus::createSDiv(lhs.value, rhs.value));
2858 // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs)
2860 // return RValue<SByte8>(Nucleus::createSRem(lhs.value, rhs.value));
2863 RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs)
2865 return RValue<SByte8>(Nucleus::createAnd(lhs.value, rhs.value));
2868 RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs)
2870 return RValue<SByte8>(Nucleus::createOr(lhs.value, rhs.value));
2873 RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs)
2875 return RValue<SByte8>(Nucleus::createXor(lhs.value, rhs.value));
2878 // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs)
2880 // return RValue<SByte8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
2883 // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs)
2885 // return RValue<SByte8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
2888 RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs)
2890 return lhs = lhs + rhs;
2893 RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs)
2895 return lhs = lhs - rhs;
2898 // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs)
2900 // return lhs = lhs * rhs;
2903 // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs)
2905 // return lhs = lhs / rhs;
2908 // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs)
2910 // return lhs = lhs % rhs;
2913 RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs)
2915 return lhs = lhs & rhs;
2918 RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs)
2920 return lhs = lhs | rhs;
2923 RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs)
2925 return lhs = lhs ^ rhs;
2928 // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs)
2930 // return lhs = lhs << rhs;
2933 // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs)
2935 // return lhs = lhs >> rhs;
2938 // RValue<SByte8> operator+(RValue<SByte8> val)
2943 // RValue<SByte8> operator-(RValue<SByte8> val)
2945 // return RValue<SByte8>(Nucleus::createNeg(val.value));
2948 RValue<SByte8> operator~(RValue<SByte8> val)
2950 return RValue<SByte8>(Nucleus::createNot(val.value));
2953 RValue<SByte8> AddSat(RValue<SByte8> x, RValue<SByte8> y)
2955 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2956 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2957 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2958 auto paddsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2959 paddsb->addArg(x.value);
2960 paddsb->addArg(y.value);
2961 ::basicBlock->appendInst(paddsb);
2963 return RValue<SByte8>(V(result));
2966 RValue<SByte8> SubSat(RValue<SByte8> x, RValue<SByte8> y)
2968 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
2969 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2970 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2971 auto psubsb = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
2972 psubsb->addArg(x.value);
2973 psubsb->addArg(y.value);
2974 ::basicBlock->appendInst(psubsb);
2976 return RValue<SByte8>(V(result));
2979 RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y)
2981 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2982 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2985 RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y)
2987 int shuffle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23}; // Real type is v16i8
2988 auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
2989 return As<Short4>(Swizzle(As<Int4>(lowHigh), 0xEE));
2992 RValue<Int> SignMask(RValue<SByte8> x)
2994 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
2995 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
2996 auto target = ::context->getConstantUndef(Ice::IceType_i32);
2997 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
2998 movmsk->addArg(x.value);
2999 ::basicBlock->appendInst(movmsk);
3001 return RValue<Int>(V(result));
3004 RValue<Byte8> CmpGT(RValue<SByte8> x, RValue<SByte8> y)
3006 return RValue<Byte8>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
3009 RValue<Byte8> CmpEQ(RValue<SByte8> x, RValue<SByte8> y)
3011 return RValue<Byte8>(Nucleus::createICmpEQ(x.value, y.value));
3014 Type *SByte8::getType()
3016 return T(Type_v8i8);
3019 Byte16::Byte16(RValue<Byte16> rhs)
3021 storeValue(rhs.value);
3024 Byte16::Byte16(const Byte16 &rhs)
3026 Value *value = rhs.loadValue();
3030 Byte16::Byte16(const Reference<Byte16> &rhs)
3032 Value *value = rhs.loadValue();
3036 RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs)
3038 storeValue(rhs.value);
3043 RValue<Byte16> Byte16::operator=(const Byte16 &rhs)
3045 Value *value = rhs.loadValue();
3048 return RValue<Byte16>(value);
3051 RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs)
3053 Value *value = rhs.loadValue();
3056 return RValue<Byte16>(value);
3059 Type *Byte16::getType()
3061 return T(Ice::IceType_v16i8);
3064 Type *SByte16::getType()
3066 return T(Ice::IceType_v16i8);
3069 Short2::Short2(RValue<Short4> cast)
3071 storeValue(Nucleus::createBitCast(cast.value, getType()));
3074 Type *Short2::getType()
3076 return T(Type_v2i16);
3079 UShort2::UShort2(RValue<UShort4> cast)
3081 storeValue(Nucleus::createBitCast(cast.value, getType()));
3084 Type *UShort2::getType()
3086 return T(Type_v2i16);
3089 Short4::Short4(RValue<Int> cast)
3091 Value *vector = loadValue();
3092 Value *element = Nucleus::createTrunc(cast.value, Short::getType());
3093 Value *insert = Nucleus::createInsertElement(vector, element, 0);
3094 Value *swizzle = Swizzle(RValue<Short4>(insert), 0x00).value;
3096 storeValue(swizzle);
3099 Short4::Short4(RValue<Int4> cast)
3101 int select[8] = {0, 2, 4, 6, 0, 2, 4, 6};
3102 Value *short8 = Nucleus::createBitCast(cast.value, Short8::getType());
3103 Value *packed = Nucleus::createShuffleVector(short8, short8, select);
3105 Value *int2 = RValue<Int2>(Int2(As<Int4>(packed))).value;
3106 Value *short4 = Nucleus::createBitCast(int2, Short4::getType());
3111 // Short4::Short4(RValue<Float> cast)
3115 Short4::Short4(RValue<Float4> cast)
3117 assert(false && "UNIMPLEMENTED");
3120 Short4::Short4(short xyzw)
3122 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3123 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3126 Short4::Short4(short x, short y, short z, short w)
3128 int64_t constantVector[4] = {x, y, z, w};
3129 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3132 Short4::Short4(RValue<Short4> rhs)
3134 storeValue(rhs.value);
3137 Short4::Short4(const Short4 &rhs)
3139 Value *value = rhs.loadValue();
3143 Short4::Short4(const Reference<Short4> &rhs)
3145 Value *value = rhs.loadValue();
3149 Short4::Short4(RValue<UShort4> rhs)
3151 storeValue(rhs.value);
3154 Short4::Short4(const UShort4 &rhs)
3156 storeValue(rhs.loadValue());
3159 Short4::Short4(const Reference<UShort4> &rhs)
3161 storeValue(rhs.loadValue());
3164 RValue<Short4> Short4::operator=(RValue<Short4> rhs)
3166 storeValue(rhs.value);
3171 RValue<Short4> Short4::operator=(const Short4 &rhs)
3173 Value *value = rhs.loadValue();
3176 return RValue<Short4>(value);
3179 RValue<Short4> Short4::operator=(const Reference<Short4> &rhs)
3181 Value *value = rhs.loadValue();
3184 return RValue<Short4>(value);
3187 RValue<Short4> Short4::operator=(RValue<UShort4> rhs)
3189 storeValue(rhs.value);
3191 return RValue<Short4>(rhs);
3194 RValue<Short4> Short4::operator=(const UShort4 &rhs)
3196 Value *value = rhs.loadValue();
3199 return RValue<Short4>(value);
3202 RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs)
3204 Value *value = rhs.loadValue();
3207 return RValue<Short4>(value);
3210 RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs)
3212 return RValue<Short4>(Nucleus::createAdd(lhs.value, rhs.value));
3215 RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs)
3217 return RValue<Short4>(Nucleus::createSub(lhs.value, rhs.value));
3220 RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs)
3222 return RValue<Short4>(Nucleus::createMul(lhs.value, rhs.value));
3225 // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs)
3227 // return RValue<Short4>(Nucleus::createSDiv(lhs.value, rhs.value));
3230 // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs)
3232 // return RValue<Short4>(Nucleus::createSRem(lhs.value, rhs.value));
3235 RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs)
3237 return RValue<Short4>(Nucleus::createAnd(lhs.value, rhs.value));
3240 RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs)
3242 return RValue<Short4>(Nucleus::createOr(lhs.value, rhs.value));
3245 RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs)
3247 return RValue<Short4>(Nucleus::createXor(lhs.value, rhs.value));
3250 RValue<Short4> operator<<(RValue<Short4> lhs, unsigned char rhs)
3252 if(emulateIntrinsics)
3255 result = Insert(result, Extract(lhs, 0) << Short(rhs), 0);
3256 result = Insert(result, Extract(lhs, 1) << Short(rhs), 1);
3257 result = Insert(result, Extract(lhs, 2) << Short(rhs), 2);
3258 result = Insert(result, Extract(lhs, 3) << Short(rhs), 3);
3264 return RValue<Short4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
3268 RValue<Short4> operator>>(RValue<Short4> lhs, unsigned char rhs)
3270 if(emulateIntrinsics)
3273 result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0);
3274 result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1);
3275 result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2);
3276 result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3);
3282 return RValue<Short4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
3286 RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs)
3288 return lhs = lhs + rhs;
3291 RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs)
3293 return lhs = lhs - rhs;
3296 RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs)
3298 return lhs = lhs * rhs;
3301 // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs)
3303 // return lhs = lhs / rhs;
3306 // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs)
3308 // return lhs = lhs % rhs;
3311 RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs)
3313 return lhs = lhs & rhs;
3316 RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs)
3318 return lhs = lhs | rhs;
3321 RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs)
3323 return lhs = lhs ^ rhs;
3326 RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs)
3328 return lhs = lhs << rhs;
3331 RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs)
3333 return lhs = lhs >> rhs;
3336 // RValue<Short4> operator+(RValue<Short4> val)
3341 RValue<Short4> operator-(RValue<Short4> val)
3343 return RValue<Short4>(Nucleus::createNeg(val.value));
3346 RValue<Short4> operator~(RValue<Short4> val)
3348 return RValue<Short4>(Nucleus::createNot(val.value));
3351 RValue<Short4> RoundShort4(RValue<Float4> cast)
3353 RValue<Int4> int4 = RoundInt(cast);
3354 return As<Short4>(Pack(int4, int4));
3357 RValue<Short4> Max(RValue<Short4> x, RValue<Short4> y)
3359 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3360 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
3361 ::basicBlock->appendInst(cmp);
3363 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3364 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3365 ::basicBlock->appendInst(select);
3367 return RValue<Short4>(V(result));
3370 RValue<Short4> Min(RValue<Short4> x, RValue<Short4> y)
3372 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3373 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
3374 ::basicBlock->appendInst(cmp);
3376 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3377 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3378 ::basicBlock->appendInst(select);
3380 return RValue<Short4>(V(result));
3383 RValue<Short4> AddSat(RValue<Short4> x, RValue<Short4> y)
3385 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3386 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3387 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3388 auto paddsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3389 paddsw->addArg(x.value);
3390 paddsw->addArg(y.value);
3391 ::basicBlock->appendInst(paddsw);
3393 return RValue<Short4>(V(result));
3396 RValue<Short4> SubSat(RValue<Short4> x, RValue<Short4> y)
3398 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3399 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3400 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3401 auto psubsw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3402 psubsw->addArg(x.value);
3403 psubsw->addArg(y.value);
3404 ::basicBlock->appendInst(psubsw);
3406 return RValue<Short4>(V(result));
3409 RValue<Short4> MulHigh(RValue<Short4> x, RValue<Short4> y)
3411 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3412 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3413 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3414 auto pmulhw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3415 pmulhw->addArg(x.value);
3416 pmulhw->addArg(y.value);
3417 ::basicBlock->appendInst(pmulhw);
3419 return RValue<Short4>(V(result));
3422 RValue<Int2> MulAdd(RValue<Short4> x, RValue<Short4> y)
3424 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3425 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyAddPairs, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3426 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3427 auto pmaddwd = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3428 pmaddwd->addArg(x.value);
3429 pmaddwd->addArg(y.value);
3430 ::basicBlock->appendInst(pmaddwd);
3432 return As<Int2>(V(result));
3435 RValue<SByte8> Pack(RValue<Short4> x, RValue<Short4> y)
3437 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3438 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3439 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3440 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3441 pack->addArg(x.value);
3442 pack->addArg(y.value);
3443 ::basicBlock->appendInst(pack);
3445 return As<SByte8>(Swizzle(As<Int4>(V(result)), 0x88));
3448 RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y)
3450 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3451 return As<Int2>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3454 RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y)
3456 int shuffle[8] = {0, 8, 1, 9, 2, 10, 3, 11}; // Real type is v8i16
3457 auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
3458 return As<Int2>(Swizzle(As<Int4>(lowHigh), 0xEE));
3461 RValue<Short4> Swizzle(RValue<Short4> x, unsigned char select)
3463 // Real type is v8i16
3466 (select >> 0) & 0x03,
3467 (select >> 2) & 0x03,
3468 (select >> 4) & 0x03,
3469 (select >> 6) & 0x03,
3470 (select >> 0) & 0x03,
3471 (select >> 2) & 0x03,
3472 (select >> 4) & 0x03,
3473 (select >> 6) & 0x03,
3476 return RValue<Short4>(Nucleus::createShuffleVector(x.value, x.value, shuffle));
3479 RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i)
3481 return RValue<Short4>(Nucleus::createInsertElement(val.value, element.value, i));
3484 RValue<Short> Extract(RValue<Short4> val, int i)
3486 return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
3489 RValue<Short4> CmpGT(RValue<Short4> x, RValue<Short4> y)
3491 return RValue<Short4>(createIntCompare(Ice::InstIcmp::Sgt, x.value, y.value));
3494 RValue<Short4> CmpEQ(RValue<Short4> x, RValue<Short4> y)
3496 return RValue<Short4>(Nucleus::createICmpEQ(x.value, y.value));
3499 Type *Short4::getType()
3501 return T(Type_v4i16);
3504 UShort4::UShort4(RValue<Int4> cast)
3506 *this = Short4(cast);
3509 UShort4::UShort4(RValue<Float4> cast, bool saturate)
3515 Int4 int4(Min(cast, Float4(0xFFFF))); // packusdw takes care of 0x0000 saturation
3516 *this = As<Short4>(Pack(As<UInt4>(int4), As<UInt4>(int4)));
3520 *this = Short4(Int4(Max(Min(cast, Float4(0xFFFF)), Float4(0x0000))));
3525 *this = Short4(Int4(cast));
3529 UShort4::UShort4(unsigned short xyzw)
3531 int64_t constantVector[4] = {xyzw, xyzw, xyzw, xyzw};
3532 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3535 UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
3537 int64_t constantVector[4] = {x, y, z, w};
3538 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3541 UShort4::UShort4(RValue<UShort4> rhs)
3543 storeValue(rhs.value);
3546 UShort4::UShort4(const UShort4 &rhs)
3548 Value *value = rhs.loadValue();
3552 UShort4::UShort4(const Reference<UShort4> &rhs)
3554 Value *value = rhs.loadValue();
3558 UShort4::UShort4(RValue<Short4> rhs)
3560 storeValue(rhs.value);
3563 UShort4::UShort4(const Short4 &rhs)
3565 Value *value = rhs.loadValue();
3569 UShort4::UShort4(const Reference<Short4> &rhs)
3571 Value *value = rhs.loadValue();
3575 RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs)
3577 storeValue(rhs.value);
3582 RValue<UShort4> UShort4::operator=(const UShort4 &rhs)
3584 Value *value = rhs.loadValue();
3587 return RValue<UShort4>(value);
3590 RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs)
3592 Value *value = rhs.loadValue();
3595 return RValue<UShort4>(value);
3598 RValue<UShort4> UShort4::operator=(RValue<Short4> rhs)
3600 storeValue(rhs.value);
3602 return RValue<UShort4>(rhs);
3605 RValue<UShort4> UShort4::operator=(const Short4 &rhs)
3607 Value *value = rhs.loadValue();
3610 return RValue<UShort4>(value);
3613 RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs)
3615 Value *value = rhs.loadValue();
3618 return RValue<UShort4>(value);
3621 RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs)
3623 return RValue<UShort4>(Nucleus::createAdd(lhs.value, rhs.value));
3626 RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs)
3628 return RValue<UShort4>(Nucleus::createSub(lhs.value, rhs.value));
3631 RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs)
3633 return RValue<UShort4>(Nucleus::createMul(lhs.value, rhs.value));
3636 RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs)
3638 return RValue<UShort4>(Nucleus::createAnd(lhs.value, rhs.value));
3641 RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs)
3643 return RValue<UShort4>(Nucleus::createOr(lhs.value, rhs.value));
3646 RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs)
3648 return RValue<UShort4>(Nucleus::createXor(lhs.value, rhs.value));
3651 RValue<UShort> Extract(RValue<UShort4> val, int i)
3653 return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i));
3656 RValue<UShort4> Insert(RValue<UShort4> val, RValue<UShort> element, int i)
3658 return RValue<UShort4>(Nucleus::createInsertElement(val.value, element.value, i));
3661 RValue<UShort4> operator<<(RValue<UShort4> lhs, unsigned char rhs)
3663 if(emulateIntrinsics)
3666 result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0);
3667 result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1);
3668 result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2);
3669 result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3);
3675 return RValue<UShort4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
3679 RValue<UShort4> operator>>(RValue<UShort4> lhs, unsigned char rhs)
3681 if(emulateIntrinsics)
3684 result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0);
3685 result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1);
3686 result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2);
3687 result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3);
3693 return RValue<UShort4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
3697 RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs)
3699 return lhs = lhs << rhs;
3702 RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs)
3704 return lhs = lhs >> rhs;
3707 RValue<UShort4> operator~(RValue<UShort4> val)
3709 return RValue<UShort4>(Nucleus::createNot(val.value));
3712 RValue<UShort4> Max(RValue<UShort4> x, RValue<UShort4> y)
3714 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3715 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
3716 ::basicBlock->appendInst(cmp);
3718 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3719 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3720 ::basicBlock->appendInst(select);
3722 return RValue<UShort4>(V(result));
3725 RValue<UShort4> Min(RValue<UShort4> x, RValue<UShort4> y)
3727 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v8i1);
3728 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
3729 ::basicBlock->appendInst(cmp);
3731 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3732 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
3733 ::basicBlock->appendInst(select);
3735 return RValue<UShort4>(V(result));
3738 RValue<UShort4> AddSat(RValue<UShort4> x, RValue<UShort4> y)
3740 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3741 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::AddSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3742 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3743 auto paddusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3744 paddusw->addArg(x.value);
3745 paddusw->addArg(y.value);
3746 ::basicBlock->appendInst(paddusw);
3748 return RValue<UShort4>(V(result));
3751 RValue<UShort4> SubSat(RValue<UShort4> x, RValue<UShort4> y)
3753 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3754 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SubtractSaturateUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3755 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3756 auto psubusw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3757 psubusw->addArg(x.value);
3758 psubusw->addArg(y.value);
3759 ::basicBlock->appendInst(psubusw);
3761 return RValue<UShort4>(V(result));
3764 RValue<UShort4> MulHigh(RValue<UShort4> x, RValue<UShort4> y)
3766 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
3767 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::MultiplyHighUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3768 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3769 auto pmulhuw = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3770 pmulhuw->addArg(x.value);
3771 pmulhuw->addArg(y.value);
3772 ::basicBlock->appendInst(pmulhuw);
3774 return RValue<UShort4>(V(result));
3777 RValue<UShort4> Average(RValue<UShort4> x, RValue<UShort4> y)
3779 assert(false && "UNIMPLEMENTED"); return RValue<UShort4>(V(nullptr));
3782 RValue<Byte8> Pack(RValue<UShort4> x, RValue<UShort4> y)
3784 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v16i8);
3785 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
3786 auto target = ::context->getConstantUndef(Ice::IceType_i32);
3787 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
3788 pack->addArg(x.value);
3789 pack->addArg(y.value);
3790 ::basicBlock->appendInst(pack);
3792 return As<Byte8>(Swizzle(As<Int4>(V(result)), 0x88));
3795 Type *UShort4::getType()
3797 return T(Type_v4i16);
3800 Short8::Short8(short c)
3802 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3803 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3806 Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7)
3808 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3809 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3812 Short8::Short8(RValue<Short8> rhs)
3814 storeValue(rhs.value);
3817 Short8::Short8(const Reference<Short8> &rhs)
3819 Value *value = rhs.loadValue();
3823 Short8::Short8(RValue<Short4> lo, RValue<Short4> hi)
3825 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3826 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3831 RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs)
3833 return RValue<Short8>(Nucleus::createAdd(lhs.value, rhs.value));
3836 RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs)
3838 return RValue<Short8>(Nucleus::createAnd(lhs.value, rhs.value));
3841 RValue<Short> Extract(RValue<Short8> val, int i)
3843 return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
3846 RValue<Short8> Insert(RValue<Short8> val, RValue<Short> element, int i)
3848 return RValue<Short8>(Nucleus::createInsertElement(val.value, element.value, i));
3851 RValue<Short8> operator<<(RValue<Short8> lhs, unsigned char rhs)
3853 if(emulateIntrinsics)
3856 result = Insert(result, Extract(lhs, 0) << Short(rhs), 0);
3857 result = Insert(result, Extract(lhs, 1) << Short(rhs), 1);
3858 result = Insert(result, Extract(lhs, 2) << Short(rhs), 2);
3859 result = Insert(result, Extract(lhs, 3) << Short(rhs), 3);
3860 result = Insert(result, Extract(lhs, 4) << Short(rhs), 4);
3861 result = Insert(result, Extract(lhs, 5) << Short(rhs), 5);
3862 result = Insert(result, Extract(lhs, 6) << Short(rhs), 6);
3863 result = Insert(result, Extract(lhs, 7) << Short(rhs), 7);
3869 return RValue<Short8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
3873 RValue<Short8> operator>>(RValue<Short8> lhs, unsigned char rhs)
3875 if(emulateIntrinsics)
3878 result = Insert(result, Extract(lhs, 0) >> Short(rhs), 0);
3879 result = Insert(result, Extract(lhs, 1) >> Short(rhs), 1);
3880 result = Insert(result, Extract(lhs, 2) >> Short(rhs), 2);
3881 result = Insert(result, Extract(lhs, 3) >> Short(rhs), 3);
3882 result = Insert(result, Extract(lhs, 4) >> Short(rhs), 4);
3883 result = Insert(result, Extract(lhs, 5) >> Short(rhs), 5);
3884 result = Insert(result, Extract(lhs, 6) >> Short(rhs), 6);
3885 result = Insert(result, Extract(lhs, 7) >> Short(rhs), 7);
3891 return RValue<Short8>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
3895 RValue<Int4> MulAdd(RValue<Short8> x, RValue<Short8> y)
3897 assert(false && "UNIMPLEMENTED"); return RValue<Int4>(V(nullptr));
3900 RValue<Int4> Abs(RValue<Int4> x)
3902 auto negative = x >> 31;
3903 return (x ^ negative) - negative;
3906 RValue<Short8> MulHigh(RValue<Short8> x, RValue<Short8> y)
3908 assert(false && "UNIMPLEMENTED"); return RValue<Short8>(V(nullptr));
3911 Type *Short8::getType()
3913 return T(Ice::IceType_v8i16);
3916 UShort8::UShort8(unsigned short c)
3918 int64_t constantVector[8] = {c, c, c, c, c, c, c, c};
3919 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3922 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)
3924 int64_t constantVector[8] = {c0, c1, c2, c3, c4, c5, c6, c7};
3925 storeValue(Nucleus::createConstantVector(constantVector, getType()));
3928 UShort8::UShort8(RValue<UShort8> rhs)
3930 storeValue(rhs.value);
3933 UShort8::UShort8(const Reference<UShort8> &rhs)
3935 Value *value = rhs.loadValue();
3939 UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi)
3941 int shuffle[8] = {0, 1, 2, 3, 8, 9, 10, 11}; // Real type is v8i16
3942 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
3947 RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs)
3949 storeValue(rhs.value);
3954 RValue<UShort8> UShort8::operator=(const UShort8 &rhs)
3956 Value *value = rhs.loadValue();
3959 return RValue<UShort8>(value);
3962 RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs)
3964 Value *value = rhs.loadValue();
3967 return RValue<UShort8>(value);
3970 RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs)
3972 return RValue<UShort8>(Nucleus::createAnd(lhs.value, rhs.value));
3975 RValue<UShort> Extract(RValue<UShort8> val, int i)
3977 return RValue<UShort>(Nucleus::createExtractElement(val.value, UShort::getType(), i));
3980 RValue<UShort8> Insert(RValue<UShort8> val, RValue<UShort> element, int i)
3982 return RValue<UShort8>(Nucleus::createInsertElement(val.value, element.value, i));
3985 RValue<UShort8> operator<<(RValue<UShort8> lhs, unsigned char rhs)
3987 if(emulateIntrinsics)
3990 result = Insert(result, Extract(lhs, 0) << UShort(rhs), 0);
3991 result = Insert(result, Extract(lhs, 1) << UShort(rhs), 1);
3992 result = Insert(result, Extract(lhs, 2) << UShort(rhs), 2);
3993 result = Insert(result, Extract(lhs, 3) << UShort(rhs), 3);
3994 result = Insert(result, Extract(lhs, 4) << UShort(rhs), 4);
3995 result = Insert(result, Extract(lhs, 5) << UShort(rhs), 5);
3996 result = Insert(result, Extract(lhs, 6) << UShort(rhs), 6);
3997 result = Insert(result, Extract(lhs, 7) << UShort(rhs), 7);
4003 return RValue<UShort8>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
4007 RValue<UShort8> operator>>(RValue<UShort8> lhs, unsigned char rhs)
4009 if(emulateIntrinsics)
4012 result = Insert(result, Extract(lhs, 0) >> UShort(rhs), 0);
4013 result = Insert(result, Extract(lhs, 1) >> UShort(rhs), 1);
4014 result = Insert(result, Extract(lhs, 2) >> UShort(rhs), 2);
4015 result = Insert(result, Extract(lhs, 3) >> UShort(rhs), 3);
4016 result = Insert(result, Extract(lhs, 4) >> UShort(rhs), 4);
4017 result = Insert(result, Extract(lhs, 5) >> UShort(rhs), 5);
4018 result = Insert(result, Extract(lhs, 6) >> UShort(rhs), 6);
4019 result = Insert(result, Extract(lhs, 7) >> UShort(rhs), 7);
4025 return RValue<UShort8>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
4029 RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs)
4031 return RValue<UShort8>(Nucleus::createAdd(lhs.value, rhs.value));
4034 RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs)
4036 return RValue<UShort8>(Nucleus::createMul(lhs.value, rhs.value));
4039 RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs)
4041 return lhs = lhs + rhs;
4044 RValue<UShort8> operator~(RValue<UShort8> val)
4046 return RValue<UShort8>(Nucleus::createNot(val.value));
4049 RValue<UShort8> Swizzle(RValue<UShort8> x, char select0, char select1, char select2, char select3, char select4, char select5, char select6, char select7)
4051 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
4054 RValue<UShort8> MulHigh(RValue<UShort8> x, RValue<UShort8> y)
4056 assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
4059 // FIXME: Implement as Shuffle(x, y, Select(i0, ..., i16)) and Shuffle(x, y, SELECT_PACK_REPEAT(element))
4060 // RValue<UShort8> PackRepeat(RValue<Byte16> x, RValue<Byte16> y, int element)
4062 // assert(false && "UNIMPLEMENTED"); return RValue<UShort8>(V(nullptr));
4065 Type *UShort8::getType()
4067 return T(Ice::IceType_v8i16);
4070 Int::Int(Argument<Int> argument)
4072 storeValue(argument.value);
4075 Int::Int(RValue<Byte> cast)
4077 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
4079 storeValue(integer);
4082 Int::Int(RValue<SByte> cast)
4084 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
4086 storeValue(integer);
4089 Int::Int(RValue<Short> cast)
4091 Value *integer = Nucleus::createSExt(cast.value, Int::getType());
4093 storeValue(integer);
4096 Int::Int(RValue<UShort> cast)
4098 Value *integer = Nucleus::createZExt(cast.value, Int::getType());
4100 storeValue(integer);
4103 Int::Int(RValue<Int2> cast)
4105 *this = Extract(cast, 0);
4108 Int::Int(RValue<Long> cast)
4110 Value *integer = Nucleus::createTrunc(cast.value, Int::getType());
4112 storeValue(integer);
4115 Int::Int(RValue<Float> cast)
4117 Value *integer = Nucleus::createFPToSI(cast.value, Int::getType());
4119 storeValue(integer);
4124 storeValue(Nucleus::createConstantInt(x));
4127 Int::Int(RValue<Int> rhs)
4129 storeValue(rhs.value);
4132 Int::Int(RValue<UInt> rhs)
4134 storeValue(rhs.value);
4137 Int::Int(const Int &rhs)
4139 Value *value = rhs.loadValue();
4143 Int::Int(const Reference<Int> &rhs)
4145 Value *value = rhs.loadValue();
4149 Int::Int(const UInt &rhs)
4151 Value *value = rhs.loadValue();
4155 Int::Int(const Reference<UInt> &rhs)
4157 Value *value = rhs.loadValue();
4161 RValue<Int> Int::operator=(int rhs)
4163 return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs)));
4166 RValue<Int> Int::operator=(RValue<Int> rhs)
4168 storeValue(rhs.value);
4173 RValue<Int> Int::operator=(RValue<UInt> rhs)
4175 storeValue(rhs.value);
4177 return RValue<Int>(rhs);
4180 RValue<Int> Int::operator=(const Int &rhs)
4182 Value *value = rhs.loadValue();
4185 return RValue<Int>(value);
4188 RValue<Int> Int::operator=(const Reference<Int> &rhs)
4190 Value *value = rhs.loadValue();
4193 return RValue<Int>(value);
4196 RValue<Int> Int::operator=(const UInt &rhs)
4198 Value *value = rhs.loadValue();
4201 return RValue<Int>(value);
4204 RValue<Int> Int::operator=(const Reference<UInt> &rhs)
4206 Value *value = rhs.loadValue();
4209 return RValue<Int>(value);
4212 RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs)
4214 return RValue<Int>(Nucleus::createAdd(lhs.value, rhs.value));
4217 RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs)
4219 return RValue<Int>(Nucleus::createSub(lhs.value, rhs.value));
4222 RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs)
4224 return RValue<Int>(Nucleus::createMul(lhs.value, rhs.value));
4227 RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs)
4229 return RValue<Int>(Nucleus::createSDiv(lhs.value, rhs.value));
4232 RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs)
4234 return RValue<Int>(Nucleus::createSRem(lhs.value, rhs.value));
4237 RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs)
4239 return RValue<Int>(Nucleus::createAnd(lhs.value, rhs.value));
4242 RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs)
4244 return RValue<Int>(Nucleus::createOr(lhs.value, rhs.value));
4247 RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs)
4249 return RValue<Int>(Nucleus::createXor(lhs.value, rhs.value));
4252 RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs)
4254 return RValue<Int>(Nucleus::createShl(lhs.value, rhs.value));
4257 RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs)
4259 return RValue<Int>(Nucleus::createAShr(lhs.value, rhs.value));
4262 RValue<Int> operator+=(Int &lhs, RValue<Int> rhs)
4264 return lhs = lhs + rhs;
4267 RValue<Int> operator-=(Int &lhs, RValue<Int> rhs)
4269 return lhs = lhs - rhs;
4272 RValue<Int> operator*=(Int &lhs, RValue<Int> rhs)
4274 return lhs = lhs * rhs;
4277 RValue<Int> operator/=(Int &lhs, RValue<Int> rhs)
4279 return lhs = lhs / rhs;
4282 RValue<Int> operator%=(Int &lhs, RValue<Int> rhs)
4284 return lhs = lhs % rhs;
4287 RValue<Int> operator&=(Int &lhs, RValue<Int> rhs)
4289 return lhs = lhs & rhs;
4292 RValue<Int> operator|=(Int &lhs, RValue<Int> rhs)
4294 return lhs = lhs | rhs;
4297 RValue<Int> operator^=(Int &lhs, RValue<Int> rhs)
4299 return lhs = lhs ^ rhs;
4302 RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs)
4304 return lhs = lhs << rhs;
4307 RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs)
4309 return lhs = lhs >> rhs;
4312 RValue<Int> operator+(RValue<Int> val)
4317 RValue<Int> operator-(RValue<Int> val)
4319 return RValue<Int>(Nucleus::createNeg(val.value));
4322 RValue<Int> operator~(RValue<Int> val)
4324 return RValue<Int>(Nucleus::createNot(val.value));
4327 RValue<Int> operator++(Int &val, int) // Post-increment
4329 RValue<Int> res = val;
4334 const Int &operator++(Int &val) // Pre-increment
4340 RValue<Int> operator--(Int &val, int) // Post-decrement
4342 RValue<Int> res = val;
4347 const Int &operator--(Int &val) // Pre-decrement
4353 RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs)
4355 return RValue<Bool>(Nucleus::createICmpSLT(lhs.value, rhs.value));
4358 RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs)
4360 return RValue<Bool>(Nucleus::createICmpSLE(lhs.value, rhs.value));
4363 RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs)
4365 return RValue<Bool>(Nucleus::createICmpSGT(lhs.value, rhs.value));
4368 RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs)
4370 return RValue<Bool>(Nucleus::createICmpSGE(lhs.value, rhs.value));
4373 RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs)
4375 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4378 RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs)
4380 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4383 RValue<Int> Max(RValue<Int> x, RValue<Int> y)
4385 return IfThenElse(x > y, x, y);
4388 RValue<Int> Min(RValue<Int> x, RValue<Int> y)
4390 return IfThenElse(x < y, x, y);
4393 RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max)
4395 return Min(Max(x, min), max);
4398 RValue<Int> RoundInt(RValue<Float> cast)
4400 if(emulateIntrinsics)
4402 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
4403 return Int((cast + Float(0x00C00000)) - Float(0x00C00000));
4407 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
4408 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
4409 auto target = ::context->getConstantUndef(Ice::IceType_i32);
4410 auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
4411 nearbyint->addArg(cast.value);
4412 ::basicBlock->appendInst(nearbyint);
4414 return RValue<Int>(V(result));
4418 Type *Int::getType()
4420 return T(Ice::IceType_i32);
4423 Long::Long(RValue<Int> cast)
4425 Value *integer = Nucleus::createSExt(cast.value, Long::getType());
4427 storeValue(integer);
4430 Long::Long(RValue<UInt> cast)
4432 Value *integer = Nucleus::createZExt(cast.value, Long::getType());
4434 storeValue(integer);
4437 Long::Long(RValue<Long> rhs)
4439 storeValue(rhs.value);
4442 RValue<Long> Long::operator=(int64_t rhs)
4444 return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs)));
4447 RValue<Long> Long::operator=(RValue<Long> rhs)
4449 storeValue(rhs.value);
4454 RValue<Long> Long::operator=(const Long &rhs)
4456 Value *value = rhs.loadValue();
4459 return RValue<Long>(value);
4462 RValue<Long> Long::operator=(const Reference<Long> &rhs)
4464 Value *value = rhs.loadValue();
4467 return RValue<Long>(value);
4470 RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs)
4472 return RValue<Long>(Nucleus::createAdd(lhs.value, rhs.value));
4475 RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs)
4477 return RValue<Long>(Nucleus::createSub(lhs.value, rhs.value));
4480 RValue<Long> operator+=(Long &lhs, RValue<Long> rhs)
4482 return lhs = lhs + rhs;
4485 RValue<Long> operator-=(Long &lhs, RValue<Long> rhs)
4487 return lhs = lhs - rhs;
4490 RValue<Long> AddAtomic(RValue<Pointer<Long> > x, RValue<Long> y)
4492 return RValue<Long>(Nucleus::createAtomicAdd(x.value, y.value));
4495 Type *Long::getType()
4497 return T(Ice::IceType_i64);
4500 UInt::UInt(Argument<UInt> argument)
4502 storeValue(argument.value);
4505 UInt::UInt(RValue<UShort> cast)
4507 Value *integer = Nucleus::createZExt(cast.value, UInt::getType());
4509 storeValue(integer);
4512 UInt::UInt(RValue<Long> cast)
4514 Value *integer = Nucleus::createTrunc(cast.value, UInt::getType());
4516 storeValue(integer);
4519 UInt::UInt(RValue<Float> cast)
4521 // Smallest positive value representable in UInt, but not in Int
4522 const unsigned int ustart = 0x80000000u;
4523 const float ustartf = float(ustart);
4525 // If the value is negative, store 0, otherwise store the result of the conversion
4526 storeValue((~(As<Int>(cast) >> 31) &
4527 // Check if the value can be represented as an Int
4528 IfThenElse(cast >= ustartf,
4529 // If the value is too large, subtract ustart and re-add it after conversion.
4530 As<Int>(As<UInt>(Int(cast - Float(ustartf))) + UInt(ustart)),
4531 // Otherwise, just convert normally
4537 storeValue(Nucleus::createConstantInt(x));
4540 UInt::UInt(unsigned int x)
4542 storeValue(Nucleus::createConstantInt(x));
4545 UInt::UInt(RValue<UInt> rhs)
4547 storeValue(rhs.value);
4550 UInt::UInt(RValue<Int> rhs)
4552 storeValue(rhs.value);
4555 UInt::UInt(const UInt &rhs)
4557 Value *value = rhs.loadValue();
4561 UInt::UInt(const Reference<UInt> &rhs)
4563 Value *value = rhs.loadValue();
4567 UInt::UInt(const Int &rhs)
4569 Value *value = rhs.loadValue();
4573 UInt::UInt(const Reference<Int> &rhs)
4575 Value *value = rhs.loadValue();
4579 RValue<UInt> UInt::operator=(unsigned int rhs)
4581 return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs)));
4584 RValue<UInt> UInt::operator=(RValue<UInt> rhs)
4586 storeValue(rhs.value);
4591 RValue<UInt> UInt::operator=(RValue<Int> rhs)
4593 storeValue(rhs.value);
4595 return RValue<UInt>(rhs);
4598 RValue<UInt> UInt::operator=(const UInt &rhs)
4600 Value *value = rhs.loadValue();
4603 return RValue<UInt>(value);
4606 RValue<UInt> UInt::operator=(const Reference<UInt> &rhs)
4608 Value *value = rhs.loadValue();
4611 return RValue<UInt>(value);
4614 RValue<UInt> UInt::operator=(const Int &rhs)
4616 Value *value = rhs.loadValue();
4619 return RValue<UInt>(value);
4622 RValue<UInt> UInt::operator=(const Reference<Int> &rhs)
4624 Value *value = rhs.loadValue();
4627 return RValue<UInt>(value);
4630 RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs)
4632 return RValue<UInt>(Nucleus::createAdd(lhs.value, rhs.value));
4635 RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs)
4637 return RValue<UInt>(Nucleus::createSub(lhs.value, rhs.value));
4640 RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs)
4642 return RValue<UInt>(Nucleus::createMul(lhs.value, rhs.value));
4645 RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs)
4647 return RValue<UInt>(Nucleus::createUDiv(lhs.value, rhs.value));
4650 RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs)
4652 return RValue<UInt>(Nucleus::createURem(lhs.value, rhs.value));
4655 RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs)
4657 return RValue<UInt>(Nucleus::createAnd(lhs.value, rhs.value));
4660 RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs)
4662 return RValue<UInt>(Nucleus::createOr(lhs.value, rhs.value));
4665 RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs)
4667 return RValue<UInt>(Nucleus::createXor(lhs.value, rhs.value));
4670 RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs)
4672 return RValue<UInt>(Nucleus::createShl(lhs.value, rhs.value));
4675 RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs)
4677 return RValue<UInt>(Nucleus::createLShr(lhs.value, rhs.value));
4680 RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs)
4682 return lhs = lhs + rhs;
4685 RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs)
4687 return lhs = lhs - rhs;
4690 RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs)
4692 return lhs = lhs * rhs;
4695 RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs)
4697 return lhs = lhs / rhs;
4700 RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs)
4702 return lhs = lhs % rhs;
4705 RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs)
4707 return lhs = lhs & rhs;
4710 RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs)
4712 return lhs = lhs | rhs;
4715 RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs)
4717 return lhs = lhs ^ rhs;
4720 RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs)
4722 return lhs = lhs << rhs;
4725 RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs)
4727 return lhs = lhs >> rhs;
4730 RValue<UInt> operator+(RValue<UInt> val)
4735 RValue<UInt> operator-(RValue<UInt> val)
4737 return RValue<UInt>(Nucleus::createNeg(val.value));
4740 RValue<UInt> operator~(RValue<UInt> val)
4742 return RValue<UInt>(Nucleus::createNot(val.value));
4745 RValue<UInt> operator++(UInt &val, int) // Post-increment
4747 RValue<UInt> res = val;
4752 const UInt &operator++(UInt &val) // Pre-increment
4758 RValue<UInt> operator--(UInt &val, int) // Post-decrement
4760 RValue<UInt> res = val;
4765 const UInt &operator--(UInt &val) // Pre-decrement
4771 RValue<UInt> Max(RValue<UInt> x, RValue<UInt> y)
4773 return IfThenElse(x > y, x, y);
4776 RValue<UInt> Min(RValue<UInt> x, RValue<UInt> y)
4778 return IfThenElse(x < y, x, y);
4781 RValue<UInt> Clamp(RValue<UInt> x, RValue<UInt> min, RValue<UInt> max)
4783 return Min(Max(x, min), max);
4786 RValue<Bool> operator<(RValue<UInt> lhs, RValue<UInt> rhs)
4788 return RValue<Bool>(Nucleus::createICmpULT(lhs.value, rhs.value));
4791 RValue<Bool> operator<=(RValue<UInt> lhs, RValue<UInt> rhs)
4793 return RValue<Bool>(Nucleus::createICmpULE(lhs.value, rhs.value));
4796 RValue<Bool> operator>(RValue<UInt> lhs, RValue<UInt> rhs)
4798 return RValue<Bool>(Nucleus::createICmpUGT(lhs.value, rhs.value));
4801 RValue<Bool> operator>=(RValue<UInt> lhs, RValue<UInt> rhs)
4803 return RValue<Bool>(Nucleus::createICmpUGE(lhs.value, rhs.value));
4806 RValue<Bool> operator!=(RValue<UInt> lhs, RValue<UInt> rhs)
4808 return RValue<Bool>(Nucleus::createICmpNE(lhs.value, rhs.value));
4811 RValue<Bool> operator==(RValue<UInt> lhs, RValue<UInt> rhs)
4813 return RValue<Bool>(Nucleus::createICmpEQ(lhs.value, rhs.value));
4816 // RValue<UInt> RoundUInt(RValue<Float> cast)
4818 // assert(false && "UNIMPLEMENTED"); return RValue<UInt>(V(nullptr));
4821 Type *UInt::getType()
4823 return T(Ice::IceType_i32);
4826 // Int2::Int2(RValue<Int> cast)
4828 // Value *extend = Nucleus::createZExt(cast.value, Long::getType());
4829 // Value *vector = Nucleus::createBitCast(extend, Int2::getType());
4831 // Constant *shuffle[2];
4832 // shuffle[0] = Nucleus::createConstantInt(0);
4833 // shuffle[1] = Nucleus::createConstantInt(0);
4835 // Value *replicate = Nucleus::createShuffleVector(vector, UndefValue::get(Int2::getType()), Nucleus::createConstantVector(shuffle, 2));
4837 // storeValue(replicate);
4840 Int2::Int2(RValue<Int4> cast)
4842 storeValue(Nucleus::createBitCast(cast.value, getType()));
4845 Int2::Int2(int x, int y)
4847 int64_t constantVector[2] = {x, y};
4848 storeValue(Nucleus::createConstantVector(constantVector, getType()));
4851 Int2::Int2(RValue<Int2> rhs)
4853 storeValue(rhs.value);
4856 Int2::Int2(const Int2 &rhs)
4858 Value *value = rhs.loadValue();
4862 Int2::Int2(const Reference<Int2> &rhs)
4864 Value *value = rhs.loadValue();
4868 Int2::Int2(RValue<Int> lo, RValue<Int> hi)
4870 int shuffle[4] = {0, 4, 1, 5};
4871 Value *packed = Nucleus::createShuffleVector(Int4(lo).loadValue(), Int4(hi).loadValue(), shuffle);
4873 storeValue(Nucleus::createBitCast(packed, Int2::getType()));
4876 RValue<Int2> Int2::operator=(RValue<Int2> rhs)
4878 storeValue(rhs.value);
4883 RValue<Int2> Int2::operator=(const Int2 &rhs)
4885 Value *value = rhs.loadValue();
4888 return RValue<Int2>(value);
4891 RValue<Int2> Int2::operator=(const Reference<Int2> &rhs)
4893 Value *value = rhs.loadValue();
4896 return RValue<Int2>(value);
4899 RValue<Int2> operator+(RValue<Int2> lhs, RValue<Int2> rhs)
4901 return RValue<Int2>(Nucleus::createAdd(lhs.value, rhs.value));
4904 RValue<Int2> operator-(RValue<Int2> lhs, RValue<Int2> rhs)
4906 return RValue<Int2>(Nucleus::createSub(lhs.value, rhs.value));
4909 // RValue<Int2> operator*(RValue<Int2> lhs, RValue<Int2> rhs)
4911 // return RValue<Int2>(Nucleus::createMul(lhs.value, rhs.value));
4914 // RValue<Int2> operator/(RValue<Int2> lhs, RValue<Int2> rhs)
4916 // return RValue<Int2>(Nucleus::createSDiv(lhs.value, rhs.value));
4919 // RValue<Int2> operator%(RValue<Int2> lhs, RValue<Int2> rhs)
4921 // return RValue<Int2>(Nucleus::createSRem(lhs.value, rhs.value));
4924 RValue<Int2> operator&(RValue<Int2> lhs, RValue<Int2> rhs)
4926 return RValue<Int2>(Nucleus::createAnd(lhs.value, rhs.value));
4929 RValue<Int2> operator|(RValue<Int2> lhs, RValue<Int2> rhs)
4931 return RValue<Int2>(Nucleus::createOr(lhs.value, rhs.value));
4934 RValue<Int2> operator^(RValue<Int2> lhs, RValue<Int2> rhs)
4936 return RValue<Int2>(Nucleus::createXor(lhs.value, rhs.value));
4939 RValue<Int2> operator<<(RValue<Int2> lhs, unsigned char rhs)
4941 if(emulateIntrinsics)
4944 result = Insert(result, Extract(lhs, 0) << Int(rhs), 0);
4945 result = Insert(result, Extract(lhs, 1) << Int(rhs), 1);
4951 return RValue<Int2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
4955 RValue<Int2> operator>>(RValue<Int2> lhs, unsigned char rhs)
4957 if(emulateIntrinsics)
4960 result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0);
4961 result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1);
4967 return RValue<Int2>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
4971 RValue<Int2> operator+=(Int2 &lhs, RValue<Int2> rhs)
4973 return lhs = lhs + rhs;
4976 RValue<Int2> operator-=(Int2 &lhs, RValue<Int2> rhs)
4978 return lhs = lhs - rhs;
4981 // RValue<Int2> operator*=(Int2 &lhs, RValue<Int2> rhs)
4983 // return lhs = lhs * rhs;
4986 // RValue<Int2> operator/=(Int2 &lhs, RValue<Int2> rhs)
4988 // return lhs = lhs / rhs;
4991 // RValue<Int2> operator%=(Int2 &lhs, RValue<Int2> rhs)
4993 // return lhs = lhs % rhs;
4996 RValue<Int2> operator&=(Int2 &lhs, RValue<Int2> rhs)
4998 return lhs = lhs & rhs;
5001 RValue<Int2> operator|=(Int2 &lhs, RValue<Int2> rhs)
5003 return lhs = lhs | rhs;
5006 RValue<Int2> operator^=(Int2 &lhs, RValue<Int2> rhs)
5008 return lhs = lhs ^ rhs;
5011 RValue<Int2> operator<<=(Int2 &lhs, unsigned char rhs)
5013 return lhs = lhs << rhs;
5016 RValue<Int2> operator>>=(Int2 &lhs, unsigned char rhs)
5018 return lhs = lhs >> rhs;
5021 // RValue<Int2> operator+(RValue<Int2> val)
5026 // RValue<Int2> operator-(RValue<Int2> val)
5028 // return RValue<Int2>(Nucleus::createNeg(val.value));
5031 RValue<Int2> operator~(RValue<Int2> val)
5033 return RValue<Int2>(Nucleus::createNot(val.value));
5036 RValue<Short4> UnpackLow(RValue<Int2> x, RValue<Int2> y)
5038 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
5039 return As<Short4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
5042 RValue<Short4> UnpackHigh(RValue<Int2> x, RValue<Int2> y)
5044 int shuffle[4] = {0, 4, 1, 5}; // Real type is v4i32
5045 auto lowHigh = RValue<Int4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
5046 return As<Short4>(Swizzle(lowHigh, 0xEE));
5049 RValue<Int> Extract(RValue<Int2> val, int i)
5051 return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
5054 RValue<Int2> Insert(RValue<Int2> val, RValue<Int> element, int i)
5056 return RValue<Int2>(Nucleus::createInsertElement(val.value, element.value, i));
5059 Type *Int2::getType()
5061 return T(Type_v2i32);
5064 UInt2::UInt2(unsigned int x, unsigned int y)
5066 int64_t constantVector[2] = {x, y};
5067 storeValue(Nucleus::createConstantVector(constantVector, getType()));
5070 UInt2::UInt2(RValue<UInt2> rhs)
5072 storeValue(rhs.value);
5075 UInt2::UInt2(const UInt2 &rhs)
5077 Value *value = rhs.loadValue();
5081 UInt2::UInt2(const Reference<UInt2> &rhs)
5083 Value *value = rhs.loadValue();
5087 RValue<UInt2> UInt2::operator=(RValue<UInt2> rhs)
5089 storeValue(rhs.value);
5094 RValue<UInt2> UInt2::operator=(const UInt2 &rhs)
5096 Value *value = rhs.loadValue();
5099 return RValue<UInt2>(value);
5102 RValue<UInt2> UInt2::operator=(const Reference<UInt2> &rhs)
5104 Value *value = rhs.loadValue();
5107 return RValue<UInt2>(value);
5110 RValue<UInt2> operator+(RValue<UInt2> lhs, RValue<UInt2> rhs)
5112 return RValue<UInt2>(Nucleus::createAdd(lhs.value, rhs.value));
5115 RValue<UInt2> operator-(RValue<UInt2> lhs, RValue<UInt2> rhs)
5117 return RValue<UInt2>(Nucleus::createSub(lhs.value, rhs.value));
5120 // RValue<UInt2> operator*(RValue<UInt2> lhs, RValue<UInt2> rhs)
5122 // return RValue<UInt2>(Nucleus::createMul(lhs.value, rhs.value));
5125 // RValue<UInt2> operator/(RValue<UInt2> lhs, RValue<UInt2> rhs)
5127 // return RValue<UInt2>(Nucleus::createUDiv(lhs.value, rhs.value));
5130 // RValue<UInt2> operator%(RValue<UInt2> lhs, RValue<UInt2> rhs)
5132 // return RValue<UInt2>(Nucleus::createURem(lhs.value, rhs.value));
5135 RValue<UInt2> operator&(RValue<UInt2> lhs, RValue<UInt2> rhs)
5137 return RValue<UInt2>(Nucleus::createAnd(lhs.value, rhs.value));
5140 RValue<UInt2> operator|(RValue<UInt2> lhs, RValue<UInt2> rhs)
5142 return RValue<UInt2>(Nucleus::createOr(lhs.value, rhs.value));
5145 RValue<UInt2> operator^(RValue<UInt2> lhs, RValue<UInt2> rhs)
5147 return RValue<UInt2>(Nucleus::createXor(lhs.value, rhs.value));
5150 RValue<UInt> Extract(RValue<UInt2> val, int i)
5152 return RValue<UInt>(Nucleus::createExtractElement(val.value, UInt::getType(), i));
5155 RValue<UInt2> Insert(RValue<UInt2> val, RValue<UInt> element, int i)
5157 return RValue<UInt2>(Nucleus::createInsertElement(val.value, element.value, i));
5160 RValue<UInt2> operator<<(RValue<UInt2> lhs, unsigned char rhs)
5162 if(emulateIntrinsics)
5165 result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0);
5166 result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1);
5172 return RValue<UInt2>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
5176 RValue<UInt2> operator>>(RValue<UInt2> lhs, unsigned char rhs)
5178 if(emulateIntrinsics)
5181 result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0);
5182 result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1);
5188 return RValue<UInt2>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
5192 RValue<UInt2> operator+=(UInt2 &lhs, RValue<UInt2> rhs)
5194 return lhs = lhs + rhs;
5197 RValue<UInt2> operator-=(UInt2 &lhs, RValue<UInt2> rhs)
5199 return lhs = lhs - rhs;
5202 // RValue<UInt2> operator*=(UInt2 &lhs, RValue<UInt2> rhs)
5204 // return lhs = lhs * rhs;
5207 // RValue<UInt2> operator/=(UInt2 &lhs, RValue<UInt2> rhs)
5209 // return lhs = lhs / rhs;
5212 // RValue<UInt2> operator%=(UInt2 &lhs, RValue<UInt2> rhs)
5214 // return lhs = lhs % rhs;
5217 RValue<UInt2> operator&=(UInt2 &lhs, RValue<UInt2> rhs)
5219 return lhs = lhs & rhs;
5222 RValue<UInt2> operator|=(UInt2 &lhs, RValue<UInt2> rhs)
5224 return lhs = lhs | rhs;
5227 RValue<UInt2> operator^=(UInt2 &lhs, RValue<UInt2> rhs)
5229 return lhs = lhs ^ rhs;
5232 RValue<UInt2> operator<<=(UInt2 &lhs, unsigned char rhs)
5234 return lhs = lhs << rhs;
5237 RValue<UInt2> operator>>=(UInt2 &lhs, unsigned char rhs)
5239 return lhs = lhs >> rhs;
5242 // RValue<UInt2> operator+(RValue<UInt2> val)
5247 // RValue<UInt2> operator-(RValue<UInt2> val)
5249 // return RValue<UInt2>(Nucleus::createNeg(val.value));
5252 RValue<UInt2> operator~(RValue<UInt2> val)
5254 return RValue<UInt2>(Nucleus::createNot(val.value));
5257 Type *UInt2::getType()
5259 return T(Type_v2i32);
5262 Int4::Int4(RValue<Byte4> cast)
5264 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
5265 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
5268 int swizzle[16] = {0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23};
5269 Value *b = Nucleus::createBitCast(a, Byte16::getType());
5270 Value *c = Nucleus::createShuffleVector(b, V(Nucleus::createNullValue(Byte16::getType())), swizzle);
5272 int swizzle2[8] = {0, 8, 1, 9, 2, 10, 3, 11};
5273 Value *d = Nucleus::createBitCast(c, Short8::getType());
5274 e = Nucleus::createShuffleVector(d, V(Nucleus::createNullValue(Short8::getType())), swizzle2);
5276 Value *f = Nucleus::createBitCast(e, Int4::getType());
5280 Int4::Int4(RValue<SByte4> cast)
5282 Value *x = Nucleus::createBitCast(cast.value, Int::getType());
5283 Value *a = Nucleus::createInsertElement(loadValue(), x, 0);
5285 int swizzle[16] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
5286 Value *b = Nucleus::createBitCast(a, Byte16::getType());
5287 Value *c = Nucleus::createShuffleVector(b, b, swizzle);
5289 int swizzle2[8] = {0, 0, 1, 1, 2, 2, 3, 3};
5290 Value *d = Nucleus::createBitCast(c, Short8::getType());
5291 Value *e = Nucleus::createShuffleVector(d, d, swizzle2);
5293 *this = As<Int4>(e) >> 24;
5296 Int4::Int4(RValue<Float4> cast)
5298 Value *xyzw = Nucleus::createFPToSI(cast.value, Int4::getType());
5303 Int4::Int4(RValue<Short4> cast)
5305 int swizzle[8] = {0, 0, 1, 1, 2, 2, 3, 3};
5306 Value *c = Nucleus::createShuffleVector(cast.value, cast.value, swizzle);
5308 *this = As<Int4>(c) >> 16;
5311 Int4::Int4(RValue<UShort4> cast)
5313 int swizzle[8] = {0, 8, 1, 9, 2, 10, 3, 11};
5314 Value *c = Nucleus::createShuffleVector(cast.value, Short8(0, 0, 0, 0, 0, 0, 0, 0).loadValue(), swizzle);
5315 Value *d = Nucleus::createBitCast(c, Int4::getType());
5319 Int4::Int4(int xyzw)
5321 constant(xyzw, xyzw, xyzw, xyzw);
5324 Int4::Int4(int x, int yzw)
5326 constant(x, yzw, yzw, yzw);
5329 Int4::Int4(int x, int y, int zw)
5331 constant(x, y, zw, zw);
5334 Int4::Int4(int x, int y, int z, int w)
5336 constant(x, y, z, w);
5339 void Int4::constant(int x, int y, int z, int w)
5341 int64_t constantVector[4] = {x, y, z, w};
5342 storeValue(Nucleus::createConstantVector(constantVector, getType()));
5345 Int4::Int4(RValue<Int4> rhs)
5347 storeValue(rhs.value);
5350 Int4::Int4(const Int4 &rhs)
5352 Value *value = rhs.loadValue();
5356 Int4::Int4(const Reference<Int4> &rhs)
5358 Value *value = rhs.loadValue();
5362 Int4::Int4(RValue<UInt4> rhs)
5364 storeValue(rhs.value);
5367 Int4::Int4(const UInt4 &rhs)
5369 Value *value = rhs.loadValue();
5373 Int4::Int4(const Reference<UInt4> &rhs)
5375 Value *value = rhs.loadValue();
5379 Int4::Int4(RValue<Int2> lo, RValue<Int2> hi)
5381 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5382 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5387 Int4::Int4(RValue<Int> rhs)
5389 Value *vector = Nucleus::createBitCast(rhs.value, Int4::getType());
5391 int swizzle[4] = {0, 0, 0, 0};
5392 Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
5394 storeValue(replicate);
5397 Int4::Int4(const Int &rhs)
5399 *this = RValue<Int>(rhs.loadValue());
5402 Int4::Int4(const Reference<Int> &rhs)
5404 *this = RValue<Int>(rhs.loadValue());
5407 RValue<Int4> Int4::operator=(RValue<Int4> rhs)
5409 storeValue(rhs.value);
5414 RValue<Int4> Int4::operator=(const Int4 &rhs)
5416 Value *value = rhs.loadValue();
5419 return RValue<Int4>(value);
5422 RValue<Int4> Int4::operator=(const Reference<Int4> &rhs)
5424 Value *value = rhs.loadValue();
5427 return RValue<Int4>(value);
5430 RValue<Int4> operator+(RValue<Int4> lhs, RValue<Int4> rhs)
5432 return RValue<Int4>(Nucleus::createAdd(lhs.value, rhs.value));
5435 RValue<Int4> operator-(RValue<Int4> lhs, RValue<Int4> rhs)
5437 return RValue<Int4>(Nucleus::createSub(lhs.value, rhs.value));
5440 RValue<Int4> operator*(RValue<Int4> lhs, RValue<Int4> rhs)
5442 return RValue<Int4>(Nucleus::createMul(lhs.value, rhs.value));
5445 RValue<Int4> operator/(RValue<Int4> lhs, RValue<Int4> rhs)
5447 return RValue<Int4>(Nucleus::createSDiv(lhs.value, rhs.value));
5450 RValue<Int4> operator%(RValue<Int4> lhs, RValue<Int4> rhs)
5452 return RValue<Int4>(Nucleus::createSRem(lhs.value, rhs.value));
5455 RValue<Int4> operator&(RValue<Int4> lhs, RValue<Int4> rhs)
5457 return RValue<Int4>(Nucleus::createAnd(lhs.value, rhs.value));
5460 RValue<Int4> operator|(RValue<Int4> lhs, RValue<Int4> rhs)
5462 return RValue<Int4>(Nucleus::createOr(lhs.value, rhs.value));
5465 RValue<Int4> operator^(RValue<Int4> lhs, RValue<Int4> rhs)
5467 return RValue<Int4>(Nucleus::createXor(lhs.value, rhs.value));
5470 RValue<Int4> operator<<(RValue<Int4> lhs, unsigned char rhs)
5472 if(emulateIntrinsics)
5475 result = Insert(result, Extract(lhs, 0) << Int(rhs), 0);
5476 result = Insert(result, Extract(lhs, 1) << Int(rhs), 1);
5477 result = Insert(result, Extract(lhs, 2) << Int(rhs), 2);
5478 result = Insert(result, Extract(lhs, 3) << Int(rhs), 3);
5484 return RValue<Int4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
5488 RValue<Int4> operator>>(RValue<Int4> lhs, unsigned char rhs)
5490 if(emulateIntrinsics)
5493 result = Insert(result, Extract(lhs, 0) >> Int(rhs), 0);
5494 result = Insert(result, Extract(lhs, 1) >> Int(rhs), 1);
5495 result = Insert(result, Extract(lhs, 2) >> Int(rhs), 2);
5496 result = Insert(result, Extract(lhs, 3) >> Int(rhs), 3);
5502 return RValue<Int4>(Nucleus::createAShr(lhs.value, V(::context->getConstantInt32(rhs))));
5506 RValue<Int4> operator<<(RValue<Int4> lhs, RValue<Int4> rhs)
5508 return RValue<Int4>(Nucleus::createShl(lhs.value, rhs.value));
5511 RValue<Int4> operator>>(RValue<Int4> lhs, RValue<Int4> rhs)
5513 return RValue<Int4>(Nucleus::createAShr(lhs.value, rhs.value));
5516 RValue<Int4> operator+=(Int4 &lhs, RValue<Int4> rhs)
5518 return lhs = lhs + rhs;
5521 RValue<Int4> operator-=(Int4 &lhs, RValue<Int4> rhs)
5523 return lhs = lhs - rhs;
5526 RValue<Int4> operator*=(Int4 &lhs, RValue<Int4> rhs)
5528 return lhs = lhs * rhs;
5531 // RValue<Int4> operator/=(Int4 &lhs, RValue<Int4> rhs)
5533 // return lhs = lhs / rhs;
5536 // RValue<Int4> operator%=(Int4 &lhs, RValue<Int4> rhs)
5538 // return lhs = lhs % rhs;
5541 RValue<Int4> operator&=(Int4 &lhs, RValue<Int4> rhs)
5543 return lhs = lhs & rhs;
5546 RValue<Int4> operator|=(Int4 &lhs, RValue<Int4> rhs)
5548 return lhs = lhs | rhs;
5551 RValue<Int4> operator^=(Int4 &lhs, RValue<Int4> rhs)
5553 return lhs = lhs ^ rhs;
5556 RValue<Int4> operator<<=(Int4 &lhs, unsigned char rhs)
5558 return lhs = lhs << rhs;
5561 RValue<Int4> operator>>=(Int4 &lhs, unsigned char rhs)
5563 return lhs = lhs >> rhs;
5566 RValue<Int4> operator+(RValue<Int4> val)
5571 RValue<Int4> operator-(RValue<Int4> val)
5573 return RValue<Int4>(Nucleus::createNeg(val.value));
5576 RValue<Int4> operator~(RValue<Int4> val)
5578 return RValue<Int4>(Nucleus::createNot(val.value));
5581 RValue<Int4> CmpEQ(RValue<Int4> x, RValue<Int4> y)
5583 return RValue<Int4>(Nucleus::createICmpEQ(x.value, y.value));
5586 RValue<Int4> CmpLT(RValue<Int4> x, RValue<Int4> y)
5588 return RValue<Int4>(Nucleus::createICmpSLT(x.value, y.value));
5591 RValue<Int4> CmpLE(RValue<Int4> x, RValue<Int4> y)
5593 return RValue<Int4>(Nucleus::createICmpSLE(x.value, y.value));
5596 RValue<Int4> CmpNEQ(RValue<Int4> x, RValue<Int4> y)
5598 return RValue<Int4>(Nucleus::createICmpNE(x.value, y.value));
5601 RValue<Int4> CmpNLT(RValue<Int4> x, RValue<Int4> y)
5603 return RValue<Int4>(Nucleus::createICmpSGE(x.value, y.value));
5606 RValue<Int4> CmpNLE(RValue<Int4> x, RValue<Int4> y)
5608 return RValue<Int4>(Nucleus::createICmpSGT(x.value, y.value));
5611 RValue<Int4> Max(RValue<Int4> x, RValue<Int4> y)
5613 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5614 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sle, condition, x.value, y.value);
5615 ::basicBlock->appendInst(cmp);
5617 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5618 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5619 ::basicBlock->appendInst(select);
5621 return RValue<Int4>(V(result));
5624 RValue<Int4> Min(RValue<Int4> x, RValue<Int4> y)
5626 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
5627 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Sgt, condition, x.value, y.value);
5628 ::basicBlock->appendInst(cmp);
5630 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5631 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
5632 ::basicBlock->appendInst(select);
5634 return RValue<Int4>(V(result));
5637 RValue<Int4> RoundInt(RValue<Float4> cast)
5639 if(emulateIntrinsics)
5641 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
5642 return Int4((cast + Float4(0x00C00000)) - Float4(0x00C00000));
5646 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
5647 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Nearbyint, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5648 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5649 auto nearbyint = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5650 nearbyint->addArg(cast.value);
5651 ::basicBlock->appendInst(nearbyint);
5653 return RValue<Int4>(V(result));
5657 RValue<Short8> Pack(RValue<Int4> x, RValue<Int4> y)
5659 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
5660 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackSigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5661 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5662 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
5663 pack->addArg(x.value);
5664 pack->addArg(y.value);
5665 ::basicBlock->appendInst(pack);
5667 return RValue<Short8>(V(result));
5670 RValue<Int> Extract(RValue<Int4> x, int i)
5672 return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
5675 RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
5677 return RValue<Int4>(Nucleus::createInsertElement(x.value, element.value, i));
5680 RValue<Int> SignMask(RValue<Int4> x)
5682 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
5683 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
5684 auto target = ::context->getConstantUndef(Ice::IceType_i32);
5685 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
5686 movmsk->addArg(x.value);
5687 ::basicBlock->appendInst(movmsk);
5689 return RValue<Int>(V(result));
5692 RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
5694 return RValue<Int4>(createSwizzle4(x.value, select));
5697 Type *Int4::getType()
5699 return T(Ice::IceType_v4i32);
5702 UInt4::UInt4(RValue<Float4> cast)
5704 // Smallest positive value representable in UInt, but not in Int
5705 const unsigned int ustart = 0x80000000u;
5706 const float ustartf = float(ustart);
5708 // Check if the value can be represented as an Int
5709 Int4 uiValue = CmpNLT(cast, Float4(ustartf));
5710 // If the value is too large, subtract ustart and re-add it after conversion.
5711 uiValue = (uiValue & As<Int4>(As<UInt4>(Int4(cast - Float4(ustartf))) + UInt4(ustart))) |
5712 // Otherwise, just convert normally
5713 (~uiValue & Int4(cast));
5714 // If the value is negative, store 0, otherwise store the result of the conversion
5715 storeValue((~(As<Int4>(cast) >> 31) & uiValue).value);
5718 UInt4::UInt4(int xyzw)
5720 constant(xyzw, xyzw, xyzw, xyzw);
5723 UInt4::UInt4(int x, int yzw)
5725 constant(x, yzw, yzw, yzw);
5728 UInt4::UInt4(int x, int y, int zw)
5730 constant(x, y, zw, zw);
5733 UInt4::UInt4(int x, int y, int z, int w)
5735 constant(x, y, z, w);
5738 void UInt4::constant(int x, int y, int z, int w)
5740 int64_t constantVector[4] = {x, y, z, w};
5741 storeValue(Nucleus::createConstantVector(constantVector, getType()));
5744 UInt4::UInt4(RValue<UInt4> rhs)
5746 storeValue(rhs.value);
5749 UInt4::UInt4(const UInt4 &rhs)
5751 Value *value = rhs.loadValue();
5755 UInt4::UInt4(const Reference<UInt4> &rhs)
5757 Value *value = rhs.loadValue();
5761 UInt4::UInt4(RValue<Int4> rhs)
5763 storeValue(rhs.value);
5766 UInt4::UInt4(const Int4 &rhs)
5768 Value *value = rhs.loadValue();
5772 UInt4::UInt4(const Reference<Int4> &rhs)
5774 Value *value = rhs.loadValue();
5778 UInt4::UInt4(RValue<UInt2> lo, RValue<UInt2> hi)
5780 int shuffle[4] = {0, 1, 4, 5}; // Real type is v4i32
5781 Value *packed = Nucleus::createShuffleVector(lo.value, hi.value, shuffle);
5786 RValue<UInt4> UInt4::operator=(RValue<UInt4> rhs)
5788 storeValue(rhs.value);
5793 RValue<UInt4> UInt4::operator=(const UInt4 &rhs)
5795 Value *value = rhs.loadValue();
5798 return RValue<UInt4>(value);
5801 RValue<UInt4> UInt4::operator=(const Reference<UInt4> &rhs)
5803 Value *value = rhs.loadValue();
5806 return RValue<UInt4>(value);
5809 RValue<UInt4> operator+(RValue<UInt4> lhs, RValue<UInt4> rhs)
5811 return RValue<UInt4>(Nucleus::createAdd(lhs.value, rhs.value));
5814 RValue<UInt4> operator-(RValue<UInt4> lhs, RValue<UInt4> rhs)
5816 return RValue<UInt4>(Nucleus::createSub(lhs.value, rhs.value));
5819 RValue<UInt4> operator*(RValue<UInt4> lhs, RValue<UInt4> rhs)
5821 return RValue<UInt4>(Nucleus::createMul(lhs.value, rhs.value));
5824 RValue<UInt4> operator/(RValue<UInt4> lhs, RValue<UInt4> rhs)
5826 return RValue<UInt4>(Nucleus::createUDiv(lhs.value, rhs.value));
5829 RValue<UInt4> operator%(RValue<UInt4> lhs, RValue<UInt4> rhs)
5831 return RValue<UInt4>(Nucleus::createURem(lhs.value, rhs.value));
5834 RValue<UInt4> operator&(RValue<UInt4> lhs, RValue<UInt4> rhs)
5836 return RValue<UInt4>(Nucleus::createAnd(lhs.value, rhs.value));
5839 RValue<UInt4> operator|(RValue<UInt4> lhs, RValue<UInt4> rhs)
5841 return RValue<UInt4>(Nucleus::createOr(lhs.value, rhs.value));
5844 RValue<UInt4> operator^(RValue<UInt4> lhs, RValue<UInt4> rhs)
5846 return RValue<UInt4>(Nucleus::createXor(lhs.value, rhs.value));
5849 RValue<UInt> Extract(RValue<UInt4> x, int i)
5851 return RValue<UInt>(Nucleus::createExtractElement(x.value, UInt::getType(), i));
5854 RValue<UInt4> Insert(RValue<UInt4> x, RValue<UInt> element, int i)
5856 return RValue<UInt4>(Nucleus::createInsertElement(x.value, element.value, i));
5859 RValue<UInt4> operator<<(RValue<UInt4> lhs, unsigned char rhs)
5861 if(emulateIntrinsics)
5864 result = Insert(result, Extract(lhs, 0) << UInt(rhs), 0);
5865 result = Insert(result, Extract(lhs, 1) << UInt(rhs), 1);
5866 result = Insert(result, Extract(lhs, 2) << UInt(rhs), 2);
5867 result = Insert(result, Extract(lhs, 3) << UInt(rhs), 3);
5873 return RValue<UInt4>(Nucleus::createShl(lhs.value, V(::context->getConstantInt32(rhs))));
5877 RValue<UInt4> operator>>(RValue<UInt4> lhs, unsigned char rhs)
5879 if(emulateIntrinsics)
5882 result = Insert(result, Extract(lhs, 0) >> UInt(rhs), 0);
5883 result = Insert(result, Extract(lhs, 1) >> UInt(rhs), 1);
5884 result = Insert(result, Extract(lhs, 2) >> UInt(rhs), 2);
5885 result = Insert(result, Extract(lhs, 3) >> UInt(rhs), 3);
5891 return RValue<UInt4>(Nucleus::createLShr(lhs.value, V(::context->getConstantInt32(rhs))));
5895 RValue<UInt4> operator<<(RValue<UInt4> lhs, RValue<UInt4> rhs)
5897 return RValue<UInt4>(Nucleus::createShl(lhs.value, rhs.value));
5900 RValue<UInt4> operator>>(RValue<UInt4> lhs, RValue<UInt4> rhs)
5902 return RValue<UInt4>(Nucleus::createLShr(lhs.value, rhs.value));
5905 RValue<UInt4> operator+=(UInt4 &lhs, RValue<UInt4> rhs)
5907 return lhs = lhs + rhs;
5910 RValue<UInt4> operator-=(UInt4 &lhs, RValue<UInt4> rhs)
5912 return lhs = lhs - rhs;
5915 RValue<UInt4> operator*=(UInt4 &lhs, RValue<UInt4> rhs)
5917 return lhs = lhs * rhs;
5920 // RValue<UInt4> operator/=(UInt4 &lhs, RValue<UInt4> rhs)
5922 // return lhs = lhs / rhs;
5925 // RValue<UInt4> operator%=(UInt4 &lhs, RValue<UInt4> rhs)
5927 // return lhs = lhs % rhs;
5930 RValue<UInt4> operator&=(UInt4 &lhs, RValue<UInt4> rhs)
5932 return lhs = lhs & rhs;
5935 RValue<UInt4> operator|=(UInt4 &lhs, RValue<UInt4> rhs)
5937 return lhs = lhs | rhs;
5940 RValue<UInt4> operator^=(UInt4 &lhs, RValue<UInt4> rhs)
5942 return lhs = lhs ^ rhs;
5945 RValue<UInt4> operator<<=(UInt4 &lhs, unsigned char rhs)
5947 return lhs = lhs << rhs;
5950 RValue<UInt4> operator>>=(UInt4 &lhs, unsigned char rhs)
5952 return lhs = lhs >> rhs;
5955 RValue<UInt4> operator+(RValue<UInt4> val)
5960 RValue<UInt4> operator-(RValue<UInt4> val)
5962 return RValue<UInt4>(Nucleus::createNeg(val.value));
5965 RValue<UInt4> operator~(RValue<UInt4> val)
5967 return RValue<UInt4>(Nucleus::createNot(val.value));
5970 RValue<UInt4> CmpEQ(RValue<UInt4> x, RValue<UInt4> y)
5972 return RValue<UInt4>(Nucleus::createICmpEQ(x.value, y.value));
5975 RValue<UInt4> CmpLT(RValue<UInt4> x, RValue<UInt4> y)
5977 return RValue<UInt4>(Nucleus::createICmpULT(x.value, y.value));
5980 RValue<UInt4> CmpLE(RValue<UInt4> x, RValue<UInt4> y)
5982 return RValue<UInt4>(Nucleus::createICmpULE(x.value, y.value));
5985 RValue<UInt4> CmpNEQ(RValue<UInt4> x, RValue<UInt4> y)
5987 return RValue<UInt4>(Nucleus::createICmpNE(x.value, y.value));
5990 RValue<UInt4> CmpNLT(RValue<UInt4> x, RValue<UInt4> y)
5992 return RValue<UInt4>(Nucleus::createICmpUGE(x.value, y.value));
5995 RValue<UInt4> CmpNLE(RValue<UInt4> x, RValue<UInt4> y)
5997 return RValue<UInt4>(Nucleus::createICmpUGT(x.value, y.value));
6000 RValue<UInt4> Max(RValue<UInt4> x, RValue<UInt4> y)
6002 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6003 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ule, condition, x.value, y.value);
6004 ::basicBlock->appendInst(cmp);
6006 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
6007 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
6008 ::basicBlock->appendInst(select);
6010 return RValue<UInt4>(V(result));
6013 RValue<UInt4> Min(RValue<UInt4> x, RValue<UInt4> y)
6015 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6016 auto cmp = Ice::InstIcmp::create(::function, Ice::InstIcmp::Ugt, condition, x.value, y.value);
6017 ::basicBlock->appendInst(cmp);
6019 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4i32);
6020 auto select = Ice::InstSelect::create(::function, result, condition, y.value, x.value);
6021 ::basicBlock->appendInst(select);
6023 return RValue<UInt4>(V(result));
6026 RValue<UShort8> Pack(RValue<UInt4> x, RValue<UInt4> y)
6030 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v8i16);
6031 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::VectorPackUnsigned, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6032 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6033 auto pack = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6034 pack->addArg(x.value);
6035 pack->addArg(y.value);
6036 ::basicBlock->appendInst(pack);
6038 return RValue<UShort8>(V(result));
6042 RValue<Int4> sx = As<Int4>(x);
6043 RValue<Int4> bx = (sx & ~(sx >> 31)) - Int4(0x8000);
6045 RValue<Int4> sy = As<Int4>(y);
6046 RValue<Int4> by = (sy & ~(sy >> 31)) - Int4(0x8000);
6048 return As<UShort8>(Pack(bx, by) + Short8(0x8000u));
6052 Type *UInt4::getType()
6054 return T(Ice::IceType_v4i32);
6057 Float::Float(RValue<Int> cast)
6059 Value *integer = Nucleus::createSIToFP(cast.value, Float::getType());
6061 storeValue(integer);
6064 Float::Float(RValue<UInt> cast)
6066 RValue<Float> result = Float(Int(cast & UInt(0x7FFFFFFF))) +
6067 As<Float>((As<Int>(cast) >> 31) & As<Int>(Float(0x80000000u)));
6069 storeValue(result.value);
6072 Float::Float(float x)
6074 storeValue(Nucleus::createConstantFloat(x));
6077 Float::Float(RValue<Float> rhs)
6079 storeValue(rhs.value);
6082 Float::Float(const Float &rhs)
6084 Value *value = rhs.loadValue();
6088 Float::Float(const Reference<Float> &rhs)
6090 Value *value = rhs.loadValue();
6094 RValue<Float> Float::operator=(RValue<Float> rhs)
6096 storeValue(rhs.value);
6101 RValue<Float> Float::operator=(const Float &rhs)
6103 Value *value = rhs.loadValue();
6106 return RValue<Float>(value);
6109 RValue<Float> Float::operator=(const Reference<Float> &rhs)
6111 Value *value = rhs.loadValue();
6114 return RValue<Float>(value);
6117 RValue<Float> operator+(RValue<Float> lhs, RValue<Float> rhs)
6119 return RValue<Float>(Nucleus::createFAdd(lhs.value, rhs.value));
6122 RValue<Float> operator-(RValue<Float> lhs, RValue<Float> rhs)
6124 return RValue<Float>(Nucleus::createFSub(lhs.value, rhs.value));
6127 RValue<Float> operator*(RValue<Float> lhs, RValue<Float> rhs)
6129 return RValue<Float>(Nucleus::createFMul(lhs.value, rhs.value));
6132 RValue<Float> operator/(RValue<Float> lhs, RValue<Float> rhs)
6134 return RValue<Float>(Nucleus::createFDiv(lhs.value, rhs.value));
6137 RValue<Float> operator+=(Float &lhs, RValue<Float> rhs)
6139 return lhs = lhs + rhs;
6142 RValue<Float> operator-=(Float &lhs, RValue<Float> rhs)
6144 return lhs = lhs - rhs;
6147 RValue<Float> operator*=(Float &lhs, RValue<Float> rhs)
6149 return lhs = lhs * rhs;
6152 RValue<Float> operator/=(Float &lhs, RValue<Float> rhs)
6154 return lhs = lhs / rhs;
6157 RValue<Float> operator+(RValue<Float> val)
6162 RValue<Float> operator-(RValue<Float> val)
6164 return RValue<Float>(Nucleus::createFNeg(val.value));
6167 RValue<Bool> operator<(RValue<Float> lhs, RValue<Float> rhs)
6169 return RValue<Bool>(Nucleus::createFCmpOLT(lhs.value, rhs.value));
6172 RValue<Bool> operator<=(RValue<Float> lhs, RValue<Float> rhs)
6174 return RValue<Bool>(Nucleus::createFCmpOLE(lhs.value, rhs.value));
6177 RValue<Bool> operator>(RValue<Float> lhs, RValue<Float> rhs)
6179 return RValue<Bool>(Nucleus::createFCmpOGT(lhs.value, rhs.value));
6182 RValue<Bool> operator>=(RValue<Float> lhs, RValue<Float> rhs)
6184 return RValue<Bool>(Nucleus::createFCmpOGE(lhs.value, rhs.value));
6187 RValue<Bool> operator!=(RValue<Float> lhs, RValue<Float> rhs)
6189 return RValue<Bool>(Nucleus::createFCmpONE(lhs.value, rhs.value));
6192 RValue<Bool> operator==(RValue<Float> lhs, RValue<Float> rhs)
6194 return RValue<Bool>(Nucleus::createFCmpOEQ(lhs.value, rhs.value));
6197 RValue<Float> Abs(RValue<Float> x)
6199 return IfThenElse(x > 0.0f, x, -x);
6202 RValue<Float> Max(RValue<Float> x, RValue<Float> y)
6204 return IfThenElse(x > y, x, y);
6207 RValue<Float> Min(RValue<Float> x, RValue<Float> y)
6209 return IfThenElse(x < y, x, y);
6212 RValue<Float> Rcp_pp(RValue<Float> x, bool exactAtPow2)
6217 RValue<Float> RcpSqrt_pp(RValue<Float> x)
6219 return Rcp_pp(Sqrt(x));
6222 RValue<Float> Sqrt(RValue<Float> x)
6224 Ice::Variable *result = ::function->makeVariable(Ice::IceType_f32);
6225 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6226 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6227 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6228 sqrt->addArg(x.value);
6229 ::basicBlock->appendInst(sqrt);
6231 return RValue<Float>(V(result));
6234 RValue<Float> Round(RValue<Float> x)
6236 return Float4(Round(Float4(x))).x;
6239 RValue<Float> Trunc(RValue<Float> x)
6241 return Float4(Trunc(Float4(x))).x;
6244 RValue<Float> Frac(RValue<Float> x)
6246 return Float4(Frac(Float4(x))).x;
6249 RValue<Float> Floor(RValue<Float> x)
6251 return Float4(Floor(Float4(x))).x;
6254 RValue<Float> Ceil(RValue<Float> x)
6256 return Float4(Ceil(Float4(x))).x;
6259 Type *Float::getType()
6261 return T(Ice::IceType_f32);
6264 Float2::Float2(RValue<Float4> cast)
6266 storeValue(Nucleus::createBitCast(cast.value, getType()));
6269 Type *Float2::getType()
6271 return T(Type_v2f32);
6274 Float4::Float4(RValue<Byte4> cast) : FloatXYZW(this)
6276 Value *a = Int4(cast).loadValue();
6277 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
6282 Float4::Float4(RValue<SByte4> cast) : FloatXYZW(this)
6284 Value *a = Int4(cast).loadValue();
6285 Value *xyzw = Nucleus::createSIToFP(a, Float4::getType());
6290 Float4::Float4(RValue<Short4> cast) : FloatXYZW(this)
6293 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
6296 Float4::Float4(RValue<UShort4> cast) : FloatXYZW(this)
6299 storeValue(Nucleus::createSIToFP(RValue<Int4>(c).value, Float4::getType()));
6302 Float4::Float4(RValue<Int4> cast) : FloatXYZW(this)
6304 Value *xyzw = Nucleus::createSIToFP(cast.value, Float4::getType());
6309 Float4::Float4(RValue<UInt4> cast) : FloatXYZW(this)
6311 RValue<Float4> result = Float4(Int4(cast & UInt4(0x7FFFFFFF))) +
6312 As<Float4>((As<Int4>(cast) >> 31) & As<Int4>(Float4(0x80000000u)));
6314 storeValue(result.value);
6317 Float4::Float4() : FloatXYZW(this)
6321 Float4::Float4(float xyzw) : FloatXYZW(this)
6323 constant(xyzw, xyzw, xyzw, xyzw);
6326 Float4::Float4(float x, float yzw) : FloatXYZW(this)
6328 constant(x, yzw, yzw, yzw);
6331 Float4::Float4(float x, float y, float zw) : FloatXYZW(this)
6333 constant(x, y, zw, zw);
6336 Float4::Float4(float x, float y, float z, float w) : FloatXYZW(this)
6338 constant(x, y, z, w);
6341 void Float4::constant(float x, float y, float z, float w)
6343 double constantVector[4] = {x, y, z, w};
6344 storeValue(Nucleus::createConstantVector(constantVector, getType()));
6347 Float4::Float4(RValue<Float4> rhs) : FloatXYZW(this)
6349 storeValue(rhs.value);
6352 Float4::Float4(const Float4 &rhs) : FloatXYZW(this)
6354 Value *value = rhs.loadValue();
6358 Float4::Float4(const Reference<Float4> &rhs) : FloatXYZW(this)
6360 Value *value = rhs.loadValue();
6364 Float4::Float4(RValue<Float> rhs) : FloatXYZW(this)
6366 Value *vector = Nucleus::createBitCast(rhs.value, Float4::getType());
6368 int swizzle[4] = {0, 0, 0, 0};
6369 Value *replicate = Nucleus::createShuffleVector(vector, vector, swizzle);
6371 storeValue(replicate);
6374 Float4::Float4(const Float &rhs) : FloatXYZW(this)
6376 *this = RValue<Float>(rhs.loadValue());
6379 Float4::Float4(const Reference<Float> &rhs) : FloatXYZW(this)
6381 *this = RValue<Float>(rhs.loadValue());
6384 RValue<Float4> Float4::operator=(float x)
6386 return *this = Float4(x, x, x, x);
6389 RValue<Float4> Float4::operator=(RValue<Float4> rhs)
6391 storeValue(rhs.value);
6396 RValue<Float4> Float4::operator=(const Float4 &rhs)
6398 Value *value = rhs.loadValue();
6401 return RValue<Float4>(value);
6404 RValue<Float4> Float4::operator=(const Reference<Float4> &rhs)
6406 Value *value = rhs.loadValue();
6409 return RValue<Float4>(value);
6412 RValue<Float4> Float4::operator=(RValue<Float> rhs)
6414 return *this = Float4(rhs);
6417 RValue<Float4> Float4::operator=(const Float &rhs)
6419 return *this = Float4(rhs);
6422 RValue<Float4> Float4::operator=(const Reference<Float> &rhs)
6424 return *this = Float4(rhs);
6427 RValue<Float4> operator+(RValue<Float4> lhs, RValue<Float4> rhs)
6429 return RValue<Float4>(Nucleus::createFAdd(lhs.value, rhs.value));
6432 RValue<Float4> operator-(RValue<Float4> lhs, RValue<Float4> rhs)
6434 return RValue<Float4>(Nucleus::createFSub(lhs.value, rhs.value));
6437 RValue<Float4> operator*(RValue<Float4> lhs, RValue<Float4> rhs)
6439 return RValue<Float4>(Nucleus::createFMul(lhs.value, rhs.value));
6442 RValue<Float4> operator/(RValue<Float4> lhs, RValue<Float4> rhs)
6444 return RValue<Float4>(Nucleus::createFDiv(lhs.value, rhs.value));
6447 RValue<Float4> operator%(RValue<Float4> lhs, RValue<Float4> rhs)
6449 return RValue<Float4>(Nucleus::createFRem(lhs.value, rhs.value));
6452 RValue<Float4> operator+=(Float4 &lhs, RValue<Float4> rhs)
6454 return lhs = lhs + rhs;
6457 RValue<Float4> operator-=(Float4 &lhs, RValue<Float4> rhs)
6459 return lhs = lhs - rhs;
6462 RValue<Float4> operator*=(Float4 &lhs, RValue<Float4> rhs)
6464 return lhs = lhs * rhs;
6467 RValue<Float4> operator/=(Float4 &lhs, RValue<Float4> rhs)
6469 return lhs = lhs / rhs;
6472 RValue<Float4> operator%=(Float4 &lhs, RValue<Float4> rhs)
6474 return lhs = lhs % rhs;
6477 RValue<Float4> operator+(RValue<Float4> val)
6482 RValue<Float4> operator-(RValue<Float4> val)
6484 return RValue<Float4>(Nucleus::createFNeg(val.value));
6487 RValue<Float4> Abs(RValue<Float4> x)
6489 Value *vector = Nucleus::createBitCast(x.value, Int4::getType());
6490 int64_t constantVector[4] = {0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF};
6491 Value *result = Nucleus::createAnd(vector, V(Nucleus::createConstantVector(constantVector, Int4::getType())));
6493 return As<Float4>(result);
6496 RValue<Float4> Max(RValue<Float4> x, RValue<Float4> y)
6498 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6499 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Ogt, condition, x.value, y.value);
6500 ::basicBlock->appendInst(cmp);
6502 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6503 auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
6504 ::basicBlock->appendInst(select);
6506 return RValue<Float4>(V(result));
6509 RValue<Float4> Min(RValue<Float4> x, RValue<Float4> y)
6511 Ice::Variable *condition = ::function->makeVariable(Ice::IceType_v4i1);
6512 auto cmp = Ice::InstFcmp::create(::function, Ice::InstFcmp::Olt, condition, x.value, y.value);
6513 ::basicBlock->appendInst(cmp);
6515 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6516 auto select = Ice::InstSelect::create(::function, result, condition, x.value, y.value);
6517 ::basicBlock->appendInst(select);
6519 return RValue<Float4>(V(result));
6522 RValue<Float4> Rcp_pp(RValue<Float4> x, bool exactAtPow2)
6524 return Float4(1.0f) / x;
6527 RValue<Float4> RcpSqrt_pp(RValue<Float4> x)
6529 return Rcp_pp(Sqrt(x));
6532 RValue<Float4> Sqrt(RValue<Float4> x)
6534 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6535 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Sqrt, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6536 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6537 auto sqrt = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6538 sqrt->addArg(x.value);
6539 ::basicBlock->appendInst(sqrt);
6541 return RValue<Float4>(V(result));
6544 RValue<Float4> Insert(RValue<Float4> x, RValue<Float> element, int i)
6546 return RValue<Float4>(Nucleus::createInsertElement(x.value, element.value, i));
6549 RValue<Float> Extract(RValue<Float4> x, int i)
6551 return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
6554 RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
6556 return RValue<Float4>(createSwizzle4(x.value, select));
6559 RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
6563 ((imm >> 0) & 0x03) + 0,
6564 ((imm >> 2) & 0x03) + 0,
6565 ((imm >> 4) & 0x03) + 4,
6566 ((imm >> 6) & 0x03) + 4,
6569 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
6572 RValue<Float4> UnpackLow(RValue<Float4> x, RValue<Float4> y)
6574 int shuffle[4] = {0, 4, 1, 5};
6575 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
6578 RValue<Float4> UnpackHigh(RValue<Float4> x, RValue<Float4> y)
6580 int shuffle[4] = {2, 6, 3, 7};
6581 return RValue<Float4>(Nucleus::createShuffleVector(x.value, y.value, shuffle));
6584 RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
6586 Value *vector = lhs.loadValue();
6587 Value *result = createMask4(vector, rhs.value, select);
6588 lhs.storeValue(result);
6590 return RValue<Float4>(result);
6593 RValue<Int> SignMask(RValue<Float4> x)
6595 Ice::Variable *result = ::function->makeVariable(Ice::IceType_i32);
6596 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::SignMask, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6597 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6598 auto movmsk = Ice::InstIntrinsicCall::create(::function, 1, result, target, intrinsic);
6599 movmsk->addArg(x.value);
6600 ::basicBlock->appendInst(movmsk);
6602 return RValue<Int>(V(result));
6605 RValue<Int4> CmpEQ(RValue<Float4> x, RValue<Float4> y)
6607 return RValue<Int4>(Nucleus::createFCmpOEQ(x.value, y.value));
6610 RValue<Int4> CmpLT(RValue<Float4> x, RValue<Float4> y)
6612 return RValue<Int4>(Nucleus::createFCmpOLT(x.value, y.value));
6615 RValue<Int4> CmpLE(RValue<Float4> x, RValue<Float4> y)
6617 return RValue<Int4>(Nucleus::createFCmpOLE(x.value, y.value));
6620 RValue<Int4> CmpNEQ(RValue<Float4> x, RValue<Float4> y)
6622 return RValue<Int4>(Nucleus::createFCmpONE(x.value, y.value));
6625 RValue<Int4> CmpNLT(RValue<Float4> x, RValue<Float4> y)
6627 return RValue<Int4>(Nucleus::createFCmpOGE(x.value, y.value));
6630 RValue<Int4> CmpNLE(RValue<Float4> x, RValue<Float4> y)
6632 return RValue<Int4>(Nucleus::createFCmpOGT(x.value, y.value));
6635 RValue<Float4> Round(RValue<Float4> x)
6637 if(emulateIntrinsics)
6639 // Push the fractional part off the mantissa. Accurate up to +/-2^22.
6640 return (x + Float4(0x00C00000)) - Float4(0x00C00000);
6642 else if(CPUID::SSE4_1)
6644 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6645 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6646 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6647 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6648 round->addArg(x.value);
6649 round->addArg(::context->getConstantInt32(0));
6650 ::basicBlock->appendInst(round);
6652 return RValue<Float4>(V(result));
6656 return Float4(RoundInt(x));
6660 RValue<Float4> Trunc(RValue<Float4> x)
6664 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6665 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6666 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6667 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6668 round->addArg(x.value);
6669 round->addArg(::context->getConstantInt32(3));
6670 ::basicBlock->appendInst(round);
6672 return RValue<Float4>(V(result));
6676 return Float4(Int4(x));
6680 RValue<Float4> Frac(RValue<Float4> x)
6690 frc = x - Float4(Int4(x)); // Signed fractional part.
6692 frc += As<Float4>(As<Int4>(CmpNLE(Float4(0.0f), frc)) & As<Int4>(Float4(1, 1, 1, 1))); // Add 1.0 if negative.
6695 // x - floor(x) can be 1.0 for very small negative x.
6696 // Clamp against the value just below 1.0.
6697 return Min(frc, As<Float4>(Int4(0x3F7FFFFF)));
6700 RValue<Float4> Floor(RValue<Float4> x)
6704 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6705 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6706 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6707 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6708 round->addArg(x.value);
6709 round->addArg(::context->getConstantInt32(1));
6710 ::basicBlock->appendInst(round);
6712 return RValue<Float4>(V(result));
6720 RValue<Float4> Ceil(RValue<Float4> x)
6724 Ice::Variable *result = ::function->makeVariable(Ice::IceType_v4f32);
6725 const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::Round, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
6726 auto target = ::context->getConstantUndef(Ice::IceType_i32);
6727 auto round = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
6728 round->addArg(x.value);
6729 round->addArg(::context->getConstantInt32(2));
6730 ::basicBlock->appendInst(round);
6732 return RValue<Float4>(V(result));
6740 Type *Float4::getType()
6742 return T(Ice::IceType_v4f32);
6745 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
6747 return lhs + RValue<Int>(Nucleus::createConstantInt(offset));
6750 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6752 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, false));
6755 RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6757 return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Byte::getType(), offset.value, true));
6760 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, int offset)
6762 return lhs = lhs + offset;
6765 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<Int> offset)
6767 return lhs = lhs + offset;
6770 RValue<Pointer<Byte>> operator+=(Pointer<Byte> &lhs, RValue<UInt> offset)
6772 return lhs = lhs + offset;
6775 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
6777 return lhs + -offset;
6780 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
6782 return lhs + -offset;
6785 RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
6787 return lhs + -offset;
6790 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, int offset)
6792 return lhs = lhs - offset;
6795 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<Int> offset)
6797 return lhs = lhs - offset;
6800 RValue<Pointer<Byte>> operator-=(Pointer<Byte> &lhs, RValue<UInt> offset)
6802 return lhs = lhs - offset;
6807 Nucleus::createRetVoid();
6808 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6809 Nucleus::createUnreachable();
6812 void Return(RValue<Int> ret)
6814 Nucleus::createRet(ret.value);
6815 Nucleus::setInsertBlock(Nucleus::createBasicBlock());
6816 Nucleus::createUnreachable();
6819 void branch(RValue<Bool> cmp, BasicBlock *bodyBB, BasicBlock *endBB)
6821 Nucleus::createCondBr(cmp.value, bodyBB, endBB);
6822 Nucleus::setInsertBlock(bodyBB);
6825 RValue<Long> Ticks()
6827 assert(false && "UNIMPLEMENTED"); return RValue<Long>(V(nullptr));