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.

CLA scratchpad new memory section convention (6.4.x) with CLA math library

Other Parts Discussed in Thread: CONTROLSUITE

In this TI Wiki

http://processors.wiki.ti.com/index.php/C2000_CLA_C_Compiler

It says

Local variables and compiler temps are placed into a scratchpad memory area. On older CGT (before 6.4.0) these variables were accessed directly using the symbols '__cla_scratchpad_start' and '__cla_scratchpad_end' and it was expected that the user would manage this area and define these symbols using a linker command file. In CGT 6.4.0 (and above) these variables are placed in a ".scratchpad" memory section, which the compiler will then partition into local frames, one for the all eight tasks, and one for each leaf function. These local frames will have unique symbols that the compiler will use to access variables.

...

The old convention for CLAScratch will still be supported by the new compiler, albeit, inefficiently from a memory allocation standpoint. The new compiler creates a common local frame for the 8 tasks, i.e. each task's local frame is overlayed on top of each other - they use the same memory locations; this is possible since there is no nesting of tasks, so one task cannot corrupt the scratch area of another. By having the CLAScratch memory section, the compiler cannot take advantage of the overlaying strategy and is, instead, forced to allocate each task's locals in separate locations within the scratchpad.

So your .cmd file either looks like this (6.2.x and older)

// Define a size for the CLA scratchpad area that will be used
// by the CLA compiler for local symbols and temps
// Also force references to the special symbols that mark the
// scratchpad area.
 
CLA_SCRATCHPAD_SIZE = 0x100; // If using --define CLA_SCRATCHPAD_SIZE=0x100, remove this line
--undef_sym=__cla_scratchpad_end
--undef_sym=__cla_scratchpad_start
 
.....
MEMORY
{
.....
}
SECTIONS
{
   //
   // Must be allocated to memory the CLA has write access to
   //
   CLAscratch       :
                        { *.obj(CLAscratch)
                        . += CLA_SCRATCHPAD_SIZE;
                        *.obj(CLAscratch_end) } > CLARAM1,  PAGE = 1
}

or like this (6.4.x and newer)

.....
MEMORY
{
.....
}
SECTIONS
{
   //
   // Must be allocated to memory the CLA has write access to
   //
   .scratchpad     : > CLARAM1,  PAGE = 1
}

One thing to note is that the CLA math library still uses the "CLAscratch" section. So even with 6.4.x compiler, if you are using CLA math library, you'd need to do the .cmd file as if you had 6.2.x or older.

I have tried to modify the CLA math library source and replace every .usect "CLAscratch" with .usect ".scratchpad" ??  Then recompile the library and use that one instead (with 6.4.x or newer).  Then you would need to only specify .scratchpad in your .cmd file, even if you are using the CLA math library.

Should I have any concern about the CLA math library functions having the same frame as the overlayed task frames?  Or are they considered leaf functions that have their own frames?

From what I see, it looks like they are all using the same frame:

This is how it was before with the old convention:

    1. First, each leaf function will have its own frame, since it will be called from within a task, so in the assembly files you must assign the function to the section  Cla1Prog:<function_name>.
    2. Then you have to declare a stack pointer "_<function_name_sp" and assign it to the scratchpad section ".scratchpad:Cla1Prog:<function_name>" and then all the temp variable must be referenced using the stack pointer

    Here is an example of the modified CLAasin function. All the changes i made are in the first 6 lines. I basically took the old "local" variables _asin_tmp and _save_MR3 and define them to offsets from the stack pointer __CLAasin_sp (two _ at the front) , so now they wont be in .ebss_cla but rather in the scratchpad area for the leaf function ".scratchpad:Cla1Prog:_CLAasin".

      .def  _CLAasin
      .sect "Cla1Prog:_CLAasin"
      .align 2
    __CLAasin_sp  .usect ".scratchpad:Cla1Prog:_CLAasin",4,0,1
    _asin_tmp     .set    __CLAasin_sp + 0
    _save_MR3     .set    __CLAasin_sp + 2
    
    _CLAasin:
    ; Context Save
         MMOV32     @_save_MR3, MR3
    ; MR0 = X(fVal) is stored in the scratchpad memory
         MMOV32     @_asin_tmp, MR0
        
    ; Perform Step (1):
         MABSF32     MR3,MR0            ; MR3 = abs(X)
         
    ; Perform Step (2):
         MMPYF32     MR2,MR3,#63.0      ; 64 = Elements In Table (indexed from 0)
         MF32TOUI16  MR2,MR2            ; MR2 = int(63*x)
         MADD32      MR2,MR2,MR2        ; MR2 = 2*MR2
         MADD32      MR1,MR2,MR2        ; MR1 = 4*MR2
         MADD32      MR2,MR2,MR1        ; MR2 = 6*MR2 this is the index value for the stored data array
         MMOV16      MAR0,MR2,#_CLAasinTable+4       ; MAR0 points to A2, this will be used in step 4
         MMOVI16     MAR1,#_CLAasinHalfPITable+2     ; MAR1 points to pi/2, this will be used in step 5
         MNOP
         MNOP
    ; Perform Step (3):
    ; arcsin(x) = A0 + x(A1 + A2*x)
         MMOV32      MR1,*MAR0[#-2]++   ; MR1 = A2
         MMPYF32     MR1,MR1,MR3        ; MR1 = A2*x
      || MMOV32      MR2,*MAR0[#-2]++   ; MR2 = A1
    
         MADDF32     MR2,MR2,MR1        ; MR2 = A1 + A2*x
      || MMOV32      MR1,*MAR0          ; MR1 = A0
         MMPYF32     MR2,MR2,MR3        ; MR3 = x*(A1 + A2*x)
      
         MADDF32     MR3,MR1,MR2        ; MR3 = A0 + x*(A1 + A2*x)
    ; Perform Step (4):
     
         MMOV32      MR2,@_asin_tmp       ; MR2 = x (set/clear NF,ZF)
      
         MNEGF32     MR3,MR3,LT         ; if (X < 0) Angle = -Angle
         MMOV32      MR0,MR3            ; Store Y = asin(X)
    ; Context Restore
         MMOV32      MR3,@_save_MR3 
         MRCNDD      UNC
         MNOP
         MNOP
         MNOP

    We will be updating this library to adhere to this model in the next revision.

  • Ahhh I see.

    Would this be the correct modifications for atan2?

        .def  _CLAatan2
        .sect "Cla1Prog:_CLAatan2"
        .align 2
    __CLAatan2_sp .usect ".scratchpad:Cla1Prog:_CLAatan2",6,0,1
    _atan2_tmp1   .set    __CLAatan2_sp + 0
    _atan2_tmp2   .set    __CLAatan2_sp + 2
    _save_MR3     .set    __CLAatan2_sp + 4

  • yeah that looks about right. Let me know if you see any issues in the build.
  • Great, thanks very much for your help Vishal!!
  • Any idea when the next rev of CLA math lib will come out more or less?
  • We are targeting the end of January for this release.

  • Hey Vishal, just hoping this isn't forgotten in future controlSUITE releases. I've seen 2 releases come out but none have included these changes.
  • Im actually working on it now. It should be ready by the middle of next month. I dont know if that falls in the next release or the one after that but its almost done.

  • Hi there,

    I was pretty happy that I have found the thread obove.

    I've included all the libaries and file search paths and so on as supposed, but I still get the message from the old convention:

    #10247-D creating output section "CLAscratch" without a SECTIONS specification

    I'm using an F28377S on the Launchpad LAUNCHXL.

    Attatched is my .cmd for creating all sections and some screenshots of the properties.

    MEMORY
    {
    PAGE 0 :  /* Program Memory */
              /* BEGIN is used for the "boot to FLASH" bootloader mode   */
    
        .....
    
    	/* Local Shared Memory */
    	LS0304SARAM  : origin = 0x009800, length = 0x001000 /* on-chip RAM for CLA program and CLAmath lookup tables */
    //	LS04SARAM  : origin = 0x00A000, length = 0x000800 /* on-chip RAM for CLA program and CLAmath lookup tables*/
    
    ....
    
        FLASHC  : origin = 0x084000, length = 0x002000  /* on-chip Flash, reserved for CLA*/
    ...
    
    PAGE 1 : /* Data Memory */
    
    	/* Local Shared Memory */
    
    	LS00SARAM          	: origin = 0x008000, length = 0x000800 	/* on-chip RAM for CLA data */
       	LS01SARAM          	: origin = 0x008800, length = 0x000800	/* on-chip RAM for CLA data and scratchpad*/
       	LS02SARAM      		: origin = 0x009000, length = 0x000800	/* on-chip RAM */
       	LS05SARAM      		: origin = 0x00A800, length = 0x000800	/* on-chip RAM */
    
    	/* Message Memory */
    
    	CLA1_MSGRAMLOW			: origin = 0x001480, length = 0x000080
    	CLA1_MSGRAMHIGH			: origin = 0x001500, length = 0x000080
    ....
    }
    
    SECTIONS
    {
    ....
    
    	/* CLA specific sections */
    
       Cla1Prog         : LOAD = FLASHC,
                          RUN = LS0304SARAM ,//| LS04SARAM,
                          LOAD_START(_Cla1funcsLoadStart),
                          LOAD_END(_Cla1funcsLoadEnd),
                          RUN_START(_Cla1funcsRunStart),
                          LOAD_SIZE(_Cla1funcsLoadSize),
                          PAGE = 0, ALIGN(4)
    
    	CLA1mathTables :	LOAD = FLASHC,    	PAGE = 0
                     		RUN = LS01SARAM,	PAGE = 1
                     		LOAD_START(_Cla1mathTablesLoadStart),
                     		LOAD_END(_Cla1mathTablesLoadEnd),
                     		RUN_START(_Cla1mathTablesRunStart),
    						LOAD_SIZE(_Cla1mathTablesLoadSize)
    
    	CLADataLS0		: > LS00SARAM, PAGE=1
    	CLADataLS1		: > LS01SARAM, PAGE=1
    
    	Cla1ToCpuMsgRAM  : > CLA1_MSGRAMLOW,   PAGE = 1
    	CpuToCla1MsgRAM  : > CLA1_MSGRAMHIGH,  PAGE = 1
    
       	/* CLA C compiler sections */
       	//
       	// Must be allocated to memory the CLA has write access to
       	//
    
       	.scratchpad      : > LS01SARAM,       PAGE = 1
       	.bss_cla		 : > LS01SARAM,       PAGE = 1
       	.const_cla	    :  LOAD = FLASHC,
                           RUN = LS01SARAM,
                           RUN_START(_Cla1ConstRunStart),
                           LOAD_START(_Cla1ConstLoadStart),
                           LOAD_SIZE(_Cla1ConstLoadSize),
                           PAGE = 1
    
    ....
    }

    Where my CLAmath is located:


    What libaries did I include:

    What type of processor do I have set up

    What did I wrong?

    Best regards.

    Tommy

  • Hi,

    You are missing the CLAScratch section in your linker command file. older version of the CLA math library used the old CLA compiler convention. I suggest you get the latest library v4.01.00.00 or if you are using the older math library you will have to place the CLAScratch section in your linker command file you can find examples under C:\ti\controlSUITE\libs\math\CLAmath\v4_00_01_00\examples

  • Vishal, I saw this was released with the new convention. Thanks for that!!! :) Great work!
  • Hi,

    I'm sorry, unfortunataly the inseration of the pics I did, didn't work. Therein you should have seen, that I'm using the v4.01.00.00 version of CLAmath. Therefore I do not understand that warning anymore!

    Originally I used the older v400 Version where the CLAscratch section was necessary. Then I have found this thread, deleted all of the old files and linked ressources and added the newest version. Still, I'm getting his warning.

    Tommy

  • Tommy,

    There is a 4.00.01.00 and the newer 4.01.00.00. You're sure you are using the latest library? Perhaps rebuild the library in CCS, the project for it should be in the ccs folder. I would recommend using the CGT used to build it - 15.12.0 i think.

  • Vishal_Coelho said:

    Tommy,

    There is a 4.00.01.00 and the newer 4.01.00.00. You're sure you are using the latest library? Perhaps rebuild the library in CCS, the project for it should be in the ccs folder. I would recommend using the CGT used to build it - 15.12.0 i think.

    Hi,

    In the picture below, you can see that I am using the 4.01.00.00 version, as well as the libs I included.

    This can't be the problem as well as the CGTs. I tried all I have (15.12.1 / 2 / 3 LTS and 16.3.0.STS) and no one got the requiered CLAscratch section moved away.

    When I am trying to build the libraryin its standalone project CCS is giving me an error:

    Description    Resource    Path    Location    Type
    gmake: *** No rule to make target 'clean'.    cla1_math_library        Unknown    C/C++ Problem

    I still have no idea where this is coming from.
    Do you have another solution approach?

    P.S.: The warning he is pushing back is as follows:

    Description    Resource    Path    Location    Type
    #10247-D creating output section "CLAscratch" without a SECTIONS specification    daidalos             C/C++ Problem

  • Ok, can you post the contents of the .map file. We can see which object files have the CLAScratch section.

  • SECTION ALLOCATION MAP
    
     output                                  attributes/
    section   page    origin      length       input sections
    --------  ----  ----------  ----------   ----------------
    PieVectTableFile 
    *          0    00000d00    000001c0     DSECT
                      00000d00    000001c0     F2837xS_GlobalVariableDefs.obj (PieVectTableFile)
    
    .
    .
    .
    .
    
    CLAscratch 
    *          1    00000002    00000006     UNINITIALIZED
                      00000002    00000006     CLAatan2PU.obj (CLAscratch)
    .
    .
    .

    and the CLAatan2PU is as follows:

    ;;#############################################################################
    ;; FILE: CLAatan2PU.asm
    ;; 
    ;; DESCRIPTION: CLA arctan2 Per Unit function
    ;; 
    ;; Group:            C2000
    ;; Target Family:    C28x+CLA
    ;;
    ;; Copyright (C) 2016 Texas Instruments Incorporated - http://www.ti.com/
    ;; ALL RIGHTS RESERVED
    ;;#############################################################################
    ;;$TI Release: CLA Math Library V4.01.00.00 $
    ;;$Release Date: Apr 6, 2016 $
    ;;#############################################################################
    
        .cdecls C,LIST,"CLAmath.h"
    ;;----------------------------------------------------------------------------
    ;; Description: 
    ;;   The algorithm steps to calculate the "atan2" of the given
    ;;   input X and Y is as follows:
    ;;  
    ;;   Step(1):   if( abs(X) >= abs(Y) )
    ;;                  Numerator   = abs(Y)
    ;;                  Denominator = abs(X)
    ;;              else
    ;;                  Numerator   = abs(X)
    ;;                  Denominator = abs(Y)
    ;;  
    ;;   Step(2):   Ratio = Numerator/Denominator
    ;;  
    ;;              Note: Ratio range = 0.0 to 1.0
    ;;  
    ;;   Step(3):   Use the upper 6-bits of the "Ratio" value as an
    ;;              index into the table to obtain the coefficients
    ;;              for a second order equation:
    ;;  
    ;;              _FPUatan2Table:
    ;;                   CoeffA0[0]
    ;;                   CoeffA1[0]
    ;;                   CoeffA2[0]
    ;;                      .
    ;;                      .
    ;;                   CoeffA0[63]
    ;;                   CoeffA1[63]
    ;;                   CoeffA2[63]
    ;;  
    ;;   Step(4):   Calculate the angle using the folowing equation:
    ;;  
    ;;              arctan(Ratio) = A0 + A1*Ratio + A2*Ratio*Ratio
    ;;              arctan(Ratio) = A0 + Ratio(A1 + A2*Ratio)
    ;;  
    ;;   Step(5):   The final angle is determined as follows:
    ;;  
    ;;              if( X >= 0 and Y >= 0 and abs(X) >= abs(Y) )
    ;;                  Angle = arctan(abs(Y)/abs(X))
    ;;              if( X >= 0 and Y >= 0 and abs(X) <  abs(Y) )
    ;;                  Angle = PI/2 - arctan(abs(X)/abs(Y))
    ;;              if( X < 0  and Y >= 0 and abs(X) <  abs(Y) )
    ;;                  Angle = PI/2 + arctan(abs(X)/abs(Y))
    ;;              if( X < 0  and Y >= 0 and abs(X) >= abs(Y) )
    ;;                  Angle = PI - arctan(abs(Y)/abs(X))
    ;;              if( Y < 0 )
    ;;                  Angle = -Angle
    ;;  
    ;;                  AnglePU =Angle/2pi 
    ;;
    ;; Equation:    z = { atan(y/x) } / 2pi
    ;;
    ;; Regs Used:   MR0, MR1, MR2, MR3, MAR0,MAR1
    ;;
    ;; Input:   x , y       two f32 values in memory
    ;;
    ;; Output:  z           f32 value in memory
    ;;          MR0 = z     f32 result
    ;; 
    ;; Benchmark:   Cycles = 46  
    ;;          Instructions = 46
    ;;
    ;; Scratchpad Usage: (Local Function Scratchpad Pointer (SP))
    ;;
    ;;   |_______|<- MR3                               (SP+4)
    ;;   |_______|<- atan2PU temporary variable 2      (SP+2)
    ;;   |_______|<- atan2PU temporary variable 1      (SP+0)
    ;;
    ;;----------------------------------------------------------------------------
    
        
        .def    _CLAatan2PU
        .sect   "Cla1Prog:_CLAatan2PU"
        .align  2
    __CLAatan2PU_sp .usect ".scratchpad:Cla1Prog:_CLAatan2PU",6,0,1
    
    _atan2PU_tmp1 .usect "CLAscratch",2
    _atan2PU_tmp2 .usect "CLAscratch",2
    _save_MR3     .usect "CLAscratch",2
    
    _CLAatan2PU:
        .asmfunc
        .asg    __CLAatan2PU_sp + 0, _atan2PU_tmp1 
        .asg    __CLAatan2PU_sp + 2, _atan2PU_tmp2 
        .asg    __CLAatan2PU_sp + 4, _save_MR3     
    ; Context Save
        MMOV32     @_save_MR3, MR3
    ; MR0 = Y(fVal1) and MR1 = X(fVal2) is stored in the 
    ; scratchpad memory
        MMOV32      @_atan2PU_tmp1,MR0  ;Y
        MMOV32      @_atan2PU_tmp2,MR1  ;X
    ; Perform Step (1):
        MABSF32     MR3,MR0             ; MR3 = abs(Y)
        MMOV32      MR2,MR3             ; Store abs(Y) in MR2
        MABSF32     MR1,MR1             ; Store abs(X) in MR1
        MMINF32     MR3,MR1             ; MR3 = numerator (A) = min(abs(Y),abs(X)) 
        MMOV32      MR1,MR2,GT          ; MR1 = denominator (B) = max(abs(Y),abs(X))
                                        ; Ratio = A/B
    ; Perform Step (2): 
        MEINVF32    MR2,MR1             ; MR2 = Ye = Estimate(1/Denominator) i.e 1/B
        MTESTTF     LEQ                 ; Set TF if 1.0 >= abs(X) , this will be used in step 5
        MMPYF32     MR0,MR2,MR1         ; MR0 = Ye*B
        MSUBF32     MR0,#2.0,MR0        ; MR0 = 2.0 - Ye*B
        MMPYF32     MR2,MR2,MR0         ; MR2 = Ye = Ye*(2.0 - Ye*B)  (first estimate)
        MMPYF32     MR0,MR2,MR1         ; MR0 = Ye*B
        MSUBF32     MR0,#2.0,MR0        ; MR0 = 2.0 - Ye*B
        MMPYF32     MR2,MR2,MR0         ; MR2 = Ye = Ye*(2.0 - Ye*B)  (second estimate)
        MMPYF32     MR0,MR2,MR3         ; MR0 = Ratio = A*Ye = A/B
    ; Perform Step (3):
        MMPYF32     MR2,MR0,#64.0       ; 64 = Elements In Table
        MF32TOUI16  MR2,MR2             ; MR2 = int(64*ratio)
        MADD32      MR2,MR2,MR2         ; MR2 = 2*MR2
        MADD32      MR1,MR2,MR2         ; MR1 = 4*MR2
        MADD32      MR2,MR2,MR1         ; MR2 = 6*MR2 this is the index value for the stored data array
        MMOV16      MAR0,MR2,#_CLAatan2Table+4     ; MAR0 points to A2, this will be used in step 4
        MMOVI16     MAR1,#_CLAatan2HalfPITable+2   ; MAR1 points to pi/2, this will be used in step 5
        MNOP
        MNOP
    ; Perform Step (4):
    ; arctan(Ratio) = A0 + Ratio(A1 + A2*Ratio)
        MMOV32      MR1,*MAR0[#-2]++    ; MR1 = A2
        MMPYF32     MR1,MR1,MR0         ; MR1 = A2*Ratio
     || MMOV32      MR3,*MAR0[#-2]++    ; MR3 = A1
        MADDF32     MR3,MR3,MR1         ; MR3 = A1 + A2*Ratio
     || MMOV32      MR1,*MAR0           ; MR1 = A0
        MMPYF32     MR3,MR3,MR0         ; MR3 = Ratio*(A1 + A2*Ratio)
        MADDF32     MR3,MR1,MR3         ; MR3 = A0 + Ratio*(A1 + A2*Ratio)
     || MMOV32      MR2,@_atan2PU_tmp2  ; MR2 = X (set/clear NF,ZF for use below)
    ; Perform Step (5):
        MMOV32      MR1,*MAR1,UNC       ; MR1 = pi/2  (no flag change)
        MNEGF32     MR0,MR1,UNC         ; MR0 = -pi/2 (no flag change)
        MMOV32      MR3,MR2,EQ          ; if (X == 0), MR3 = 0
        MNEGF32     MR3,MR3,GEQ         ; if (X >= 0) MR3 flip sign of atan(Ratio)
        MNEGF32     MR3,MR3,TF          ; if (abs(X) >= abs(Y)) flip sign of atan(Ratio)
            
        MNEGF32     MR0,MR0,LT          ; if (X < 0) MR0 = pi/2
        MADDF32     MR0,MR0,MR1         ; MR0 = MR0+pi/2
                                        ; if(X < 0) MR0 = pi
                                        ; if(X > 0) MR0 = 0
     || MMOV32      MR2,@_atan2PU_tmp1  ; MR2 = Y (set/clear NF,ZF)
        MMOV32      MR0,MR1,NTF         ; if(abs(X) < abs(Y) R3H = pi/2
        MADDF32     MR3,MR3,MR0         ; MR3 = Angle
        MNEGF32     MR3,MR3,LT          ; if (Y < 0) Angle = -Angle
        
        MMOV32      MR1,@_CLAINV2PI     ; MR1 = 1/pi*2, this will be used in step 5
    
    ; Context Restore and Final Operations
        MRCNDD      UNC
        MMPYF32     MR3,MR3,MR1         ; MR3= Angle*(1/pi*2)
        MMOV32      MR0,MR3             ; Store Y = atan2PU(X)
        MMOV32      MR3,@_save_MR3 
        .unasg  _atan2PU_tmp1 
        .unasg  _atan2PU_tmp2 
        .unasg  _save_MR3     
        .endasmfunc
            
    ;; End of File
    

    great idea!!! Did never think about that one, now that I've seen what I've seen:

  •  You have to delete these lines and rebuild the library. These variables are being assigned to CLAscratch.

    _atan2PU_tmp1 .usect "CLAscratch",2
    _atan2PU_tmp2 .usect "CLAscratch",2
    _save_MR3     .usect "CLAscratch",2

    It looks like i missed the warnings on these legacy variables during test. I will file a bug to have it fixed on the next minor revision. Ill try to get that out quickly. Thanks for spotting it.

  • I was thrilled to find this post as I ran into the same problems with the CLA scratchpad and CLAmath.  I can confirm that the updates to the new compiler (tried with both TI v15.12.1.LTS and TI v6.4.11) and CLAmath library v4_01_00_00 are now compatible with the new scratchpad.  Fortunately, I was using CLAsinPU and CLAcosPU functions and didn't experience the same problem as found with CLAatan2PU.  Thank you for getting this updated.