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/TMS320C28346: Tell compiler to use data blocking in another translation unit using "extern" global variables

Part Number: TMS320C28346

Tool/software: TI C/C++ Compiler

I have file hello.c

/**
 * hello.c
 */

#include "defs.h"

int main(void)
{
    a = 1;
    b = 1;
    c = 1;

    foo();
	return 0;
}
/**
 * hello.c
 */

#include "defs.h"

int main(void)
{
    a = 1;
    b = 1;
    c = 1;

    foo();
	return 0;
}

and i have foo.c

/*
 * foo.c
 *
 */
#include "defs.h"

#pragma SET_DATA_SECTION("sect")
int a;
int b;
int c;
#pragma SET_DATA_SECTION()

int foo()
{
    a++;
    b++;
    c++;

    return 0;
}

and i have defs.h

/*
 * defs.h
 *
 */

#ifndef DEFS_H_
#define DEFS_H_

int foo();

extern int a;
extern int b;
extern int c;

#endif /* DEFS_H_ */


the assembly code for foo.c in foo.asm looks like:

;***************************************************************
;* TMS320C2000 C/C++ Codegen                    PC v16.9.6.LTS *
;* Date/Time created: Fri Feb 07 10:07:33 2020                 *
;***************************************************************
	.compiler_opts --abi=coffabi --float_support=fpu32 --hll_source=on --mem_model:code=flat --mem_model:data=large --object_format=coff --silicon_version=28 --symdebug:none 
	.asg	XAR2, FP
	.global	_b
_b:	.usect	"sect",1,1,0
	.global	_c
_c:	.usect	"sect",1,1,0
	.global	_a
_a:	.usect	"sect",1,1,0
;	C:\ti\ccsv7\tools\compiler\ti-cgt-c2000_16.9.6.LTS\bin\ac2000.exe -@C:\\Users\\Vadim\\AppData\\Local\\Temp\\{DBEFC6D6-CDE5-4F19-886A-E7AD4BD4A397} 
	.sect	".text"
	.clink
	.global	_foo

;***************************************************************
;* FNAME: _foo                          FR SIZE:   0           *
;*                                                             *
;* FUNCTION ENVIRONMENT                                        *
;*                                                             *
;* FUNCTION PROPERTIES                                         *
;*                            0 Parameter,  0 Auto,  0 SOE     *
;***************************************************************

_foo:
        MOVW      DP,#_a                ; [CPU_U] 
        INC       @_a                   ; [CPU_] |17| 
        INC       @_b                   ; [CPU_] |18| 
        INC       @_c                   ; [CPU_] |19| 
        MOVB      AL,#0                 ; [CPU_] |21| 
        LRETR     ; [CPU_] 
        ; return occurs ; [] 

and in hello.asm

;***************************************************************
;* TMS320C2000 C/C++ Codegen                    PC v16.9.6.LTS *
;* Date/Time created: Fri Feb 07 10:07:33 2020                 *
;***************************************************************
	.compiler_opts --abi=coffabi --float_support=fpu32 --hll_source=on --mem_model:code=flat --mem_model:data=large --object_format=coff --silicon_version=28 --symdebug:none 
	.asg	XAR2, FP
;	C:\ti\ccsv7\tools\compiler\ti-cgt-c2000_16.9.6.LTS\bin\ac2000.exe -@C:\\Users\\Vadim\\AppData\\Local\\Temp\\{CB2ED061-6C5B-4791-8B03-04F530BE6B67} 
	.sect	".text"
	.clink
	.global	_main

;***************************************************************
;* FNAME: _main                         FR SIZE:   0           *
;*                                                             *
;* FUNCTION ENVIRONMENT                                        *
;*                                                             *
;* FUNCTION PROPERTIES                                         *
;*                            0 Parameter,  0 Auto,  0 SOE     *
;***************************************************************

_main:
        MOVW      DP,#_a                ; [CPU_U] 
        MOVB      @_a,#1,UNC            ; [CPU_] |15| 
        MOVW      DP,#_b                ; [CPU_U] 
        MOVB      @_b,#1,UNC            ; [CPU_] |16| 
        MOVW      DP,#_c                ; [CPU_U] 
        MOVB      @_c,#1,UNC            ; [CPU_] |17| 
        LCR       #_foo                 ; [CPU_] |19| 
        ; call occurs [#_foo] ; [] |19| 
        MOVB      AL,#0                 ; [CPU_] |23| 
        LRETR     ; [CPU_] 
        ; return occurs ; [] 
;**************************************************************
;* UNDEFINED EXTERNAL REFERENCES                              *
;**************************************************************
	.global	_b
	.global	_c
	.global	_a
	.global	_foo

My question how i tell compiler to use data_blocking also in hello.c with external variables, so DP optimization will be executed by compiler?

I know i can make a struct but i need actual variables because i need the adress in .map file for each variable.

Thanks.

  • Use the compiler option --opt_level=4.  That enables the compiler to optimize across files.  In turn, this allows the compiler to see that all those variables are on the same data page, even in the source files which do not define those variables.

    Thanks and regards,

    -George