I have a header file containing a lot of small inline functions. Most of them happen to have constant data. Since these functions are performance critical, the way they handle constants becomes important. AFAIK there are two ways to refer to constants:
1) Define them in a separate source file that is later linked with the application.
2) Define the constants in-place.
I would choose the latter way because it's more maintainable. However, the it might be slower if the compiler doesn't optimize thousands of equal constants that are created by inlining.
The question:
Will the compiler combine these equal constants? In particular, which of the following methods will be utilized?
1) Combining of equal constants across the compilation unit.
2) Combining of equal constants across the linking module (whole program or library)
3) Combining the constants with any static constant data that happens to have the same bit pattern and fulfills the alignment requirements across the compilation unit or whole program.
I use a modern compiler (GCC4.5).
I'm not an expert in assembler, thus I couldn't answer this question myself using several simple tests :)
EDIT:
The constants are quite big (most of them at least 16 bytes), so the compiler can't make them immediate values.
EDIT2:
EXAMPLE of the code
This one uses the constant in-place:
float_4 sign(float_4 a)
{
const __attribute__((aligned(16))) float mask[4] = { //I use a macro for this line
0x80000000, 0x80000000, 0x80000000, 0x80000000};
const int128 mask = load(mask);
return b_and(a, mask);
}