Floating Point Services
Note
Floating point services are currently available only for platforms based on the Intel x86 architecture.
Concepts
The kernel allows an application’s tasks and fibers to use floating point registers on board configurations that support these registers. Threads that use the x87 FPU/MMX registers are known as “FPU users”, while threads that use SSE registers are known as “SSE users”.
Note
The kernel does not support the use of floating point registers by ISRs.
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 tasks or fibers that use floating point registers. It is the kernel’s default floating point services mode.
If a task or fiber uses any floating point register, the kernel generates a fatal error condition and aborts the thread.
Purpose
Use the kernel floating point services when an application needs to perform floating point operations.
Usage
Configuring Floating Point Services
To configure unshared FP registers mode, enable the FLOAT
configuration option and leave the FP_SHARING
configuration option
disabled.
To configure shared FP registers mode, enable both the FLOAT
configuration option and the FP_SHARING
configuration option.
Also, ensure that any task 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 SSE
configuration option to enable support for
SSEx instructions.
Example: Performing Floating Point Arithmetic
This code shows how a routine can use floating point arithmetic to avoid overflow issues when computing the average of a series of integer values. Note that no special coding is required if the kernel is properly configured.
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);
}
APIs
The following floating point services APIs are provided by
microkernel.h
and by nanokernel.h
:
fiber_float_enable()
- Tells the kernel that the specified task or fiber is now an FPU user or SSE user.
task_float_enable()
- Tells the kernel that the specified task or fiber is now an FPU user or SSE user.
fiber_float_disable()
- Tells the kernel that the specified task or fiber is no longer an FPU user or SSE user.
task_float_disable()
- Tells the kernel that the specified task or fiber is no longer an FPU user or SSE user.