[PATCH, soft-fp]: Use mode(word) as a return type from soft-fp comparisons

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH, soft-fp]: Use mode(word) as a return type from soft-fp comparisons

Uros Bizjak-3
Hello!

This patch fixes the problems exposed with the testcase below. The
problem is, that soft-fp functions return int value, where gcc expects
the return from soft-fp functions to be in word mode. On x86_64 target,
word_mode equals DImode, where int equals SImode, leading to comparison
failures for certain class of input operands.

The testcase (actually from gcc.gnu.org/PR32286):

--cut here--
void abort(void);

int test_lt(__float128 x, __float128 y)
{
return x < y;
}

int test_gt (__float128 x, __float128 y)
{
return x > y;
}

int main()
{
__float128 a = 0.0;
__float128 b = 1.0;

int r;

r = test_lt (a, b);
if (r != ((double) a < (double) b))
abort();

r = test_gt (a, b);
if (r != ((double) a > (double) b))
abort();

return 0;
--cut here--
}

This testcase aborts with current soft-fp implementation on
x86_64-pc-linux-gnu (latest SVN gcc-4.3 is needed that includes soft-fp
library for __float128) and passes with the patch, attached to this message.

2007-06-09  Uros Bizjak  <[hidden email]>

        * soft-fp/soft-fp.h (CMPtype): New typedef.
        * soft-fp/eqdf2.c (__eqdf2): Use CMPtype instead of int
        as the return type.
        * soft-fp/eqsf2.c (__eqsf2): Ditto.
        * soft-fp/eqtf2.c (__eqtf2): Ditto.
        * soft-fp/gedf2.c (__gedf2): Ditto.
        * soft-fp/gesf2.c (__gesf2): Ditto.
        * soft-fp/getf2.c (__getf2): Ditto.
        * soft-fp/ledf2.c (__ledf2): Ditto.
        * soft-fp/lesf2.c (__lesf2): Ditto.
        * soft-fp/letf2.c (__letf2): Ditto.
        * soft-fp/unorddf2 (__unorddf2): Ditto.
        * soft-fp/unordsf2 (__unordsf2): Ditto.
        * soft-fp/unordtf2 (__unordtf2): Ditto.

Uros.

Index: unordsf2.c
===================================================================
--- unordsf2.c (revision 125589)
+++ unordsf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 1 iff a or b is a NaN, 0 otherwise.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Joseph Myers ([hidden email]).
 
@@ -31,8 +31,7 @@
 #include "soft-fp.h"
 #include "single.h"
 
