Variance in size of struct between ppu and spu

238 views Asked by At

I'm doing some cell broadband engine programming, and I've come across a strange thing I can't explain, while investigating a segmentation fault, based on the following code:

struct SPU_DATA
{
    unsigned char *i;
    unsigned char *o;
    unsigned int width;
    unsigned int height;
    unsigned int bpp;
    char padding[108];
} __attribute__((aligned(128)));

When I output the size of this struct to the console on the ppu, the value 256 is output. However, when I output the size on an spu, it comes out as 128, which is what's expected.

I can't find a reason for this. Any ideas?

1

There are 1 answers

0
Ian Young On

After some additional reading I discovered the following: the ppu-g++ compiler seems to default to 64 bit, which means that pointer values will occupy 8 bytes in memory. This can lead to inconsistancies in data values send to the SPU program for DMA transfer.

To prevent such problems, instead of storing a pointer in the struct, you should store an unsigned long long, which contains the value of the pointer, like so:

struct SPU_DATA
{
    unsigned long long i;
    unsigned long long o;
    unsigned int width;
    unsigned int height;
    unsigned int bpp;
    char padding[108];
} __attribute__((aligned(128)));

In this way the pointer value will not be truncated, and the correct effective address of data sent to the SPU program will be correct, preventing further problems in the case of 64bit PPU programs running 32bit SPU programs.