[Beignet] [PATCH 1/2] Fix non-4byte program global constant issue.
Ruiling Song
ruiling.song at intel.com
Wed Sep 11 00:22:03 PDT 2013
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
More information about the Beignet
mailing list