Commit e95d534a by Nicolas Capens

Refactor vector operations.

Subzero does not know the element types of vectors, so pass it as an argument. Also deprecate createSwizzle() and createMask() from Nucleus since we only need Float4 Swizzle(). Bug swiftshader:15 Change-Id: I38b630f48f8f43e1248338d564a7406d7c8cd5ef Reviewed-on: https://swiftshader-review.googlesource.com/7395Tested-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 8820f64b
...@@ -654,8 +654,9 @@ namespace sw ...@@ -654,8 +654,9 @@ namespace sw
return V(::builder->CreateFCmpULE(lhs, rhs)); return V(::builder->CreateFCmpULE(lhs, rhs));
} }
Value *Nucleus::createExtractElement(Value *vector, int index) Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
{ {
assert(vector->getType()->getContainedType(0) == type);
return V(::builder->CreateExtractElement(vector, createConstantInt(index))); return V(::builder->CreateExtractElement(vector, createConstantInt(index)));
} }
...@@ -689,7 +690,7 @@ namespace sw ...@@ -689,7 +690,7 @@ namespace sw
::builder->CreateUnreachable(); ::builder->CreateUnreachable();
} }
Value *Nucleus::createSwizzle(Value *val, unsigned char select) static Value *createSwizzle4(Value *val, unsigned char select)
{ {
Constant *swizzle[4]; Constant *swizzle[4];
swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03); swizzle[0] = Nucleus::createConstantInt((select >> 0) & 0x03);
...@@ -702,7 +703,7 @@ namespace sw ...@@ -702,7 +703,7 @@ namespace sw
return shuffle; return shuffle;
} }
Value *Nucleus::createMask(Value *lhs, Value *rhs, unsigned char select) static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
{ {
bool mask[4] = {false, false, false, false}; bool mask[4] = {false, false, false, false};
...@@ -2684,7 +2685,7 @@ namespace sw ...@@ -2684,7 +2685,7 @@ namespace sw
Value *shuffle1 = Nucleus::createShuffleVector(short8, V(UndefValue::get(Short8::getType())), V(Nucleus::createConstantVector(pshuflw, 8))); Value *shuffle1 = Nucleus::createShuffleVector(short8, V(UndefValue::get(Short8::getType())), V(Nucleus::createConstantVector(pshuflw, 8)));
Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, V(UndefValue::get(Short8::getType())), V(Nucleus::createConstantVector(pshufhw, 8))); Value *shuffle2 = Nucleus::createShuffleVector(shuffle1, V(UndefValue::get(Short8::getType())), V(Nucleus::createConstantVector(pshufhw, 8)));
Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType()); Value *int4 = Nucleus::createBitCast(shuffle2, Int4::getType());
packed = Nucleus::createSwizzle(int4, 0x88); packed = createSwizzle4(int4, 0x88);
} }
else else
{ {
...@@ -3148,7 +3149,7 @@ namespace sw ...@@ -3148,7 +3149,7 @@ namespace sw
} }
else else
{ {
return RValue<Short4>(Nucleus::createSwizzle(x.value, select)); return RValue<Short4>(createSwizzle4(x.value, select));
} }
} }
...@@ -3172,7 +3173,7 @@ namespace sw ...@@ -3172,7 +3173,7 @@ namespace sw
} }
else else
{ {
return RValue<Short>(Nucleus::createExtractElement(val.value, i)); return RValue<Short>(Nucleus::createExtractElement(val.value, Short::getType(), i));
} }
} }
...@@ -4601,7 +4602,7 @@ namespace sw ...@@ -4601,7 +4602,7 @@ namespace sw
Int2::Int2(RValue<Int4> cast) Int2::Int2(RValue<Int4> cast)
{ {
Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType()); Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType());
Value *element = Nucleus::createExtractElement(long2, 0); Value *element = Nucleus::createExtractElement(long2, Long::getType(), 0);
Value *int2 = Nucleus::createBitCast(element, Int2::getType()); Value *int2 = Nucleus::createBitCast(element, Int2::getType());
storeValue(int2); storeValue(int2);
...@@ -4916,13 +4917,13 @@ namespace sw ...@@ -4916,13 +4917,13 @@ namespace sw
{ {
if(false) // FIXME: LLVM does not generate optimal code if(false) // FIXME: LLVM does not generate optimal code
{ {
return RValue<Int>(Nucleus::createExtractElement(val.value, i)); return RValue<Int>(Nucleus::createExtractElement(val.value, Int::getType(), i));
} }
else else
{ {
if(i == 0) if(i == 0)
{ {
return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, T(VectorType::get(Int::getType(), 2))), 0)); return RValue<Int>(Nucleus::createExtractElement(Nucleus::createBitCast(val.value, T(VectorType::get(Int::getType(), 2))), Int::getType(), 0));
} }
else else
{ {
...@@ -5750,7 +5751,7 @@ namespace sw ...@@ -5750,7 +5751,7 @@ namespace sw
RValue<Int> Extract(RValue<Int4> x, int i) RValue<Int> Extract(RValue<Int4> x, int i)
{ {
return RValue<Int>(Nucleus::createExtractElement(x.value, i)); return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
} }
RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
...@@ -5765,7 +5766,7 @@ namespace sw ...@@ -5765,7 +5766,7 @@ namespace sw
RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
{ {
return RValue<Int4>(Nucleus::createSwizzle(x.value, select)); return RValue<Int4>(createSwizzle4(x.value, select));
} }
Type *Int4::getType() Type *Int4::getType()
...@@ -6360,7 +6361,7 @@ namespace sw ...@@ -6360,7 +6361,7 @@ namespace sw
// xyzw.parent = this; // xyzw.parent = this;
Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType()); Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
Value *int64 = Nucleus::createExtractElement(int64x2, 0); Value *int64 = Nucleus::createExtractElement(int64x2, Long::getType(), 0);
Value *float2 = Nucleus::createBitCast(int64, Float2::getType()); Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
storeValue(float2); storeValue(float2);
...@@ -6726,12 +6727,12 @@ namespace sw ...@@ -6726,12 +6727,12 @@ namespace sw
RValue<Float> Extract(RValue<Float4> x, int i) RValue<Float> Extract(RValue<Float4> x, int i)
{ {
return RValue<Float>(Nucleus::createExtractElement(x.value, i)); return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
} }
RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
{ {
return RValue<Float4>(Nucleus::createSwizzle(x.value, select)); return RValue<Float4>(createSwizzle4(x.value, select));
} }
RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
...@@ -6770,7 +6771,7 @@ namespace sw ...@@ -6770,7 +6771,7 @@ namespace sw
RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
{ {
Value *vector = lhs.loadValue(); Value *vector = lhs.loadValue();
Value *shuffle = Nucleus::createMask(vector, rhs.value, select); Value *shuffle = createMask4(vector, rhs.value, select);
lhs.storeValue(shuffle); lhs.storeValue(shuffle);
return RValue<Float4>(shuffle); return RValue<Float4>(shuffle);
...@@ -7050,7 +7051,7 @@ namespace sw ...@@ -7050,7 +7051,7 @@ namespace sw
Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0); Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0);
return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rcpss, vector)), 0)); return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rcpss, vector)), Float::getType(), 0));
} }
RValue<Float> sqrtss(RValue<Float> val) RValue<Float> sqrtss(RValue<Float> val)
...@@ -7059,7 +7060,7 @@ namespace sw ...@@ -7059,7 +7060,7 @@ namespace sw
Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0); Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0);
return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(sqrtss, vector)), 0)); return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(sqrtss, vector)), Float::getType(), 0));
} }
RValue<Float> rsqrtss(RValue<Float> val) RValue<Float> rsqrtss(RValue<Float> val)
...@@ -7068,7 +7069,7 @@ namespace sw ...@@ -7068,7 +7069,7 @@ namespace sw
Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0); Value *vector = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), val.value, 0);
return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rsqrtss, vector)), 0)); return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall(rsqrtss, vector)), Float::getType(), 0));
} }
RValue<Float4> rcpps(RValue<Float4> val) RValue<Float4> rcpps(RValue<Float4> val)
...@@ -7113,7 +7114,7 @@ namespace sw ...@@ -7113,7 +7114,7 @@ namespace sw
Value *undef = V(UndefValue::get(Float4::getType())); Value *undef = V(UndefValue::get(Float4::getType()));
Value *vector = Nucleus::createInsertElement(undef, val.value, 0); Value *vector = Nucleus::createInsertElement(undef, val.value, 0);
return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(roundss, undef, vector, V(Nucleus::createConstantInt(imm)))), 0)); return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(roundss, undef, vector, V(Nucleus::createConstantInt(imm)))), Float::getType(), 0));
} }
RValue<Float> floorss(RValue<Float> val) RValue<Float> floorss(RValue<Float> val)
...@@ -7197,7 +7198,7 @@ namespace sw ...@@ -7197,7 +7198,7 @@ namespace sw
Value *vector1 = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), x.value, 0); Value *vector1 = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), x.value, 0);
Value *vector2 = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), y.value, 0); Value *vector2 = Nucleus::createInsertElement(V(UndefValue::get(Float4::getType())), y.value, 0);
return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(cmpss, vector1, vector2, V(Nucleus::createConstantByte(imm)))), 0)); return RValue<Float>(Nucleus::createExtractElement(V(::builder->CreateCall3(cmpss, vector1, vector2, V(Nucleus::createConstantByte(imm)))), Float::getType(), 0));
} }
RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y) RValue<Float> cmpeqss(RValue<Float> x, RValue<Float> y)
......
...@@ -143,7 +143,7 @@ namespace sw ...@@ -143,7 +143,7 @@ namespace sw
static Value *createFCmpUNE(Value *lhs, Value *rhs); static Value *createFCmpUNE(Value *lhs, Value *rhs);
// Vector instructions // Vector instructions
static Value *createExtractElement(Value *vector, int index); static Value *createExtractElement(Value *vector, Type *type, int index);
static Value *createInsertElement(Value *vector, Value *element, int index); static Value *createInsertElement(Value *vector, Value *element, int index);
static Value *createShuffleVector(Value *V1, Value *V2, Value *mask); static Value *createShuffleVector(Value *V1, Value *V2, Value *mask);
...@@ -153,10 +153,6 @@ namespace sw ...@@ -153,10 +153,6 @@ namespace sw
static void addSwitchCase(Value *Switch, int Case, BasicBlock *Branch); static void addSwitchCase(Value *Switch, int Case, BasicBlock *Branch);
static void createUnreachable(); static void createUnreachable();
// Derived instructions
static Value *createSwizzle(Value *val, unsigned char select);
static Value *createMask(Value *lhs, Value *rhs, unsigned char select);
// Constant values // Constant values
static Constant *createNullValue(Type *Ty); static Constant *createNullValue(Type *Ty);
static Constant *createConstantInt(int64_t i); static Constant *createConstantInt(int64_t i);
......
...@@ -2468,7 +2468,7 @@ namespace sw ...@@ -2468,7 +2468,7 @@ namespace sw
{ {
Value *vector = parent->loadValue(); Value *vector = parent->loadValue();
return RValue<Float4>(Nucleus::createSwizzle(vector, T)); return Swizzle(RValue<Float4>(vector), T);
} }
template<int T> template<int T>
...@@ -2476,7 +2476,7 @@ namespace sw ...@@ -2476,7 +2476,7 @@ namespace sw
{ {
Value *vector = parent->loadValue(); Value *vector = parent->loadValue();
return RValue<Float4>(Nucleus::createSwizzle(vector, T)); return Swizzle(RValue<Float4>(vector), T);
} }
template<int T> template<int T>
...@@ -2484,7 +2484,7 @@ namespace sw ...@@ -2484,7 +2484,7 @@ namespace sw
{ {
Value *vector = parent->loadValue(); Value *vector = parent->loadValue();
return RValue<Float4>(Nucleus::createSwizzle(vector, T)); return Swizzle(RValue<Float4>(vector), T);
} }
template<int T> template<int T>
...@@ -2510,7 +2510,7 @@ namespace sw ...@@ -2510,7 +2510,7 @@ namespace sw
{ {
Value *vector = parent->loadValue(); Value *vector = parent->loadValue();
return RValue<Float4>(Nucleus::createSwizzle(vector, T)); return Swizzle(RValue<Float4>(vector), T);
} }
template<int T> template<int T>
...@@ -2536,7 +2536,7 @@ namespace sw ...@@ -2536,7 +2536,7 @@ namespace sw
{ {
Value *vector = parent->loadValue(); Value *vector = parent->loadValue();
return RValue<Float4>(Nucleus::createSwizzle(vector, T)); return Swizzle(RValue<Float4>(vector), T);
} }
template<int T> template<int T>
......
...@@ -693,7 +693,7 @@ namespace sw ...@@ -693,7 +693,7 @@ namespace sw
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Value *Nucleus::createExtractElement(Value *vector, int index) Value *Nucleus::createExtractElement(Value *vector, Type *type, int index)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
...@@ -728,12 +728,12 @@ namespace sw ...@@ -728,12 +728,12 @@ namespace sw
assert(false && "UNIMPLEMENTED"); assert(false && "UNIMPLEMENTED");
} }
Value *Nucleus::createSwizzle(Value *val, unsigned char select) static Value *createSwizzle4(Value *val, unsigned char select)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
Value *Nucleus::createMask(Value *lhs, Value *rhs, unsigned char select) static Value *createMask4(Value *lhs, Value *rhs, unsigned char select)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(false && "UNIMPLEMENTED"); return nullptr;
} }
...@@ -3951,7 +3951,7 @@ namespace sw ...@@ -3951,7 +3951,7 @@ namespace sw
Int2::Int2(RValue<Int4> cast) Int2::Int2(RValue<Int4> cast)
{ {
Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType()); Value *long2 = Nucleus::createBitCast(cast.value, Long2::getType());
Value *element = Nucleus::createExtractElement(long2, 0); Value *element = Nucleus::createExtractElement(long2, Long2::getType(), 0);
Value *int2 = Nucleus::createBitCast(element, Int2::getType()); Value *int2 = Nucleus::createBitCast(element, Int2::getType());
storeValue(int2); storeValue(int2);
...@@ -4717,7 +4717,7 @@ namespace sw ...@@ -4717,7 +4717,7 @@ namespace sw
RValue<Int> Extract(RValue<Int4> x, int i) RValue<Int> Extract(RValue<Int4> x, int i)
{ {
return RValue<Int>(Nucleus::createExtractElement(x.value, i)); return RValue<Int>(Nucleus::createExtractElement(x.value, Int::getType(), i));
} }
RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i) RValue<Int4> Insert(RValue<Int4> x, RValue<Int> element, int i)
...@@ -4732,7 +4732,7 @@ namespace sw ...@@ -4732,7 +4732,7 @@ namespace sw
RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select) RValue<Int4> Swizzle(RValue<Int4> x, unsigned char select)
{ {
return RValue<Int4>(Nucleus::createSwizzle(x.value, select)); return RValue<Int4>(createSwizzle4(x.value, select));
} }
Type *Int4::getType() Type *Int4::getType()
...@@ -5235,7 +5235,7 @@ namespace sw ...@@ -5235,7 +5235,7 @@ namespace sw
// xyzw.parent = this; // xyzw.parent = this;
Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType()); Value *int64x2 = Nucleus::createBitCast(cast.value, Long2::getType());
Value *int64 = Nucleus::createExtractElement(int64x2, 0); Value *int64 = Nucleus::createExtractElement(int64x2, Long::getType(), 0);
Value *float2 = Nucleus::createBitCast(int64, Float2::getType()); Value *float2 = Nucleus::createBitCast(int64, Float2::getType());
storeValue(float2); storeValue(float2);
...@@ -5521,12 +5521,12 @@ namespace sw ...@@ -5521,12 +5521,12 @@ namespace sw
RValue<Float> Extract(RValue<Float4> x, int i) RValue<Float> Extract(RValue<Float4> x, int i)
{ {
return RValue<Float>(Nucleus::createExtractElement(x.value, i)); return RValue<Float>(Nucleus::createExtractElement(x.value, Float::getType(), i));
} }
RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select) RValue<Float4> Swizzle(RValue<Float4> x, unsigned char select)
{ {
return RValue<Float4>(Nucleus::createSwizzle(x.value, select)); return RValue<Float4>(createSwizzle4(x.value, select));
} }
RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm) RValue<Float4> ShuffleLowHigh(RValue<Float4> x, RValue<Float4> y, unsigned char imm)
...@@ -5547,7 +5547,7 @@ namespace sw ...@@ -5547,7 +5547,7 @@ namespace sw
RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select) RValue<Float4> Mask(Float4 &lhs, RValue<Float4> rhs, unsigned char select)
{ {
Value *vector = lhs.loadValue(); Value *vector = lhs.loadValue();
Value *shuffle = Nucleus::createMask(vector, rhs.value, select); Value *shuffle = createMask4(vector, rhs.value, select);
lhs.storeValue(shuffle); lhs.storeValue(shuffle);
return RValue<Float4>(shuffle); return RValue<Float4>(shuffle);
......
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