gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Forcing a struct to 16-bit alignment

#177496 - brave_orakio - Tue Jul 10, 2012 9:06 pm

Hi guys. How do I force this
Code:

struct 4words{
u32 data1;
u32 data2;
u32 data3;
u32 data4;
}

into a 16-bit aligned address? I`m using it to quickly copy data from ROM to vram but unfortunately it messes up big time cause I think its forced into a 32-bit aligned address. Using ALIGN2 doesn`t work unfortunately. Using a loop gives me the correct output but that is very slow of course.
For those who are curious I`m using a bunch of similar structs so I can quickly copy data in a LZSS uncompress function.
_________________
help me

#177497 - Dwedit - Wed Jul 11, 2012 1:10 am

Anything aligned to a 32-bit boundary is also aligned to a 16-bit boundary.
Any instance of that struct you create on the stack, globals, or heap will be aligned to a 32-bit boundary.

The only time you could get an unaligned version is if you are casting some other pointer that isn't aligned.

If you're having problems with video memory here, alignment isn't the problem.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#177498 - brave_orakio - Wed Jul 11, 2012 1:56 am

Quote:
The only time you could get an unaligned version is if you are casting some other pointer that isn't aligned.


Yeah this is pretty much what I'm doing unfortunately. Rather the source and destination address could be HW aligned or W aligned and casting to the struct pointer forces it to be W aligned.

Anyway to anyone in the same situation, being HW aligned means that you have to manually copy each element since the assembly version doesn't have a ldmiah or stmiah. Those operations don't exist so what I wanted to do was impossible. I should probably use the dma16bit copy in this situation I think. Thanks guys!
_________________
help me