Commit 81f1830d by Nicolas Capens

Make Function arguments type-safe.

Change-Id: I3d4262ea4be0c7b1128b2ca410e985cc6f58c9c9 Reviewed-on: https://swiftshader-review.googlesource.com/1970Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 2ab859f2
...@@ -236,8 +236,8 @@ namespace sw ...@@ -236,8 +236,8 @@ namespace sw
Function<Void(Pointer<Byte>, Pointer<Byte>)> function; Function<Void(Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> dst(function.arg(0)); Pointer<Byte> dst(function.Arg<0>());
Pointer<Byte> src(function.arg(1)); Pointer<Byte> src(function.Arg<1>());
For(Int y = 0, y < height, y++) For(Int y = 0, y < height, y++)
{ {
......
...@@ -294,7 +294,7 @@ namespace sw ...@@ -294,7 +294,7 @@ namespace sw
return function; return function;
} }
llvm::Argument *Nucleus::getArgument(llvm::Function *function, unsigned int index) llvm::Value *Nucleus::getArgument(llvm::Function *function, unsigned int index)
{ {
llvm::Function::arg_iterator args = function->arg_begin(); llvm::Function::arg_iterator args = function->arg_begin();
...@@ -847,9 +847,9 @@ namespace sw ...@@ -847,9 +847,9 @@ namespace sw
return Type::getX86_MMXTy(*Nucleus::getContext()); return Type::getX86_MMXTy(*Nucleus::getContext());
} }
Bool::Bool(Argument *argument) Bool::Bool(Argument<Bool> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
Bool::Bool() Bool::Bool()
...@@ -921,9 +921,9 @@ namespace sw ...@@ -921,9 +921,9 @@ namespace sw
return Type::getInt1Ty(*Nucleus::getContext()); return Type::getInt1Ty(*Nucleus::getContext());
} }
Byte::Byte(Argument *argument) Byte::Byte(Argument<Byte> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
Byte::Byte(RValue<Int> cast) Byte::Byte(RValue<Int> cast)
...@@ -1187,9 +1187,9 @@ namespace sw ...@@ -1187,9 +1187,9 @@ namespace sw
return Type::getInt8Ty(*Nucleus::getContext()); return Type::getInt8Ty(*Nucleus::getContext());
} }
SByte::SByte(Argument *argument) SByte::SByte(Argument<SByte> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
SByte::SByte(RValue<Int> cast) SByte::SByte(RValue<Int> cast)
...@@ -1441,9 +1441,9 @@ namespace sw ...@@ -1441,9 +1441,9 @@ namespace sw
return Type::getInt8Ty(*Nucleus::getContext()); return Type::getInt8Ty(*Nucleus::getContext());
} }
Short::Short(Argument *argument) Short::Short(Argument<Short> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
Short::Short(RValue<Int> cast) Short::Short(RValue<Int> cast)
...@@ -1688,9 +1688,9 @@ namespace sw ...@@ -1688,9 +1688,9 @@ namespace sw
return Type::getInt16Ty(*Nucleus::getContext()); return Type::getInt16Ty(*Nucleus::getContext());
} }
UShort::UShort(Argument *argument) UShort::UShort(Argument<UShort> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
UShort::UShort(RValue<UInt> cast) UShort::UShort(RValue<UInt> cast)
...@@ -3747,9 +3747,9 @@ namespace sw ...@@ -3747,9 +3747,9 @@ namespace sw
return VectorType::get(UShort::getType(), 8); return VectorType::get(UShort::getType(), 8);
} }
Int::Int(Argument *argument) Int::Int(Argument<Int> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
Int::Int(RValue<Byte> cast) Int::Int(RValue<Byte> cast)
...@@ -4225,9 +4225,9 @@ namespace sw ...@@ -4225,9 +4225,9 @@ namespace sw
return VectorType::get(Long::getType(), 2); return VectorType::get(Long::getType(), 2);
} }
UInt::UInt(Argument *argument) UInt::UInt(Argument<UInt> argument)
{ {
storeValue(argument); storeValue(argument.value);
} }
UInt::UInt(RValue<UShort> cast) UInt::UInt(RValue<UShort> cast)
...@@ -6765,62 +6765,62 @@ namespace sw ...@@ -6765,62 +6765,62 @@ namespace sw
return VectorType::get(Float::getType(), 4); return VectorType::get(Float::getType(), 4);
} }
RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset) RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
{ {
return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset))); return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, Nucleus::createConstantInt(offset)));
} }
RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset) RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
{ {
return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value)); return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
} }
RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset) RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
{ {
return RValue<Pointer<Byte> >(Nucleus::createGEP(lhs.value, offset.value)); return RValue<Pointer<Byte>>(Nucleus::createGEP(lhs.value, offset.value));
} }
RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset) RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset)
{ {
return lhs = lhs + offset; return lhs = lhs + offset;
} }
RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset) RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset)
{ {
return lhs = lhs + offset; return lhs = lhs + offset;
} }
RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset) RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset)
{ {
return lhs = lhs + offset; return lhs = lhs + offset;
} }
RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset) RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset)
{ {
return lhs + -offset; return lhs + -offset;
} }
RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset) RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset)
{ {
return lhs + -offset; return lhs + -offset;
} }
RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset) RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset)
{ {
return lhs + -offset; return lhs + -offset;
} }
RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset) RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset)
{ {
return lhs = lhs - offset; return lhs = lhs - offset;
} }
RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset) RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset)
{ {
return lhs = lhs - offset; return lhs = lhs - offset;
} }
RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset) RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset)
{ {
return lhs = lhs - offset; return lhs = lhs - offset;
} }
...@@ -7761,7 +7761,7 @@ namespace sw ...@@ -7761,7 +7761,7 @@ namespace sw
return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value)); return RValue<Int>(Nucleus::createCall(pmovmskb, As<MMX>(x).value));
} }
//RValue<Int2> movd(RValue<Pointer<Int> > x) //RValue<Int2> movd(RValue<Pointer<Int>> x)
//{ //{
// Value *element = Nucleus::createLoad(x.value); // Value *element = Nucleus::createLoad(x.value);
......
...@@ -88,7 +88,7 @@ namespace sw ...@@ -88,7 +88,7 @@ namespace sw
static llvm::BasicBlock *getPredecessor(llvm::BasicBlock *basicBlock); static llvm::BasicBlock *getPredecessor(llvm::BasicBlock *basicBlock);
static llvm::Function *createFunction(llvm::Type *ReturnType, std::vector<llvm::Type*> &Params); static llvm::Function *createFunction(llvm::Type *ReturnType, std::vector<llvm::Type*> &Params);
static llvm::Argument *getArgument(llvm::Function *function, unsigned int index); static llvm::Value *getArgument(llvm::Function *function, unsigned int index);
// Terminators // Terminators
static llvm::Value *createRetVoid(); static llvm::Value *createRetVoid();
...@@ -293,7 +293,7 @@ namespace sw ...@@ -293,7 +293,7 @@ namespace sw
public: public:
Variable(int arraySize = 0); Variable(int arraySize = 0);
RValue<Pointer<T> > operator&(); RValue<Pointer<T>> operator&();
}; };
template<class T> template<class T>
...@@ -368,6 +368,14 @@ namespace sw ...@@ -368,6 +368,14 @@ namespace sw
llvm::Value *value; // FIXME: Make private llvm::Value *value; // FIXME: Make private
}; };
template<typename T>
struct Argument
{
explicit Argument(llvm::Value *value) : value(value) {}
llvm::Value *value;
};
class MMX : public Variable<MMX> class MMX : public Variable<MMX>
{ {
public: public:
...@@ -377,7 +385,7 @@ namespace sw ...@@ -377,7 +385,7 @@ namespace sw
class Bool : public Variable<Bool> class Bool : public Variable<Bool>
{ {
public: public:
explicit Bool(llvm::Argument *argument); Bool(Argument<Bool> argument);
Bool(); Bool();
Bool(bool x); Bool(bool x);
...@@ -400,7 +408,7 @@ namespace sw ...@@ -400,7 +408,7 @@ namespace sw
class Byte : public Variable<Byte> class Byte : public Variable<Byte>
{ {
public: public:
explicit Byte(llvm::Argument *argument); Byte(Argument<Byte> argument);
explicit Byte(RValue<Int> cast); explicit Byte(RValue<Int> cast);
explicit Byte(RValue<UInt> cast); explicit Byte(RValue<UInt> cast);
...@@ -458,7 +466,7 @@ namespace sw ...@@ -458,7 +466,7 @@ namespace sw
class SByte : public Variable<SByte> class SByte : public Variable<SByte>
{ {
public: public:
explicit SByte(llvm::Argument *argument); SByte(Argument<SByte> argument);
explicit SByte(RValue<Int> cast); explicit SByte(RValue<Int> cast);
explicit SByte(RValue<Short> cast); explicit SByte(RValue<Short> cast);
...@@ -514,7 +522,7 @@ namespace sw ...@@ -514,7 +522,7 @@ namespace sw
class Short : public Variable<Short> class Short : public Variable<Short>
{ {
public: public:
explicit Short(llvm::Argument *argument); Short(Argument<Short> argument);
explicit Short(RValue<Int> cast); explicit Short(RValue<Int> cast);
...@@ -569,7 +577,7 @@ namespace sw ...@@ -569,7 +577,7 @@ namespace sw
class UShort : public Variable<UShort> class UShort : public Variable<UShort>
{ {
public: public:
explicit UShort(llvm::Argument *argument); UShort(Argument<UShort> argument);
explicit UShort(RValue<UInt> cast); explicit UShort(RValue<UInt> cast);
explicit UShort(RValue<Int> cast); explicit UShort(RValue<Int> cast);
...@@ -1167,7 +1175,7 @@ namespace sw ...@@ -1167,7 +1175,7 @@ namespace sw
class Int : public Variable<Int> class Int : public Variable<Int>
{ {
public: public:
explicit Int(llvm::Argument *argument); Int(Argument<Int> argument);
explicit Int(RValue<Byte> cast); explicit Int(RValue<Byte> cast);
explicit Int(RValue<SByte> cast); explicit Int(RValue<SByte> cast);
...@@ -1239,7 +1247,7 @@ namespace sw ...@@ -1239,7 +1247,7 @@ namespace sw
class Long : public Variable<Long> class Long : public Variable<Long>
{ {
public: public:
// explicit Long(llvm::Argument *argument); // Long(Argument<Long> argument);
// explicit Long(RValue<Short> cast); // explicit Long(RValue<Short> cast);
// explicit Long(RValue<UShort> cast); // explicit Long(RValue<UShort> cast);
...@@ -1302,12 +1310,12 @@ namespace sw ...@@ -1302,12 +1310,12 @@ namespace sw
// RValue<Bool> operator==(RValue<Long> lhs, RValue<Long> rhs); // RValue<Bool> operator==(RValue<Long> lhs, RValue<Long> rhs);
// RValue<Long> RoundLong(RValue<Float> cast); // RValue<Long> RoundLong(RValue<Float> cast);
RValue<Long> AddAtomic( RValue<Pointer<Long> > x, RValue<Long> y); RValue<Long> AddAtomic( RValue<Pointer<Long>> x, RValue<Long> y);
class Long1 : public Variable<Long1> class Long1 : public Variable<Long1>
{ {
public: public:
// explicit Long1(llvm::Argument *argument); // Long1(Argument<Long1> argument);
// explicit Long1(RValue<Short> cast); // explicit Long1(RValue<Short> cast);
// explicit Long1(RValue<UShort> cast); // explicit Long1(RValue<UShort> cast);
...@@ -1437,7 +1445,7 @@ namespace sw ...@@ -1437,7 +1445,7 @@ namespace sw
class UInt : public Variable<UInt> class UInt : public Variable<UInt>
{ {
public: public:
explicit UInt(llvm::Argument *argument); UInt(Argument<UInt> argument);
explicit UInt(RValue<UShort> cast); explicit UInt(RValue<UShort> cast);
explicit UInt(RValue<Long> cast); explicit UInt(RValue<Long> cast);
...@@ -2393,11 +2401,11 @@ namespace sw ...@@ -2393,11 +2401,11 @@ namespace sw
RValue<Float4> Ceil(RValue<Float4> x); RValue<Float4> Ceil(RValue<Float4> x);
template<class T> template<class T>
class Pointer : public Variable<Pointer<T> > class Pointer : public Variable<Pointer<T>>
{ {
public: public:
template<class S> template<class S>
Pointer(RValue<Pointer<S> > pointerS, int alignment = 1) : alignment(alignment) Pointer(RValue<Pointer<S>> pointerS, int alignment = 1) : alignment(alignment)
{ {
llvm::Value *pointerT = Nucleus::createBitCast(pointerS.value, Nucleus::getPointerType(T::getType())); llvm::Value *pointerT = Nucleus::createBitCast(pointerS.value, Nucleus::getPointerType(T::getType()));
LValue::storeValue(pointerT); LValue::storeValue(pointerT);
...@@ -2411,17 +2419,17 @@ namespace sw ...@@ -2411,17 +2419,17 @@ namespace sw
LValue::storeValue(pointerT); LValue::storeValue(pointerT);
} }
explicit Pointer(llvm::Argument *argument); Pointer(Argument<Pointer<T>> argument);
explicit Pointer(const void *external); explicit Pointer(const void *external);
Pointer(); Pointer();
Pointer(RValue<Pointer<T> > rhs); Pointer(RValue<Pointer<T>> rhs);
Pointer(const Pointer<T> &rhs); Pointer(const Pointer<T> &rhs);
Pointer(const Reference<Pointer<T> > &rhs); Pointer(const Reference<Pointer<T>> &rhs);
RValue<Pointer<T> > operator=(RValue<Pointer<T> > rhs) const; RValue<Pointer<T>> operator=(RValue<Pointer<T>> rhs) const;
RValue<Pointer<T> > operator=(const Pointer<T> &rhs) const; RValue<Pointer<T>> operator=(const Pointer<T> &rhs) const;
RValue<Pointer<T> > operator=(const Reference<Pointer<T> > &rhs) const; RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs) const;
Reference<T> operator*(); Reference<T> operator*();
...@@ -2431,19 +2439,19 @@ namespace sw ...@@ -2431,19 +2439,19 @@ namespace sw
const int alignment; const int alignment;
}; };
RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, int offset); RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset);
RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<Int> offset); RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
RValue<Pointer<Byte> > operator+(RValue<Pointer<Byte> > lhs, RValue<UInt> offset); RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, int offset); RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, int offset);
RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<Int> offset); RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<Int> offset);
RValue<Pointer<Byte> > operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset); RValue<Pointer<Byte>> operator+=(const Pointer<Byte> &lhs, RValue<UInt> offset);
RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, int offset); RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, int offset);
RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<Int> offset); RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<Int> offset);
RValue<Pointer<Byte> > operator-(RValue<Pointer<Byte> > lhs, RValue<UInt> offset); RValue<Pointer<Byte>> operator-(RValue<Pointer<Byte>> lhs, RValue<UInt> offset);
RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, int offset); RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, int offset);
RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<Int> offset); RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<Int> offset);
RValue<Pointer<Byte> > operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset); RValue<Pointer<Byte>> operator-=(const Pointer<Byte> &lhs, RValue<UInt> offset);
template<class T, int S = 1> template<class T, int S = 1>
class Array : public Variable<T> class Array : public Variable<T>
...@@ -2456,9 +2464,9 @@ namespace sw ...@@ -2456,9 +2464,9 @@ namespace sw
Reference<T> operator[](RValue<UInt> index); Reference<T> operator[](RValue<UInt> index);
}; };
// RValue<Array<T> > operator++(const Array<T> &val, int); // Post-increment // RValue<Array<T>> operator++(const Array<T> &val, int); // Post-increment
// const Array<T> &operator++(const Array<T> &val); // Pre-increment // const Array<T> &operator++(const Array<T> &val); // Pre-increment
// RValue<Array<T> > operator--(const Array<T> &val, int); // Post-decrement // RValue<Array<T>> operator--(const Array<T> &val, int); // Post-decrement
// const Array<T> &operator--(const Array<T> &val); // Pre-decrement // const Array<T> &operator--(const Array<T> &val); // Pre-decrement
llvm::BasicBlock *beginLoop(); llvm::BasicBlock *beginLoop();
...@@ -2473,7 +2481,22 @@ namespace sw ...@@ -2473,7 +2481,22 @@ namespace sw
void Return(const Pointer<T> &ret); void Return(const Pointer<T> &ret);
template<class T> template<class T>
void Return(RValue<Pointer<T> > ret); void Return(RValue<Pointer<T>> ret);
template<unsigned int index, typename... Arguments>
struct ArgI;
template<typename Arg0, typename... Arguments>
struct ArgI<0, Arg0, Arguments...>
{
typedef Arg0 Type;
};
template<unsigned int index, typename Arg0, typename... Arguments>
struct ArgI<index, Arg0, Arguments...>
{
typedef typename ArgI<index - 1, Arguments...>::Type Type;
};
// Generic template, leave undefined! // Generic template, leave undefined!
template<typename FunctionType> template<typename FunctionType>
...@@ -2488,7 +2511,12 @@ namespace sw ...@@ -2488,7 +2511,12 @@ namespace sw
virtual ~Function(); virtual ~Function();
llvm::Argument *arg(int index); template<int index>
Argument<typename ArgI<index, Arguments...>::Type> Arg() const
{
llvm::Value *arg = Nucleus::getArgument(function, index);
return Argument<typename ArgI<index, Arguments...>::Type>(arg);
}
Routine *operator()(const wchar_t *name, ...); Routine *operator()(const wchar_t *name, ...);
...@@ -2498,6 +2526,12 @@ namespace sw ...@@ -2498,6 +2526,12 @@ namespace sw
std::vector<llvm::Type*> arguments; std::vector<llvm::Type*> arguments;
}; };
template<int index, typename Return, typename... Arguments>
Argument<typename ArgI<index, Arguments...>::Type> Arg(Function<Return(Arguments...)> &function)
{
return Argument<typename ArgI<index, Arguments...>::Type>(function.arg(index));
}
RValue<Long> Ticks(); RValue<Long> Ticks();
} }
...@@ -2509,9 +2543,9 @@ namespace sw ...@@ -2509,9 +2543,9 @@ namespace sw
} }
template<class T> template<class T>
RValue<Pointer<T> > Variable<T>::operator&() RValue<Pointer<T>> Variable<T>::operator&()
{ {
return RValue<Pointer<T> >(LValue::address); return RValue<Pointer<T>>(LValue::address);
} }
template<class T> template<class T>
...@@ -2740,9 +2774,9 @@ namespace sw ...@@ -2740,9 +2774,9 @@ namespace sw
} }
template<class T> template<class T>
Pointer<T>::Pointer(llvm::Argument *argument) : alignment(1) Pointer<T>::Pointer(Argument<Pointer<T>> argument) : alignment(1)
{ {
LValue::storeValue((llvm::Value*)argument); LValue::storeValue(argument.value);
} }
template<class T> template<class T>
...@@ -2767,7 +2801,7 @@ namespace sw ...@@ -2767,7 +2801,7 @@ namespace sw
} }
template<class T> template<class T>
Pointer<T>::Pointer(RValue<Pointer<T> > rhs) : alignment(1) Pointer<T>::Pointer(RValue<Pointer<T>> rhs) : alignment(1)
{ {
LValue::storeValue(rhs.value); LValue::storeValue(rhs.value);
} }
...@@ -2780,14 +2814,14 @@ namespace sw ...@@ -2780,14 +2814,14 @@ namespace sw
} }
template<class T> template<class T>
Pointer<T>::Pointer(const Reference<Pointer<T> > &rhs) : alignment(rhs.getAlignment()) Pointer<T>::Pointer(const Reference<Pointer<T>> &rhs) : alignment(rhs.getAlignment())
{ {
llvm::Value *value = rhs.loadValue(); llvm::Value *value = rhs.loadValue();
LValue::storeValue(value); LValue::storeValue(value);
} }
template<class T> template<class T>
RValue<Pointer<T> > Pointer<T>::operator=(RValue<Pointer<T> > rhs) const RValue<Pointer<T>> Pointer<T>::operator=(RValue<Pointer<T>> rhs) const
{ {
LValue::storeValue(rhs.value); LValue::storeValue(rhs.value);
...@@ -2795,21 +2829,21 @@ namespace sw ...@@ -2795,21 +2829,21 @@ namespace sw
} }
template<class T> template<class T>
RValue<Pointer<T> > Pointer<T>::operator=(const Pointer<T> &rhs) const RValue<Pointer<T>> Pointer<T>::operator=(const Pointer<T> &rhs) const
{ {
llvm::Value *value = rhs.loadValue(); llvm::Value *value = rhs.loadValue();
LValue::storeValue(value); LValue::storeValue(value);
return RValue<Pointer<T> >(value); return RValue<Pointer<T>>(value);
} }
template<class T> template<class T>
RValue<Pointer<T> > Pointer<T>::operator=(const Reference<Pointer<T> > &rhs) const RValue<Pointer<T>> Pointer<T>::operator=(const Reference<Pointer<T>> &rhs) const
{ {
llvm::Value *value = rhs.loadValue(); llvm::Value *value = rhs.loadValue();
LValue::storeValue(value); LValue::storeValue(value);
return RValue<Pointer<T> >(value); return RValue<Pointer<T>>(value);
} }
template<class T> template<class T>
...@@ -2854,7 +2888,7 @@ namespace sw ...@@ -2854,7 +2888,7 @@ namespace sw
} }
// template<class T> // template<class T>
// RValue<Array<T> > operator++(const Array<T> &val, int) // RValue<Array<T>> operator++(const Array<T> &val, int)
// { // {
// // FIXME: Requires storing the address of the array // // FIXME: Requires storing the address of the array
// } // }
...@@ -2866,7 +2900,7 @@ namespace sw ...@@ -2866,7 +2900,7 @@ namespace sw
// } // }
// template<class T> // template<class T>
// RValue<Array<T> > operator--(const Array<T> &val, int) // RValue<Array<T>> operator--(const Array<T> &val, int)
// { // {
// // FIXME: Requires storing the address of the array // // FIXME: Requires storing the address of the array
// } // }
...@@ -2916,7 +2950,7 @@ namespace sw ...@@ -2916,7 +2950,7 @@ namespace sw
} }
template<class T> template<class T>
void Return(RValue<Pointer<T> > ret) void Return(RValue<Pointer<T>> ret)
{ {
Nucleus::createRet(ret.value); Nucleus::createRet(ret.value);
Nucleus::setInsertBlock(Nucleus::createBasicBlock()); Nucleus::setInsertBlock(Nucleus::createBasicBlock());
...@@ -2931,7 +2965,7 @@ namespace sw ...@@ -2931,7 +2965,7 @@ namespace sw
for(llvm::Type *type : types) for(llvm::Type *type : types)
{ {
arguments.push_back(type); arguments.push_back(type);
} }
function = Nucleus::createFunction(Return::getType(), arguments); function = Nucleus::createFunction(Return::getType(), arguments);
Nucleus::setFunction(function); Nucleus::setFunction(function);
...@@ -2944,12 +2978,6 @@ namespace sw ...@@ -2944,12 +2978,6 @@ namespace sw
} }
template<typename Return, typename... Arguments> template<typename Return, typename... Arguments>
llvm::Argument *Function<Return(Arguments...)>::arg(int index)
{
return Nucleus::getArgument(function, index);
}
template<typename Return, typename... Arguments>
Routine *Function<Return(Arguments...)>::operator()(const wchar_t *name, ...) Routine *Function<Return(Arguments...)>::operator()(const wchar_t *name, ...)
{ {
wchar_t fullName[1024 + 1]; wchar_t fullName[1024 + 1];
......
...@@ -589,7 +589,7 @@ namespace sw ...@@ -589,7 +589,7 @@ namespace sw
{ {
unsigned short mask = (writeB ? 0x001F : 0x0000) | (writeG ? 0x07E0 : 0x0000) | (writeR ? 0xF800 : 0x0000); unsigned short mask = (writeB ? 0x001F : 0x0000) | (writeG ? 0x07E0 : 0x0000) | (writeR ? 0xF800 : 0x0000);
unsigned short unmask = ~mask; unsigned short unmask = ~mask;
*Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) | *Pointer<UShort>(element) = (*Pointer<UShort>(element) & UShort(unmask)) |
(UShort(RoundInt(Float(c.z)) | (UShort(RoundInt(Float(c.z)) |
(RoundInt(Float(c.y)) << Int(5)) | (RoundInt(Float(c.y)) << Int(5)) |
(RoundInt(Float(c.x)) << Int(11))) & UShort(mask)); (RoundInt(Float(c.x)) << Int(11))) & UShort(mask));
...@@ -966,10 +966,10 @@ namespace sw ...@@ -966,10 +966,10 @@ namespace sw
{ {
Function<Void(Pointer<Byte>)> function; Function<Void(Pointer<Byte>)> function;
{ {
Pointer<Byte> blit(function.arg(0)); Pointer<Byte> blit(function.Arg<0>());
Pointer<Byte> source = *Pointer<Pointer<Byte> >(blit + OFFSET(BlitData,source)); Pointer<Byte> source = *Pointer<Pointer<Byte>>(blit + OFFSET(BlitData,source));
Pointer<Byte> dest = *Pointer<Pointer<Byte> >(blit + OFFSET(BlitData,dest)); Pointer<Byte> dest = *Pointer<Pointer<Byte>>(blit + OFFSET(BlitData,dest));
Int sPitchB = *Pointer<Int>(blit + OFFSET(BlitData,sPitchB)); Int sPitchB = *Pointer<Int>(blit + OFFSET(BlitData,sPitchB));
Int dPitchB = *Pointer<Int>(blit + OFFSET(BlitData,dPitchB)); Int dPitchB = *Pointer<Int>(blit + OFFSET(BlitData,dPitchB));
...@@ -1147,7 +1147,7 @@ namespace sw ...@@ -1147,7 +1147,7 @@ namespace sw
criticalSection.lock(); criticalSection.lock();
Routine *blitRoutine = blitCache->query(state); Routine *blitRoutine = blitCache->query(state);
if(!blitRoutine) if(!blitRoutine)
{ {
blitRoutine = generate(state); blitRoutine = generate(state);
...@@ -1179,7 +1179,7 @@ namespace sw ...@@ -1179,7 +1179,7 @@ namespace sw
data.h = 1.0f / (dRect.y1 - dRect.y0) * (sRect.y1 - sRect.y0); data.h = 1.0f / (dRect.y1 - dRect.y0) * (sRect.y1 - sRect.y0);
data.x0 = (float)sRect.x0 + 0.5f * data.w; data.x0 = (float)sRect.x0 + 0.5f * data.w;
data.y0 = (float)sRect.y0 + 0.5f * data.h; data.y0 = (float)sRect.y0 + 0.5f * data.h;
data.x0d = dRect.x0; data.x0d = dRect.x0;
data.x1d = dRect.x1; data.x1d = dRect.x1;
data.y0d = dRect.y0; data.y0d = dRect.y0;
......
...@@ -53,16 +53,16 @@ namespace sw ...@@ -53,16 +53,16 @@ namespace sw
Long pixelTime = Ticks(); Long pixelTime = Ticks();
#endif #endif
Pointer<Byte> primitive(function.arg(0)); Pointer<Byte> primitive(function.Arg<0>());
Int count(function.arg(1)); Int count(function.Arg<1>());
Int cluster(function.arg(2)); Int cluster(function.Arg<2>());
Pointer<Byte> data(function.arg(3)); Pointer<Byte> data(function.Arg<3>());
Registers& r = *createRegisters(shader); Registers& r = *createRegisters(shader);
r.constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants)); r.constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants));
r.cluster = cluster; r.cluster = cluster;
r.data = data; r.data = data;
Do Do
{ {
r.primitive = primitive; r.primitive = primitive;
...@@ -134,20 +134,20 @@ namespace sw ...@@ -134,20 +134,20 @@ namespace sw
} }
Int y = yMin; Int y = yMin;
Do Do
{ {
Int x0a = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span))); Int x0a = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span)));
Int x0b = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span))); Int x0b = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span)));
Int x0 = Min(x0a, x0b); Int x0 = Min(x0a, x0b);
for(unsigned int q = 1; q < state.multiSample; q++) for(unsigned int q = 1; q < state.multiSample; q++)
{ {
x0a = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span))); x0a = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 0) * sizeof(Primitive::Span)));
x0b = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span))); x0b = Int(*Pointer<Short>(r.primitive + q * sizeof(Primitive) + OFFSET(Primitive,outline->left) + (y + 1) * sizeof(Primitive::Span)));
x0 = Min(x0, Min(x0a, x0b)); x0 = Min(x0, Min(x0a, x0b));
} }
x0 &= 0xFFFFFFFE; x0 &= 0xFFFFFFFE;
Int x1a = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span))); Int x1a = Int(*Pointer<Short>(r.primitive + OFFSET(Primitive,outline->right) + (y + 0) * sizeof(Primitive::Span)));
...@@ -193,7 +193,7 @@ namespace sw ...@@ -193,7 +193,7 @@ namespace sw
pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB)); pitch = *Pointer<Int>(r.data + OFFSET(DrawData,depthPitchB));
} }
else else
{ {
buffer = zBuffer + 8 * x0; buffer = zBuffer + 8 * x0;
} }
...@@ -202,7 +202,7 @@ namespace sw ...@@ -202,7 +202,7 @@ namespace sw
Float4 z = interpolate(xxxx, r.Dz[0], z, r.primitive + OFFSET(Primitive,z), false, false); Float4 z = interpolate(xxxx, r.Dz[0], z, r.primitive + OFFSET(Primitive,z), false, false);
Float4 zValue; Float4 zValue;
if(!state.quadLayoutDepthBuffer) if(!state.quadLayoutDepthBuffer)
{ {
// FIXME: Properly optimizes? // FIXME: Properly optimizes?
......
...@@ -36,10 +36,10 @@ namespace sw ...@@ -36,10 +36,10 @@ namespace sw
{ {
Function<Bool(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function; Function<Bool(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> primitive(function.arg(0)); Pointer<Byte> primitive(function.Arg<0>());
Pointer<Byte> tri(function.arg(1)); Pointer<Byte> tri(function.Arg<1>());
Pointer<Byte> polygon(function.arg(2)); Pointer<Byte> polygon(function.Arg<2>());
Pointer<Byte> data(function.arg(3)); Pointer<Byte> data(function.Arg<3>());
Pointer<Byte> constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants)); Pointer<Byte> constants = *Pointer<Pointer<Byte> >(data + OFFSET(DrawData,constants));
......
...@@ -36,10 +36,10 @@ namespace sw ...@@ -36,10 +36,10 @@ namespace sw
{ {
Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function; Function<Void(Pointer<Byte>, Pointer<Byte>, Pointer<Byte>, Pointer<Byte>)> function;
{ {
Pointer<Byte> vertex(function.arg(0)); Pointer<Byte> vertex(function.Arg<0>());
Pointer<Byte> batch(function.arg(1)); Pointer<Byte> batch(function.Arg<1>());
Pointer<Byte> task(function.arg(2)); Pointer<Byte> task(function.Arg<2>());
Pointer<Byte> data(function.arg(3)); Pointer<Byte> data(function.Arg<3>());
const bool texldl = state.shaderContainsTexldl; const bool texldl = state.shaderContainsTexldl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment