all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Enge <andreas@enge.fr>
To: Michael Schierl <schierlm@gmx.de>
Cc: guix-devel@gnu.org
Subject: Re: Procps in core-updates
Date: Mon, 20 Mar 2023 15:54:53 +0100	[thread overview]
Message-ID: <ZBhzvdPsXmFnrCkr@jurong> (raw)
In-Reply-To: <e4211dc8-d94d-d612-a229-a0b04c6e4b8a@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 1736 bytes --]

Hello Michael,

Am Sun, Mar 19, 2023 at 06:36:09PM +0100 schrieb Michael Schierl:
> At the first printf, GCC knows that val still resides in some floating
> point register of your CPU (be it SSE, MMX or x87 registers, depending
> on the processor models your gcc targets).
> Hardware floating point registers on x86 are a mess, and they usually do
> not have the same precision as the IEEE floating point values that are
> stored in variables (e.g. on the stack or heap), but are slightly more
> precise.

this is an interesting guess, and at least gives a hint of why things
happen. I am attaching a simplified C file and the corresponding assembly
output; which I cannot read, but there are differences between the two
invocations of fprintf.

Now to me this still looks like a GCC bug, which is supposed to honour
the IEEE 754 standard for floating point as specified in the C99 standard
(the compiler flag -std=gnu99 was used to compile the file) at least for
"simple" operations. Comparisons should be exact. But I found this:
   https://gcc.gnu.org/wiki/FloatingPointMath
"Note on x86 and m68080 floating-point math
For legacy x86 processors without SSE2 support, and for m68080 processors,
GCC is only able to fully comply with IEEE 754 semantics for the IEEE
double extended (long double) type." So this appears to be a bug with a
"wontfix" tag...

And as indicated there, the compiler option -ffloat-store makes the problem
go away!

The weirdest thing is that actually the value is the integer 123. So it
should be stored in any kind of register exactly.

Thanks for making me learn something new!

Actually I also found an upstream patch:
   https://gitlab.com/procps-ng/procps/-/issues/271
which I will apply now.

Andreas


[-- Attachment #2: test_strtod_nol.c --]
[-- Type: text/plain, Size: 460 bytes --]


#include <stdio.h>
#include <stdlib.h>
#include "strutils.h"

struct strtod_tests {
    char *string;
    long double result;
};

struct strtod_tests tests[] = {
    {"123",     123.0},
};



int main(int argc, char *argv[])
{
    long double val;

    val = strtod_nol_or_err(tests[0].string, "Cannot parse number");
    fprintf(stderr, "CMP %i\n", val != tests[0].result);
    fprintf(stderr, "CMP %i\n", val != tests[0].result);
    return EXIT_FAILURE;
}

[-- Attachment #3: test_strtod_nol.o --]
[-- Type: text/plain, Size: 394 bytes --]

\x7fELF\x01\x01\x01?J?l??_?W?\x02Yo?-??5?\x18?\x1eN\vS?}r?t?}7??"?\x04?7?P?Z\x13?(]a\x13E@???OxI^@J+\x0e??C8:?3n?v??\x17]?^[?\x0e\x11?	?('f???{????1Ru(?????F??\x04??\x06?????^[??{?KZed??/q\x1c?E'?????,gf_?k?6???>?/<gmn^?8\x18??:f\x04?\a?
\x7f???????edl???HO8Gd\f???\f\x1d?e?\x7f\x01?^[`h\x01%? #??o,Z?\x05J?0D?\a\)k???e:j?.j????uu^[???p??CU?\x03)![q\x7f\x19B?Z\x06?L??M&L?`\x0f?*Q\x19??\x18~.*G\x7f|s?}???e\x1aO?R???D?06?????\x1c(94_v?U\f???????&\x15?{???=\x12?\x10???????3?x???_\x1e????J?^[\x19??u\x1flC??\x01--q2qMYh7Y/44Ye03h--

  reply	other threads:[~2023-03-20 14:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-18 12:32 Procps in core-updates Andreas Enge
2023-03-18 17:38 ` Leo Famulari
2023-03-18 17:44   ` Andreas Enge
2023-03-19 17:36 ` Michael Schierl
2023-03-20 14:54   ` Andreas Enge [this message]
2023-03-20 20:02     ` Michael Schierl
2023-03-20 21:25       ` Andreas Enge
2023-03-19 17:49 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2023-03-19 19:22   ` Kaelyn

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=ZBhzvdPsXmFnrCkr@jurong \
    --to=andreas@enge.fr \
    --cc=guix-devel@gnu.org \
    --cc=schierlm@gmx.de \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.