3
votes

This is for an Android NDK project, but I'm guessing it applies to GCC in general for ARM.

I know that the Android NDK uses soft float to maintain compatibility with ARMv5, but it occurs to me that when compiling an ARMv7 library for our project, all calls internal to the library could use hard float, and only use soft float for calls to other libraries, but I'm not sure if it's even possible to tell the compiler to do this. My feeling is that it's not, but I'm hoping that someone might know a way to do it.

(As a side note - if this is possible with Clang in the NDK or if Clang just does this, it'd be good to know)

Some background: it's a physics based library being compiled with the NDK, so heavy on the use of floating point, and I'm looking into possible optimisations.

Edit: thinking about it, it could only determine whether or not a function was external at link time, whereas hard/soft float affects the compiler, so I'm guessing that if this is possible, I'd need to manually specify the functions where hard float should be used so the compiler would know.

1

1 Answers

3
votes

Update: NDK r9b added support for building libraries with -mhard-float. See the NDK page.

(Original answer follows.)

There's no easy way to do it. The compiler would need to know per-method what calling conventions to use, and there's no "soft fp" attribute. You could write (or generate) wrapper functions that convert between calling conventions, but that's awkward and annoying.

If you have a library that uses float, but doesn't have any functions that take float as arguments, and doesn't call out to external functions that take float (e.g. libc utility functions) -- essentially a black box that doesn't appear to an external viewer to use float at all -- then you should be able to build with "hard fp".