Short/Char Memory Alignment

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Short/Char Memory Alignment

Post by Andy »

If I have a large array of shorts or chars in C, such as:

Code: Select all

const unsigned short huffTable[] = {
	0xf003, 0x3112, 0x3101, 0x2011....
How are these being packed into memory? I was wondering if they are word aligned by default and if so, can I pack 2 shorts or 4 chars into one 32 bit word to save space?


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

There is no padding inside arrays. An array of n chars will take up n bytes. The ABI defines the layout of data types in memory, see the document XMOS XS1 32-Bit Application Binary Interface.
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

OK thanks - what kind of data does
All global objects are word aligned. Unsigned scalar types smaller than 32 bits are stored as zero extended 32-bit values
refer to?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

That refers to scalar globals such as "char c". If you have an array of chars as a global the base of the array will be word aligned but each element inside the array will not be word aligned.