mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Min and Max of 2 Floating Point numbers
@ 2020-02-23  7:08 Damian McGuckin
  2020-02-23 15:21 ` Rich Felker
  2020-02-23 21:18 ` Florian Weimer
  0 siblings, 2 replies; 5+ messages in thread
From: Damian McGuckin @ 2020-02-23  7:08 UTC (permalink / raw)
  To: musl


Curiosity only (i.e. not a MUSL question). But it is somewhat relevant to 
MUSL which I note at the end of this email.

Besides the latest Intels, PowerPC, ARMs, I am just curious which of the 
CPU architectures implement this function directly at the assembler level, 
i.e. and hence avoiding a branch, i.e.

 	double f ....
 	double g ....
and
 	double fgmax = f > g ? f : g;

The word 'implement' is a bit loose. I am not talking about the definition 
in Annex F of the C standard.

The IEEE 754-2019 standard has changed the definition so as to properly 
propogate NaNs. The 1.2.0 version I just downloaded still follows the
2008 definition.

ARM is smart enough to have 2 instructions, one (FMAX) which did propogate 
NaNs and one (FMAXNM) which follows the 2008 standard. That said, I do not 
personally compile on an ARM so I have no idea how you ask for FMAX or how 
you ask for FMAXNM?

The PowerPC ISA 3.0 instruction properly propogates NaNs so it agrees with 
the new standard.

The Intel instruction follows neither standard as far as I can tell. An
interesting condition.

Please tell me if I am wrong.

MUSL relevance: I believe that even in 1.2.0, MUSL's own fmax/fmin libc
routines violate the IEEE 754-2019 standard which came out recently. Well, 
it was approved June, published July, released November. I think that is 
recent.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Min and Max of 2 Floating Point numbers
  2020-02-23  7:08 [musl] Min and Max of 2 Floating Point numbers Damian McGuckin
@ 2020-02-23 15:21 ` Rich Felker
  2020-02-23 21:03   ` Damian McGuckin
  2020-02-23 21:18 ` Florian Weimer
  1 sibling, 1 reply; 5+ messages in thread
From: Rich Felker @ 2020-02-23 15:21 UTC (permalink / raw)
  To: musl

On Sun, Feb 23, 2020 at 06:08:25PM +1100, Damian McGuckin wrote:
> The IEEE 754-2019 standard has changed the definition so as to
> properly propogate NaNs. The 1.2.0 version I just downloaded still
> follows the
> 2008 definition.
> 
> ARM is smart enough to have 2 instructions, one (FMAX) which did
> propogate NaNs and one (FMAXNM) which follows the 2008 standard.
> That said, I do not personally compile on an ARM so I have no idea
> how you ask for FMAX or how you ask for FMAXNM?
> 
> The PowerPC ISA 3.0 instruction properly propogates NaNs so it
> agrees with the new standard.
> 
> The Intel instruction follows neither standard as far as I can tell. An
> interesting condition.
> 
> Please tell me if I am wrong.

I'm not particularly aware of what the insns do. However..

> MUSL relevance: I believe that even in 1.2.0, MUSL's own fmax/fmin libc
> routines violate the IEEE 754-2019 standard which came out recently.
> Well, it was approved June, published July, released November. I
> think that is recent.

Unless by "propagate nans" you mean some specific behavior beyond
preserving one of the input nans, I don't see how we're violating it.
The < operator is only used if there are no nans and the signs are the
same.

Rich

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Min and Max of 2 Floating Point numbers
  2020-02-23 15:21 ` Rich Felker
@ 2020-02-23 21:03   ` Damian McGuckin
  0 siblings, 0 replies; 5+ messages in thread
From: Damian McGuckin @ 2020-02-23 21:03 UTC (permalink / raw)
  To: musl

On Sun, 23 Feb 2020, Rich Felker wrote:

> Unless by "propagate nans" you mean some specific behavior beyond
> preserving one of the input nans,

Correct.  Corrently, for input 'x' and 'y', the routines agree with IEEE 
754 2008 and say

 	if (isnan(x))
 		return y;

To agree with IEEE 754 2019, they shold say.

 	if (isnan(x))
 		return x;

There is a new operation defined which I think preserves the old 
behaviour.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Min and Max of 2 Floating Point numbers
  2020-02-23  7:08 [musl] Min and Max of 2 Floating Point numbers Damian McGuckin
  2020-02-23 15:21 ` Rich Felker
@ 2020-02-23 21:18 ` Florian Weimer
  2020-02-23 23:20   ` Damian McGuckin
  1 sibling, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2020-02-23 21:18 UTC (permalink / raw)
  To: Damian McGuckin; +Cc: musl

* Damian McGuckin:

> Please tell me if I am wrong.
>
> MUSL relevance: I believe that even in 1.2.0, MUSL's own fmax/fmin libc
> routines violate the IEEE 754-2019 standard which came out recently.

I don't think the new IEEE 754 version specifies the behavior of the
fmax/fmin functions due to the way they implemented this change.  Do
you have a publicly accessible reference?

For ISO C, there is a different proposal here:

  <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2489.pdf>

It preserves the existing behavior of fmax/fmin, as far as I can tell.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [musl] Min and Max of 2 Floating Point numbers
  2020-02-23 21:18 ` Florian Weimer
@ 2020-02-23 23:20   ` Damian McGuckin
  0 siblings, 0 replies; 5+ messages in thread
From: Damian McGuckin @ 2020-02-23 23:20 UTC (permalink / raw)
  To: musl

On Sun, 23 Feb 2020, Florian Weimer wrote:

> I don't think the new IEEE 754 version specifies the behavior of the
> fmax/fmin functions due to the way they implemented this change.  Do
> you have a publicly accessible reference?

Silly me. Yes, fmax and fmin stay functionally the same.
>
> For ISO C, there is a different proposal here:
>
>  <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2489.pdf>
>
> It preserves the existing behavior of fmax/fmin, as far as I can tell.

Yes it does. I got confused.

Apologies - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-02-23 23:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-23  7:08 [musl] Min and Max of 2 Floating Point numbers Damian McGuckin
2020-02-23 15:21 ` Rich Felker
2020-02-23 21:03   ` Damian McGuckin
2020-02-23 21:18 ` Florian Weimer
2020-02-23 23:20   ` Damian McGuckin

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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).