Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-05 Thread Michael Matz

Hello,

On Wed, 6 Jan 2021, ian wrote:


Hi to all, and happy new year.

AFAIK neither -NaN nor +NaN have sense (how to put a sign at a 'not a
number' ).


To be precise, the sense isn't specified.  Like for the payload of IEEE 
NaNs you can give it any meaning you like, including none.  But if you 
regard unary minus as a non-arithmetic but algebraic operation (like 
recommended by IEEE) on an extension of the float numbers, it should do 
something to the (algebraic) sign.



For instance, in my own language NaN have no sign, but on the other hand I
use -Inf and +Inf :


That's completely fine.


It seems to me that using a sign bit on NaN is a design error.


Possibly.  But it's the more orthogonal choice with IEEE float (where 
simply all specified values have a sign).



Ciao,
Michael.



Regards to all, and best wishes.

ian

Le 05/01/2021 à 10:27, Vincent Lefevre a écrit :

On 2021-01-04 04:59:28 +0100, Michael Matz wrote:

Hello,

On Mon, 4 Jan 2021, Vincent Lefevre wrote:

-
#include 
#include 
#include 

int main(int argc, char **argv)
{
double d = strtod("-nan", NULL);
d = -d;
printf("%g, signbit(d) = %d\n", d, signbit(d));
return 0;
}
-

Results:

$ gcc foo.c -o foo && ./foo
-nan, signbit(d) = 1

$ tcc foo.c -o foo2 && ./foo2
nan, signbit(d) = 0

I get the same results as gcc with clang and pcc. tcc is the outlier.

AFAIK, the status of the sign bit of a NaN is unspecified, except
for some particular functions, but not strtod. So I don't see a
bug in tcc.

Note: for GCC, there's an inconsistency between your testcase
and the result.

Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is
there, applying unary '-' to a NaN doesn't change the sign of it in TCC.

