qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Richard Henderson <richard.henderson@linaro.org>,
	Laurent Vivier <laurent@vivier.eu>,
	bharata@linux.vnet.ibm.com,
	Andrew Dutcher <andrew@andrewdutcher.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Aurelien Jarno <aurelien@aurel32.net>
Subject: Re: [Qemu-devel] [PATCH v2 07/20] fpu/softfloat: propagate signalling NaNs in MINMAX
Date: Tue, 16 Jan 2018 11:53:29 +0000	[thread overview]
Message-ID: <87d12anhom.fsf@linaro.org> (raw)
In-Reply-To: <87efmqnipz.fsf@linaro.org>


Alex Bennée <alex.bennee@linaro.org> writes:

> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> On 9 January 2018 at 12:22, Alex Bennée <alex.bennee@linaro.org> wrote:
>>> While a comparison between a QNaN and a number will return the number
>>> it is not the same with a signaling NaN. In this case the SNaN will
>>> "win" and after potentially raising an exception it will be quietened.
>>>
>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>>> ---
>>> v2
>>>   - added return for propageFloat
>>> ---
>>>  fpu/softfloat.c | 8 ++++++--
>>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fpu/softfloat.c b/fpu/softfloat.c
>>> index 3a4ab1355f..44c043924e 100644
>>> --- a/fpu/softfloat.c
>>> +++ b/fpu/softfloat.c
>>> @@ -7683,6 +7683,7 @@ int float128_compare_quiet(float128 a, float128 b, float_status *status)
>>>   * minnum() and maxnum() functions. These are similar to the min()
>>>   * and max() functions but if one of the arguments is a QNaN and
>>>   * the other is numerical then the numerical argument is returned.
>>> + * SNaNs will get quietened before being returned.
>>>   * minnum() and maxnum correspond to the IEEE 754-2008 minNum()
>>>   * and maxNum() operations. min() and max() are the typical min/max
>>>   * semantics provided by many CPUs which predate that specification.
>>> @@ -7703,11 +7704,14 @@ static inline float ## s float ## s ## _minmax(float ## s a, float ## s b,     \
>>>      if (float ## s ## _is_any_nan(a) ||                                 \
>>>          float ## s ## _is_any_nan(b)) {                                 \
>>>          if (isieee) {                                                   \
>>> -            if (float ## s ## _is_quiet_nan(a, status) &&               \
>>> +            if (float ## s ## _is_signaling_nan(a, status) ||           \
>>> +                float ## s ## _is_signaling_nan(b, status)) {           \
>>> +                return propagateFloat ## s ## NaN(a, b, status);        \
>>> +            } else  if (float ## s ## _is_quiet_nan(a, status) &&       \
>>>                  !float ## s ##_is_any_nan(b)) {                         \
>>>                  return b;                                               \
>>>              } else if (float ## s ## _is_quiet_nan(b, status) &&        \
>>> -                       !float ## s ## _is_any_nan(a)) {                \
>>> +                       !float ## s ## _is_any_nan(a)) {                 \
>>>                  return a;                                               \
>>>              }                                                           \
>>>          }                                                               \
>>>          return propagateFloat ## s ## NaN(a, b, status);                \
>>>      }                                                                   \
>>
>> [added a couple of extra lines of context at the end for clarity]
>>
>> Am I misreading this patch? I can't see in what case it makes a
>> difference to the result. The code change adds an explicit "if
>> either A or B is an SNaN then return the propagateFloat*NaN() result".
>> But if either A or B is an SNaN then we won't take either of the
>> previously existing branches in this if() ("if A is a QNaN and B is
>> not a NaN" and "if B is a QNaN and A is not a NaN"), and so we'll
>> end up falling through to the "return propagateFloat*NaN" line after
>> the end of the "is (ieee) {...}".
>
> I see your point. However the bug is there if we don't check for
> signalling NaNs first which probably means the xxx_is_quiet_nan() check
> is broken and reporting signalling NaN's as quiet.
>
> The logic is correct in the decomposed function as we have many NaN
> types to check against so we check for the signalling NaNs first.

So maybe the helper functions need to be clearer:

  /*----------------------------------------------------------------------------
  | Returns 1 if the half-precision floating-point value `a' is a quiet
  | NaN; otherwise returns 0.
  *----------------------------------------------------------------------------*/

  int float16_is_quiet_nan(float16 a_, float_status *status)
  {
      if (float16_is_any_nan(a_)) {
          uint16_t sbit = float16_val(a_) & (1 << 9);
          if (status->snan_bit_is_one) {
              return sbit ? 0 : 1;
          } else {
              return sbit ? 1 : 0;
          }

      }
      return 0;
  }

  /*----------------------------------------------------------------------------
  | Returns 1 if the half-precision floating-point value `a' is a signaling
  | NaN; otherwise returns 0.
  *----------------------------------------------------------------------------*/

  int float16_is_signaling_nan(float16 a_, float_status *status)
  {
      if (float16_is_any_nan(a_)) {
          uint16_t sbit = float16_val(a_) & (1 << 9);
          if (status->snan_bit_is_one) {
              return sbit ? 1 : 0;
          } else {
              return sbit ? 0 : 1;
          }

      }
      return 0;
  }


--
Alex Bennée

  reply	other threads:[~2018-01-16 11:53 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-09 12:22 [Qemu-devel] [PATCH v2 00/20] re-factor softfloat and add fp16 functions Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 01/20] fpu/softfloat: implement float16_squash_input_denormal Alex Bennée
2018-01-12 13:41   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 02/20] include/fpu/softfloat: remove USE_SOFTFLOAT_STRUCT_TYPES Alex Bennée
2018-01-09 12:27   ` Laurent Vivier
2018-01-09 14:12     ` Aurelien Jarno
2018-01-09 14:14       ` Peter Maydell
2018-01-09 14:20         ` Laurent Vivier
2018-01-09 14:43           ` Peter Maydell
2018-01-09 16:45             ` Richard Henderson
2018-01-09 15:25           ` Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 03/20] include/fpu/softfloat: implement float16_abs helper Alex Bennée
2018-01-12 13:42   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 04/20] include/fpu/softfloat: implement float16_chs helper Alex Bennée
2018-01-12 13:43   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 05/20] include/fpu/softfloat: implement float16_set_sign helper Alex Bennée
2018-01-12 13:43   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 06/20] include/fpu/softfloat: add some float16 constants Alex Bennée
2018-01-09 13:27   ` Philippe Mathieu-Daudé
2018-01-09 15:16     ` Alex Bennée
2018-01-12 13:47   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 07/20] fpu/softfloat: propagate signalling NaNs in MINMAX Alex Bennée
2018-01-12 14:04   ` Peter Maydell
2018-01-16 11:31     ` Alex Bennée
2018-01-16 11:53       ` Alex Bennée [this message]
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 08/20] fpu/softfloat: improve comments on ARM NaN propagation Alex Bennée
2018-01-12 14:07   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 09/20] fpu/softfloat: move the extract functions to the top of the file Alex Bennée
2018-01-12 14:07   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 10/20] fpu/softfloat: define decompose structures Alex Bennée
2018-01-09 17:01   ` Richard Henderson
2018-01-12 14:22   ` Peter Maydell
2018-01-12 16:21   ` Philippe Mathieu-Daudé
2018-01-18 13:08     ` Alex Bennée
2018-01-18 14:26       ` Philippe Mathieu-Daudé
2018-01-18 14:31         ` Peter Maydell
2018-01-18 14:59           ` Philippe Mathieu-Daudé
2018-01-18 15:17             ` Peter Maydell
2018-01-23 12:00               ` Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 11/20] fpu/softfloat: re-factor add/sub Alex Bennée
2018-01-12 15:57   ` Peter Maydell
2018-01-12 18:30     ` Richard Henderson
2018-01-18 16:43     ` Alex Bennée
2018-01-18 16:47       ` Richard Henderson
2018-01-23 20:05     ` Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 12/20] fpu/softfloat: re-factor mul Alex Bennée
2018-01-09 12:43   ` Philippe Mathieu-Daudé
2018-01-12 16:17   ` Peter Maydell
2018-01-16 10:16     ` Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 13/20] fpu/softfloat: re-factor div Alex Bennée
2018-01-12 16:22   ` Peter Maydell
2018-01-12 18:35     ` Richard Henderson
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 14/20] fpu/softfloat: re-factor muladd Alex Bennée
2018-02-13 15:15   ` Peter Maydell
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 15/20] fpu/softfloat: re-factor round_to_int Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 16/20] fpu/softfloat: re-factor float to int/uint Alex Bennée
2018-01-09 17:12   ` Richard Henderson
2018-01-12 16:36   ` Peter Maydell
2018-01-16 17:06   ` Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 17/20] fpu/softfloat: re-factor int/uint to float Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 18/20] fpu/softfloat: re-factor scalbn Alex Bennée
2018-01-12 16:31   ` Peter Maydell
2018-01-24 12:03     ` Alex Bennée
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 19/20] fpu/softfloat: re-factor minmax Alex Bennée
2018-01-09 17:16   ` Richard Henderson
2018-01-09 12:22 ` [Qemu-devel] [PATCH v2 20/20] fpu/softfloat: re-factor compare Alex Bennée
2018-01-09 17:18   ` Richard Henderson
2018-01-09 13:07 ` [Qemu-devel] [PATCH v2 00/20] re-factor softfloat and add fp16 functions no-reply

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=87d12anhom.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=andrew@andrewdutcher.com \
    --cc=aurelien@aurel32.net \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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 NNTP newsgroup(s).