public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: Implement C11 _Atomic
Date: Thu, 07 Nov 2013 22:25:00 -0000	[thread overview]
Message-ID: <CAFULd4Z8dGokLpL4pJS53iDTqg9K_EdwEuU_xnbWqfLw=HiHrA@mail.gmail.com> (raw)
In-Reply-To: <CAFULd4aUWACLc2cnB6vhenMOy9VZBLaxT2vBVDKtwsPMsQN_Ug@mail.gmail.com>

On Thu, Nov 7, 2013 at 9:55 PM, Uros Bizjak <ubizjak@gmail.com> wrote:

>>> > I see code of the form (testing compilation rather than execution):
>>> >
>>> >         flds    4(%esp)
>>> >         flds    8(%esp)
>>> >         fmulp   %st, %st(1)
>>> >         fstps   12(%esp)
>>> >
>>> > where the fstps should result in the exception, and glibc uses volatile in
>>> > several places, conditional on __FLT_EVAL_METHOD__ != 0, to force a
>>> > conversion to the semantic type (whether for correct results, or to ensure
>>> > exceptions).
>>>
>>> Yes, this is the exact sequence my example compiles to:
>>>
>>>  8048405:       d9 44 24 14             flds   0x14(%esp)
>>>  8048409:       d9 44 24 18             flds   0x18(%esp)
>>>  804840d:       de c9                   fmulp  %st,%st(1)
>>>  804840f:       d9 5c 24 1c             fstps  0x1c(%esp)
>>>
>>> unfortunately, it won't generate exception.
>>
>> Are you sure?  It's documented as generating an exception.  That may mean,
>> as usual on x87, setting the exception bit (as can be tested by
>> fetestexcept) and only calling a trap handler on the *next* x87
>> instruction.  So if fstps is the last floating-point instruction executed
>> by the program, a trap handler may not be called - but that's no different
>> from an ordinary floating-point compound assignment having the
>> exception-raising operation as the last floating-point instruction.
>
> Aha, here is the problem.
>
> The exception is not generated by fmulp, but by the fstps that follows
> fmulp. The fstps will close exception window from fmulp, but fstps
> needs another fwait to generate exception. I have added fwait after
> fstps manually:
>
>    0x080483fd <+29>:    fstps  0x18(%esp)
>    0x08048401 <+33>:    flds   0x18(%esp)
>    0x08048405 <+37>:    flds   0x18(%esp)
>    0x08048409 <+41>:    fmulp  %st,%st(1)
>    0x0804840b <+43>:    fstps  0x1c(%esp)
> => 0x0804840f <+47>:    fwait
>    0x08048410 <+48>:    leave
>
> And in this case, exception was generated, as marked by "=>" in gdb.

However, this insn also raised FE_INEXACT flag (also on x86_64),
probably not what you wanted. Your code that generates FE_UNDERFLOW
will also raise FE_INEXACT. (and FE_DENORMAL).

Uros.

  reply	other threads:[~2013-11-07 21:26 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-06  0:44 Joseph S. Myers
2013-11-06 22:42 ` Andrew MacLeod
2013-11-07 17:16 ` Uros Bizjak
2013-11-07 17:24 ` Jakub Jelinek
2013-11-07 18:10   ` Uros Bizjak
2013-11-07 18:44     ` Joseph S. Myers
2013-11-07 18:47       ` Uros Bizjak
2013-11-07 18:55         ` Joseph S. Myers
     [not found]           ` <CAFULd4ZrAEECG+pptH8cRaWznioaM9VXS4TetpEvkWj--n7H1w@mail.gmail.com>
2013-11-07 21:02             ` Joseph S. Myers
2013-11-07 21:08               ` Uros Bizjak
2013-11-07 22:25                 ` Uros Bizjak [this message]
2013-11-07 22:43                   ` Joseph S. Myers
2013-11-08 10:09       ` Uros Bizjak
2013-11-08 13:33         ` Joseph S. Myers
2013-11-21 13:19 ` Hans-Peter Nilsson
2013-11-21 18:03   ` Andrew MacLeod
2013-11-21 18:20     ` Hans-Peter Nilsson
2013-11-21 18:30       ` Andrew MacLeod
2013-11-21 18:49         ` Joseph S. Myers
2013-11-21 18:58           ` Andrew MacLeod
2013-11-21 19:24         ` Hans-Peter Nilsson
2013-11-22  2:57         ` Hans-Peter Nilsson
2013-11-22  3:03           ` Andrew MacLeod
2013-11-22  3:32           ` Hans-Peter Nilsson
2013-11-22  3:32             ` Joseph S. Myers
2013-11-22 19:12             ` Andrew MacLeod
2013-11-22 20:01               ` Hans-Peter Nilsson
2013-11-08 13:28 Dominique Dhumieres
2013-11-08 13:34 ` Joseph S. Myers
2013-11-08 13:43   ` Dominique Dhumieres

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFULd4Z8dGokLpL4pJS53iDTqg9K_EdwEuU_xnbWqfLw=HiHrA@mail.gmail.com' \
    --to=ubizjak@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).