Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12873 closed defect (fixed)

Clear FPU in i386/x86_64 longjmp()

Reported by: jdemeyer Owned by: jdemeyer
Priority: major Milestone: sage-5.1
Component: c_lib Keywords:
Cc: leif Merged in: sage-5.1.beta0
Authors: Jeroen Demeyer Reviewers: Volker Braun
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

If an interrupt occurs during a 387 FPU computation or during an MMX computation (which also uses the FPU registers), then some of the FPU registers will be occupied. This may lead to failures with subsequent FPU compuations, see for example #12777. Some operating systems (e.g. Linux and OS X 10.6) restore the FPU state when an interrupt occurs, but on Solaris this is not the case.

The proposed solution is to clear the FPU "tag word" (using the EMMS or FFREE instructions) in the signal handler.

To see the problem in action, compile emms.c on i686 hardware with

gcc -march=pentium2 -m32 -mfpmath=387 -lm emms.c -o emms

Apply 12873_emms.patch

Obsoleted by #13076 and fixed in a better way.

Attachments (3)

emms.c (1.7 KB) - added by jdemeyer 9 years ago.
Test program
12873_emms.patch (2.9 KB) - added by jdemeyer 9 years ago.
context.c (1.8 KB) - added by jdemeyer 9 years ago.
Similar test program using setcontext()

Download all attachments as: .zip

Change History (17)

comment:1 Changed 9 years ago by jdemeyer

Well, actually it's not so clear whether longjmp() should restore the FPU state. I'll try to see whether I can reproduce the problem on Linux i686.

comment:2 Changed 9 years ago by leif

  • Cc leif added

comment:3 Changed 9 years ago by jdemeyer

  • Component changed from solaris to c_lib
  • Description modified (diff)
  • Owner changed from drkirkby to jdemeyer
  • Summary changed from Clear MMX state in i686 Solaris longjmp() to Clear MMX state in i686 longjmp()

I can't be sure that the problem is limited to Solaris. Using a test program (attached), I managed to reproduce the issue on Linux also.

comment:4 Changed 9 years ago by jdemeyer

  • Description modified (diff)

comment:5 Changed 9 years ago by jdemeyer

  • Description modified (diff)

Changed 9 years ago by jdemeyer

Test program

comment:6 Changed 9 years ago by jdemeyer

  • Description modified (diff)

comment:7 Changed 9 years ago by jdemeyer

  • Description modified (diff)

comment:8 Changed 9 years ago by jdemeyer

  • Description modified (diff)
  • Status changed from new to needs_review

Changed 9 years ago by jdemeyer

comment:9 Changed 9 years ago by jdemeyer

  • Description modified (diff)
  • Summary changed from Clear MMX state in i686 longjmp() to Clear FPU in i386/x86_64 longjmp()

comment:10 Changed 9 years ago by jdemeyer

  • Description modified (diff)

comment:11 Changed 9 years ago by vbraun

  • Reviewers set to Volker Braun
  • Status changed from needs_review to positive_review

The joys of the x86 architechture! ;-)

Patch looks good to me.

comment:12 Changed 9 years ago by jdemeyer

  • Milestone changed from sage-5.0 to sage-5.1

comment:13 Changed 9 years ago by jdemeyer

  • Merged in set to sage-5.1.beta0
  • Resolution set to fixed
  • Status changed from positive_review to closed

Changed 9 years ago by jdemeyer

Similar test program using setcontext()

comment:14 Changed 9 years ago by jdemeyer

  • Description modified (diff)

#13076 fixes this problem in a much better way, so that ticket effectively undoes this.

Note: See TracTickets for help on using tickets.