This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [fortran PATCH] Implement a(:,:) = 0.0 using memset (take 2)
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: sgk at troutmask dot apl dot washington dot edu (Steve Kargl)
- Cc: pinskia at physics dot uc dot edu (Andrew Pinski), roger at eyesopen dot com, gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Mon, 18 Dec 2006 22:24:46 -0500 (EST)
- Subject: Re: [fortran PATCH] Implement a(:,:) = 0.0 using memset (take 2)
>
> On Mon, Dec 18, 2006 at 09:46:35PM -0500, Andrew Pinski wrote:
> > >
> > > + case BT_REAL:
> > > + return mpfr_sgn (expr->value.real) == 0;
> >
> > How well does the above handle -0's?
> >
>
> It handles it as you would expect, and gfortran has depended
> on this behavior for a long time.
>
> #include <stdio.h>
> #include <gmp.h>
> #include <mpfr.h>
>
> int main(void) {
> mpfr_t z;
> mpfr_init(z);
> mpfr_set_ui(z, 0, GMP_RNDN);
> mpfr_out_str(stdout, 10, 0, z, GMP_RNDN); printf("\n");
> if (mpfr_sgn(z) == 0) printf("zero\n");
> mpfr_neg(z,z,GMP_RNDN);
> mpfr_out_str(stdout, 10, 0, z, GMP_RNDN); printf("\n");
> if (mpfr_sgn(z) == 0) printf("zero\n");
> return 0;
> }
> % gcc -o z a.c -I/usr/local/include -L/usr/local/lib -lmpfr -lgmp
> % ./z
> 0
> zero
> -0
> zero
Except -0 should not be done using memset so really we are handling it incorrectly :).
The reason why I say we should not handle -0 with memset is because -0 has the upper bit set only
which cannot be done using memset.
Thanks,
Andrew Pinski