This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [PATCH] pa-RISC correct conversion (long double -> unsigned int)


I unfortunately diffed the wrong source tree in the previous email. 
wcohen.hpfix-2.patch attached to this mail has the correct external
declaration of the library function.

-Will Cohen

Will Cohen wrote:
> 
> The PA port of GCC does not handle the conversion of TFmode (16-byte
> double) to unsigned SImode. This presents a problem with some code in
> GDB because the code in GDB attempt to ensure that the FP number is
> between 2^31 and 2^32 in value.  This is too large to fit in a signed
> 32-bit quantity, but will fit in an unsigned 32-bit quantity. The
> attached program x3.c demonstrates the problem.  When executed the x3.c
> program will get an error in the library. The HP library doesn't have a
> 16-byte double to unsigned 32-bit quantity conversion, and a function
> had to be written to handle this correctly in gcc.
> 
> The patch is attached to this mail and below is the change log.  The
> patch was tested with the current version of fsf and corrected the
> problem.  Is it okay to apply this patch?
> 
> 2001-02-11  Will Cohen  <wcohen@redhat.com>
> 
>         * config/pa/quadlib.c (_U_Qfcnvfxt_quad_to_usgl): New function.
>         * config/pa/long_double.h (FIXUNS_TRUNCTFSI2_LIBCALL): Added.
>         (INIT_TARGET_OPTABS): Use FIXUNS_TRUNCTFSI2_LIBCALL for
>         fixunstfsi_libfunc.
> 
> -Will
> 
>   ------------------------------------------------------------------------
> 
> /*
>  * This test program boils down a sequence of operations that happen
>  * in floatformat_from_doublest when converting the value "1.1" in
>  * long double (16-byte) format to some target.
>  *
>  * I am seeing a bug where the mant_long assignment throws SIGFPE.
>  */
> 
> #include <stdio.h>
> 
> long double dfrom = 1.1;
> long double m1;
> long double m2;
> unsigned long mant_long;
> 
> int main( )
> {
>   /* Simulate frexp */
>   m1 = dfrom / 2.0;
> 
>   m2 = m1 * 4294967296.0;
>   mant_long = ((unsigned long) m2) & 0xffffffff;
> 
>   /* The correct value here is 0x8ccccccc.  */
>   printf( "%x\n", mant_long );
>   return 0;
> }
>
Index: long_double.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/config/pa/long_double.h,v
retrieving revision 1.4
diff -c -r1.4 long_double.h
*** long_double.h	2000/05/06 00:38:58	1.4
--- long_double.h	2001/02/12 23:30:44
***************
*** 52,57 ****
--- 52,58 ----
     we can massage its return value for PA64.  */
  #define FIX_TRUNCTFSI2_LIBCALL \
    (TARGET_64BIT ? "__U_Qfcnvfxt_quad_to_sgl" : "_U_Qfcnvfxt_quad_to_sgl")
+ #define FIXUNS_TRUNCTFSI2_LIBCALL "_U_Qfcnvfxt_quad_to_usgl"
  #define FIX_TRUNCTFDI2_LIBCALL "_U_Qfcnvfxt_quad_to_dbl"
  #define EQTF2_LIBCALL "_U_Qfeq"
  #define NETF2_LIBCALL "_U_Qfne"
***************
*** 89,95 ****
      floatditf_libfunc = gen_rtx_SYMBOL_REF (Pmode, FLOATDITF2_LIBCALL);  \
      fixtfsi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFSI2_LIBCALL);\
      fixtfdi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFDI2_LIBCALL);\
!     fixunstfsi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFSI2_LIBCALL);  \
      fixunstfdi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFDI2_LIBCALL);  \
      eqtf2_libfunc = gen_rtx_SYMBOL_REF (Pmode, EQTF2_LIBCALL);		\
      netf2_libfunc = gen_rtx_SYMBOL_REF (Pmode, NETF2_LIBCALL);		\
--- 90,96 ----
      floatditf_libfunc = gen_rtx_SYMBOL_REF (Pmode, FLOATDITF2_LIBCALL);  \
      fixtfsi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFSI2_LIBCALL);\
      fixtfdi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFDI2_LIBCALL);\
!     fixunstfsi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIXUNS_TRUNCTFSI2_LIBCALL);\
      fixunstfdi_libfunc = gen_rtx_SYMBOL_REF (Pmode, FIX_TRUNCTFDI2_LIBCALL);  \
      eqtf2_libfunc = gen_rtx_SYMBOL_REF (Pmode, EQTF2_LIBCALL);		\
      netf2_libfunc = gen_rtx_SYMBOL_REF (Pmode, NETF2_LIBCALL);		\
Index: quadlib.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/config/pa/quadlib.c,v
retrieving revision 1.3
diff -c -r1.3 quadlib.c
*** quadlib.c	2000/05/23 17:26:00	1.3
--- quadlib.c	2001/02/12 23:30:44
***************
*** 92,94 ****
--- 92,103 ----
    return _U_Qfcnvfxt_quad_to_sgl (a) >> 32;
  }
  #endif
+ 
+ /* HP only has signed conversion in library, so need to synthesize an
+    unsigned version */
+ unsigned int
+ _U_Qfcnvfxt_quad_to_usgl(long double a)
+ {
+   extern long long _U_Qfcnvfxt_quad_to_dbl (long double a);
+   return (unsigned int) _U_Qfcnvfxt_quad_to_dbl (a);
+ }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]