I am writing C code and compiling it for a PowerPC architecture. At the same time, the C code contains floating point variable variables that I want to put in the .text section instead of .rodata , so the function code is autonomous.
The problem is that in PowerPC , the only way to move a floating point value to a floating point register is to load it from memory . This is a limitation of the set of instructions.
To convince GCC to help me, I tried to declare a float as a static const . No difference. Using pointers, same results. Using __attribute__((section(".text"))) for a function, the same results for each floating point variable individually:
error: myFloatConstant causes a section type conflict with myFunction
I also tried disabling optimization using #pragma GCC push_options #pragma GCC optimize("O0") and #pragma GCC pop_options . Plus, I pretend that I have an unsigned int :
unsigned int *myFloatConstant = (unsigned int *) (0x11000018); *myFloatConstant = 0x4C000000;
Using float:
float theActualFloat = *(float *) myFloatConstant;
I would still like to save -O3 , but it uses .rodata again, so the potential response would include an optimization flag which creates floats in .rodata starting with -O1 does this happen?
The best scenario is that I can use the “usually” float in the code plus the maximum optimization, and they will never fit in .rodata at all.
I believe that GCC will probably place the float constant between the code by mixing the data and the code, loading from this place into the floating point register, and continuing. It can be written manually, I believe, but how to make GCC do it? Forcing an attribute on a variable causes an error from above, but technically this should be feasible.
c assembly gcc floating-point powerpc
BullyWiiPlaza
source share