There are three ways to deal with floating point:
- You can restrict all floating-point activity to one task level. While highly restrictive, this approach can be useful where calculations are slow and high priority activities are very time critical.
- You can disable interrupts while performing floating-point operations. This could slow things down dramatically on interrupt response.
- You can attempt to make the floating point reentrant. Borland C++ 3.0 floating-point operations are documented to be reentrant. Microsoft states that theirs are not except when you use the command line option /FPi87, which requires the use of a coprocessor. Example:
union {
char state[108];
int control;
} coproc;
Tasks using the coprocessor must save and restore its context using assembly language instructions.
/* Coprocessor Context Save *
* for in line assembly */
asm fsave coproc.state
asm fldcw coproc.control
.
/* floating point operations */
.
.
/* Coprocessor Context Restore */
asm frstor coproc.state
Coprocessor hardware provides a reentrancy problem for multitasking. To save the context of an 80x87 coprocessor, 94 bytes are needed for the 8087 or 80287, 108 bytes for 80387 coprocessors.