Search code examples
gccpowerpc

PowerPC GCC floating point instructions


Currently I am developing for a MPC5777 board, with e200z7 cores. Most of the things are going well, but I am stuck with a problem that is really annoying me already. I am trying to use floating point operations on portions of my code, using the embedded hardware support. My toolchain is GCC 6.3 (powerpc-gcc), for which I am using the following flags:

ASFLAGS_BASE = -g -a32 -mbooke -me500 --fatal-warnings

ARCH_FLAGS   = -mpowerpc-gpopt -mfprnd -misel -m32 -mhard-float -mabi=spe -mmfpgpr -mfloat-gprs=single

Please notice the -mfloat-gprs=single flag. That is the one that is giving problems.

When I use -mfloat-gprs=single, I am not able to compile things properly, as some functions are not implemented:

undefined reference to `__extendsfdf2`,
undefined reference to `__adddf3`,
undefined reference to `__divdf3`,

- among others.

Now, if I compile using -mfloat-gprs=double, it goes till the end and generate all my execution files. BUT, using this flag also generates extra functions, not implemented by the e200z7. I can't tell for sure all of them, as the code is getting bigger and it is mostly impossible to track all generated assembly. For instance, at the moment my execution gets stuck when it reaches the efscfd instruction, which is implemented by the e500 core, that has double precision floating point support, but not for the e200, that has single precision support only.

So, any piece of advice here would be amazingly welcome!

Thanks in advance,


Solution

  • In case someone ends up here with a similar problem, I have fixed it by using three flags:

    -mfloat-gprs=single -Wdouble-promotion -fsingle-precision-constant

    What they do is: -mfloat-gprs=single tells the compiler to use general purpose register for floating point operations, instead of floating point registers. =single means it has single precision

    -Wdouble-promotion enables a compiler warning for when gcc tries to convert a single float to a double float

    -fsingle-precision-constant enforces GCC not to convert single float to double float

    I am using -fsingle-precision-constant and -Wdouble-promotion at the same time to be 100% that double will not be used.