Designed for plug-and-play, emFloat can replace a default floating-point library, delivering better performance with less code. Very fast and very small, it delivers FPU-like performance in pure software. Where available, it even boosts the performance of an FPU for complex mathematical functions.
It is available stand-alone, in source code form, for developers who wish to increase performance or reduce the code size of their application without replacing the entire runtime library supplied with their toolchain.
emFloat can also be licensed for inclusion in third-party IDEs. An example is Microchip choosing to include emFloat in the Microchip XC32 V4.0 Compiler Toolchain.
Benchmarking for both floating-point and runtime libraries can be done quickly and easily using Embedded Studio, which is readily available at no cost for evaluation and non-commercial usage under SEGGER’s Friendly License.
For details on why using a thoughtfully designed runtime library is important, refer to the emRun page.
- Small code size, high performance
- Plug-and-play: Can easily replace the default floating point library, delivering better performance with less code.
- Flexible licensing, for integration into user applications or toolchains.
- C-Variant can be used on any 8/16/32/64-bit CPU.
- Hand-coded, assembly-optimized variants for RISC-V and ARM
- Fully reentrant
- No heap requirements
emFloat is available for integration into specific projects by end users, as well as to toolchain providers that want to deliver a top-of-the-line runtime and/or floating-point library to their users.
Licensing options are available to fit any such needs, usually with a single payment and no royalty obligation.
The library is delivered in source code, with optional rights for redistribution in object code form. All delivered C and assembly language source files are fully commented.
SEGGER software is not covered by an open source or required attribution license, and can be integrated into any commercial or proprietary product, without the obligation to disclose the combined source.
emFloat is available in a universal variant written in C, and specific variants for different CPUs. The specific variants include modules written in assembly language, optimized for the CPU architecture, and deliver a higher performance than the universal C variant.
Universal C Variant:
The universal version is written in C. The performance is highly optimized and much higher than the performance of comparable, C-coded open source implementations.
Supported CPUs: The universal variant can be used on any platform, including 8-, 16-, 32, and 64- bit processors.
The ARM-optimized variant is fully coded in Assembly language, conforming to the AEABI.This means it is compatible with any (A)EABI compliant tool chain, including any GCC, LLVM/Clang based tool chains as well as Arm’s own compiler (incl. Keil) and IAR and can replace the default runtime library or parts of it.
Supported CPUs: The Arm Variant supports any 32-bit ARM CPU, starting from ARM Architecture V4. This includes Cortex-M, Cortex-A, and Cortex-R.
The RISC-V Variant is written in assembly language, providing functions compatible with the EABI. It can easily be used to replace the default runtime library of EABI compliant toolchains.
Supported CPUs: The RISC-V Variant supports RV32I and RV32E with architecture-specific acceleration. It supports faster multiply and divide with the M (multiply/divide) extension. It also supports fast division even if if the M extension lacks a divide instruction.
Implementation and design
emFloat consists of two parts:
- Arithmetic functions
implementing functionality similar to that of the FPU, such as floating-point add, subtract, multiply, divide, comparisons, and conversions
- Mathematical functions
using the most efficient, modern algorithms, benefiting systems with or without an FPU
While all mathematical functions are written in C, the arithmetic functions for the Arm and RISC-V variants are hand-coded in assembly language. For other processor architectures the library has a portable C implementation.
emFloat is optimized on both, the design level (using efficient algorithms) as well as the implementation level (running on different architectures). The source code contains options to fine-tune it for high performance or small code size or a balance of the two, delivering excellent performance in all cases.
It provides a consistent execution environment which ensures that infinities, not-a-number, and zero results with correct sign are accepted as inputs and generated as outputs. To be consistent with floating-point units executing in fast mode, the library elects to flush subnormals to a correctly-signed zero. Because subnormals do not typically occur in embedded systems, this optimization enables significant code size reduction.
Integration and use
emFloat provides all well-known floating-point-related API functions of C standard libraries, as well as floating-point-operation functions defined by the architecture’s EABI which are implicitly called and added by the compiler.
The floating-point Library can either be integrated into a toolchain to replace the existing standard library implementation, or it can be used side-by-side. The side-by-side use enables selective calls to the Floating-Point Library, while retaining the toolchain’s standard library, which makes the integration and use easy and simple.
Example: To return the sine of a value x:
- With the integrated use, call sin(x).
- With the side-by-side use, call SEGGER_sin(x).
To multiply two float values A and B without the use of an FPU:
- With the integrated use, call A * B, for which the compiler will implicitly call __mulsf3(A, B) or __aeabi_fmul(A, B).
- With the side-by-side use, call SEGGER_fmul(A,B)
emFloat is configurable for small code size or increased execution speed or a combination. Optimizing for code-size or execution-speed or a balance of both does not cause any loss of accuracy. Calculated results are identical in all modes.
In the source distribution, the library can be configured and tuned to favor faster or smaller code with different levels of optimization:
-2 – Favor size at the expense of speed
-1 – Favor size over speed
0 – Balanced
+1 – Favor speed over size
+2 – Favor speed at the expense of size
The sections below show the performance of the high-level explicit functions and the low-level implicit floating-point functions of different architectures. For more information please refer to the blog post Floating-point face-off, part 2.
Note: Due to the specific features of each architecture, the performance values should not be compared to each other. Instead these values are generated for comparison with other floating-point libraries.
The assembly language variants of the emFloat take advantage of processor-specific features. Each architecture has its own fine-tuned implementation.
In the Arm variant, the floating-point support makes use of the 32-bit Arm and Thumb-2 instruction set and uses divide instructions and extended multiply instructions, when available, which results in a smaller and faster implementation. Pure Thumb instruction sets, such as on Cortex-M0 and Cortex-M23 processors, are, of course, supported entirely, too.
In the RISC-V variant, software floating-point is supported on all RV32I and RV32E architectures. The floating-point implementation takes full advantage of processors that have the M extension, and processors that have the M extension but without a divide instruction. The C extension is supported to select registers that make the best use of the compact instruction encoding, achieving smaller code.
The assembly language versions have multiple implementations of arithmetic operations, using architectural details and tailored algorithms to make the best use of the available instruction set. For instance, for single precision division:
- Use a division instruction to iteratively develop a quotient, if available.
- If no division instruction, but there is a multiplication instruction, use an initial reciprocal approximation refined by Newton-Raphson iterations with a final correction and multiplication.
- If no division and no multiplication instruction, use a non-restoring division algorithm.
Similar optimizations apply to double-precision division.
API functions — Explicit & implicit
Explicit Functions: emFloat implements all standard library functions which are usually exposed through math.h. These functions are always explicitly called by a user application.
With the integrated use of the library, the standard function can simply be called (no prefix), with the side-by-side use, the functions of this library can be called instead of the standard library implementation by adding the prefix “SEGGER_”. The API interface is compatible.
Implicit Functions: When there is no hardware support for basic operations, such as multiplication of two floats, the compiler adds calls to helper functions emulating the operation with available resources. These are the implicit functions, defined by the toolchain’s and architecture’s EABI.
With the integrated use of the specific variants of emFloat, the compiler will use its implicit functions. When used side-by-side, the functions can be explicitly called instead of writing the standard operation in code.
Explicit function performance
For verification and benchmark of the explicit functions, the IEEE-754 Floating-point Library Benchmark application is available. It measures performance and precision of the implementation. For each function, significant values have been chosen to get best coverage.
The tables below show the results of the benchmark application running the C implementation on different architectures.
Performance on Arm: The benchmark has been done on an Arm Cortex-M4 microcontroller (NXP K66FN2M0), running from RAM.
Performance on RISC-V: The benchmark has been done on an RISC-V RV32IMAC microcontroller (GigaDevice GD32VF103), running from RAM.
Implicit function performance
The following tables show the performance and code size of the Arm and RISC-V EABI floating-point functions.
The performance benchmark runs the speed-optimized implementation of the floating-point library (__SEGGER_RTL_OPTIMIZE +2).
The code size has been measured with size optimization (__SEGGER_RTL_OPTIMIZE -2). The speed-optimized configuration requires slightly more code.
Performance on Arm: The benchmarks have been done on an Arm Cortex-M4 microcontroller (NXP K66FN2M0), running from RAM, compiled with Embedded Studio (GCC).
EABI function performance on RISC-V
The benchmarks have been done on a GD32VD107 (RV32IMAC), running from Flash, compiled with Embedded Studio (GCC), optimized for speed.
|Function||Cycles, Min||Cycles, Max||Cycles, Avg|
EABI function code size on RISC-V
For function code size, the floating-point library has been compiled with optimization for size, targeting RV32IMC.
|Function||Code Size [Bytes]|
Notes: __subsf3 tail-calls __addsf3, __subdf3 tail-calls __adddf3. __nesf2 is an alias of __eqsf2, __nedf2 is an alias of __eqdf2.
To demonstrate how competitive the floating-point library is from a size perspective, a level -playing-field benchmark is available. Quite simply, it calls a selection of the explicit floating-point library functions from main().
For the Arm variant and similarly for RISC-V, a single application and startup code can successfully link against multiple vendor-provided runtime systems thanks to all compilers conforming to the core-specific EABI. This simplifies the swapping of libraries both in the benchmark and in other projects.
The benchmark project uses exactly the same object modules with different runtimes for each vendor. The project uses Embedded Studio and a standard project template to build for different architectures.
The Arm applications are built with the SEGGER Compiler and the SEGGER Linker. The RISC-V applications use the GNU tools which are included in Embedded Studio.
Size comparison on Arm
emFloat has been tested against:
- IAR Embedded Workbench 8.50
- GNU Arm Embedded 9-2020-q2-update
- Arm Compiler 6.14, standard Arm libraries (flush-to-zero mode)
- Arm Compiler 6.14, MicroLib (non-conforming IEEE implementation)
- TI Code Composer 20.2.1 LTS
The table shows the results for ARMv7M with full software floating point.
|AC6 MicroLib||18,668 bytes|
Size comparison on RISC-V
For RISC-V emFloat has been tested against:
- standard 2019-08-gcc-8.3.0 toolset (maintained by SiFive)
These are the results for RV32IMC.