I am working on a project in which I have the following code:
file1.c
extern const int z;
int x;
do_some_stuff_to_calculate_x();
y = x / z;
do_some_stuff_with_y();
file2.c
const int z = Z_INIT_VALUE;
Of interest is dividing by file1.c. Because z- extern, therefore, it is not known at compile time [it will be determined at connection time]. Thus, the compiler cannot optimize the separation.
I know that if the value is zknown at compile time, then the compiler will convert division to multiplication and some other manipulations.
Note that the1.c file will be delivered as a library, so recompiling file1.cwith is file2.cnot a parameter.
Does anyone know to make the linker optimize such things? Or any other trick to avoid this EXPENSIVE division?
:)
:
, , , , .
- renesas ( SH725).
- .
- ( , : * 0x0ABCDEFF = 15).
, , .
extern const int common_divisor;
extern const int common_addition;
void handleTheDamnInterrupt(void)
{
int x = *(REG_FOO_1);
int y = x / common_divisor;
y += common_addition;
if( x > some_value )
{
y += blah_blah;
}
else
{
y += foo_bar;
}
*(REG_BAR_1) = y;
}
. , , .
extern const , .