Commit 584088c0 by Nicolas Capens

Fix array addressing of emulated vector types.

operator[] on a pointer was using the vector register size (16 bytes) instead of the size of the (emulated) vector type. Change-Id: Ice8677b41a3af81176fe9495fd02ede9f8b0482f Reviewed-on: https://swiftshader-review.googlesource.com/8569Tested-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 29eee717
...@@ -140,6 +140,25 @@ namespace sw ...@@ -140,6 +140,25 @@ namespace sw
return reinterpret_cast<BasicBlock*>(b); return reinterpret_cast<BasicBlock*>(b);
} }
static size_t typeSize(Type *type)
{
if(reinterpret_cast<std::intptr_t>(type) & EmulatedBits)
{
switch(reinterpret_cast<std::intptr_t>(type))
{
case Type_v2i32: return 8;
case Type_v4i16: return 8;
case Type_v2i16: return 4;
case Type_v8i8: return 8;
case Type_v4i8: return 4;
case Type_v2f32: return 8;
default: assert(false);
}
}
return Ice::typeWidthInBytes(T(type));
}
Optimization optimization[10] = {InstructionCombining, Disabled}; Optimization optimization[10] = {InstructionCombining, Disabled};
using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type; using ElfHeader = std::conditional<sizeof(void*) == 8, Elf64_Ehdr, Elf32_Ehdr>::type;
...@@ -744,34 +763,12 @@ namespace sw ...@@ -744,34 +763,12 @@ namespace sw
if(valueType & EmulatedBits) if(valueType & EmulatedBits)
{ {
switch(valueType) const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
{ auto target = ::context->getConstantUndef(Ice::IceType_i32);
case Type_v4i8: auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
case Type_v2i16: load->addArg(ptr);
{ load->addArg(::context->getConstantInt32(typeSize(type)));
const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F}; ::basicBlock->appendInst(load);
auto target = ::context->getConstantUndef(Ice::IceType_i32);
auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
load->addArg(ptr);
load->addArg(::context->getConstantInt32(4));
::basicBlock->appendInst(load);
}
break;
case Type_v2i32:
case Type_v8i8:
case Type_v4i16:
case Type_v2f32:
{
const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::LoadSubVector, Ice::Intrinsics::SideEffects_F, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_F};
auto target = ::context->getConstantUndef(Ice::IceType_i32);
auto load = Ice::InstIntrinsicCall::create(::function, 2, result, target, intrinsic);
load->addArg(ptr);
load->addArg(::context->getConstantInt32(8));
::basicBlock->appendInst(load);
}
break;
default: assert(false && "UNIMPLEMENTED");
}
} }
else else
{ {
...@@ -788,36 +785,13 @@ namespace sw ...@@ -788,36 +785,13 @@ namespace sw
if(valueType & EmulatedBits) if(valueType & EmulatedBits)
{ {
switch(valueType) const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
{ auto target = ::context->getConstantUndef(Ice::IceType_i32);
case Type_v4i8: auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
case Type_v2i16: store->addArg(value);
{ store->addArg(ptr);
const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T}; store->addArg(::context->getConstantInt32(typeSize(type)));
auto target = ::context->getConstantUndef(Ice::IceType_i32); ::basicBlock->appendInst(store);
auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
store->addArg(value);
store->addArg(ptr);
store->addArg(::context->getConstantInt32(4));
::basicBlock->appendInst(store);
}
break;
case Type_v2i32:
case Type_v8i8:
case Type_v4i16:
case Type_v2f32:
{
const Ice::Intrinsics::IntrinsicInfo intrinsic = {Ice::Intrinsics::StoreSubVector, Ice::Intrinsics::SideEffects_T, Ice::Intrinsics::ReturnsTwice_F, Ice::Intrinsics::MemoryWrite_T};
auto target = ::context->getConstantUndef(Ice::IceType_i32);
auto store = Ice::InstIntrinsicCall::create(::function, 3, nullptr, target, intrinsic);
store->addArg(value);
store->addArg(ptr);
store->addArg(::context->getConstantInt32(8));
::basicBlock->appendInst(store);
}
break;
default: assert(false && "UNIMPLEMENTED");
}
} }
else else
{ {
...@@ -836,7 +810,7 @@ namespace sw ...@@ -836,7 +810,7 @@ namespace sw
if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index)) if(auto *constant = llvm::dyn_cast<Ice::ConstantInteger32>(index))
{ {
int32_t offset = constant->getValue() * (int)Ice::typeWidthInBytes(T(type)); int32_t offset = constant->getValue() * (int)typeSize(type);
if(offset == 0) if(offset == 0)
{ {
...@@ -848,7 +822,7 @@ namespace sw ...@@ -848,7 +822,7 @@ namespace sw
if(!Ice::isByteSizedType(T(type))) if(!Ice::isByteSizedType(T(type)))
{ {
index = createMul(index, createConstantInt((int)Ice::typeWidthInBytes(T(type)))); index = createMul(index, createConstantInt((int)typeSize(type)));
} }
if(sizeof(void*) == 8) if(sizeof(void*) == 8)
......
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