| // Copyright 2019 The SwiftShader Authors. All Rights Reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "Reactor.hpp" |
| |
| #include "CPUID.hpp" |
| #include "Debug.hpp" |
| #include "Print.hpp" |
| |
| #if defined(_WIN32) |
| # ifndef WIN32_LEAN_AND_MEAN |
| # define WIN32_LEAN_AND_MEAN |
| # endif |
| # include <windows.h> |
| #endif |
| |
| #include <algorithm> |
| #include <cmath> |
| |
| // Define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION to non-zero to ensure all |
| // variables have a stack location obtained throuch alloca(). |
| #ifndef REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION |
| # define REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION 0 |
| #endif |
| |
| namespace rr { |
| |
| Config Config::Edit::apply(const Config &cfg) const |
| { |
| auto level = optLevelChanged ? optLevel : cfg.optimization.getLevel(); |
| auto passes = cfg.optimization.getPasses(); |
| apply(optPassEdits, passes); |
| return Config{ Optimization{ level, passes } }; |
| } |
| |
| template<typename T> |
| void rr::Config::Edit::apply(const std::vector<std::pair<ListEdit, T>> &edits, std::vector<T> &list) const |
| { |
| for(auto &edit : edits) |
| { |
| switch(edit.first) |
| { |
| case ListEdit::Add: |
| list.push_back(edit.second); |
| break; |
| case ListEdit::Remove: |
| list.erase(std::remove_if(list.begin(), list.end(), [&](T item) { |
| return item == edit.second; |
| }), |
| list.end()); |
| break; |
| case ListEdit::Clear: |
| list.clear(); |
| break; |
| } |
| } |
| } |
| |
| thread_local Variable::UnmaterializedVariables *Variable::unmaterializedVariables = nullptr; |
| |
| void Variable::UnmaterializedVariables::add(const Variable *v) |
| { |
| variables.emplace(v, counter++); |
| } |
| |
| void Variable::UnmaterializedVariables::remove(const Variable *v) |
| { |
| auto iter = variables.find(v); |
| if(iter != variables.end()) |
| { |
| variables.erase(iter); |
| } |
| } |
| |
| void Variable::UnmaterializedVariables::clear() |
| { |
| variables.clear(); |
| } |
| |
| void Variable::UnmaterializedVariables::materializeAll() |
| { |
| // Flatten map of Variable* to monotonically increasing counter to a vector, |
| // then sort it by the counter, so that we materialize in variable usage order. |
| std::vector<std::pair<const Variable *, int>> sorted; |
| sorted.resize(variables.size()); |
| std::copy(variables.begin(), variables.end(), sorted.begin()); |
| std::sort(sorted.begin(), sorted.end(), [&](auto &lhs, auto &rhs) { |
| return lhs.second < rhs.second; |
| }); |
| |
| for(auto &v : sorted) |
| { |
| v.first->materialize(); |
| } |
| |
| variables.clear(); |
| } |
| |
| Variable::Variable(Type *type, int arraySize) |
| : type(type) |
| , arraySize(arraySize) |
| { |
| #if REACTOR_MATERIALIZE_LVALUES_ON_DEFINITION |
| materialize(); |
| #else |
| unmaterializedVariables->add(this); |
| #endif |
| } |
| |
| Variable::~Variable() |
| { |
| // `unmaterializedVariables` can be null at this point due to the function |
| // already having been finalized, while classes derived from `Function<>` |
| // can have member `Variable` fields which are destructed afterwards. |
| if(unmaterializedVariables) |
| { |
| unmaterializedVariables->remove(this); |
| } |
| } |
| |
| void Variable::materialize() const |
| { |
| if(!address) |
| { |
| address = Nucleus::allocateStackVariable(getType(), arraySize); |
| RR_DEBUG_INFO_EMIT_VAR(address); |
| |
| if(rvalue) |
| { |
| storeValue(rvalue); |
| rvalue = nullptr; |
| } |
| } |
| } |
| |
| Value *Variable::loadValue() const |
| { |
| if(rvalue) |
| { |
| return rvalue; |
| } |
| |
| if(!address) |
| { |
| // TODO: Return undef instead. |
| materialize(); |
| } |
| |
| return Nucleus::createLoad(address, getType(), false, 0); |
| } |
| |
| Value *Variable::storeValue(Value *value) const |
| { |
| if(address) |
| { |
| return Nucleus::createStore(value, address, getType(), false, 0); |
| } |
| |
| rvalue = value; |
| |
| return value; |
| } |
| |
| Value *Variable::getBaseAddress() const |
| { |
| materialize(); |
| |
| return address; |
| } |
| |
| Value *Variable::getElementPointer(Value *index, bool unsignedIndex) const |
| { |
| return Nucleus::createGEP(getBaseAddress(), getType(), index, unsignedIndex); |
| } |
| |
| void Variable::materializeAll() |
| { |
| unmaterializedVariables->materializeAll(); |
| } |
| |
| void Variable::killUnmaterialized() |
| { |
| unmaterializedVariables->clear(); |
| } |
| |
| // NOTE: Only 12 bits out of 16 of the |select| value are used. |
| // More specifically, the value should look like: |
| // |
| // msb lsb |
| // v v |
| // [.xxx|.yyy|.zzz|.www] where '.' means an ignored bit |
| // |
| // This format makes it easy to write calls with hexadecimal select values, |
| // since each hex digit is a separate swizzle index. |
| // |
| // For example: |
| // createShuffle4( [a,b,c,d], [e,f,g,h], 0x0123 ) -> [a,b,c,d] |
| // createShuffle4( [a,b,c,d], [e,f,g,h], 0x4567 ) -> [e,f,g,h] |
| // createShuffle4( [a,b,c,d], [e,f,g,h], 0x4012 ) -> [e,a,b,c] |
| // |
| static Value *createShuffle4(Value *lhs, Value *rhs, uint16_t select) |
| { |
| int swizzle[4] = { |
| (select >> 12) & 0x07, |
| (select >> 8) & 0x07, |
| (select >> 4) & 0x07, |
| (select >> 0) & 0x07, |
| }; |
| |
| return Nucleus::createShuffleVector(lhs, rhs, swizzle); |
| } |
| |
| // NOTE: Only 8 bits out of 16 of the |select| value are used. |
| // More specifically, the value should look like: |
| // |
| // msb lsb |
| // v v |
| // [..xx|..yy|..zz|..ww] where '.' means an ignored bit |
| // |
| // This format makes it easy to write calls with hexadecimal select values, |
| // since each hex digit is a separate swizzle index. |
| // |
| // For example: |
| // createSwizzle4( [a,b,c,d], 0x0123 ) -> [a,b,c,d] |
| // createSwizzle4( [a,b,c,d], 0x0033 ) -> [a,a,d,d] |
| // |
| static Value *createSwizzle4(Value *val, uint16_t select) |
| { |
| int swizzle[4] = { |
| (select >> 12) & 0x03, |
| (select >> 8) & 0x03, |
| (select >> 4) & 0x03, |
| (select >> 0) & 0x03, |
| }; |
| |
| return Nucleus::createShuffleVector(val, val, swizzle); |
| } |
| |
| static Value *createMask4(Value *lhs, Value *rhs, uint16_t select) |
| { |
| bool mask[4] = { false, false, false, false }; |
| |
| mask[(select >> 12) & 0x03] = true; |
| mask[(select >> 8) & 0x03] = true; |
| mask[(select >> 4) & 0x03] = true; |
| mask[(select >> 0) & 0x03] = true; |
| |
| int swizzle[4] = { |
| mask[0] ? 4 : 0, |
| mask[1] ? 5 : 1, |
| mask[2] ? 6 : 2, |
| mask[3] ? 7 : 3, |
| }; |
| |
| return Nucleus::createShuffleVector(lhs, rhs, swizzle); |
| } |
| |
| Bool::Bool(Argument<Bool> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| Bool::Bool(bool x) |
| { |
| storeValue(Nucleus::createConstantBool(x)); |
| } |
| |
| Bool::Bool(RValue<Bool> rhs) |
| { |
| store(rhs); |
| } |
| |
| Bool::Bool(const Bool &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Bool::Bool(const Reference<Bool> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<Bool> Bool::operator=(RValue<Bool> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Bool> Bool::operator=(const Bool &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Bool> Bool::operator=(const Reference<Bool> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Bool> operator!(RValue<Bool> val) |
| { |
| return RValue<Bool>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Bool> operator&&(RValue<Bool> lhs, RValue<Bool> rhs) |
| { |
| return RValue<Bool>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator||(RValue<Bool> lhs, RValue<Bool> rhs) |
| { |
| return RValue<Bool>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator!=(RValue<Bool> lhs, RValue<Bool> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpNE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator==(RValue<Bool> lhs, RValue<Bool> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpEQ(lhs.value(), rhs.value())); |
| } |
| |
| Byte::Byte(Argument<Byte> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| Byte::Byte(RValue<Int> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), Byte::type()); |
| |
| storeValue(integer); |
| } |
| |
| Byte::Byte(RValue<UInt> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), Byte::type()); |
| |
| storeValue(integer); |
| } |
| |
| Byte::Byte(RValue<UShort> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), Byte::type()); |
| |
| storeValue(integer); |
| } |
| |
| Byte::Byte(int x) |
| { |
| storeValue(Nucleus::createConstantByte((unsigned char)x)); |
| } |
| |
| Byte::Byte(unsigned char x) |
| { |
| storeValue(Nucleus::createConstantByte(x)); |
| } |
| |
| Byte::Byte(RValue<Byte> rhs) |
| { |
| store(rhs); |
| } |
| |
| Byte::Byte(const Byte &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Byte::Byte(const Reference<Byte> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<Byte> Byte::operator=(RValue<Byte> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Byte> Byte::operator=(const Byte &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Byte> Byte::operator=(const Reference<Byte> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Byte> operator+(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator-(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator*(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator/(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createUDiv(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator%(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createURem(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator&(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator|(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator^(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator<<(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createShl(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator>>(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Byte>(Nucleus::createLShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte> operator+=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<Byte> operator-=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<Byte> operator*=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| RValue<Byte> operator/=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs / rhs; |
| } |
| |
| RValue<Byte> operator%=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs % rhs; |
| } |
| |
| RValue<Byte> operator&=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<Byte> operator|=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<Byte> operator^=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<Byte> operator<<=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<Byte> operator>>=(Byte &lhs, RValue<Byte> rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| RValue<Byte> operator+(RValue<Byte> val) |
| { |
| return val; |
| } |
| |
| RValue<Byte> operator-(RValue<Byte> val) |
| { |
| return RValue<Byte>(Nucleus::createNeg(val.value())); |
| } |
| |
| RValue<Byte> operator~(RValue<Byte> val) |
| { |
| return RValue<Byte>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Byte> operator++(Byte &val, int) // Post-increment |
| { |
| RValue<Byte> res = val; |
| |
| Value *inc = Nucleus::createAdd(res.value(), Nucleus::createConstantByte((unsigned char)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const Byte &operator++(Byte &val) // Pre-increment |
| { |
| Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<Byte> operator--(Byte &val, int) // Post-decrement |
| { |
| RValue<Byte> res = val; |
| |
| Value *inc = Nucleus::createSub(res.value(), Nucleus::createConstantByte((unsigned char)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const Byte &operator--(Byte &val) // Pre-decrement |
| { |
| Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((unsigned char)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<Bool> operator<(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpULT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator<=(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpULE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpUGT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>=(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpUGE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator!=(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpNE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator==(RValue<Byte> lhs, RValue<Byte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpEQ(lhs.value(), rhs.value())); |
| } |
| |
| SByte::SByte(Argument<SByte> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| SByte::SByte(RValue<Int> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), SByte::type()); |
| |
| storeValue(integer); |
| } |
| |
| SByte::SByte(RValue<Short> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), SByte::type()); |
| |
| storeValue(integer); |
| } |
| |
| SByte::SByte(signed char x) |
| { |
| storeValue(Nucleus::createConstantByte(x)); |
| } |
| |
| SByte::SByte(RValue<SByte> rhs) |
| { |
| store(rhs); |
| } |
| |
| SByte::SByte(const SByte &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| SByte::SByte(const Reference<SByte> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<SByte> SByte::operator=(RValue<SByte> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<SByte> SByte::operator=(const SByte &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<SByte> SByte::operator=(const Reference<SByte> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<SByte> operator+(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator-(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator*(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator/(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createSDiv(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator%(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createSRem(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator&(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator|(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator^(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator<<(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createShl(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator>>(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<SByte>(Nucleus::createAShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte> operator+=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<SByte> operator-=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<SByte> operator*=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| RValue<SByte> operator/=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs / rhs; |
| } |
| |
| RValue<SByte> operator%=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs % rhs; |
| } |
| |
| RValue<SByte> operator&=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<SByte> operator|=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<SByte> operator^=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<SByte> operator<<=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<SByte> operator>>=(SByte &lhs, RValue<SByte> rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| RValue<SByte> operator+(RValue<SByte> val) |
| { |
| return val; |
| } |
| |
| RValue<SByte> operator-(RValue<SByte> val) |
| { |
| return RValue<SByte>(Nucleus::createNeg(val.value())); |
| } |
| |
| RValue<SByte> operator~(RValue<SByte> val) |
| { |
| return RValue<SByte>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<SByte> operator++(SByte &val, int) // Post-increment |
| { |
| RValue<SByte> res = val; |
| |
| Value *inc = Nucleus::createAdd(res.value(), Nucleus::createConstantByte((signed char)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const SByte &operator++(SByte &val) // Pre-increment |
| { |
| Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantByte((signed char)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<SByte> operator--(SByte &val, int) // Post-decrement |
| { |
| RValue<SByte> res = val; |
| |
| Value *inc = Nucleus::createSub(res.value(), Nucleus::createConstantByte((signed char)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const SByte &operator--(SByte &val) // Pre-decrement |
| { |
| Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantByte((signed char)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<Bool> operator<(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSLT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator<=(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSLE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSGT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>=(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSGE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator!=(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpNE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator==(RValue<SByte> lhs, RValue<SByte> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpEQ(lhs.value(), rhs.value())); |
| } |
| |
| Short::Short(Argument<Short> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| Short::Short(RValue<Int> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), Short::type()); |
| |
| storeValue(integer); |
| } |
| |
| Short::Short(short x) |
| { |
| storeValue(Nucleus::createConstantShort(x)); |
| } |
| |
| Short::Short(RValue<Short> rhs) |
| { |
| store(rhs); |
| } |
| |
| Short::Short(const Short &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Short::Short(const Reference<Short> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<Short> Short::operator=(RValue<Short> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Short> Short::operator=(const Short &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Short> Short::operator=(const Reference<Short> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Short> operator+(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator-(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator*(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator/(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createSDiv(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator%(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createSRem(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator&(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator|(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator^(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator<<(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createShl(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator>>(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Short>(Nucleus::createAShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short> operator+=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<Short> operator-=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<Short> operator*=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| RValue<Short> operator/=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs / rhs; |
| } |
| |
| RValue<Short> operator%=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs % rhs; |
| } |
| |
| RValue<Short> operator&=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<Short> operator|=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<Short> operator^=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<Short> operator<<=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<Short> operator>>=(Short &lhs, RValue<Short> rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| RValue<Short> operator+(RValue<Short> val) |
| { |
| return val; |
| } |
| |
| RValue<Short> operator-(RValue<Short> val) |
| { |
| return RValue<Short>(Nucleus::createNeg(val.value())); |
| } |
| |
| RValue<Short> operator~(RValue<Short> val) |
| { |
| return RValue<Short>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Short> operator++(Short &val, int) // Post-increment |
| { |
| RValue<Short> res = val; |
| |
| Value *inc = Nucleus::createAdd(res.value(), Nucleus::createConstantShort((short)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const Short &operator++(Short &val) // Pre-increment |
| { |
| Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((short)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<Short> operator--(Short &val, int) // Post-decrement |
| { |
| RValue<Short> res = val; |
| |
| Value *inc = Nucleus::createSub(res.value(), Nucleus::createConstantShort((short)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const Short &operator--(Short &val) // Pre-decrement |
| { |
| Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((short)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<Bool> operator<(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSLT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator<=(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSLE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSGT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>=(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSGE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator!=(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpNE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator==(RValue<Short> lhs, RValue<Short> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpEQ(lhs.value(), rhs.value())); |
| } |
| |
| UShort::UShort(Argument<UShort> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| UShort::UShort(RValue<UInt> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), UShort::type()); |
| |
| storeValue(integer); |
| } |
| |
| UShort::UShort(RValue<Int> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), UShort::type()); |
| |
| storeValue(integer); |
| } |
| |
| UShort::UShort(unsigned short x) |
| { |
| storeValue(Nucleus::createConstantShort(x)); |
| } |
| |
| UShort::UShort(RValue<UShort> rhs) |
| { |
| store(rhs); |
| } |
| |
| UShort::UShort(const UShort &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| UShort::UShort(const Reference<UShort> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<UShort> UShort::operator=(RValue<UShort> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<UShort> UShort::operator=(const UShort &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UShort> UShort::operator=(const Reference<UShort> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UShort> operator+(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator-(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator*(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator/(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createUDiv(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator%(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createURem(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator&(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator|(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator^(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator<<(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createShl(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator>>(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<UShort>(Nucleus::createLShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort> operator+=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<UShort> operator-=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<UShort> operator*=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| RValue<UShort> operator/=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs / rhs; |
| } |
| |
| RValue<UShort> operator%=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs % rhs; |
| } |
| |
| RValue<UShort> operator&=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<UShort> operator|=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<UShort> operator^=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<UShort> operator<<=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<UShort> operator>>=(UShort &lhs, RValue<UShort> rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| RValue<UShort> operator+(RValue<UShort> val) |
| { |
| return val; |
| } |
| |
| RValue<UShort> operator-(RValue<UShort> val) |
| { |
| return RValue<UShort>(Nucleus::createNeg(val.value())); |
| } |
| |
| RValue<UShort> operator~(RValue<UShort> val) |
| { |
| return RValue<UShort>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<UShort> operator++(UShort &val, int) // Post-increment |
| { |
| RValue<UShort> res = val; |
| |
| Value *inc = Nucleus::createAdd(res.value(), Nucleus::createConstantShort((unsigned short)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const UShort &operator++(UShort &val) // Pre-increment |
| { |
| Value *inc = Nucleus::createAdd(val.loadValue(), Nucleus::createConstantShort((unsigned short)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<UShort> operator--(UShort &val, int) // Post-decrement |
| { |
| RValue<UShort> res = val; |
| |
| Value *inc = Nucleus::createSub(res.value(), Nucleus::createConstantShort((unsigned short)1)); |
| val.storeValue(inc); |
| |
| return res; |
| } |
| |
| const UShort &operator--(UShort &val) // Pre-decrement |
| { |
| Value *inc = Nucleus::createSub(val.loadValue(), Nucleus::createConstantShort((unsigned short)1)); |
| val.storeValue(inc); |
| |
| return val; |
| } |
| |
| RValue<Bool> operator<(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpULT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator<=(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpULE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpUGT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>=(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpUGE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator!=(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpNE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator==(RValue<UShort> lhs, RValue<UShort> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpEQ(lhs.value(), rhs.value())); |
| } |
| |
| Byte4::Byte4(RValue<Byte8> cast) |
| { |
| storeValue(Nucleus::createBitCast(cast.value(), type())); |
| } |
| |
| Byte4::Byte4(RValue<UShort4> cast) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| *this = As<Byte4>(Swizzle(As<Byte8>(cast), 0x0246'0246)); |
| } |
| |
| Byte4::Byte4(RValue<Short4> cast) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| *this = As<Byte4>(Swizzle(As<Byte8>(cast), 0x0246'0246)); |
| } |
| |
| Byte4::Byte4(RValue<UInt4> cast) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| *this = As<Byte4>(Swizzle(As<Byte16>(cast), 0x048C'048C'048C'048C)); |
| } |
| |
| Byte4::Byte4(RValue<Int4> cast) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| *this = As<Byte4>(Swizzle(As<Byte16>(cast), 0x048C'048C'048C'048C)); |
| } |
| |
| Byte4::Byte4(RValue<Byte4> rhs) |
| { |
| store(rhs); |
| } |
| |
| Byte4::Byte4(const Byte4 &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Byte4::Byte4(const Reference<Byte4> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<Byte4> Byte4::operator=(RValue<Byte4> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Byte4> Byte4::operator=(const Byte4 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| 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) |
| { |
| int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| Byte8::Byte8(RValue<Byte8> rhs) |
| { |
| store(rhs); |
| } |
| |
| Byte8::Byte8(const Byte8 &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Byte8::Byte8(const Reference<Byte8> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<Byte8> Byte8::operator=(RValue<Byte8> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Byte8> Byte8::operator=(const Byte8 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Byte8> Byte8::operator=(const Reference<Byte8> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Byte8> operator+(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| { |
| return RValue<Byte8>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte8> operator-(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| { |
| return RValue<Byte8>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| // RValue<Byte8> operator*(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| // { |
| // return RValue<Byte8>(Nucleus::createMul(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<Byte8> operator/(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| // { |
| // return RValue<Byte8>(Nucleus::createUDiv(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<Byte8> operator%(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| // { |
| // return RValue<Byte8>(Nucleus::createURem(lhs.value(), rhs.value())); |
| // } |
| |
| RValue<Byte8> operator&(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| { |
| return RValue<Byte8>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte8> operator|(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| { |
| return RValue<Byte8>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Byte8> operator^(RValue<Byte8> lhs, RValue<Byte8> rhs) |
| { |
| return RValue<Byte8>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| // RValue<Byte8> operator<<(RValue<Byte8> lhs, unsigned char rhs) |
| // { |
| // return RValue<Byte8>(Nucleus::createShl(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<Byte8> operator>>(RValue<Byte8> lhs, unsigned char rhs) |
| // { |
| // return RValue<Byte8>(Nucleus::createLShr(lhs.value(), rhs.value())); |
| // } |
| |
| RValue<Byte8> operator+=(Byte8 &lhs, RValue<Byte8> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<Byte8> operator-=(Byte8 &lhs, RValue<Byte8> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| // RValue<Byte8> operator*=(Byte8 &lhs, RValue<Byte8> rhs) |
| // { |
| // return lhs = lhs * rhs; |
| // } |
| |
| // RValue<Byte8> operator/=(Byte8 &lhs, RValue<Byte8> rhs) |
| // { |
| // return lhs = lhs / rhs; |
| // } |
| |
| // RValue<Byte8> operator%=(Byte8 &lhs, RValue<Byte8> rhs) |
| // { |
| // return lhs = lhs % rhs; |
| // } |
| |
| RValue<Byte8> operator&=(Byte8 &lhs, RValue<Byte8> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<Byte8> operator|=(Byte8 &lhs, RValue<Byte8> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<Byte8> operator^=(Byte8 &lhs, RValue<Byte8> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| // RValue<Byte8> operator<<=(Byte8 &lhs, RValue<Byte8> rhs) |
| // { |
| // return lhs = lhs << rhs; |
| // } |
| |
| // RValue<Byte8> operator>>=(Byte8 &lhs, RValue<Byte8> rhs) |
| // { |
| // return lhs = lhs >> rhs; |
| // } |
| |
| // RValue<Byte8> operator+(RValue<Byte8> val) |
| // { |
| // return val; |
| // } |
| |
| // RValue<Byte8> operator-(RValue<Byte8> val) |
| // { |
| // return RValue<Byte8>(Nucleus::createNeg(val.value())); |
| // } |
| |
| RValue<Byte8> operator~(RValue<Byte8> val) |
| { |
| return RValue<Byte8>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Byte8> Swizzle(RValue<Byte8> x, uint32_t select) |
| { |
| // Real type is v16i8 |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[16] = { |
| static_cast<int>((select >> 28) & 0x07), |
| static_cast<int>((select >> 24) & 0x07), |
| static_cast<int>((select >> 20) & 0x07), |
| static_cast<int>((select >> 16) & 0x07), |
| static_cast<int>((select >> 12) & 0x07), |
| static_cast<int>((select >> 8) & 0x07), |
| static_cast<int>((select >> 4) & 0x07), |
| static_cast<int>((select >> 0) & 0x07), |
| static_cast<int>((select >> 28) & 0x07), |
| static_cast<int>((select >> 24) & 0x07), |
| static_cast<int>((select >> 20) & 0x07), |
| static_cast<int>((select >> 16) & 0x07), |
| static_cast<int>((select >> 12) & 0x07), |
| static_cast<int>((select >> 8) & 0x07), |
| static_cast<int>((select >> 4) & 0x07), |
| static_cast<int>((select >> 0) & 0x07), |
| }; |
| |
| return As<Byte8>(Nucleus::createShuffleVector(x.value(), x.value(), shuffle)); |
| } |
| |
| RValue<Short4> Unpack(RValue<Byte4> x) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[16] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 }; // Real type is v16i8 |
| return As<Short4>(Nucleus::createShuffleVector(x.value(), x.value(), shuffle)); |
| } |
| |
| RValue<Short4> Unpack(RValue<Byte4> x, RValue<Byte4> y) |
| { |
| return UnpackLow(As<Byte8>(x), As<Byte8>(y)); |
| } |
| |
| RValue<Short4> UnpackLow(RValue<Byte8> x, RValue<Byte8> y) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[16] = { 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23 }; // Real type is v16i8 |
| return As<Short4>(Nucleus::createShuffleVector(x.value(), y.value(), shuffle)); |
| } |
| |
| RValue<Short4> UnpackHigh(RValue<Byte8> x, RValue<Byte8> y) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[16] = { 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23 }; // Real type is v16i8 |
| auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value(), y.value(), shuffle)); |
| return As<Short4>(Swizzle(As<Int4>(lowHigh), 0x2323)); |
| } |
| |
| 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) |
| { |
| int64_t constantVector[8] = { x0, x1, x2, x3, x4, x5, x6, x7 }; |
| Value *vector = Nucleus::createConstantVector(constantVector, type()); |
| |
| storeValue(Nucleus::createBitCast(vector, type())); |
| } |
| |
| SByte8::SByte8(RValue<SByte8> rhs) |
| { |
| store(rhs); |
| } |
| |
| SByte8::SByte8(const SByte8 &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| SByte8::SByte8(const Reference<SByte8> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<SByte8> SByte8::operator=(RValue<SByte8> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<SByte8> SByte8::operator=(const SByte8 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<SByte8> SByte8::operator=(const Reference<SByte8> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<SByte8> operator+(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| { |
| return RValue<SByte8>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte8> operator-(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| { |
| return RValue<SByte8>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| // RValue<SByte8> operator*(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| // { |
| // return RValue<SByte8>(Nucleus::createMul(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<SByte8> operator/(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| // { |
| // return RValue<SByte8>(Nucleus::createSDiv(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<SByte8> operator%(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| // { |
| // return RValue<SByte8>(Nucleus::createSRem(lhs.value(), rhs.value())); |
| // } |
| |
| RValue<SByte8> operator&(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| { |
| return RValue<SByte8>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte8> operator|(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| { |
| return RValue<SByte8>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<SByte8> operator^(RValue<SByte8> lhs, RValue<SByte8> rhs) |
| { |
| return RValue<SByte8>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| // RValue<SByte8> operator<<(RValue<SByte8> lhs, unsigned char rhs) |
| // { |
| // return RValue<SByte8>(Nucleus::createShl(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<SByte8> operator>>(RValue<SByte8> lhs, unsigned char rhs) |
| // { |
| // return RValue<SByte8>(Nucleus::createAShr(lhs.value(), rhs.value())); |
| // } |
| |
| RValue<SByte8> operator+=(SByte8 &lhs, RValue<SByte8> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<SByte8> operator-=(SByte8 &lhs, RValue<SByte8> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| // RValue<SByte8> operator*=(SByte8 &lhs, RValue<SByte8> rhs) |
| // { |
| // return lhs = lhs * rhs; |
| // } |
| |
| // RValue<SByte8> operator/=(SByte8 &lhs, RValue<SByte8> rhs) |
| // { |
| // return lhs = lhs / rhs; |
| // } |
| |
| // RValue<SByte8> operator%=(SByte8 &lhs, RValue<SByte8> rhs) |
| // { |
| // return lhs = lhs % rhs; |
| // } |
| |
| RValue<SByte8> operator&=(SByte8 &lhs, RValue<SByte8> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<SByte8> operator|=(SByte8 &lhs, RValue<SByte8> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<SByte8> operator^=(SByte8 &lhs, RValue<SByte8> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| // RValue<SByte8> operator<<=(SByte8 &lhs, RValue<SByte8> rhs) |
| // { |
| // return lhs = lhs << rhs; |
| // } |
| |
| // RValue<SByte8> operator>>=(SByte8 &lhs, RValue<SByte8> rhs) |
| // { |
| // return lhs = lhs >> rhs; |
| // } |
| |
| // RValue<SByte8> operator+(RValue<SByte8> val) |
| // { |
| // return val; |
| // } |
| |
| // RValue<SByte8> operator-(RValue<SByte8> val) |
| // { |
| // return RValue<SByte8>(Nucleus::createNeg(val.value())); |
| // } |
| |
| RValue<SByte8> operator~(RValue<SByte8> val) |
| { |
| return RValue<SByte8>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Short4> UnpackLow(RValue<SByte8> x, RValue<SByte8> y) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[16] = { 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23 }; // Real type is v16i8 |
| return As<Short4>(Nucleus::createShuffleVector(x.value(), y.value(), shuffle)); |
| } |
| |
| RValue<Short4> UnpackHigh(RValue<SByte8> x, RValue<SByte8> y) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[16] = { 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23 }; // Real type is v16i8 |
| auto lowHigh = RValue<Byte16>(Nucleus::createShuffleVector(x.value(), y.value(), shuffle)); |
| return As<Short4>(Swizzle(As<Int4>(lowHigh), 0x2323)); |
| } |
| |
| Byte16::Byte16(RValue<Byte16> rhs) |
| { |
| store(rhs); |
| } |
| |
| Byte16::Byte16(const Byte16 &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Byte16::Byte16(const Reference<Byte16> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| RValue<Byte16> Byte16::operator=(RValue<Byte16> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Byte16> Byte16::operator=(const Byte16 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Byte16> Byte16::operator=(const Reference<Byte16> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Byte16> Swizzle(RValue<Byte16> x, uint64_t select) |
| { |
| int shuffle[16] = { |
| static_cast<int>((select >> 60) & 0x0F), |
| static_cast<int>((select >> 56) & 0x0F), |
| static_cast<int>((select >> 52) & 0x0F), |
| static_cast<int>((select >> 48) & 0x0F), |
| static_cast<int>((select >> 44) & 0x0F), |
| static_cast<int>((select >> 40) & 0x0F), |
| static_cast<int>((select >> 36) & 0x0F), |
| static_cast<int>((select >> 32) & 0x0F), |
| static_cast<int>((select >> 28) & 0x0F), |
| static_cast<int>((select >> 24) & 0x0F), |
| static_cast<int>((select >> 20) & 0x0F), |
| static_cast<int>((select >> 16) & 0x0F), |
| static_cast<int>((select >> 12) & 0x0F), |
| static_cast<int>((select >> 8) & 0x0F), |
| static_cast<int>((select >> 4) & 0x0F), |
| static_cast<int>((select >> 0) & 0x0F), |
| }; |
| |
| return As<Byte16>(Nucleus::createShuffleVector(x.value(), x.value(), shuffle)); |
| } |
| |
| Short2::Short2(RValue<Short4> cast) |
| { |
| storeValue(Nucleus::createBitCast(cast.value(), type())); |
| } |
| |
| UShort2::UShort2(RValue<UShort4> cast) |
| { |
| storeValue(Nucleus::createBitCast(cast.value(), type())); |
| } |
| |
| Short4::Short4(RValue<Int> cast) |
| { |
| Value *vector = loadValue(); |
| Value *element = Nucleus::createTrunc(cast.value(), Short::type()); |
| Value *insert = Nucleus::createInsertElement(vector, element, 0); |
| Value *swizzle = Swizzle(RValue<Short4>(insert), 0x0000).value(); |
| |
| storeValue(swizzle); |
| } |
| |
| // Short4::Short4(RValue<Float> cast) |
| // { |
| // } |
| |
| Short4::Short4(short xyzw) |
| { |
| int64_t constantVector[4] = { xyzw, xyzw, xyzw, xyzw }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| Short4::Short4(short x, short y, short z, short w) |
| { |
| int64_t constantVector[4] = { x, y, z, w }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| Short4::Short4(RValue<Short4> rhs) |
| { |
| store(rhs); |
| } |
| |
| Short4::Short4(const Short4 &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Short4::Short4(const Reference<Short4> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Short4::Short4(RValue<UShort4> rhs) |
| { |
| storeValue(rhs.value()); |
| } |
| |
| Short4::Short4(const UShort4 &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| Short4::Short4(const Reference<UShort4> &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| RValue<Short4> Short4::operator=(RValue<Short4> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Short4> Short4::operator=(const Short4 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Short4> Short4::operator=(const Reference<Short4> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Short4> Short4::operator=(RValue<UShort4> rhs) |
| { |
| return RValue<Short4>(storeValue(rhs.value())); |
| } |
| |
| RValue<Short4> Short4::operator=(const UShort4 &rhs) |
| { |
| return RValue<Short4>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<Short4> Short4::operator=(const Reference<UShort4> &rhs) |
| { |
| return RValue<Short4>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<Short4> operator+(RValue<Short4> lhs, RValue<Short4> rhs) |
| { |
| return RValue<Short4>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short4> operator-(RValue<Short4> lhs, RValue<Short4> rhs) |
| { |
| return RValue<Short4>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short4> operator*(RValue<Short4> lhs, RValue<Short4> rhs) |
| { |
| return RValue<Short4>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| // RValue<Short4> operator/(RValue<Short4> lhs, RValue<Short4> rhs) |
| // { |
| // return RValue<Short4>(Nucleus::createSDiv(lhs.value(), rhs.value())); |
| // } |
| |
| // RValue<Short4> operator%(RValue<Short4> lhs, RValue<Short4> rhs) |
| // { |
| // return RValue<Short4>(Nucleus::createSRem(lhs.value(), rhs.value())); |
| // } |
| |
| RValue<Short4> operator&(RValue<Short4> lhs, RValue<Short4> rhs) |
| { |
| return RValue<Short4>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short4> operator|(RValue<Short4> lhs, RValue<Short4> rhs) |
| { |
| return RValue<Short4>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short4> operator^(RValue<Short4> lhs, RValue<Short4> rhs) |
| { |
| return RValue<Short4>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short4> operator+=(Short4 &lhs, RValue<Short4> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<Short4> operator-=(Short4 &lhs, RValue<Short4> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<Short4> operator*=(Short4 &lhs, RValue<Short4> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| // RValue<Short4> operator/=(Short4 &lhs, RValue<Short4> rhs) |
| // { |
| // return lhs = lhs / rhs; |
| // } |
| |
| // RValue<Short4> operator%=(Short4 &lhs, RValue<Short4> rhs) |
| // { |
| // return lhs = lhs % rhs; |
| // } |
| |
| RValue<Short4> operator&=(Short4 &lhs, RValue<Short4> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<Short4> operator|=(Short4 &lhs, RValue<Short4> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<Short4> operator^=(Short4 &lhs, RValue<Short4> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<Short4> operator<<=(Short4 &lhs, unsigned char rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<Short4> operator>>=(Short4 &lhs, unsigned char rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| // RValue<Short4> operator+(RValue<Short4> val) |
| // { |
| // return val; |
| // } |
| |
| RValue<Short4> operator-(RValue<Short4> val) |
| { |
| return RValue<Short4>(Nucleus::createNeg(val.value())); |
| } |
| |
| RValue<Short4> operator~(RValue<Short4> val) |
| { |
| return RValue<Short4>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Short4> RoundShort4(RValue<Float4> cast) |
| { |
| RValue<Int4> int4 = RoundInt(cast); |
| return As<Short4>(PackSigned(int4, int4)); |
| } |
| |
| RValue<Int2> UnpackLow(RValue<Short4> x, RValue<Short4> y) |
| { |
| int shuffle[8] = { 0, 8, 1, 9, 2, 10, 3, 11 }; // Real type is v8i16 |
| return As<Int2>(Nucleus::createShuffleVector(x.value(), y.value(), shuffle)); |
| } |
| |
| RValue<Int2> UnpackHigh(RValue<Short4> x, RValue<Short4> y) |
| { |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[8] = { 0, 8, 1, 9, 2, 10, 3, 11 }; // Real type is v8i16 |
| auto lowHigh = RValue<Short8>(Nucleus::createShuffleVector(x.value(), y.value(), shuffle)); |
| return As<Int2>(Swizzle(As<Int4>(lowHigh), 0x2323)); |
| } |
| |
| RValue<Short4> Swizzle(RValue<Short4> x, uint16_t select) |
| { |
| // Real type is v8i16 |
| // TODO(b/148379603): Optimize narrowing swizzle. |
| int shuffle[8] = { |
| (select >> 12) & 0x03, |
| (select >> 8) & 0x03, |
| (select >> 4) & 0x03, |
| (select >> 0) & 0x03, |
| (select >> 12) & 0x03, |
| (select >> 8) & 0x03, |
| (select >> 4) & 0x03, |
| (select >> 0) & 0x03, |
| }; |
| |
| return As<Short4>(Nucleus::createShuffleVector(x.value(), x.value(), shuffle)); |
| } |
| |
| RValue<Short4> Insert(RValue<Short4> val, RValue<Short> element, int i) |
| { |
| return RValue<Short4>(Nucleus::createInsertElement(val.value(), element.value(), i)); |
| } |
| |
| RValue<Short> Extract(RValue<Short4> val, int i) |
| { |
| return RValue<Short>(Nucleus::createExtractElement(val.value(), Short::type(), i)); |
| } |
| |
| UShort4::UShort4(RValue<Int4> cast) |
| { |
| *this = Short4(cast); |
| } |
| |
| UShort4::UShort4(unsigned short xyzw) |
| { |
| int64_t constantVector[4] = { xyzw, xyzw, xyzw, xyzw }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| UShort4::UShort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) |
| { |
| int64_t constantVector[4] = { x, y, z, w }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| UShort4::UShort4(RValue<UShort4> rhs) |
| { |
| store(rhs); |
| } |
| |
| UShort4::UShort4(const UShort4 &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| UShort4::UShort4(const Reference<UShort4> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| UShort4::UShort4(RValue<Short4> rhs) |
| { |
| storeValue(rhs.value()); |
| } |
| |
| UShort4::UShort4(const Short4 &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| UShort4::UShort4(const Reference<Short4> &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| RValue<UShort4> UShort4::operator=(RValue<UShort4> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<UShort4> UShort4::operator=(const UShort4 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UShort4> UShort4::operator=(const Reference<UShort4> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UShort4> UShort4::operator=(RValue<Short4> rhs) |
| { |
| return RValue<UShort4>(storeValue(rhs.value())); |
| } |
| |
| RValue<UShort4> UShort4::operator=(const Short4 &rhs) |
| { |
| return RValue<UShort4>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<UShort4> UShort4::operator=(const Reference<Short4> &rhs) |
| { |
| return RValue<UShort4>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<UShort4> operator+(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| { |
| return RValue<UShort4>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort4> operator-(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| { |
| return RValue<UShort4>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort4> operator*(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| { |
| return RValue<UShort4>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort4> operator&(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| { |
| return RValue<UShort4>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort4> operator|(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| { |
| return RValue<UShort4>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort4> operator^(RValue<UShort4> lhs, RValue<UShort4> rhs) |
| { |
| return RValue<UShort4>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort4> operator<<=(UShort4 &lhs, unsigned char rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<UShort4> operator>>=(UShort4 &lhs, unsigned char rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| RValue<UShort4> operator~(RValue<UShort4> val) |
| { |
| return RValue<UShort4>(Nucleus::createNot(val.value())); |
| } |
| |
| Short8::Short8(short c) |
| { |
| int64_t constantVector[8] = { c, c, c, c, c, c, c, c }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| Short8::Short8(short c0, short c1, short c2, short c3, short c4, short c5, short c6, short c7) |
| { |
| int64_t constantVector[8] = { c0, c1, c2, c3, c4, c5, c6, c7 }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| Short8::Short8(RValue<Short8> rhs) |
| { |
| store(rhs); |
| } |
| |
| Short8::Short8(const Reference<Short8> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Short8::Short8(RValue<Short4> lo, RValue<Short4> hi) |
| { |
| int shuffle[8] = { 0, 1, 2, 3, 8, 9, 10, 11 }; // Real type is v8i16 |
| Value *packed = Nucleus::createShuffleVector(lo.value(), hi.value(), shuffle); |
| |
| storeValue(packed); |
| } |
| |
| RValue<Short8> Short8::operator=(RValue<Short8> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Short8> Short8::operator=(const Short8 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Short8> Short8::operator=(const Reference<Short8> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Short8> operator+(RValue<Short8> lhs, RValue<Short8> rhs) |
| { |
| return RValue<Short8>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Short8> operator&(RValue<Short8> lhs, RValue<Short8> rhs) |
| { |
| return RValue<Short8>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int4> Abs(RValue<Int4> x) |
| { |
| // TODO: Optimize. |
| auto negative = x >> 31; |
| return (x ^ negative) - negative; |
| } |
| |
| UShort8::UShort8(unsigned short c) |
| { |
| int64_t constantVector[8] = { c, c, c, c, c, c, c, c }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| 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) |
| { |
| int64_t constantVector[8] = { c0, c1, c2, c3, c4, c5, c6, c7 }; |
| storeValue(Nucleus::createConstantVector(constantVector, type())); |
| } |
| |
| UShort8::UShort8(RValue<UShort8> rhs) |
| { |
| store(rhs); |
| } |
| |
| UShort8::UShort8(const Reference<UShort8> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| UShort8::UShort8(RValue<UShort4> lo, RValue<UShort4> hi) |
| { |
| int shuffle[8] = { 0, 1, 2, 3, 8, 9, 10, 11 }; // Real type is v8i16 |
| Value *packed = Nucleus::createShuffleVector(lo.value(), hi.value(), shuffle); |
| |
| storeValue(packed); |
| } |
| |
| RValue<UShort8> UShort8::operator=(RValue<UShort8> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<UShort8> UShort8::operator=(const UShort8 &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UShort8> UShort8::operator=(const Reference<UShort8> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UShort8> operator&(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| { |
| return RValue<UShort8>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort8> operator+(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| { |
| return RValue<UShort8>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort8> operator*(RValue<UShort8> lhs, RValue<UShort8> rhs) |
| { |
| return RValue<UShort8>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UShort8> operator+=(UShort8 &lhs, RValue<UShort8> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<UShort8> operator~(RValue<UShort8> val) |
| { |
| return RValue<UShort8>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<UShort8> Swizzle(RValue<UShort8> x, uint32_t select) |
| { |
| int swizzle[16] = { |
| static_cast<int>((select >> 28) & 0x07), |
| static_cast<int>((select >> 24) & 0x07), |
| static_cast<int>((select >> 20) & 0x07), |
| static_cast<int>((select >> 16) & 0x07), |
| static_cast<int>((select >> 12) & 0x07), |
| static_cast<int>((select >> 8) & 0x07), |
| static_cast<int>((select >> 4) & 0x07), |
| static_cast<int>((select >> 0) & 0x07), |
| }; |
| |
| return RValue<UShort8>(Nucleus::createShuffleVector(x.value(), x.value(), swizzle)); |
| } |
| |
| Int::Int(Argument<Int> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| Int::Int(RValue<Byte> cast) |
| { |
| Value *integer = Nucleus::createZExt(cast.value(), Int::type()); |
| |
| storeValue(integer); |
| } |
| |
| Int::Int(RValue<SByte> cast) |
| { |
| Value *integer = Nucleus::createSExt(cast.value(), Int::type()); |
| |
| storeValue(integer); |
| } |
| |
| Int::Int(RValue<Short> cast) |
| { |
| Value *integer = Nucleus::createSExt(cast.value(), Int::type()); |
| |
| storeValue(integer); |
| } |
| |
| Int::Int(RValue<UShort> cast) |
| { |
| Value *integer = Nucleus::createZExt(cast.value(), Int::type()); |
| |
| storeValue(integer); |
| } |
| |
| Int::Int(RValue<Int2> cast) |
| { |
| *this = Extract(cast, 0); |
| } |
| |
| Int::Int(RValue<Long> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), Int::type()); |
| |
| storeValue(integer); |
| } |
| |
| Int::Int(RValue<Float> cast) |
| { |
| Value *integer = Nucleus::createFPToSI(cast.value(), Int::type()); |
| |
| storeValue(integer); |
| } |
| |
| Int::Int(int x) |
| { |
| storeValue(Nucleus::createConstantInt(x)); |
| } |
| |
| Int::Int(RValue<Int> rhs) |
| { |
| store(rhs); |
| } |
| |
| Int::Int(RValue<UInt> rhs) |
| { |
| storeValue(rhs.value()); |
| } |
| |
| Int::Int(const Int &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Int::Int(const Reference<Int> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| Int::Int(const UInt &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| Int::Int(const Reference<UInt> &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| RValue<Int> Int::operator=(int rhs) |
| { |
| return RValue<Int>(storeValue(Nucleus::createConstantInt(rhs))); |
| } |
| |
| RValue<Int> Int::operator=(RValue<Int> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Int> Int::operator=(RValue<UInt> rhs) |
| { |
| storeValue(rhs.value()); |
| |
| return RValue<Int>(rhs); |
| } |
| |
| RValue<Int> Int::operator=(const Int &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Int> Int::operator=(const Reference<Int> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Int> Int::operator=(const UInt &rhs) |
| { |
| return RValue<Int>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<Int> Int::operator=(const Reference<UInt> &rhs) |
| { |
| return RValue<Int>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<Int> operator+(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator-(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator*(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator/(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createSDiv(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator%(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createSRem(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator&(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator|(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator^(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator<<(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createShl(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator>>(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Int>(Nucleus::createAShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> operator+=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<Int> operator-=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<Int> operator*=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| RValue<Int> operator/=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs / rhs; |
| } |
| |
| RValue<Int> operator%=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs % rhs; |
| } |
| |
| RValue<Int> operator&=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<Int> operator|=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<Int> operator^=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<Int> operator<<=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<Int> operator>>=(Int &lhs, RValue<Int> rhs) |
| { |
| return lhs = lhs >> rhs; |
| } |
| |
| RValue<Int> operator+(RValue<Int> val) |
| { |
| return val; |
| } |
| |
| RValue<Int> operator-(RValue<Int> val) |
| { |
| return RValue<Int>(Nucleus::createNeg(val.value())); |
| } |
| |
| RValue<Int> operator~(RValue<Int> val) |
| { |
| return RValue<Int>(Nucleus::createNot(val.value())); |
| } |
| |
| RValue<Bool> operator<(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSLT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator<=(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSLE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSGT(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator>=(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpSGE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator!=(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpNE(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Bool> operator==(RValue<Int> lhs, RValue<Int> rhs) |
| { |
| return RValue<Bool>(Nucleus::createICmpEQ(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Int> Max(RValue<Int> x, RValue<Int> y) |
| { |
| return IfThenElse(x > y, x, y); |
| } |
| |
| RValue<Int> Min(RValue<Int> x, RValue<Int> y) |
| { |
| return IfThenElse(x < y, x, y); |
| } |
| |
| RValue<Int> Clamp(RValue<Int> x, RValue<Int> min, RValue<Int> max) |
| { |
| return Min(Max(x, min), max); |
| } |
| |
| Long::Long(RValue<Int> cast) |
| { |
| Value *integer = Nucleus::createSExt(cast.value(), Long::type()); |
| |
| storeValue(integer); |
| } |
| |
| Long::Long(RValue<UInt> cast) |
| { |
| Value *integer = Nucleus::createZExt(cast.value(), Long::type()); |
| |
| storeValue(integer); |
| } |
| |
| Long::Long(RValue<Long> rhs) |
| { |
| store(rhs); |
| } |
| |
| RValue<Long> Long::operator=(int64_t rhs) |
| { |
| return RValue<Long>(storeValue(Nucleus::createConstantLong(rhs))); |
| } |
| |
| RValue<Long> Long::operator=(RValue<Long> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<Long> Long::operator=(const Long &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Long> Long::operator=(const Reference<Long> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<Long> operator+(RValue<Long> lhs, RValue<Long> rhs) |
| { |
| return RValue<Long>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Long> operator-(RValue<Long> lhs, RValue<Long> rhs) |
| { |
| return RValue<Long>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Long> operator*(RValue<Long> lhs, RValue<Long> rhs) |
| { |
| return RValue<Long>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Long> operator>>(RValue<Long> lhs, RValue<Long> rhs) |
| { |
| return RValue<Long>(Nucleus::createAShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<Long> operator+=(Long &lhs, RValue<Long> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<Long> operator-=(Long &lhs, RValue<Long> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<Long> AddAtomic(RValue<Pointer<Long>> x, RValue<Long> y) |
| { |
| return RValue<Long>(Nucleus::createAtomicAdd(x.value(), y.value())); |
| } |
| |
| RValue<UInt> AddAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder) |
| { |
| return RValue<UInt>(Nucleus::createAtomicAdd(x.value(), y.value(), memoryOrder)); |
| } |
| |
| RValue<UInt> SubAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder) |
| { |
| return RValue<UInt>(Nucleus::createAtomicSub(x.value(), y.value(), memoryOrder)); |
| } |
| |
| RValue<UInt> AndAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder) |
| { |
| return RValue<UInt>(Nucleus::createAtomicAnd(x.value(), y.value(), memoryOrder)); |
| } |
| |
| RValue<UInt> OrAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder) |
| { |
| return RValue<UInt>(Nucleus::createAtomicOr(x.value(), y.value(), memoryOrder)); |
| } |
| |
| RValue<UInt> XorAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder) |
| { |
| return RValue<UInt>(Nucleus::createAtomicXor(x.value(), y.value(), memoryOrder)); |
| } |
| |
| RValue<UInt> ExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, std::memory_order memoryOrder) |
| { |
| return RValue<UInt>(Nucleus::createAtomicExchange(x.value(), y.value(), memoryOrder)); |
| } |
| |
| RValue<UInt> CompareExchangeAtomic(RValue<Pointer<UInt>> x, RValue<UInt> y, RValue<UInt> compare, std::memory_order memoryOrderEqual, std::memory_order memoryOrderUnequal) |
| { |
| return RValue<UInt>(Nucleus::createAtomicCompareExchange(x.value(), y.value(), compare.value(), memoryOrderEqual, memoryOrderUnequal)); |
| } |
| |
| UInt::UInt(Argument<UInt> argument) |
| { |
| store(argument.rvalue()); |
| } |
| |
| UInt::UInt(RValue<UShort> cast) |
| { |
| Value *integer = Nucleus::createZExt(cast.value(), UInt::type()); |
| |
| storeValue(integer); |
| } |
| |
| UInt::UInt(RValue<Long> cast) |
| { |
| Value *integer = Nucleus::createTrunc(cast.value(), UInt::type()); |
| |
| storeValue(integer); |
| } |
| |
| UInt::UInt(int x) |
| { |
| storeValue(Nucleus::createConstantInt(x)); |
| } |
| |
| UInt::UInt(unsigned int x) |
| { |
| storeValue(Nucleus::createConstantInt(x)); |
| } |
| |
| UInt::UInt(RValue<UInt> rhs) |
| { |
| store(rhs); |
| } |
| |
| UInt::UInt(RValue<Int> rhs) |
| { |
| storeValue(rhs.value()); |
| } |
| |
| UInt::UInt(const UInt &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| UInt::UInt(const Reference<UInt> &rhs) |
| { |
| store(rhs.load()); |
| } |
| |
| UInt::UInt(const Int &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| UInt::UInt(const Reference<Int> &rhs) |
| { |
| storeValue(rhs.loadValue()); |
| } |
| |
| RValue<UInt> UInt::operator=(unsigned int rhs) |
| { |
| return RValue<UInt>(storeValue(Nucleus::createConstantInt(rhs))); |
| } |
| |
| RValue<UInt> UInt::operator=(RValue<UInt> rhs) |
| { |
| return store(rhs); |
| } |
| |
| RValue<UInt> UInt::operator=(RValue<Int> rhs) |
| { |
| storeValue(rhs.value()); |
| |
| return RValue<UInt>(rhs); |
| } |
| |
| RValue<UInt> UInt::operator=(const UInt &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UInt> UInt::operator=(const Reference<UInt> &rhs) |
| { |
| return store(rhs.load()); |
| } |
| |
| RValue<UInt> UInt::operator=(const Int &rhs) |
| { |
| return RValue<UInt>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<UInt> UInt::operator=(const Reference<Int> &rhs) |
| { |
| return RValue<UInt>(storeValue(rhs.loadValue())); |
| } |
| |
| RValue<UInt> operator+(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createAdd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator-(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createSub(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator*(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createMul(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator/(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createUDiv(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator%(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createURem(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator&(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createAnd(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator|(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createOr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator^(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createXor(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator<<(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createShl(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator>>(RValue<UInt> lhs, RValue<UInt> rhs) |
| { |
| return RValue<UInt>(Nucleus::createLShr(lhs.value(), rhs.value())); |
| } |
| |
| RValue<UInt> operator+=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs + rhs; |
| } |
| |
| RValue<UInt> operator-=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs - rhs; |
| } |
| |
| RValue<UInt> operator*=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs * rhs; |
| } |
| |
| RValue<UInt> operator/=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs / rhs; |
| } |
| |
| RValue<UInt> operator%=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs % rhs; |
| } |
| |
| RValue<UInt> operator&=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs & rhs; |
| } |
| |
| RValue<UInt> operator|=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs | rhs; |
| } |
| |
| RValue<UInt> operator^=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs ^ rhs; |
| } |
| |
| RValue<UInt> operator<<=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs << rhs; |
| } |
| |
| RValue<UInt> operator>>=(UInt &lhs, RValue<UInt> rhs) |
| { |
| return lhs = lhs >> rhs; |
|