This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

memory optimizations

Hello,

I write code C using C51 for DP8051 (of DCD).
I start to experience problem with the too small 256-bytes internal memory.
It seems that when adding an automatic idata variables (function-internal) even to functions that are never called, the number of bytes used in the idata memory grows.
I have read some information about the fact that the compiler will not use stack, and instead will choose which variables it can overlay on the same memory locations. I still think that if a function is never called then another parameter in it should not change the number of idata bytes used. I have also found that adding automatic idata variables to some functions will change the number of used idata bytes (after compile and build) while adding the same variable to another function may not change the used idata bytes after compilation. this is expected, but still is like a mist to me, since I don't have the knoledge that will help me to get the best out of the comiler.
The following code demonstrates what I saw:

static void Cmd_parser_write (UINT8 DPP_megablock, UINT16 write_addr, UINT8 write_value)
{
	UINT8 idata DPP_save_val = DPP;
//	UINT8 idata temp_memcheck0;// ### remove this comment
//	UINT8 idata temp_memcheck1;// ### remove this comment
	DPP = DPP_megablock;
	XBYTE[write_addr] = write_value;
	DPP = DPP_save_val;
} /* end of Cmd_parser_write */

static void Cmd_parser_read (UINT8 DPP_megablock, UINT16 read_addr, UINT8 DPP_storage, UINT16 storage_addr)
{
	UINT8 idata DPP_save_val = DPP;
	UINT8 idata data_read;
//	UINT8 idata temp_memcheck0;// ### remove this comment
//	UINT8 idata temp_memcheck1;// ### remove this comment

	DPP = DPP_megablock;
	data_read = XBYTE[read_addr];
	DPP = DPP_storage;
	XBYTE[storage_addr] = data_read;
	DPP = DPP_save_val;
} /* end of Cmd_parser_read */
when unmarking temp_memcheck0 from Cmd_parser_write function the memory size will not change, while when unmarking this variable from Cmd_parser_read function the size if internal data grows.


I would like to get explanation about the way that the compiler analyze the code and choose which variables can be overlaid, in order to write more efficient code that will consume as less idata memory as possible, and leave as much memory as possible for the stack. Will the compiler cross files in this kind of optimization ?
Another question in the same issue:
While looking at the map file, is see the following:
            TYPE    BASE      LENGTH    RELOCATION   SEGMENT NAME
            -----------------------------------------------------

            * * * * * * *   D A T A   M E M O R Y   * * * * * * *
            REG     0000H     0008H     ABSOLUTE     "REG BANK 0"
            REG     0008H     0008H     ABSOLUTE     "REG BANK 1"
            REG     0010H     0008H     ABSOLUTE     "REG BANK 2"
            DATA    0018H     0008H     UNIT         ?DT?C2C_IF_DRIVER
            BIT     0020H.0   0001H.1   UNIT         _BIT_GROUP_
            BIT     0021H.1   0000H.3   UNIT         ?BI?PCC_GLOBALS
            BIT     0021H.4   0000H.1   UNIT         ?BI?_PCC_TIMER_1_WAIT?PCC_SERVICE_ROUTINES
            BIT     0021H.5   0000H.1   UNIT         ?BI?PCC_UART_DRIVER
            BIT     0021H.6   0000H.1   UNIT         ?BI?LOG?LOG
                    0021H.7   0000H.1                *** GAP ***
            DATA    0022H     002CH     UNIT         _DATA_GROUP_
            DATA    004EH     0008H     UNIT         ?DT?_FLOOR?FLOOR
            DATA    0056H     0004H     UNIT         ?DT?_PCC_TIMER_1_WAIT?PCC_SERVICE_ROUTINES
            DATA    005AH     0004H     UNIT         ?DT?LOG?LOG
            DATA    005EH     0001H     UNIT         ?DT?PCC_GLOBALS
            DATA    005FH     0001H     UNIT         ?DT?_CMD_PARSER_CALC_TX_GAINS?PCC_CMD_PARSER
            IDATA   0060H     0049H     UNIT         _IDATA_GROUP_
            IDATA   00A9H     0011H     UNIT         ?ID?_CMD_PARSER_CALC_TX_GAINS?PCC_CMD_PARSER
            IDATA   00BAH     0004H     UNIT         ?ID?MPC_PCC_IF_DRIVER
            IDATA   00BEH     0002H     UNIT         ?ID?UART_COM_GETCHAR?PCC_UART_DRIVER
            IDATA   00C0H     0002H     UNIT         ?ID?UART_GET_RBUFLEN?PCC_UART_DRIVER
            IDATA   00C2H     0001H     UNIT         ?ID?_PCC_TIMER_1_WAIT?PCC_SERVICE_ROUTINES
            IDATA   00C3H     0001H     UNIT         ?STACK
It is not clear to me why after _IDATA_GROUP_ only few functions will be reported as IDATA memory consumers, while many other functions will not report any idata consuming at all (and their local automatic variables are probably included in the _IDATA_GROUP_ general section). I would also like to know if and how I can get a detailed description for the usage of the _IDATA_GROUP_ (which variables from which functions are included in that space). This information will hopefully help me to optimize the code to consume less memory.

Thanks,
Amit Alon.

0