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.

Assembler Removing Post LDW "NOP 4" in Hand Scheduled Assembly File (CGT 7.4.4)

The CGT 7.4.4 assembler is removing a "NOP 4" instruction from a hand-scheduled assembly function under different code and assembler option scenarios.

First, a little background on the assembly function.  The purpose of the function is to set the stack frame prior to calling any C-functions for a specific boot case.  The assembly function extracts the stack pointer from a global variable and puts it into B15 and A15.  It then jumps to a C initialization function.

The problem I'm seeing is as soon as I try to modify B15 (stack) and A15 (frame) the assembler blows away the "NOP 4" needed after the LDW that loads the stack address from the global variable.  I found I can work around the problem by adding the --no_compress option when assembling the file or adding four NOP instructions.  Despite the workaround I really can't find, or think of, a reason why the assembler is removing instructions explicitly written in a hand-scheduled assembly file.

I should also note that as a test I replaced the modification B15 and A15 with modification of two arbitrary B and A registers and the assembler DID NOT remove the NOP 4 after the LDW.

I'm attaching four .txt files with the scenarios I've just described.  The files contain the asm source, the assembler command, and the output .lst file for each.

"NOP 4" Removed B15/A15 Modified:

test.asm:

glblRecoverStart:
   .asg B4, pTempStack
   .asg B15, tempStack
   .asg A15, tempStack2
   .asg A6, restoreAddr
   .def  glblRecoverStart
   .ref endGlblTempStack, globalRestoreInit

 MVKL.S2 endGlblTempStack, pTempStack
 MVKH.S2 endGlblTempStack, pTempStack
 LDW.D2T2  *pTempStack, tempStack
 NOP  4
 MV.D1X   tempStack, tempStack2
    
 MVKL.S1 globalRestoreInit, restoreAddr
 MVKH.S1 globalRestoreInit, restoreAddr
 BNOP.S2X restoreAddr, 5


Command Line:

C:\>"C:/ti/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6600 --abi=eabi --asm_listing -c --asm_file "C:/test.asm"


test.lst:

TMS320C6x Assembler PC v7.4.4 Tue Dec 03 18:00:38 2013

Tools Copyright (c) 1996-2013 Texas Instruments Incorporated
C:/test.asm        PAGE    1

       1                    glblRecoverStart:
       2                       .asg B4, pTempStack
       3                       .asg B15, tempStack
       4                       .asg A15, tempStack2
       5                       .asg A6, restoreAddr
       6                       .def  glblRecoverStart
       7                       .ref endGlblTempStack, globalRestoreInit
       8                    
       9 00000000 0200002a!  MVKL.S2 endGlblTempStack, pTempStack
      10 00000004 0200006a!  MVKH.S2 endGlblTempStack, pTempStack
      11 00000008 079002e6   LDW.D2T2  *pTempStack, tempStack
      12 0000000c 00000000   NOP  4
      13 0000000c 07bc18f0   MV.D1X   tempStack, tempStack2
      14                        
      15 00000010 03000028!  MVKL.S1 globalRestoreInit, restoreAddr
      16 00000014 03000068!  MVKH.S1 globalRestoreInit, restoreAddr
      17 00000018 0098b362   BNOP.S2X restoreAddr, 5

No Assembly Errors, No Assembly Warnings

"NOP 4" Remains B15/A15 Modified + --no_compress:

test.asm:

test.asm:

glblRecoverStart:
   .asg B4, pTempStack
   .asg B15, tempStack
   .asg A15, tempStack2
   .asg A6, restoreAddr
   .def  glblRecoverStart
   .ref endGlblTempStack, globalRestoreInit

 MVKL.S2 endGlblTempStack, pTempStack
 MVKH.S2 endGlblTempStack, pTempStack
 LDW.D2T2  *pTempStack, tempStack
 NOP  4
 MV.D1X   tempStack, tempStack2
    
 MVKL.S1 globalRestoreInit, restoreAddr
 MVKH.S1 globalRestoreInit, restoreAddr
 BNOP.S2X restoreAddr, 5


Command Line:

C:\>"C:/ti/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6600 --abi=eabi --asm_listing -c  --no_compress --asm_file "C:/test.asm"

test.lst

TMS320C6x Assembler PC v7.4.4 Tue Dec 03 18:01:22 2013

Tools Copyright (c) 1996-2013 Texas Instruments Incorporated
C:/test.asm        PAGE    1

       1                    glblRecoverStart:
       2                       .asg B4, pTempStack
       3                       .asg B15, tempStack
       4                       .asg A15, tempStack2
       5                       .asg A6, restoreAddr
       6                       .def  glblRecoverStart
       7                       .ref endGlblTempStack, globalRestoreInit
       8                    
       9 00000000 0200002A!  MVKL.S2 endGlblTempStack, pTempStack
      10 00000004 0200006A!  MVKH.S2 endGlblTempStack, pTempStack
      11 00000008 079002E6   LDW.D2T2  *pTempStack, tempStack
      12 0000000c 00006000   NOP  4
      13 00000010 07BC18F0   MV.D1X   tempStack, tempStack2
      14                        
      15 00000014 03000028!  MVKL.S1 globalRestoreInit, restoreAddr
      16 00000018 03000068!  MVKH.S1 globalRestoreInit, restoreAddr
      17 0000001c 0098B362   BNOP.S2X restoreAddr, 5

No Assembly Errors, No Assembly Warnings

"NOP 4" Remains B7/A7 Modified Instead of B15/A15:

test.asm:

