QFPlib is an alternative floating-point library for the Cortex-M CPUs. The original version is written for the Cortex-M0 core, optimized for size (using just slightly over 1K bytes of code space, including the trigonometric functions), and yet is compliant with the IEE754 single precision floating-point standard. This is significantly smaller than the routines in Nanolib and other “optimized” floating-point libraries.
A new version of QFPlib written for Cortex-M3 (and above) is optimized for speed and accuracy, while keeping code size within reasonable bounds. QFPlib for M3 provides correctly rounded addition, subtraction, multiplication, division and square root operations, and sine, cosine, tangent, arctangent, logarithm and exponential functions that give a very high degree of accuracy. QFPlib for Cortex-M3 takes up approximately 12K bytes of code space if all routines are used. It is benchmarked to be faster and more IEEE754 compliant than the routines provided by Micro Digital’s ‘GoFast’, IAR, and Keil as of 2016. See the webpage https://www.quinapalus.com/qfplib-m3.html.
In this document, QFPlib refers to either version of the libraries. It is simple to use QFPlib with JumpStart Embedded Tools for Cortex; you need only to enable the checkbox in the Build Options under Nanolib. ImageCraft has written a set of interface functions to make using QFPlib easy. To use QFPlib for basic floating-point operations such as add/sub/mul/div. All you need is to enable the checkbox as described, and use normal C/C++ operations, e.g. float_a + float_b, and QFPlib will be used in place of the Nanolib’s routines.
Behind the scenes: the IDE inserts the libraries libqfplib-m0.a or libqfplib-m3.a before the reference to Nanolib. The libqfplib functions include the QFPlib routines by the original author and the interface routines written by ImageCraft. The ImageCraft-written interface functions have the same names as the ones defined in Nanolib, thus overriding the Nanolib implementation when linked prior to the default library.
QFPlib also defines some trigonometric routines. You will have to call these functions explicitly, as they do not map directly to the ways GCC treats these function calls. GCC generates inline table lookup code for these function calls and no function call is actually made. You must include either the header file qfplib.h (for Cortex-M0 core) or qfplib-m3.h (for Cortex-M3 or above cores) so that their function signatures are known. These header files are in the <install root>\include directory (whose path to known to the IDE so you do not have to enter the path in the Build Options).
Unless otherwise noted, all of the QFPlib functions have been minimally tested by ImageCraft. The following tables summarize the two sets of functions:
Functions that are called implicitly by GCC through the interface functions
Function |
Note |
Tested by ImageCraft |
qfp_fadd |
Mapped to floating point ‘+’ operator |
Yes |
qfp_fsub |
Mapped to floating point ‘-‘ operator |
Yes |
qfp_fmul |
Mapped to floating point ‘*’ operator |
Yes |
qfp_fdiv |
Mapped to floating point ‘/‘ operator |
Yes |
qfp_fdiv_fast |
Not mapped by ImageCraft. Must be called explicitly. Faster but less accurate version of qfp_fdiv. |
No |
qfp_float2int |
Mapped to (int) cast operator |
Yes |
qfp_float2uint |
Mapped to (unsigned int) cast operator |
Yes |
qfp_float2fixed |
Float to fixed point conversion. Not used |
No |
qfp_float2ufixed |
Float to unsigned fixed point conversion. Not used |
No |
qfp_int2float |
Mapped to (float) cast operator from int |
Yes |
qfp_uint2float |
Mapped to (float) cast operator from unsigned int |
Yes |
qfp_fix2float |
Fixed point to float conversion. Not used |
No |
qfp_ufix2float |
Unsigned fixed point to float conversion. Not used |
No |
qfp_fcmp |
Core float compare routine, used by compare routines below |
Yes |
qfp_fcmpeq |
Mapped to floating point ‘==’ and ‘!=’ operators |
Yes |
qfp_fcmplt |
Mapped to floating point ‘<’ operator |
Yes |
qfp_fcmple |
Mapped to floating point ‘<=’ operator |
Yes |
qfp_fcmppge |
Mapped to floating point ‘>=’ operator |
Yes |
qfp_fcmppgt |
Mapped to floating point ‘>’ operator |
Yes |
Functions that must be explicitly called by the user program.
Function |
Note |
qfp_fcos |
Cosine |
qfp_fsin |
Sine |
qfp_ftan |
Tangent |
qfp_fatan2 |
Arctangent |
qfp_fexp |
Exponent |
qfp_fln |
Natural Log |
qfp_fsqrt |
Square Root |
qfp_fsqrt_fast |
Faster but less accurate version of qfp_fsqrt. Not tested. |
The arguments and return values for the trigonometric functions are in radians, the same as their GCC counterparts.
Some routines in the QFPlib-m0, i.e. qfp_ftan, qftp_atan2, and qfp_fexp may produce slightly different results than the table lookup code used by GCC. Other trig functions may behave similarly for some arguments. The differences are within the limits of computing these functions using 32-bit floats.
NOTE: QFPlib is released under GPL. According to its author, Mark Owen:
Qfplib is licensed under version 2 of the GNU GPL: see http://www.gnu.org/licenses/. Roughly speaking, this means that if you wish to use it in conjunction with non-GPL code you will require an alternative license, which you may purchase from the author of Qfplib. For more information please contact qfplib@quinapalus.com or visit http://www.quinapalus.com/qfplib.html.