Re: [AD] SSE2 vs malloc() |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Chris wrote:
On Saturday 15 October 2005 02:28 am, aj wrote:
You would not be doing SSE2 instructions on video bitmaps, it makes no
sense to do so.
Depends on what you're doing. As I understand it, for properly implemented
systems, when you lock a bitmap the system gives you a pointer to the VRAM
data to do with what you need (write to it, read from it, whichever). You
can't gaurantee the alignment of that pointer.
Also, it's worth pointing out, that bitmaps are aligned per pixel. Since SSE2
uses 16-byte alignment, that means someone grabbing pixel 2 through 15 of an
8-bit bitmap is grabbing unaligned data.
Part of me thinks the compiler is smart enough to not handle pointer variables
using SSE2 for this very reason.. because it can't know if it's aligned or
not. Instead, it would do this for global or local variables where it can
predetermine the memory address, and it will know where it's aligned and safe
to use SSE2 instructions on.
There are some SSE2 instructions that do not require alignment, but they
are few.
from msdn2:
"Many of the new intrinsics have data alignment requirements. If these
intrinsics are used and data is not appropriately aligned, the program
will throw an exception that must be handled by the program; otherwise,
the program will fault."
I see this is opening a big can of wriggly earth creatures.
Sub bitmaps will be a problem, as they align on pixel boundaries.
I guess it will be a long time before allegro contains SSE2
instructions, due to these design limits.
It seems a waste to have something as powerful as SSE2 (that many people
have) go to waste, espeacilly for a game library.
I still intend to use it, the best plan so far is to just write a
wrapper for create_bitmap()
aligned_create_bitmap(.... )
{
AL_BITMAP* p = create_bitmap(...);
free( p->dat );
p->dat = _aligned_malloc(...);
p->line[]'s = p->dat[ w steps ];
return p;
}