saving FPU state in setjmp/longjmp

David Schultz das at FreeBSD.ORG
Mon Jun 16 19:35:33 UTC 2008

Are setjmp/longjmp supposed to save and restore the FPU control
word (rounding mode, exception masks, etc.)? They're specifically
not supposed to touch the status word, and one would think that
they shouldn't touch the control word either. From a pragmatic
point of view, most apps don't touch the FP control word anyway,
and the few that do are better off with fegetenv/fesetenv and friends.

A brief survey of setjmp/longjmp implementations indicates:
- freebsd/arm saves and restores the FPU status word, which is wrong.
- freebsd/i386 and freebsd/amd64 save and restore the x87 control word
  but not the SSE control word, which is half wrong in one direction or
  the other.
- freebsd/everything-else don't touch the FPU.
- linux doesn't touch the FPU.
- solaris doesn't touch the FPU.

So the real question is whether to remove the part of setjmp and
longjmp that fiddle with the x87 control word, or whether to
extend these functions to also save and restore the SSE control
word. The fact that SSE has been around for a while and nobody has
noticed the breakage suggests that either change should have
minimal impact on compatibility.

More information about the freebsd-amd64 mailing list