Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear FPU in i386/x86_64 longjmp() #12873

Closed
jdemeyer opened this issue Apr 24, 2012 · 19 comments
Closed

Clear FPU in i386/x86_64 longjmp() #12873

jdemeyer opened this issue Apr 24, 2012 · 19 comments

Comments

@jdemeyer
Copy link

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 attachment: emms.c on i686 hardware with

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

Apply attachment: 12873_emms.patch

Obsoleted by #13076 and fixed in a better way.

CC: @nexttime

Component: c_lib

Author: Jeroen Demeyer

Reviewer: Volker Braun

Merged: sage-5.1.beta0

Issue created by migration from https://trac.sagemath.org/ticket/12873

@jdemeyer
Copy link
Author

comment:1

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.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

comment:3

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.

@jdemeyer jdemeyer changed the title Clear MMX state in i686 Solaris longjmp() Clear MMX state in i686 longjmp() Apr 25, 2012
@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

Test program

@jdemeyer
Copy link
Author

comment:6

Attachment: emms.c.gz

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

comment:9

Attachment: 12873_emms.patch.gz

@jdemeyer

This comment has been minimized.

@jdemeyer jdemeyer changed the title Clear MMX state in i686 longjmp() Clear FPU in i386/x86_64 longjmp() Apr 30, 2012
@jdemeyer

This comment has been minimized.

@vbraun
Copy link
Member

vbraun commented Apr 30, 2012

Reviewer: Volker Braun

@vbraun
Copy link
Member

vbraun commented Apr 30, 2012

comment:11

The joys of the x86 architechture! ;-)

Patch looks good to me.

@jdemeyer jdemeyer removed this from the sage-5.0 milestone Apr 30, 2012
@jdemeyer jdemeyer added this to the sage-5.1 milestone Apr 30, 2012
@jdemeyer
Copy link
Author

jdemeyer commented May 6, 2012

Merged: sage-5.1.beta0

@jdemeyer
Copy link
Author

jdemeyer commented Jun 3, 2012

Similar test program using setcontext()

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

jdemeyer commented Jun 3, 2012

comment:14

Attachment: context.c.gz

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants