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.

OMAPL137 DSP and double storage problem

I have a problem with writing to doubles that are members of unions.  My guess is it is an alignment problem but should not be happening, thus figured I'd see if anyone else had noticed or it is a known compiler issue.  Code works fine on numerous other platforms and am porting to DSP side of L137.

If I try and store a double to a union in my code only the first half gets copied.  Verified with JTAG memory dump.  'memcpy' does the same thing with sizeof(double) and just reference address of doubles.  With no optimization, if I cast the pointers to 'unsigned char *' then memcpy works fine.  Had to use 'memcpy' since direct storage, for example, myunion.mydouble = mydouble_var, only stored the first half of the data.

If I turn the optimization up to o2/o3 then memcpy no longer works and only half the double is stored (4 bytes).

If I cheat and do a byte for byte copy with a 'for' loop, works fine regardless of optimization.  I would have assumed that the compiler would have handled any alignment issues with the union?

I have resolved it with the for loop for the moment but figured I'd see if anyone else new of any limitations I needed to be aware of before I try to dive deeper into the problem.  Using Far Aggregate memory model and code works fine on numerous ARM processors with gcc.  Use memory structure for passing data back and forth to Linux ARM through shared memory, Linux has no problems.

union
 {
  int iValue;
  unsigned int uiValue;
  long long llValue;
  float fValue;
  double dValue;     // This is the value that fails for all but a byte for byte copy...
  unsigned int dSwap[2]; 
  char *psValue;
  char sValue[224];
  int rpc_result[MAX_RPC_RESULTS];
 } data;

memcpy(&data.dValue, &mydouble, sizeof(double));     // this always fails, only first 4 bytes copied

memcpy((unsigned char *)&data.dValue, (unsigned char *)&mydouble, sizeof(double));  // this works with no optimization

unsigned char *ptr1 = (unsigned char *)&data.dValue;

unsigned char *ptr2 = (unsigned char *)&mydouble;

for (int i;i!=sizeof(double);i++,ptr1++,ptr2++) {

    *ptr1 = *ptr2;

}   // this works with no problems regardless of optimization

 Any thoughts?

Thanks,

Kev