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.

Compiler 4byte memcpy issue.

Hi,

I'm using TI DSP C6678.

 

For 4byte memcpy with  unaligned source address, 2 least significant address bits are cleared  to 0.    

 

For example:    

memcpy(&A, &B, 4);

 

The assembly code generated code is like this:

LDW .D2T2 *B11,B5 ; |2497|

ADDAW .D2 SP,18,B4 ; |2497|

NOP 3

     STW .D2T2 B5,*B4 ; |2497|

At this time, If B11 = 0x90800036,  actually 4bytes start from 0x90800034 are read to B5

I found other people had the same problem: http://e2e.ti.com/support/dsp/tms320c6000_high_performance_dsps/f/115/t/190185.aspx

 I tried to cast source address to uint8_t*, but the same assembly code were generated.

 Currently we cannot gurantee all our memcpy() source addresses are aligned to 4 bytes. Please give us suggestions on this problem, thanks.

  • What are the types of A and B?  Depending on the types, the compiler may presume A and B are aligned on a 4-byte boundary, and this presumption may be supported by the ANSI standard.

    Please tell me the compiler version and the exact build options you use.

    Thanks and regards,

    -George

  • HI,

     

    "A" is unsinged int, "B" is struct or enum in struct.

    I could not find comopiler version but My Code Composer Studio Version is N201105110900.

    Compiler Option is this.

    -mv6600 --symdebug:skeletal -O3 --gcc --include_path="C:/Texas Instruments/C6000 Code Generation Tools 7.3.0/include" ... ... --diag_warning=225 --big_endian --mem_model:data=far --abi=eabi --opt_for_speed=5 --gen_opt_info=2 -k --output_all_syms

    I hope this information will help resolve this problem.

    Thanks.

  • Kim Myunghwan said:
    "A" is unsinged int, "B" is struct or enum in struct.

    I'm sorry, but that is not precise enough.  Let's do this instead ...

    Please submit the source file which contains the problem memcpy.  Preprocess that source file like this.  Please mark the problem memcpy with a comment like /* PROBLEM HERE */ .

    Thanks and regards,

    -George