- unsigned long control;
-
- control = os_context_fp_control(context) &
- /* FIXME: Should we preserve the user's requested rounding mode?
-
- Note that doing
-
- ~(FLOAT_STICKY_BITS_MASK | FLOAT_EXCEPTIONS_BYTE_MASK)
-
- here leads to infinite SIGFPE for invalid operations, as
- there are bits in the control register that need to be
- cleared that are let through by that mask. -- CSR, 2002-07-16 */
- FLOAT_TRAPS_BYTE_MASK;
-
- /* FIXME: Shoot me now.
-
- Hardcoded nastiness: the "0"s below refer to the first floating
- point registers -- we should let gcc deal with that. The 8(31)
- refers to the position on the stack, less one, of control (we
- need for control to be the high word of the double loaded by
- lfd; how do I know that r31 contains the stack? I don't, I'm
- just guessing. The 255, on the other hand, is a valid constant
- -- it says "move everything in the upper word into the floating
- point control register. -- CSR, 2002-07-16 */
-
- /* FIXME: it appears that the above text is quite accurate, in the
- sense that this
-
- asm ("stw %0, 12(31); lfd 0, 8(31); mtfsf 255, 0" : : "r" (control) : "r31");
-
- no longer works. */
+ /* KLUDGE: mtfsf has to be run against a float register, so we
+ * construct the float we need to use as an integer, then cast
+ * a pointer to its storage to a double and load that. For
+ * this to work, control must be the same width as a double,
+ * 64 bits. And why aren't we using a union here, anyway? */
+ unsigned long long control;
+ double d;
+
+ /* FIXME: We are only preserving enabled traps and rounding
+ * mode here. Do we also want to preserve "fast mode"? */
+ control = os_context_fp_control(context) &
+ (FLOAT_TRAPS_BYTE_MASK | FLOAT_ROUNDING_MODE_MASK);
+
+ d = *((double *) &control);
+ asm volatile ("mtfsf 0xff,%0" : : "f" (d));