[cairo] Data alignment and SSE2
Soeren Sandmann
sandmann at daimi.au.dk
Wed Mar 12 13:48:56 PDT 2008
"André Tupinambá" <andrelrt at gmail.com> writes:
> To execute SSE2 load and store instructions the fastest way is
> accessing memory address on a 16-byte boundary, but my function must
> work with any aligned data. So I create some code to read the head and
> tail of unaligned DWORDs. There's ok, and everything works fine.
>
> Well... Whats happen if the data address is something like 0x00400001?
> This address isn't 4-byte aligned, so reading DWORD after DWORD I'll
> never get a 16-bytes aligned address. I can still use SSE2, but I need
> to load and save data with unaligned instructions (slower than the
> aligned ones).
>
> The question is: Can I expect that all data is 4-byte aligned or I
> need to check if the address is 4-byte aligned?
Yes, just assume that data is 4-byte aligned. There has been talk
about supporting 1-byte alignment for things like a8 and 2-byte for
r5b6g5, but for now that's not the case.
If we ever do that, we should probably simply check that the address
is 4-byte aligned before even looking up any mmx/sse fast path - they
are not going to be able to do a very good job on such data anyway.
I think the strategy of ensuring the destination is 16-byte aligned
and using unaligned reads for source and mask is a good one.
Btw., did you see the patch adding a pixman-sse.c file?
Soren
More information about the cairo
mailing list