Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Jan 2002 10:32:11 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Daniel Eischen <eischen@pcnet1.pcnet.com>
Cc:        Nate Williams <nate@yogotech.com>, Dan Eischen <eischen@vigrid.com>, Peter Wemm <peter@wemm.org>, Archie Cobbs <archie@dellroad.org>, Alfred Perlstein <bright@mu.org>, <arch@FreeBSD.ORG>
Subject:   Re: Request for review: getcontext, setcontext, etc
Message-ID:  <20020108100855.D2662-100000@gamplex.bde.org>
In-Reply-To: <Pine.SUN.3.91.1020107153321.18416A-100000@pcnet1.pcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 7 Jan 2002, Daniel Eischen wrote:

> If you have a call to a function in the middle of doing
> some FP stuff, that function itself could do a slew of
> other FP calculations:
>
>   /* FP munch */
>   foo_fp_munch_lots_more();
>   /* FP munch some more */
>
> What guarantees do you have that the FP state is restored
> to where it was prior to calling foo_fp_munch_lots_more()?

The compiler must arrange to preserve sufficient FP state across
normal function calls, just like it must do for non-FP state.
This may be a very machine-dependent subset of the full FP state.

On i386's, only the control word and the tag word are normally preserved
across (application) functions.  In C99, the control word may be changed
by functions in the feset*() family.  The scope of these changes is
not completely clear, but since the functions are functions, it is
clear that not all functions preserve the control word.  The tag word
conventionally must say that all FP registers are free on entry to a
function call and keep saying this if function doesn't return an FP
result; OTOH, if the function returns an FP result, then that result
will be in a register and the tag for that register will change).

The i386 setjmp()/longjmp() takes advantage of this to only preserve
the control word explicitly.  It doesn't completelty understand the
feset*() family yet.  Neither do I :-).  My current understanding is
that longjmp() must _not_ undo the effects of feset*().  This is not
easy to implement, since longjmp() must restore any FP state that set
temporarily (e.g., changes of the rounding mode for conversion from
FP to integer).  The tag word is preserved automatically since neither
setjmp() nor longjmp returns an FP result.

OTOH, asynchronous function calls (signal handlers) need to preserve
the full state.

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020108100855.D2662-100000>