[CW7.1 for coldfire] Data Alignment

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[CW7.1 for coldfire] Data Alignment

1,650 Views
Nouchi
Senior Contributor II
Hello,

What is the best way to align one Tab array on a 16 bytes boundary?
I didn't find any pragmas to do that.

Emmanuel.



Labels (1)
0 Kudos
2 Replies

216 Views
RichTestardi
Senior Contributor II
I'm not 100% sure if this is what you're asking, but if you want a simple platform-independent way to align a data structure on a 16 byte boundary, and you don't mind wasting 15 bytes of memory, you can simply do something like the following, which allocates a struct foo aligned to a 16 byte boundary, pointed to by fooptr:
 
struct foo {
  int x;
  int y;
};
 
char fooplus[sizeof(struct foo)+15];
struct foo *fooptr;
 
static
void
fooinit()
{
    printf("fooplus = 0x%x\n", fooplus);
    fooptr = (struct foo *)(((int)fooplus+15)&~15);
    printf("fooptr = 0x%x\n", fooptr);
}

And you'll end up with addresses like:
 
fooplus = 0x20000158
fooptr = 0x20000160

Note that fooplus was not aligned to a 16 byte boundary, but fooptr is.

Otherwise, you might find some other ideas here:

http://forums.freescale.com/freescale/board/message?board.id=CWCFCOMM&thread.id=517
 
I actually put all of my "alignment sensitive" variables at the start of my data section in the linker command file, so I can control their addresses more carefully (mine actually need 512 byte alignment, and I don't want to waste 511 bytes to get it!).
0 Kudos

216 Views
J2MEJediMaster
Specialist I
I don't know if this will help or not, but here's a forum thread where it is discussed how to place a variable at a specific address for ColdFire. This should help you at least start the data on a 16 byte boundary.

---Tom
0 Kudos