-int
-__unordsf2(SFtype a, SFtype b)
+CMPtype __unordsf2(SFtype a, SFtype b)
 {
   FP_DECL_S(A);
   FP_DECL_S(B);
Index: unordtf2.c
===================================================================
--- unordtf2.c (revision 125589)
+++ unordtf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 1 iff a or b is a NaN, 0 otherwise.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Joseph Myers ([hidden email]).
 
@@ -31,8 +31,7 @@
 #include "soft-fp.h"
 #include "quad.h"
 
-int
-__unordtf2(TFtype a, TFtype b)
+CMPtype __unordtf2(TFtype a, TFtype b)
 {
   FP_DECL_Q(A);
   FP_DECL_Q(B);
Index: lesf2.c
===================================================================
--- lesf2.c (revision 125589)
+++ lesf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 iff a > b, 2 iff a ? b, -1 iff a < b
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "single.h"
 
-int __lesf2(SFtype a, SFtype b)
+CMPtype __lesf2(SFtype a, SFtype b)
 {
   FP_DECL_EX;
   FP_DECL_S(A); FP_DECL_S(B);
Index: letf2.c
===================================================================
--- letf2.c (revision 125589)
+++ letf2.c (working copy)
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "quad.h"
 
-int __letf2(TFtype a, TFtype b)
+CMPtype __letf2(TFtype a, TFtype b)
 {
   FP_DECL_EX;
   FP_DECL_Q(A); FP_DECL_Q(B);
Index: gedf2.c
===================================================================
--- gedf2.c (revision 125589)
+++ gedf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 iff a > b, -2 iff a ? b, -1 iff a < b
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "double.h"
 
-int __gedf2(DFtype a, DFtype b)
+CMPtype __gedf2(DFtype a, DFtype b)
 {
   FP_DECL_EX;
   FP_DECL_D(A); FP_DECL_D(B);
Index: eqdf2.c
===================================================================
--- eqdf2.c (revision 125589)
+++ eqdf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 otherwise
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "double.h"
 
-int __eqdf2(DFtype a, DFtype b)
+CMPtype __eqdf2(DFtype a, DFtype b)
 {
   FP_DECL_EX;
   FP_DECL_D(A); FP_DECL_D(B);
Index: gesf2.c
===================================================================
--- gesf2.c (revision 125589)
+++ gesf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 iff a > b, -2 iff a ? b, -1 iff a < b
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "single.h"
 
-int __gesf2(SFtype a, SFtype b)
+CMPtype __gesf2(SFtype a, SFtype b)
 {
   FP_DECL_EX;
   FP_DECL_S(A); FP_DECL_S(B);
Index: getf2.c
===================================================================
--- getf2.c (revision 125589)
+++ getf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 iff a > b, -2 iff a ? b, -1 iff a < b
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "quad.h"
 
-int __getf2(TFtype a, TFtype b)
+CMPtype __getf2(TFtype a, TFtype b)
 {
   FP_DECL_EX;
   FP_DECL_Q(A); FP_DECL_Q(B);
Index: eqsf2.c
===================================================================
--- eqsf2.c (revision 125589)
+++ eqsf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 otherwise
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "single.h"
 
-int __eqsf2(SFtype a, SFtype b)
+CMPtype __eqsf2(SFtype a, SFtype b)
 {
   FP_DECL_EX;
   FP_DECL_S(A); FP_DECL_S(B);
Index: eqtf2.c
===================================================================
--- eqtf2.c (revision 125589)
+++ eqtf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 otherwise
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "quad.h"
 
-int __eqtf2(TFtype a, TFtype b)
+CMPtype __eqtf2(TFtype a, TFtype b)
 {
   FP_DECL_EX;
   FP_DECL_Q(A); FP_DECL_Q(B);
Index: soft-fp.h
===================================================================
--- soft-fp.h (revision 125589)
+++ soft-fp.h (working copy)
@@ -189,6 +189,8 @@
 typedef USItype UHWtype;
 #endif
 
+typedef int CMPtype __attribute__ ((mode (word)));
+
 #define SI_BITS (__CHAR_BIT__ * (int)sizeof(SItype))
 #define DI_BITS (__CHAR_BIT__ * (int)sizeof(DItype))
 
Index: unorddf2.c
===================================================================
--- unorddf2.c (revision 125589)
+++ unorddf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 1 iff a or b is a NaN, 0 otherwise.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Joseph Myers ([hidden email]).
 
@@ -31,8 +31,7 @@
 #include "soft-fp.h"
 #include "double.h"
 
-int
-__unorddf2(DFtype a, DFtype b)
+CMPtype __unorddf2(DFtype a, DFtype b)
 {
   FP_DECL_D(A); FP_DECL_D(B);
   int r;
Index: ledf2.c
===================================================================
--- ledf2.c (revision 125589)
+++ ledf2.c (working copy)
@@ -1,6 +1,6 @@
 /* Software floating-point emulation.
    Return 0 iff a == b, 1 iff a > b, 2 iff a ? b, -1 iff a < b
-   Copyright (C) 1997,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson ([hidden email]) and
   Jakub Jelinek ([hidden email]).
@@ -32,7 +32,7 @@
 #include "soft-fp.h"
 #include "double.h"
 
-int __ledf2(DFtype a, DFtype b)
+CMPtype __ledf2(DFtype a, DFtype b)
 {
   FP_DECL_EX;
   FP_DECL_D(A); FP_DECL_D(B);
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH, soft-fp]: Use mode(word) as a return type from soft-fp comparisons

Daniel Jacobowitz-2
On Sat, Jun 09, 2007 at 11:05:18AM +0200, Uros Bizjak wrote:
> Hello!
>
> This patch fixes the problems exposed with the testcase below. The problem is,
> that soft-fp functions return int value, where gcc expects the return from
> soft-fp functions to be in word mode. On x86_64 target, word_mode equals
> DImode, where int equals SImode, leading to comparison failures for certain
> class of input operands.

Isn't someone (Andreas Krebbel?) trying to eliminate uses of
mode((word))?

--
Daniel Jacobowitz
CodeSourcery
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH, soft-fp]: Use mode(word) as a return type from soft-fp comparisons

Uros Bizjak-3
Daniel Jacobowitz wrote:

> On Sat, Jun 09, 2007 at 11:05:18AM +0200, Uros Bizjak wrote:
>  
>> Hello!
>>
>> This patch fixes the problems exposed with the testcase below. The problem is,
>> that soft-fp functions return int value, where gcc expects the return from
>> soft-fp functions to be in word mode. On x86_64 target, word_mode equals
>> DImode, where int equals SImode, leading to comparison failures for certain
>> class of input operands.
>>    
>
> Isn't someone (Andreas Krebbel?) trying to eliminate uses of
> mode((word))?
>  

Yes, but regarding soft-fp compares, we have this comment in
config/fp-bit.h:

/* The type of the result of a floating point comparison.  This must
   match `word_mode' in GCC for the target.  */
#ifndef CMPtype
typedef int CMPtype __attribute__ ((mode (word)));
#endif

And gcc indeed expands the check for returned variable in word_mode
(DImode on x86_64).

The problem is, that glibc emits FP comparison return tristate as "int".
soft-fp from glibc is currently not compatible with gcc expansion on
targets, where word_mode != int.

Here is a $1m question:

Which part is to be fixed?

a) gcc+libgcc should be converted to return (libgcc) and to expect (gcc)
"int" from soft-fp comparisons.
b) soft-fp from glibc should convert soft-fp functions to return word mode

Uros.