Option to disable floating point in gcc

Asked by Bryn Smith

Is there some way to disable floating point operations in GCC? A number of the supported cores do not have FPUs and so floating point operations are emulated in software by GCC. It would be good to disable this at the compiler level so that we do not inadvertently write code which brings in GCC's (huge) libraries!

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Thomas Preud'homme
Solved:
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Bryn,

We have already started working on a such a feature, although for different purpose initially. It would be nice to hear more about how such a feature should look like for you. Should the compiler refuse to compile if any floating-point data type is found in the source code (whether as variable, litteral values or function parameters and return value)? Should it be a warning instead? Have you met some example where the source code didn't contain any floating-point data type but the generated code contained some floating-point operation?

Your input would help us make sure that the solution we develop is well adapted to the users.

Best regards.

Revision history for this message
Bryn Smith (9-bsmith) said :
#2

I have used the Green Hills V800 compiler in previous systems. This compiler has an option to refuse any floating point data types and flag an error if any are in the source. This was a very useful option to ensure that all developers and third party libraries did not inadvertently cause blow outs in code size. I can see that an error could be too strict for some projects and so an option to generate a compiler warning might be a better choice.

I have not seen any situation where the compiler has generated floating point code where no floating data types are used in the source.

Revision history for this message
Best Thomas Preud'homme (thomas-preudhomme) said :
#3

Thanks a lot for the precisions Bryn.

I cannot commit to any timeline but I can tell you that it is something we are working on. The current approach would fit in your requirements and give an error in case a float is encountered. We will consider turning it into a warning (that could become error with the proper -Werror flag).

Best regards.

Revision history for this message
Bryn Smith (9-bsmith) said :
#4

Thank you Thomas. I will keep an eye out for new releases!

Revision history for this message
Saul F (saulpwanson) said :
#5

We also would like an option to disable floating-point. However, our code uses compile-time floating point arithmetic to convert floating point literals into our proprietary fixed point type. We need these to compile correctly, but would like the ability to generate a compile-time warning and/or link-time error for code that would call the soft fp library at runtime (e.g. accidentally using the conversion macro on a non-literal).

Hopefully this request is compatible with your implementation.

Thanks,
Saul

Revision history for this message
Saul F (saulpwanson) said :
#6

A minor clarification to my above comment: we use compile-time floating point to compute constant floating point expressions, not just literals.

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#7

Hi Saul,

Thank you for explaining your use case. Right now the approached followed was to forbid any floating point type of float litteral in the front end as this allows to do the detection while parsing the code. However as you point it out this wouldn't work for your use case. We'll take into consideration your use case and think how difficult it would be to address it.

Best regards.