But my point is that with the above testcase, you cannot know whether
the difference between gcc and tcc comes from strtod (which would be
valid, as strtod doesn't specify the sign or NaN) or the "d = -d;"
(which would be invalid). A printf should have been added between
the strtod and the "d = -d;" to be sure.

--
-- sibian0...@gmail.com
-- Développeur compulsif

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-05 Thread ian
Hi to all, and *happy new year*.

AFAIK neither -NaN nor +NaN have sense (how to put a sign at a 'not a
number' ).

So, d=-d is a non-sense too.

For instance, in my own language NaN have no sign, but on the other hand
I use -Inf and +Inf :

? (/ -1 0)
-Inf.
? (/ 1 0)
+Inf.
? (* 0 (/ -1 0))
NaN


It seems to me that using a sign bit on NaN is a design error.

Regards to all, and best wishes.

*ian*

Le 05/01/2021 à 10:27, Vincent Lefevre a écrit :
> On 2021-01-04 04:59:28 +0100, Michael Matz wrote:
>> Hello,
>>
>> On Mon, 4 Jan 2021, Vincent Lefevre wrote:
>>
 -
 #include 
 #include 
 #include 

 int main(int argc, char **argv)
 {
double d = strtod("-nan", NULL);
d = -d;
printf("%g, signbit(d) = %d\n", d, signbit(d));
return 0;
 }
 -

 Results:

$ gcc foo.c -o foo && ./foo
-nan, signbit(d) = 1

$ tcc foo.c -o foo2 && ./foo2
nan, signbit(d) = 0

 I get the same results as gcc with clang and pcc. tcc is the outlier.
>>> AFAIK, the status of the sign bit of a NaN is unspecified, except
>>> for some particular functions, but not strtod. So I don't see a
>>> bug in tcc.
>>>
>>> Note: for GCC, there's an inconsistency between your testcase
>>> and the result.
>> Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is
>> there, applying unary '-' to a NaN doesn't change the sign of it in TCC.
> But my point is that with the above testcase, you cannot know whether
> the difference between gcc and tcc comes from strtod (which would be
> valid, as strtod doesn't specify the sign or NaN) or the "d = -d;"
> (which would be invalid). A printf should have been added between
> the strtod and the "d = -d;" to be sure.
>
-- 
-- sibian0...@gmail.com
-- Développeur compulsif
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-05 Thread grischka

Michael Matz wrote:


So the current "-0.0-x" expansion of unary '-' needs a change.  It
turned out to be a bit uglier than I wished for, ...


Hm, yes, the more as on x87 using just 'fchs' could be so easy.
Anyway, I tried to make it look a bit less ugly:

https://repo.or.cz/tinycc.git/commitdiff/aeb8f427e2be133d6a0a67b695eb9579f5fa4232

-- grischka


... but alas, fixed in mob.

Thanks for the report, Arnold.



___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-05 Thread arnold
Vincent Lefevre  wrote:

>
> But my point is that with the above testcase, you cannot know whether
> the difference between gcc and tcc comes from strtod (which would be
> valid, as strtod doesn't specify the sign or NaN) or the "d = -d;"
> (which would be invalid). A printf should have been added between
> the strtod and the "d = -d;" to be sure.

It was definitely the "d = -d".  Sorry I wasn't more clear.

Arnold

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-05 Thread Vincent Lefevre
On 2021-01-04 04:59:28 +0100, Michael Matz wrote:
> Hello,
> 
> On Mon, 4 Jan 2021, Vincent Lefevre wrote:
> 
> > > -
> > > #include 
> > > #include 
> > > #include 
> > > 
> > > int main(int argc, char **argv)
> > > {
> > >   double d = strtod("-nan", NULL);
> > >   d = -d;
> > >   printf("%g, signbit(d) = %d\n", d, signbit(d));
> > >   return 0;
> > > }
> > > -
> > > 
> > > Results:
> > > 
> > >   $ gcc foo.c -o foo && ./foo
> > >   -nan, signbit(d) = 1
> > > 
> > >   $ tcc foo.c -o foo2 && ./foo2
> > >   nan, signbit(d) = 0
> > > 
> > > I get the same results as gcc with clang and pcc. tcc is the outlier.
> > 
> > AFAIK, the status of the sign bit of a NaN is unspecified, except
> > for some particular functions, but not strtod. So I don't see a
> > bug in tcc.
> > 
> > Note: for GCC, there's an inconsistency between your testcase
> > and the result.
> 
> Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is
> there, applying unary '-' to a NaN doesn't change the sign of it in TCC.

But my point is that with the above testcase, you cannot know whether
the difference between gcc and tcc comes from strtod (which would be
valid, as strtod doesn't specify the sign or NaN) or the "d = -d;"
(which would be invalid). A printf should have been added between
the strtod and the "d = -d;" to be sure.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-04 Thread Christian Jullien
As long as my script that tests many build tcc configurations is happy, I'm 
happy too :o)

-Original Message-
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On 
Behalf Of Michael Matz
Sent: Monday, January 04, 2021 23:42
To: jull...@eligis.com; tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

Hello,

On Mon, 4 Jan 2021, Christian Jullien wrote:

> Also on OpenBSD x64 with clang 10

Bah.  I could fix this generically with using signbit(3) to check 
for the required sign flip, but I'm not sure how widespread it's 
availability or correctnes is on other platforms.  So Hermans disabling 
for clang works for me as well.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-04 Thread Michael Matz

Hello,

On Mon, 4 Jan 2021, Christian Jullien wrote:


Also on OpenBSD x64 with clang 10


Bah.  I could fix this generically with using signbit(3) to check 
for the required sign flip, but I'm not sure how widespread it's 
availability or correctnes is on other platforms.  So Hermans disabling 
for clang works for me as well.



Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-03 Thread arnold
Michael Matz  wrote:

> Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is 
> there, applying unary '-' to a NaN doesn't change the sign of it in TCC.

Yep, that was the issue. Sorry I wasn't clear.

> So the current "-0.0-x" expansion of unary '-' needs a change.  It turned 
> out to be a bit uglier than I wished for, but alas, fixed in mob.

It now works for me. Thanks for the fix!

> Thanks for the report, Arnold.

You're welcome.

Take it easy,

Arnold

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-03 Thread Christian Jullien
Also on OpenBSD x64 with clang 10

./configure --strip-binaries --with-selinux --cc=clang 
--prefix=/home/jullien/tinycc/static
Binary directory/home/jullien/tinycc/static/bin
TinyCC directory/home/jullien/tinycc/static/lib/tcc
Library directory   /home/jullien/tinycc/static/lib
Include directory   /home/jullien/tinycc/static/include
Manual directory/home/jullien/tinycc/static/share/man
Info directory  /home/jullien/tinycc/static/share/info
Doc directory   /home/jullien/tinycc/static/share/doc
Source path /home/jullien/tinycc
C compiler  clang (10.0)
Target OS   OpenBSD
CPU x86_64
Config  BSD ldl=no strip selinux
Creating config.mak and config.h
...
 test3 
--- test.refMon Jan  4 08:35:32 2021
+++ test.out3   Mon Jan  4 08:35:32 2021
@@ -573,7 +573,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan -nan
+nantest: -nan nan
 testing 'double'
 0 1 1 0 0 1
 1.00 2.50 3.50 -1.50 2.50 0.40 -1.00
@@ -613,7 +613,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan -nan
+nantest: -nan nan
 testing 'long double'
 0 1 1 0 0 1
 1.00 2.50 3.50 -1.50 2.50 0.40 -1.00
@@ -653,7 +653,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan -nan
+nantest: -nan nan
 1.20 3.40 -5.60
 2.12 0.50 230.00
 da=123.00
gmake[2]: *** [Makefile:128: test3] Error 1
 memtest 

-Original Message-
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On 
Behalf Of Christian Jullien
Sent: Monday, January 04, 2021 07:18
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

Hi Michael,
The fix does not make the test suite happy, at least, on Linux Aarch64 when 
clang is used (gcc and tcc are Ok):

./configure --strip-binaries --with-selinux --cc=clang 
--prefix=/home/jullien/tinycc/static
Binary directory/home/jullien/tinycc/static/bin
TinyCC directory/home/jullien/tinycc/static/lib/tcc
Library directory   /home/jullien/tinycc/static/lib
Include directory   /home/jullien/tinycc/static/include
Manual directory/home/jullien/tinycc/static/share/man
Info directory  /home/jullien/tinycc/static/share/info
Doc directory   /home/jullien/tinycc/static/share/doc
Source path /home/jullien/tinycc
C compiler  clang (11.0)
Target OS   Linux
CPU aarch64
Config  strip selinux
Creating config.mak and config.h

...

 test3 
--- test.ref2021-01-04 06:54:01.523848942 +0100
+++ test.out3   2021-01-04 06:54:03.523846911 +0100
@@ -653,7 +653,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan nan
+nantest: nan -nan
 1.20 3.40 -5.60
 2.12 0.50 230.00
 da=123.00
gmake[2]: *** [Makefile:128: test3] Error 1


-Original Message-
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On 
Behalf Of Michael Matz
Sent: Monday, January 04, 2021 04:59
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

Hello,

On Mon, 4 Jan 2021, Vincent Lefevre wrote:

>> -
>> #include 
>> #include 
>> #include 
>> 
>> int main(int argc, char **argv)
>> {
>>  double d = strtod("-nan", NULL);
>>  d = -d;
>>  printf("%g, signbit(d) = %d\n", d, signbit(d));
>>  return 0;
>> }
>> -
>> 
>> Results:
>>
>>  $ gcc foo.c -o foo && ./foo
>>  -nan, signbit(d) = 1
>>
>>  $ tcc foo.c -o foo2 && ./foo2
>>  nan, signbit(d) = 0
>> 
>> I get the same results as gcc with clang and pcc. tcc is the outlier.
>
> AFAIK, the status of the sign bit of a NaN is unspecified, except
> for some particular functions, but not strtod. So I don't see a
> bug in tcc.
>
> Note: for GCC, there's an inconsistency between your testcase
> and the result.

Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is 
there, applying unary '-' to a NaN doesn't change the sign of it in TCC.

While the interpretation of sign bits in NaNs isn't specified in 
IEEE754/854/P754, its existence is a given (in particular it talks about 
"the sign of a NaN", in order to say that th

Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-03 Thread Christian Jullien
Hi Michael,
The fix does not make the test suite happy, at least, on Linux Aarch64 when 
clang is used (gcc and tcc are Ok):

./configure --strip-binaries --with-selinux --cc=clang 
--prefix=/home/jullien/tinycc/static
Binary directory/home/jullien/tinycc/static/bin
TinyCC directory/home/jullien/tinycc/static/lib/tcc
Library directory   /home/jullien/tinycc/static/lib
Include directory   /home/jullien/tinycc/static/include
Manual directory/home/jullien/tinycc/static/share/man
Info directory  /home/jullien/tinycc/static/share/info
Doc directory   /home/jullien/tinycc/static/share/doc
Source path /home/jullien/tinycc
C compiler  clang (11.0)
Target OS   Linux
CPU aarch64
Config  strip selinux
Creating config.mak and config.h

...

 test3 
--- test.ref2021-01-04 06:54:01.523848942 +0100
+++ test.out3   2021-01-04 06:54:03.523846911 +0100
@@ -653,7 +653,7 @@
 Test 1.0 / x != 1.0 / -x returns 1 (should be 1).
 Test 1.0 / x != 1.0 / +y returns 1 (should be 1).
 Test 1.0 / x != 1.0 / -y returns 0 (should be 0).
-nantest: nan nan
+nantest: nan -nan
 1.20 3.40 -5.60
 2.12 0.50 230.00
 da=123.00
gmake[2]: *** [Makefile:128: test3] Error 1


-Original Message-
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On 
Behalf Of Michael Matz
Sent: Monday, January 04, 2021 04:59
To: tinycc-devel@nongnu.org
Subject: Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

Hello,

On Mon, 4 Jan 2021, Vincent Lefevre wrote:

>> -
>> #include 
>> #include 
>> #include 
>> 
>> int main(int argc, char **argv)
>> {
>>  double d = strtod("-nan", NULL);
>>  d = -d;
>>  printf("%g, signbit(d) = %d\n", d, signbit(d));
>>  return 0;
>> }
>> -
>> 
>> Results:
>>
>>  $ gcc foo.c -o foo && ./foo
>>  -nan, signbit(d) = 1
>>
>>  $ tcc foo.c -o foo2 && ./foo2
>>  nan, signbit(d) = 0
>> 
>> I get the same results as gcc with clang and pcc. tcc is the outlier.
>
> AFAIK, the status of the sign bit of a NaN is unspecified, except
> for some particular functions, but not strtod. So I don't see a
> bug in tcc.
>
> Note: for GCC, there's an inconsistency between your testcase
> and the result.

Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is 
there, applying unary '-' to a NaN doesn't change the sign of it in TCC.

While the interpretation of sign bits in NaNs isn't specified in 
IEEE754/854/P754, its existence is a given (in particular it talks about 
"the sign of a NaN", in order to say that their interpretation isn't 
determined :) )

Further IEEE754 recommends implementations to provide a negate(x) 
operation that copies x with reversed sign, that is to work on NaNs (and 
due to copysign needs to have observable behaviour).  C99 and up specify 
that the unary '-' operator maps to that operation.

So, I think it's pretty clear, that whatever the sign bit of NaNs is 
supposed to mean, it must be switchable by unary '-' when IEEE754 
conformance is claimed.  We currently don't claim so, but we aim for it if 
possible :)

So the current "-0.0-x" expansion of unary '-' needs a change.  It turned 
out to be a bit uglier than I wished for, but alas, fixed in mob.

Thanks for the report, Arnold.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-03 Thread Michael Matz

Hello,

On Mon, 4 Jan 2021, Vincent Lefevre wrote:


-
#include 
#include 
#include 

int main(int argc, char **argv)
{
double d = strtod("-nan", NULL);
d = -d;
printf("%g, signbit(d) = %d\n", d, signbit(d));
return 0;
}
-

Results:

$ gcc foo.c -o foo && ./foo
-nan, signbit(d) = 1

$ tcc foo.c -o foo2 && ./foo2
nan, signbit(d) = 0

I get the same results as gcc with clang and pcc. tcc is the outlier.


AFAIK, the status of the sign bit of a NaN is unspecified, except
for some particular functions, but not strtod. So I don't see a
bug in tcc.

Note: for GCC, there's an inconsistency between your testcase
and the result.


Yeah, I think that's merely a typo in Arnolds email.  The inconsistency is 
there, applying unary '-' to a NaN doesn't change the sign of it in TCC.


While the interpretation of sign bits in NaNs isn't specified in 
IEEE754/854/P754, its existence is a given (in particular it talks about 
"the sign of a NaN", in order to say that their interpretation isn't 
determined :) )


Further IEEE754 recommends implementations to provide a negate(x) 
operation that copies x with reversed sign, that is to work on NaNs (and 
due to copysign needs to have observable behaviour).  C99 and up specify 
that the unary '-' operator maps to that operation.


So, I think it's pretty clear, that whatever the sign bit of NaNs is 
supposed to mean, it must be switchable by unary '-' when IEEE754 
conformance is claimed.  We currently don't claim so, but we aim for it if 
possible :)


So the current "-0.0-x" expansion of unary '-' needs a change.  It turned 
out to be a bit uglier than I wished for, but alas, fixed in mob.


Thanks for the report, Arnold.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-03 Thread Vincent Lefevre
On 2021-01-03 21:17:03 +0200, Arnold Robbins wrote:
> Hi.
> 
> I found this bug in current mob on the current gawk sources. Test case:
> 
> -
> #include 
> #include 
> #include 
> 
> int main(int argc, char **argv)
> {
>   double d = strtod("-nan", NULL);
>   d = -d;
>   printf("%g, signbit(d) = %d\n", d, signbit(d));
>   return 0;
> }
> -
> 
> Results:
> 
>   $ gcc foo.c -o foo && ./foo
>   -nan, signbit(d) = 1
> 
>   $ tcc foo.c -o foo2 && ./foo2
>   nan, signbit(d) = 0
> 
> I get the same results as gcc with clang and pcc. tcc is the outlier.

AFAIK, the status of the sign bit of a NaN is unspecified, except
for some particular functions, but not strtod. So I don't see a
bug in tcc.

Note: for GCC, there's an inconsistency between your testcase
and the result.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] x86_64 tcc doesn't set sign bit on NaNs

2021-01-03 Thread Arnold Robbins
Hi.

I found this bug in current mob on the current gawk sources. Test case:

-
#include 
#include 
#include 

int main(int argc, char **argv)
{
double d = strtod("-nan", NULL);
d = -d;
printf("%g, signbit(d) = %d\n", d, signbit(d));
return 0;
}
-

Results:

$ gcc foo.c -o foo && ./foo
-nan, signbit(d) = 1

$ tcc foo.c -o foo2 && ./foo2
nan, signbit(d) = 0

I get the same results as gcc with clang and pcc. tcc is the outlier.

Can we get this fixed please?

Thanks!

Arnold

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel