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]
Other format: [Raw text]

Better fixunsdfdi and fixunssfdi


At least on one machine (a PowerPC) this gives a 3-fold speedup
for these conversions.

2002-09-22  Torbjorn Granlund  <tege@swox.com>

	* libgcc2.c (fixunsdfdi, fixunssfdi): Rewrite, avoiding `long long'
        arithmetic.

*** /u/gcc/gcc-3.2/gcc/libgcc2.c	Wed May 22 01:44:38 2002
--- /home/tege/libgcc2.c	Sun Sep 22 23:11:04 2002
***************
*** 925,948 ****
  {
!   DFtype b;
!   UDWtype v;
  
!   if (a < 0)
!     return 0;
  
!   /* Compute high word of result, as a flonum.  */
!   b = (a / HIGH_WORD_COEFF);
!   /* Convert that to fixed (but not to DWtype!),
!      and shift it into the high word.  */
!   v = (UWtype) b;
!   v <<= WORD_SIZE;
!   /* Remove high part from the DFtype, leaving the low part as flonum.  */
!   a -= (DFtype)v;
!   /* Convert that to fixed (but not to DWtype!) and add it in.
!      Sometimes A comes out negative.  This is significant, since
!      A has more bits than a long int does.  */
!   if (a < 0)
!     v -= (UWtype) (- a);
!   else
!     v += (UWtype) a;
!   return v;
  }
--- 925,940 ----
  {
!   UWtype hi, lo;
  
!   /* Get high part of result.  The division here will just moves the radix
!      point and will not cause any rounding.  Then the conversion to integral
!      type chops result as desired.  */
!   hi = a / HIGH_WORD_COEFF;
! 
!   /* Get low part of result.  Convert `hi' to floating type and scale it back,
!      then subtract this from the number being converted.  This leaves the low
!      part.  Convert that to integral type.  */
!   lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
  
!   /* Assemble result from the two parts.  */
!   return ((UDWtype) hi << WORD_SIZE) | lo;
  }
***************
*** 971,994 ****
    DFtype a = original_a;
!   DFtype b;
!   UDWtype v;
  
!   if (a < 0)
!     return 0;
  
!   /* Compute high word of result, as a flonum.  */
!   b = (a / HIGH_WORD_COEFF);
!   /* Convert that to fixed (but not to DWtype!),
!      and shift it into the high word.  */
!   v = (UWtype) b;
!   v <<= WORD_SIZE;
!   /* Remove high part from the DFtype, leaving the low part as flonum.  */
!   a -= (DFtype) v;
!   /* Convert that to fixed (but not to DWtype!) and add it in.
!      Sometimes A comes out negative.  This is significant, since
!      A has more bits than a long int does.  */
!   if (a < 0)
!     v -= (UWtype) (- a);
!   else
!     v += (UWtype) a;
!   return v;
  }
--- 963,978 ----
    DFtype a = original_a;
!   UWtype hi, lo;
  
!   /* Get high part of result.  The division here will just moves the radix
!      point and will not cause any rounding.  Then the conversion to integral
!      type chops result as desired.  */
!   hi = a / HIGH_WORD_COEFF;
! 
!   /* Get low part of result.  Convert `hi' to floating type and scale it back,
!      then subtract this from the number being converted.  This leaves the low
!      part.  Convert that to integral type.  */
!   lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
  
!   /* Assemble result from the two parts.  */
!   return ((UDWtype) hi << WORD_SIZE) | lo;
  }

-- 
Torbjörn


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