I am using Compiler Version TI 5.2.5 targeting multiple Tiva processors.
I need to optimize a single function. The optimization levels are for --opt_level=n --opt_for_speec=m, which for short hand I will specify as (n,m).
This function takes the following times:
project level, file level, function level
(off,0), (off,0), (no pragmas): 451msec
(off,0), (3,5), (no pragmas): 151msec
(off,0), (off,0), (3,5): 353msec
BTW, the function below is the only function defined in the file. There are no global or static data defined at the file level.
I have used pragma statements as below and neither achieves the 151msec speed of file optimization.:
#pragma FUNCTION_OPTIONS ( CRC_Calc, "--opt_level=3" );
#pragma FUNCTION_OPTIONS ( CRC_Calc, "--opt_for_speed=5" );
and
#pragma FUNCTION_OPTIONS ( CRC_Calc, "--opt_level=3 --opt_for_speed=5" );
The function reads (standard CRC 16 bit CCITT calculation):
UINT16 CRC_Calc(UINT16 seed,UINT8 *p, UINT32 len)
{
UINT16 rv = seed;
while (len--) {
UINT8 i;
UINT8 byte = *p++;
for (i = 0; i < 8; ++i) {
UINT32 osum = rv;
rv <<= 1;
if (byte & 0x80)
rv |= 1 ;
if (osum & 0x8000)
rv ^= 0x1021;
byte <<= 1;
}
}
return rv;
}
I do not want to optimize an entire library or an entire file of multiple functions. If I have the space, I desire non-optimized code for the ease of debugging.
I can see wanting to optimize a single function out of a file of many functions.
So I have several questions:
Why are the pragmas coming up with a different performance than the file optimizations?
Is the string I am handing to the pragma of the correct syntax?
Should I conclude at this point, if you need to optimize a single function, drag it into its own file and optimize at the file level?