Floating Point Services
The kernel allows threads to use floating point registers on board configurations that support these registers.
Note
Floating point services are currently available only for boards based on the ARM Cortex-M4 or the Intel x86 architectures. The services provided are architecture specific.
The kernel does not support the use of floating point registers by ISRs.
Concepts
The kernel can be configured to provide only the floating point services required by an application. Three modes of operation are supported, which are described below. In addition, the kernel’s support for the SSE registers can be included or omitted, as desired.
No FP registers mode
This mode is used when the application has no threads that use floating point registers. It is the kernel’s default floating point services mode.
If a thread uses any floating point register, the kernel generates a fatal error condition and aborts the thread.
Implementation
Performing Floating Point Arithmetic
No special coding is required for a thread to use floating point arithmetic if the kernel is properly configured.
The following code shows how a routine can use floating point arithmetic to avoid overflow issues when computing the average of a series of integer values.
int average(int *values, int num_values)
{
double sum;
int i;
sum = 0.0;
for (i = 0; i < num_values; i++) {
sum += *values;
values++;
}
return (int)((sum / num_values) + 0.5);
}
Suggested Uses
Use the kernel floating point services when an application needs to perform floating point operations.
Configuration Options
To configure unshared FP registers mode, enable the CONFIG_FLOAT
configuration option and leave the CONFIG_FP_SHARING
configuration
option disabled.
To configure shared FP registers mode, enable both the CONFIG_FLOAT
configuration option and the CONFIG_FP_SHARING
configuration option.
Also, ensure that any thread that uses the floating point registers has
sufficient added stack space for saving floating point register values
during context switches, as described above.
Use the CONFIG_SSE
configuration option to enable support for
SSEx instructions (x86 only).
APIs
The following floating point APIs (x86 only) are provided by kernel.h
: