Commit 8820f64b by Nicolas Capens

Implement pointer arithmetic.

Bug swiftshader:11 Change-Id: I50bb9c6bf7bbe21630bd5f1eb5e0aa0aeb06fdb3 Reviewed-on: https://swiftshader-review.googlesource.com/7393Tested-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 a0c2fc50
...@@ -174,15 +174,15 @@ namespace es2 ...@@ -174,15 +174,15 @@ namespace es2
} }
// This object has to be mem aligned // This object has to be mem aligned
void* Device::operator new(size_t size) void* Device::operator new(size_t size)
{ {
ASSERT(size == sizeof(Device)); // This operator can't be called from a derived class ASSERT(size == sizeof(Device)); // This operator can't be called from a derived class
return sw::allocate(sizeof(Device), 16); return sw::allocate(sizeof(Device), 16);
} }
void Device::operator delete(void * mem) void Device::operator delete(void * mem)
{ {
sw::deallocate(mem); sw::deallocate(mem);
} }
void Device::clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask) void Device::clearColor(float red, float green, float blue, float alpha, unsigned int rgbaMask)
......
...@@ -20,7 +20,7 @@ using namespace sw; ...@@ -20,7 +20,7 @@ using namespace sw;
int reference(int *p, int y) int reference(int *p, int y)
{ {
int x = *p; int x = p[-1];
int z = 4; int z = 4;
for(int i = 0; i < 10; i++) for(int i = 0; i < 10; i++)
...@@ -41,7 +41,7 @@ int main() ...@@ -41,7 +41,7 @@ int main()
Function<Int(Pointer<Int>, Int)> function; Function<Int(Pointer<Int>, Int)> function;
{ {
Pointer<Int> p = function.Arg<0>(); Pointer<Int> p = function.Arg<0>();
Int x = *p; Int x = p[-1];
Int y = function.Arg<1>(); Int y = function.Arg<1>();
Int z = 4; Int z = 4;
...@@ -60,9 +60,9 @@ int main() ...@@ -60,9 +60,9 @@ int main()
if(routine) if(routine)
{ {
int (*callable)(int*, int) = (int(*)(int*,int))routine->getEntry(); int (*callable)(int*, int) = (int(*)(int*,int))routine->getEntry();
int one = 1; int one[2] = {1, 0};
int result = callable(&one, 2); int result = callable(&one[1], 2);
assert(result == reference(&one, 2)); assert(result == reference(&one[1], 2));
} }
} }
......
...@@ -259,14 +259,7 @@ namespace sw ...@@ -259,14 +259,7 @@ namespace sw
assert(arraySize == 0 && "UNIMPLEMENTED"); assert(arraySize == 0 && "UNIMPLEMENTED");
Ice::Type type = T(t); Ice::Type type = T(t);
int size = Ice::typeWidthInBytes(type);
int32_t size = 0;
switch(type)
{
case Ice::IceType_i32: size = 4; break;
case Ice::IceType_i64: size = 8; break;
default: assert(false && "UNIMPLEMENTED" && type);
}
auto bytes = Ice::ConstantInteger32::create(::context, type, size); auto bytes = Ice::ConstantInteger32::create(::context, type, size);
auto address = ::function->makeVariable(T(getPointerType(t))); auto address = ::function->makeVariable(T(getPointerType(t)));
...@@ -490,7 +483,19 @@ namespace sw ...@@ -490,7 +483,19 @@ namespace sw
Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index) Value *Nucleus::createGEP(Value *ptr, Type *type, Value *index)
{ {
assert(false && "UNIMPLEMENTED"); return nullptr; assert(index->getType() == Ice::IceType_i32);
if(!Ice::isByteSizedType(T(type)))
{
index = createMul(index, createAssign(createConstantInt((int)Ice::typeWidthInBytes(T(type)))));
}
if(sizeof(void*) == 8)
{
index = createSExt(index, T(Ice::IceType_i64));
}
return createAdd(ptr, index);
} }
Value *Nucleus::createAtomicAdd(Value *ptr, Value *value) Value *Nucleus::createAtomicAdd(Value *ptr, Value *value)
...@@ -5615,7 +5620,7 @@ namespace sw ...@@ -5615,7 +5620,7 @@ namespace sw
RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset) RValue<Pointer<Byte>> operator+(RValue<Pointer<Byte>> lhs, int offset)
{ {
assert(false && "UNIMPLEMENTED"); return RValue<Pointer<Byte>>(V(nullptr)); return lhs + RValue<Int>(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)
......
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