glblRecoverStart:
   .asg B4, pTempStack
   .asg B7, tempStack
   .asg A7, tempStack2
   .asg A6, restoreAddr
   .def  glblRecoverStart
   .ref endGlblTempStack, globalRestoreInit

 MVKL.S2 endGlblTempStack, pTempStack
 MVKH.S2 endGlblTempStack, pTempStack
 LDW.D2T2  *pTempStack, tempStack
 NOP  4
 MV.D1X   tempStack, tempStack2
    
 MVKL.S1 globalRestoreInit, restoreAddr
 MVKH.S1 globalRestoreInit, restoreAddr
 BNOP.S2X restoreAddr, 5


Command Line:

C:\>"C:/ti/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6600 --abi=eabi --asm_listing -c --asm_file "C:/test.asm"

test.lst:

TMS320C6x Assembler PC v7.4.4 Tue Dec 03 17:57:25 2013

Tools Copyright (c) 1996-2013 Texas Instruments Incorporated
C:/test.asm        PAGE    1

       1                    glblRecoverStart:  ;.cproc 
       2                       .asg B4, pTempStack
       3                       .asg B7, tempStack
       4                       .asg A7, tempStack2
       5                       .asg A6, restoreAddr
       6                       .def  glblRecoverStart
       7                       .ref endGlblTempStack, globalRestoreInit
       8                    
       9 00000000 0200002a!  MVKL.S2 endGlblTempStack, pTempStack
      10 00000004 0200006a!  MVKH.S2 endGlblTempStack, pTempStack
      11 00000008     107d   LDW.D2T2  *pTempStack, tempStack
      12 0000000a     6c6e   NOP  4
      13 0000000c 039c18f0   MV.D1X   tempStack, tempStack2
      14                        
      15 00000010 03000028!  MVKL.S1 globalRestoreInit, restoreAddr
      16 00000014 03000068!  MVKH.S1 globalRestoreInit, restoreAddr
      17 00000018 0098b362   BNOP.S2X restoreAddr, 5
      18                    ;.endproc

No Assembly Errors, No Assembly Warnings


4 "NOP" Used Instead of "NOP 4":

test.asm:

glblRecoverStart:
   .asg B4, pTempStack
   .asg B15, tempStack
   .asg A15, tempStack2
   .asg A6, restoreAddr
   .def  glblRecoverStart
   .ref endGlblTempStack, globalRestoreInit

 MVKL.S2 endGlblTempStack, pTempStack
 MVKH.S2 endGlblTempStack, pTempStack
 LDW.D2T2  *pTempStack, tempStack
 NOP  
 NOP  
 NOP  
 NOP  
 MV.D1X   tempStack, tempStack2
    
 MVKL.S1 globalRestoreInit, restoreAddr
 MVKH.S1 globalRestoreInit, restoreAddr
 BNOP.S2X restoreAddr, 5


Command Line:

C:\>"C:/ti/ccsv5/tools/compiler/c6000_7.4.4/bin/cl6x" -mv6600 --abi=eabi --asm_listing -c --asm_file "C:/test.asm"

test.lst:

TMS320C6x Assembler PC v7.4.4 Tue Dec 03 18:08:08 2013

Tools Copyright (c) 1996-2013 Texas Instruments Incorporated
C:/test.asm        PAGE    1

       1                    glblRecoverStart:
       2                       .asg B4, pTempStack
       3                       .asg B15, tempStack
       4                       .asg A15, tempStack2
       5                       .asg A6, restoreAddr
       6                       .def  glblRecoverStart
       7                       .ref endGlblTempStack, globalRestoreInit
       8                    
       9 00000000 0200002a!  MVKL.S2 endGlblTempStack, pTempStack
      10 00000004 0200006a!  MVKH.S2 endGlblTempStack, pTempStack
      11 00000008 079002e6   LDW.D2T2  *pTempStack, tempStack
      12 0000000c     0c6e   NOP  
      13 0000000e     0c6e   NOP  
      14 00000010     0c6e   NOP  
      15 00000012     0c6e   NOP  
      16 00000014 07bc18f0   MV.D1X   tempStack, tempStack2
      17                        
      18 00000018 03000028!  MVKL.S1 globalRestoreInit, restoreAddr
      19 00000020 03000068!  MVKH.S1 globalRestoreInit, restoreAddr
      20 00000024 0098b362   BNOP.S2X restoreAddr, 5

No Assembly Errors, No Assembly Warnings

Justin

  • The compiler is producing a "compressed" object file by compacting the 32-bit instruction encoding into the "compact" mixed 16- and 32-bit encoding.   As part of this encoding, each fetch packet may be treated as a protected or unprotected packet.  Protected fetch packets automatically re-insert NOPs when necessary for instructions like LDW.  In other words, the NOP 4 is not gone, it has been encoded as a protected packet.  I do not see an error here.  Can you be more specific about what run-time problems you are seeing?

  • Brett appears to be correct. The assembler/compressor (asm6x/cmp6x) is "removing" the NOP 4 in an attempt to save code size.  It encodes the fetch packet with a bit set in the fetch packet header that tells the CPU to insert a NOP 4 after any load instruction in that fetch packet.  This applies to C6400+, C6740 and C6600 ISAs.

    Just for reference,

    TMS320C66x DSP CPU and Instruction Set Reference Guide (sprugh7), Section 3.10.2.2 "Expansion Field in Compact Header Word", Figure 3-8, and 3-13.

  • Thanks for the clarification.  I assembly stepped through the compressed code and noticed it does wait 4 cycles until proceeding to the instruction after the LDW.  I focused on the removal of the NOP as the root cause for a bug I was chasing in the start up code.  The actual bug ended up being a bootrom race condition between DSP cores.  Either way, thanks for the responses.

    Justin