This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TI compiler memory alignment

Hi guys,

I am trying to clarify some information about the TI compiler. 

I am using: 

processor: DSP F2806

compiler: C200 processor version 28

Since the processor I am using is 32-bit, do I need to be concerned with any memory alignment exceptions? I have read online that most modern processors take care of this in the compiler. Is this one of those cases and if so, is there a significant performance impact? 

Any information that would help me better understand memory alignment issues would be great. Thanks. 

  • The C28x family is generally considered a 16-bit processor because "int" is 16 bits. I'm not sure what you mean about being concerned with memory alignment exceptions. If you're programming strictly in C, the compiler takes care of most alignment issues for you. You should take care when trying to access data with pointers to make sure that you don't mix types. In some cases you must mix types, and you will need to be concerned with alignment if you try to access an object with a pointer to a wider type, because the processor does not automatically handle misaligned types. Could you be a bit more specific about what you mean by alignment issues?
  • Adam Batakji said:
    Since the processor I am using is 32-bit, do I need to be concerned with any memory alignment exceptions?

    Yes, but not too much.  The compiler handles all the details for you.  You have to work fairly hard to get in trouble.

    The C2000 CPU is 16-bit word addressable.  Each address corresponds to one 16-bit word.  There are instructions which read or write 32-bits of memory at once.  These instructions presume the address is even.  If that presumption is violated, the instruction silently does the wrong thing.  The compiler aligns all 32-bit wide types and accesses for you.  You can only get in trouble if, by type casting, you force an odd word address into a pointer to a 32-bit type.

    Thanks and regards,

    -George

  • Archaeologist,

    Thanks for your reply. I am not sure what exact exception would be thrown since I have not experienced it before, but the issue I am trying to avoid is my code throwing an exception when trying to access an address in memory. Based on what you say, as long as I use proper coding technique and not mix different types of data together, I should be fine.