https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110622

--- Comment #16 from Mathieu Malaterre <malat at debian dot org> ---
(In reply to Xi Ruoyao from comment #15)
> (In reply to Mathieu Malaterre from comment #14)
> > (In reply to Andrew Pinski from comment #13)
> > > (In reply to Mathieu Malaterre from comment #12)
> > > > I am seeing a difference in result (log1p computation) in the range:
> > > > 
> > > > 4318952042648305665 - 0x1.0000000000001p-64
> > > > 4368493837572636672 - 0x1.002p-53
> > > > 
> > > > the other values seems to match expectation of log1p computation.
> > > 
> > > But you used excess-precision=fast
> > > 
> > > *** This bug has been marked as a duplicate of bug 323 ***
> > 
> > AFAIK bug #323 does not mention my trick:
> > 
> >   asm volatile("" : "+r"(y.raw[0]) : : "memory");
> > 
> > That simple line totally changed the optimizer code generation.
> 
> Because in x87 the excessive precision only exists in x87 stack-like
> registers.  The "memory" clobber forces a store and reload for all
> non-register variables, thus the value is truncated into a normal double
> value and the excessive precision is lost.
> 
> There are infinite ways to work around an issue, but it does not mean PR 323
> must mention all of them.

Oh, I see. Basically my trick is convoluted `-ffloat-store`.

I finally took myself by the hand and convinced me with a simple code:

```
// gcc -m32 -fexcess-precision=fast -O2 t.c
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

[[gnu::noipa]] void test(uint64_t v, double x, double y) {
  const double y2 = x + 1.0;
  if (y != y2)
    printf("error %" PRIu64 " %.17g %a\n", v, x, x);
  else
    printf("ok %" PRIu64 " %.17g %a\n", v, x, x);
}

void main() {

  uint64_t kSamplesPerRange = 4000, start = 0, stop = 9218868437227405311;
  uint64_t step = (stop / kSamplesPerRange);
  for (uint64_t value_bits = start; value_bits <= stop; value_bits += step) {
    double value;
    memcpy(&value, &value_bits, sizeof value);
    double x = value;
    double y = x + 1.0;

    test(value_bits, x, y);
  }
}
```

please accept my apologies for the noise.

Reply via email to