Jump to content

Basic FPU question

Recommended Posts

I have what is probably a stupid question.  If I am using the gcc toolchain to compile c code for the launchpad (LM4F) how exactly do I use the floating point unit? TI has functions to enable the floating point unit in driverlib, but once I enable it does that mean all math operators (like + * / -) get handled by the fpu automatically? or just all the ones where the arguments are floats, or do I have to specify somehow that i want it to use the FPU?  I feel like this is a basic universal concept that I just do not know, and can't seem to find addressed anywhere.





Share this post

Link to post
Share on other sites

Hello Itolias, I can't really say anything specific to GCC since I'm a CCS user but... You might look into using the IQMath Library. If you look in your Stellarisware folder $STELLARIS/docs, you'll find the pdf for the IQMath. With either just using the FPU.h or using the IQMath library, standard operators are handled normally. You will directly load values of specified types into HW registers for operation with the FPU.


Looking in $STELLARIS/IQMath, there appears to be a version for GCC so you're set there. I definitely recommend IQMath; chaper 5 is where I'm at with trig functions for my compass display.


Also, if you've downloaded the full Stellarisware DRL (not just for the LP), look in $STELLARIS/boads/dk-lm3s9d96 for a good IQMath example.


edit: http://www.ti.com/lsds/ti/microcontroller/arm_stellaris/iq_math.page?DCMP=iqmath&HQS=Other+OT+iqmath

Share this post

Link to post
Share on other sites

I don't know the answer but have a suggestion that might help you find out.


You probably have to tell gcc to use the hardware floating point.  (Your toolchain may already do

this for you.)


From http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html




    Specifies which floating-point ABI to use. Permissible values are: `soft', `softfp' and `hard'.
    Specifying `soft' causes GCC to generate output containing library calls for floating-point operations. `softfp' allows the generation of code using hardware floating-point instructions, but still uses the soft-float calling conventions. `hard' allows generation of floating-point instructions and uses FPU-specific calling conventions.
    The default depends on the specific target configuration. Note that the hard-float and soft-float ABIs are not link-compatible; you must compile your entire program with the same ABI, and link with a compatible set of libraries.



I assume that once you tell the compiler to use the fpu, it would automatically use the FPU only for operations involving floating point - i.e. if I multiply 2 ints, it uses integer multiply if I use a float or double.  (That is how c works on regular processors that I am aware of.)


To find out for sure - have your compiler generate a listing of the assembly source code

(preferably interspersed with the original c code).

Then compare the output with and without the hardware FPU enabled.

(Even if you don't know assembler you can see what code changes)

Share this post

Link to post
Share on other sites

What I remember reading from the reference manual is that the LM4F120 defaults, on reset or powered on, to the FPU being "disabled" or off. It has to be enabled in code prior to being used.


I think it was mentioned as a "backwards compatible" thing so M4 and other code without FPU abilities could run without modification.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now