Short/Char Memory Alignment

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Short/Char Memory Alignment

Postby Andy » Thu Mar 11, 2010 4:00 pm

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

Postby richard » Thu Mar 11, 2010 4:33 pm

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

Postby Andy » Thu Mar 11, 2010 4:45 pm

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

Postby richard » Thu Mar 11, 2010 4:53 pm

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.

Who is online

Users browsing this forum: No registered users and 8 guests