Floating point exceptions with -pthread

Daniel Eischen deischen at freebsd.org
Wed May 4 14:47:09 PDT 2005


On Wed, 4 May 2005, Marc Olzheim wrote:

> On Wed, May 04, 2005 at 09:51:53PM +0200, Marc Olzheim wrote:
> > On Wed, May 04, 2005 at 03:15:06PM -0400, Daniel Eischen wrote:
> > > > It seems to me like something about the floorf() assembly might have
> > > > something to do with it.
> > >
> > > Yeah, I was just trying to narrow down the problem a bit more.
> >
> > I've attached one that's built very tight around floorf().
>
> Replacing floorf() in the program by:
> fabs()
> rintf()
> sqrt()
> expf()
> log10f()
> logf()
> cosf()
> powf(,)
>
> doesn't crash.
>
> The only two functions I found to crash are floorf() and ceilf().
>
> Replacing all floats by doubles and using floor() or ceil() doesn't
> crash either.

floorf() seems to fiddle with the FP control word.  The kernel
and libpthread use fxsave and fxrstor respectively.  These
save and restore the control word, but something may not be
working correctly.

ENTRY(floorf)
        pushl   %ebp
        movl    %esp,%ebp
        subl    $8,%esp

        fstcw   -12(%ebp)               /* store fpu control word */
        movw    -12(%ebp),%dx
        orw     $0x0400,%dx             /* round towards -oo */
        andw    $0xf7ff,%dx
        movw    %dx,-16(%ebp)
        fldcw   -16(%ebp)               /* load modfied control word */

        flds    8(%ebp);                /* round */
        frndint

        fldcw   -12(%ebp)               /* restore original control word */

        leave
        ret

-- 
DE



More information about the freebsd-threads mailing list