[Beignet] [PATCH 1/2] Fix non-4byte program global constant issue.
Zhigang Gong
zhigang.gong at linux.intel.com
Tue Sep 17 01:42:07 PDT 2013
LGTM, thanks.
-----Original Message-----
From: beignet-bounces+zhigang.gong=linux.intel.com at lists.freedesktop.org
[mailto:beignet-bounces+zhigang.gong=linux.intel.com at lists.freedesktop.org]
On Behalf Of Song, Ruiling
Sent: Tuesday, September 17, 2013 3:50 PM
To: beignet at lists.freedesktop.org
Subject: Re: [Beignet] [PATCH 1/2] Fix non-4byte program global constant
issue.
Ping for review comments.
-----Original Message-----
From: Song, Ruiling
Sent: Wednesday, September 11, 2013 3:22 PM
To: beignet at lists.freedesktop.org
Cc: Song, Ruiling
Subject: [PATCH 1/2] Fix non-4byte program global constant issue.
We put array elements simply one after another, that is packed.
So, constant memory address should be calculated using real type size.
Signed-off-by: Ruiling Song <ruiling.song at intel.com>
---
backend/src/llvm/llvm_gen_backend.cpp | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/backend/src/llvm/llvm_gen_backend.cpp
b/backend/src/llvm/llvm_gen_backend.cpp
index e747d00..63af6ed 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -575,8 +575,8 @@ namespace gbe
switch(c->getType()->getTypeID()) {
case Type::TypeID::IntegerTyID: {
const ConstantInt *ci = dyn_cast<ConstantInt>(c);
- *(int *)mem = ci->isNegative() ? ci->getSExtValue() :
ci->getZExtValue();
- size = sizeof(int);
+ *(uint64_t *)mem = ci->isNegative() ? ci->getSExtValue() :
ci->getZExtValue();
+ size = ci->getBitWidth() / 8;
break;
}
case Type::TypeID::FloatTyID: { @@ -604,8 +604,6 @@ namespace
gbe
unsigned len = cda->getNumElements();
uint64_t elementSize = cda->getElementByteSize();
Type::TypeID typeID = cda->getElementType()->getTypeID();
- if(typeID == Type::TypeID::IntegerTyID)
- elementSize = sizeof(unsigned);
void *mem = malloc(elementSize * len);
for(unsigned j = 0; j < len; j ++) {
switch(typeID) {
@@ -623,14 +621,15 @@ namespace gbe
break;
case Type::TypeID::IntegerTyID:
{
- unsigned u = (unsigned) cda->getElementAsInteger(j);
- memcpy((unsigned *)mem + j, &u, elementSize);
+ uint64_t u = (uint64_t) cda->getElementAsInteger(j);
+ memcpy((char *)mem + j*elementSize, &u, elementSize);
}
break;
default:
NOT_IMPLEMENTED;
}
}
+
unit.newConstant((char *)mem, name, elementSize * len,
sizeof(unsigned));
free(mem);
}
@@ -825,7 +824,7 @@ namespace gbe
auto offset1 = dyn_cast<ConstantInt>(CE->getOperand(1));
GBE_ASSERT(offset1->getZExtValue() == 0);
auto offset2 = dyn_cast<ConstantInt>(CE->getOperand(2));
- int type_size = pointer->getType()->getTypeID() ==
Type::TypeID::DoubleTyID ? sizeof(double) : sizeof(int);
+ int type_size = pointer->getType()->getPrimitiveSizeInBits() /
+ 8;
int type_offset = offset2->getSExtValue() * type_size;
auto pointer_name = pointer->getName().str();
ir::Register pointer_reg =
ir::Register(unit.getConstantSet().getConstant(pointer_name).getReg());
--
1.7.9.5
_______________________________________________
Beignet mailing list
Beignet at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list