* -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
@ 2015-09-08 20:00 Mathieu Malaterre
2015-09-08 20:05 ` Mathieu Malaterre
0 siblings, 1 reply; 9+ messages in thread
From: Mathieu Malaterre @ 2015-09-08 20:00 UTC (permalink / raw)
To: gcc-help
Andrew,
On Tue, Sep 8, 2015 at 3:22 PM, Andrew Haley <aph@redhat.com> wrote:
> On 09/08/2015 01:40 PM, Mathieu Malaterre wrote:
>> On Tue, Sep 8, 2015 at 2:00 PM, Mathieu Malaterre <malat@debian.org> wrote:
>>> FYI,
>>>
>>> On Tue, Sep 8, 2015 at 12:04 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>>> [...]
>>>> That's not the only option. You could compile one file with GCC and
>>>> all others with Clang and see if you can reproduce it. Repeat for each
>>>> file, which will narrow down the file where the problem occurs. Then
>>>> you can try splitting that file into smaller pieces, with one function
>>>> per file, and repeat the process. That would tell you which function
>>>> or functions get miscompiled by GCC.
>>>
>>> Ok so if I compile eveything with gcc and then only `tcd.c` using
>>> clang, then everything works as expected (no symptoms).
>>> ref: https://github.com/uclouvain/openjpeg/blob/master/src/lib/openjp2/tcd.c
>>>
>>> I'll repeat your approach to find the culprit function.
>>
>> And the culprit function is `opj_tcd_makelayer`:
>>
>> https://github.com/uclouvain/openjpeg/blob/master/src/lib/openjp2/tcd.c#L218
>>
>> Other than the `if (dd / dr >= thresh)` I do not see anything
>> obviously suspicious.
>
> I see floating point, despite your earlier denial. :-)
lol. Sorry about that :(
> Libopenjpeg has a bad reputation for messing with the floating-
> point state. Please make sure the library is not linked with
> -ffast-math.
>
> Beyond that, a few printf()s and "diff" should find the problem.
So here what seems to be working for me, replace:
if (dd / dr >= thresh)
with:
double div; /* OPJ_FLOAT64 */
div = dd / dr;
if (div >= thresh)
However reading the documentation of gcc:
https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/Optimize-Options.html#index-ffloat-store-1074
It appears that -ffloat-store is not activated by default (I did check
that using also the output of `gcc -Q -v`).
So could someone please let me know why `gcc -m32` (no other option!)
produce different behavior (=removes excess precision if my
understanding is correct) in the two above cases ?
Thanks much again for help,
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-08 20:00 -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32)) Mathieu Malaterre
@ 2015-09-08 20:05 ` Mathieu Malaterre
2015-09-08 21:31 ` Manuel López-Ibáñez
0 siblings, 1 reply; 9+ messages in thread
From: Mathieu Malaterre @ 2015-09-08 20:05 UTC (permalink / raw)
To: gcc-help
On Tue, Sep 8, 2015 at 10:00 PM, Mathieu Malaterre <malat@debian.org> wrote:
> Andrew,
>
> On Tue, Sep 8, 2015 at 3:22 PM, Andrew Haley <aph@redhat.com> wrote:
>> On 09/08/2015 01:40 PM, Mathieu Malaterre wrote:
>>> On Tue, Sep 8, 2015 at 2:00 PM, Mathieu Malaterre <malat@debian.org> wrote:
>>>> FYI,
>>>>
>>>> On Tue, Sep 8, 2015 at 12:04 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>>>> [...]
>>>>> That's not the only option. You could compile one file with GCC and
>>>>> all others with Clang and see if you can reproduce it. Repeat for each
>>>>> file, which will narrow down the file where the problem occurs. Then
>>>>> you can try splitting that file into smaller pieces, with one function
>>>>> per file, and repeat the process. That would tell you which function
>>>>> or functions get miscompiled by GCC.
>>>>
>>>> Ok so if I compile eveything with gcc and then only `tcd.c` using
>>>> clang, then everything works as expected (no symptoms).
>>>> ref: https://github.com/uclouvain/openjpeg/blob/master/src/lib/openjp2/tcd.c
>>>>
>>>> I'll repeat your approach to find the culprit function.
>>>
>>> And the culprit function is `opj_tcd_makelayer`:
>>>
>>> https://github.com/uclouvain/openjpeg/blob/master/src/lib/openjp2/tcd.c#L218
>>>
>>> Other than the `if (dd / dr >= thresh)` I do not see anything
>>> obviously suspicious.
>>
>> I see floating point, despite your earlier denial. :-)
>
> lol. Sorry about that :(
>
>> Libopenjpeg has a bad reputation for messing with the floating-
>> point state. Please make sure the library is not linked with
>> -ffast-math.
>>
>> Beyond that, a few printf()s and "diff" should find the problem.
>
> So here what seems to be working for me, replace:
>
> if (dd / dr >= thresh)
>
> with:
>
> double div; /* OPJ_FLOAT64 */
> div = dd / dr;
> if (div >= thresh)
>
> However reading the documentation of gcc:
>
> https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/Optimize-Options.html#index-ffloat-store-1074
>
> It appears that -ffloat-store is not activated by default (I did check
> that using also the output of `gcc -Q -v`).
>
> So could someone please let me know why `gcc -m32` (no other option!)
> produce different behavior (=removes excess precision if my
> understanding is correct) in the two above cases ?
Ok, I think I understand now. -O0 did produce code that is compatible
with -ffloat-store. However I am still required to use -ffloat-store
(explicitly) for any other optimization (at least required with -O2 in
my case).
Sorry for the noise,
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-08 20:05 ` Mathieu Malaterre
@ 2015-09-08 21:31 ` Manuel López-Ibáñez
2015-09-09 5:19 ` Markus Trippelsdorf
2015-09-09 6:08 ` Mathieu Malaterre
0 siblings, 2 replies; 9+ messages in thread
From: Manuel López-Ibáñez @ 2015-09-08 21:31 UTC (permalink / raw)
To: Mathieu Malaterre, gcc-help; +Cc: Andrew Haley, Markus Trippelsdorf
On 08/09/15 22:05, Mathieu Malaterre wrote:
>
> Ok, I think I understand now. -O0 did produce code that is compatible
> with -ffloat-store. However I am still required to use -ffloat-store
> (explicitly) for any other optimization (at least required with -O2 in
> my case).
You are not required to use -ffloat-store, neither is -ffloat-store guaranteed
to work. Please read https://gcc.gnu.org/wiki/FAQ#PR323
(If there is something that is not explained there, it would be better to
expand the answer rather than reply here with bits of info.)
Cheers,
Manuel.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-08 21:31 ` Manuel López-Ibáñez
@ 2015-09-09 5:19 ` Markus Trippelsdorf
2015-09-09 6:08 ` Mathieu Malaterre
1 sibling, 0 replies; 9+ messages in thread
From: Markus Trippelsdorf @ 2015-09-09 5:19 UTC (permalink / raw)
To: Manuel López-Ibáñez
Cc: Mathieu Malaterre, gcc-help, Andrew Haley
On 2015.09.08 at 23:31 +0200, Manuel López-Ibáñez wrote:
> On 08/09/15 22:05, Mathieu Malaterre wrote:
> >
> > Ok, I think I understand now. -O0 did produce code that is compatible
> > with -ffloat-store. However I am still required to use -ffloat-store
> > (explicitly) for any other optimization (at least required with -O2 in
> > my case).
>
> You are not required to use -ffloat-store, neither is -ffloat-store guaranteed
> to work. Please read https://gcc.gnu.org/wiki/FAQ#PR323
And please note that he whole issue has nothing to do with gcc. See
e.g.:
http://stackoverflow.com/questions/31973139/gcc-m32-option-changes-floating-point-rounding-when-not-running-valgrind
for a similar example.
--
Markus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-08 21:31 ` Manuel López-Ibáñez
2015-09-09 5:19 ` Markus Trippelsdorf
@ 2015-09-09 6:08 ` Mathieu Malaterre
2015-09-09 7:19 ` Mathieu Malaterre
1 sibling, 1 reply; 9+ messages in thread
From: Mathieu Malaterre @ 2015-09-09 6:08 UTC (permalink / raw)
To: Manuel López-Ibáñez
Cc: gcc-help, Andrew Haley, Markus Trippelsdorf
Manuel,
On Tue, Sep 8, 2015 at 11:31 PM, Manuel López-Ibáñez
<lopezibanez@gmail.com> wrote:
> On 08/09/15 22:05, Mathieu Malaterre wrote:
>>
>>
>> Ok, I think I understand now. -O0 did produce code that is compatible
>> with -ffloat-store. However I am still required to use -ffloat-store
>> (explicitly) for any other optimization (at least required with -O2 in
>> my case).
>
>
> You are not required to use -ffloat-store, neither is -ffloat-store
> guaranteed to work. Please read https://gcc.gnu.org/wiki/FAQ#PR323
>
> (If there is something that is not explained there, it would be better to
> expand the answer rather than reply here with bits of info.)
Thanks for the link. However -in my case- the compile option
`-fexcess-precision=standard` does produce the same code as
`-ffloat-store`. At least for
[...]
double div; /* OPJ_FLOAT64 */
div = dd / dr;
if (div >= thresh)
[...]
Is there a longer description for `-fexcess-precision=standard` which
explains case of failures ?
Thanks again,
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-09 6:08 ` Mathieu Malaterre
@ 2015-09-09 7:19 ` Mathieu Malaterre
2015-09-09 8:58 ` Andrew Haley
2015-09-09 9:24 ` Manuel López-Ibáñez
0 siblings, 2 replies; 9+ messages in thread
From: Mathieu Malaterre @ 2015-09-09 7:19 UTC (permalink / raw)
To: Manuel López-Ibáñez
Cc: gcc-help, Andrew Haley, Markus Trippelsdorf
On Wed, Sep 9, 2015 at 8:07 AM, Mathieu Malaterre <malat@debian.org> wrote:
> Manuel,
>
> On Tue, Sep 8, 2015 at 11:31 PM, Manuel López-Ibáñez
> <lopezibanez@gmail.com> wrote:
>> On 08/09/15 22:05, Mathieu Malaterre wrote:
>>>
>>>
>>> Ok, I think I understand now. -O0 did produce code that is compatible
>>> with -ffloat-store. However I am still required to use -ffloat-store
>>> (explicitly) for any other optimization (at least required with -O2 in
>>> my case).
>>
>>
>> You are not required to use -ffloat-store, neither is -ffloat-store
>> guaranteed to work. Please read https://gcc.gnu.org/wiki/FAQ#PR323
>>
>> (If there is something that is not explained there, it would be better to
>> expand the answer rather than reply here with bits of info.)
>
> Thanks for the link. However -in my case- the compile option
> `-fexcess-precision=standard` does produce the same code as
> `-ffloat-store`. At least for
Meant to say `does not produce`
> [...]
> double div; /* OPJ_FLOAT64 */
> div = dd / dr;
> if (div >= thresh)
> [...]
>
> Is there a longer description for `-fexcess-precision=standard` which
> explains case of failures ?
From a clean debian/sid 32bits chroot I can no longer reproduce this.
In summary:
1. removed -ffast-math
2. add -std=c99
3. Change the code for an explicit storage of division (div = dd / dr)
=> issue solved !
Thx
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-09 7:19 ` Mathieu Malaterre
@ 2015-09-09 8:58 ` Andrew Haley
2015-09-09 9:24 ` Manuel López-Ibáñez
1 sibling, 0 replies; 9+ messages in thread
From: Andrew Haley @ 2015-09-09 8:58 UTC (permalink / raw)
To: gcc-help
Hi,
On 09/09/2015 08:18 AM, Mathieu Malaterre wrote:
> 1. removed -ffast-math
> 2. add -std=c99
> 3. Change the code for an explicit storage of division (div = dd / dr)
> => issue solved !
Not really, no. Al you've done is conceal the bug.
I really think you should fix the bug. Otherwise it will keep coming
back. -ffloat-store and -fexcess-precision=standard are just
workarounds.
My problem, of course, is that I don't really know what this code is
trying to do, and why it is so sensitive to the last significant bits
of floating-point precision.
Andrew.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-09 7:19 ` Mathieu Malaterre
2015-09-09 8:58 ` Andrew Haley
@ 2015-09-09 9:24 ` Manuel López-Ibáñez
2015-09-09 13:32 ` Mathieu Malaterre
1 sibling, 1 reply; 9+ messages in thread
From: Manuel López-Ibáñez @ 2015-09-09 9:24 UTC (permalink / raw)
To: Mathieu Malaterre; +Cc: gcc-help, Andrew Haley, Markus Trippelsdorf
On 9 September 2015 at 09:18, Mathieu Malaterre <malat@debian.org> wrote:
>> Thanks for the link. However -in my case- the compile option
>> `-fexcess-precision=standard` does produce the same code as
>> `-ffloat-store`. At least for
>
> Meant to say `does not produce`
The FAQ now says: "(whether this option has effect or not depends on
other options, please read the manual entry for -fexcess-precision=
carefully)."
The manual says: "-fexcess-precision=standard is not implemented for
languages other than C, and has no effect if
-funsafe-math-optimizations or -ffast-math is specified. On the x86,
it also has no effect if -mfpmath=sse or -mfpmath=sse+387 is
specified; in the former case, IEEE semantics apply without excess
precision, and in the latter, rounding is unpredictable"
>
>> [...]
>> double div; /* OPJ_FLOAT64 */
>> div = dd / dr;
>> if (div >= thresh)
>> [...]
>>
>> Is there a longer description for `-fexcess-precision=standard` which
>> explains case of failures ?
The manual says: "if -fexcess-precision=standard is specified then
excess precision follows the rules specified in ISO C99; in
particular, both casts and assignments cause values to be rounded to
their semantic types (whereas -ffloat-store only affects
assignments)."
The FAQ says: "Floating-point results may still depend on the
optimization level and target architecture in some cases that are
allowed by the ISO C standard. For instance, different sets of
instructions may be used for code such as x*y+z depending on the
target architecture and the optimization level, and this difference
may change the results."
I don't have a list of cases allowed by the standard. If you know more
examples, we could add them to the answer.
> From a clean debian/sid 32bits chroot I can no longer reproduce this.
> In summary:
>
> 1. removed -ffast-math
> 2. add -std=c99
> 3. Change the code for an explicit storage of division (div = dd / dr)
> => issue solved !
The manual says: "This option is enabled by default for C if a strict
conformance option such as -std=c99 is used." Thus, you are in fact
using -fexcess-precision=standard.
That only means that floating-point computations will follow ISO C
rules. FAQ: "Floating-point results may still depend on the
optimization level and target architecture".
Cheers,
Manuel.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32))
2015-09-09 9:24 ` Manuel López-Ibáñez
@ 2015-09-09 13:32 ` Mathieu Malaterre
0 siblings, 0 replies; 9+ messages in thread
From: Mathieu Malaterre @ 2015-09-09 13:32 UTC (permalink / raw)
To: Manuel López-Ibáñez
Cc: gcc-help, Andrew Haley, Markus Trippelsdorf
Manuel,
On Wed, Sep 9, 2015 at 11:23 AM, Manuel López-Ibáñez
<lopezibanez@gmail.com> wrote:
[...]
> The manual says: "if -fexcess-precision=standard is specified then
> excess precision follows the rules specified in ISO C99; in
> particular, both casts and assignments cause values to be rounded to
> their semantic types (whereas -ffloat-store only affects
> assignments)."
[...]
That was the important part I misread: I needed an explicit cast
and/or assignment. So documentation is crystal clear, sorry for the
noise.
But anyway as Andrew pointed out this only solve the symptoms, not the
actual bug.
-M
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-09-09 13:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-08 20:00 -ffloat-store behavior (Re: Susprising behavior of gcc on x86 (-m32)) Mathieu Malaterre
2015-09-08 20:05 ` Mathieu Malaterre
2015-09-08 21:31 ` Manuel López-Ibáñez
2015-09-09 5:19 ` Markus Trippelsdorf
2015-09-09 6:08 ` Mathieu Malaterre
2015-09-09 7:19 ` Mathieu Malaterre
2015-09-09 8:58 ` Andrew Haley
2015-09-09 9:24 ` Manuel López-Ibáñez
2015-09-09 13:32 ` Mathieu Malaterre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).