Date: Fri, 26 Mar 2010 05:19:53 +0000 (UTC) From: Juli Mallett <jmallett@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r205668 - user/jmallett/octeon/contrib/gcc/config Message-ID: <201003260519.o2Q5JrVn048192@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jmallett Date: Fri Mar 26 05:19:53 2010 New Revision: 205668 URL: http://svn.freebsd.org/changeset/base/205668 Log: Add Adam Nemet's 64-bit softfloat<->int functions. Original message: http://gcc.gnu.org/ml/gcc-patches/2006-05/msg00350.html Added: user/jmallett/octeon/contrib/gcc/config/fixdfdi.c user/jmallett/octeon/contrib/gcc/config/fixsfdi.c user/jmallett/octeon/contrib/gcc/config/fixunsdfsi.c user/jmallett/octeon/contrib/gcc/config/fixunssfsi.c user/jmallett/octeon/contrib/gcc/config/floatdidf.c user/jmallett/octeon/contrib/gcc/config/floatdisf.c user/jmallett/octeon/contrib/gcc/config/floatundidf.c user/jmallett/octeon/contrib/gcc/config/floatundisf.c Added: user/jmallett/octeon/contrib/gcc/config/fixdfdi.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/fixdfdi.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,28 @@ +/* Public domain. */ +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef int DItype __attribute__ ((mode (DI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); +typedef float DFtype __attribute__ ((mode (DF))); + +DItype __fixdfdi (DFtype); + +/* This version is needed to prevent recursion; fixunsdfdi in libgcc + calls fixdfdi, which in turn calls calls fixunsdfdi. */ + +static DItype +local_fixunsdfdi (DFtype a) +{ + USItype hi, lo; + + hi = a / (((UDItype) 1) << (sizeof (USItype) * 8)); + lo = a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (USItype) * 8)); + return ((UDItype) hi << (sizeof (USItype) * 8)) | lo; +} + +DItype +__fixdfdi (DFtype a) +{ + if (a < 0) + return - local_fixunsdfdi (-a); + return local_fixunsdfdi (a); +} Added: user/jmallett/octeon/contrib/gcc/config/fixsfdi.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/fixsfdi.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,30 @@ +/* Public domain. */ +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef int DItype __attribute__ ((mode (DI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); +typedef float SFtype __attribute__ ((mode (SF))); +typedef float DFtype __attribute__ ((mode (DF))); + +DItype __fixsfdi (SFtype); + +/* This version is needed to prevent recursion; fixunssfdi in libgcc + calls fixsfdi, which in turn calls calls fixunssfdi. */ + +static DItype +local_fixunssfdi (SFtype original_a) +{ + DFtype a = original_a; + USItype hi, lo; + + hi = a / (((UDItype) 1) << (sizeof (USItype) * 8)); + lo = a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (USItype) * 8)); + return ((UDItype) hi << (sizeof (USItype) * 8)) | lo; +} + +DItype +__fixsfdi (SFtype a) +{ + if (a < 0) + return - local_fixunssfdi (-a); + return local_fixunssfdi (a); +} Added: user/jmallett/octeon/contrib/gcc/config/fixunsdfsi.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/fixunsdfsi.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,18 @@ +/* Public domain. */ +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef int SItype __attribute__ ((mode (SI))); +typedef float SFtype __attribute__ ((mode (SF))); +typedef float DFtype __attribute__ ((mode (DF))); + +USItype __fixunsdfsi (DFtype); + +#define SItype_MIN \ + (- ((SItype) (((USItype) 1 << ((sizeof (SItype) * 8) - 1)) - 1)) - 1) + +USItype +__fixunsdfsi (DFtype a) +{ + if (a >= - (DFtype) SItype_MIN) + return (SItype) (a + SItype_MIN) - SItype_MIN; + return (SItype) a; +} Added: user/jmallett/octeon/contrib/gcc/config/fixunssfsi.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/fixunssfsi.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,17 @@ +/* Public domain. */ +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef int SItype __attribute__ ((mode (SI))); +typedef float SFtype __attribute__ ((mode (SF))); + +USItype __fixunssfsi (SFtype); + +#define SItype_MIN \ + (- ((SItype) (((USItype) 1 << ((sizeof (SItype) * 8) - 1)) - 1)) - 1) + +USItype +__fixunssfsi (SFtype a) +{ + if (a >= - (SFtype) SItype_MIN) + return (SItype) (a + SItype_MIN) - SItype_MIN; + return (SItype) a; +} Added: user/jmallett/octeon/contrib/gcc/config/floatdidf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/floatdidf.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,17 @@ +/* Public domain. */ +typedef int SItype __attribute__ ((mode (SI))); +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef int DItype __attribute__ ((mode (DI))); +typedef float DFtype __attribute__ ((mode (DF))); + +DFtype __floatdidf (DItype); + +DFtype +__floatdidf (DItype u) +{ + /* When the word size is small, we never get any rounding error. */ + DFtype f = (SItype) (u >> (sizeof (SItype) * 8)); + f *= 0x1p32f; + f += (USItype) u; + return f; +} Added: user/jmallett/octeon/contrib/gcc/config/floatdisf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/floatdisf.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,38 @@ +/* Public domain. */ +typedef int DItype __attribute__ ((mode (DI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); +typedef int SItype __attribute__ ((mode (SI))); +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef float SFtype __attribute__ ((mode (SF))); +typedef float DFtype __attribute__ ((mode (DF))); + +SFtype __floatdisf (DItype); + +SFtype +__floatdisf (DItype u) +{ + /* Protect against double-rounding error. + Represent any low-order bits, that might be truncated by a bit that + won't be lost. The bit can go in anywhere below the rounding position + of SFtype. A fixed mask and bit position handles all usual + configurations. */ + if (53 < (sizeof (DItype) * 8) + && 53 > ((sizeof (DItype) * 8) - 53 + 24)) + { + if (!(- ((DItype) 1 << 53) < u + && u < ((DItype) 1 << 53))) + { + if ((UDItype) u & (((UDItype) 1 << (sizeof (DItype) * 8 - 53)) - 1)) + { + u &= ~ (((UDItype) 1 << (sizeof (DItype) * 8 - 53)) - 1); + u |= (UDItype) 1 << (sizeof (DItype) * 8 - 53); + } + } + } + /* Do the calculation in a wider type so that we don't lose any of + the precision of the high word while multiplying it. */ + DFtype f = (SItype) (u >> (sizeof (SItype) * 8)); + f *= 0x1p32f; + f += (USItype) u; + return (SFtype) f; +} Added: user/jmallett/octeon/contrib/gcc/config/floatundidf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/floatundidf.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,16 @@ +/* Public domain. */ +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); +typedef float DFtype __attribute__ ((mode (DF))); + +DFtype __floatundidf (UDItype); + +DFtype +__floatundidf (UDItype u) +{ + /* When the word size is small, we never get any rounding error. */ + DFtype f = (USItype) (u >> (sizeof (USItype) * 8)); + f *= 0x1p32f; + f += (USItype) u; + return f; +} Added: user/jmallett/octeon/contrib/gcc/config/floatundisf.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/jmallett/octeon/contrib/gcc/config/floatundisf.c Fri Mar 26 05:19:53 2010 (r205668) @@ -0,0 +1,36 @@ +/* Public domain. */ +typedef int DItype __attribute__ ((mode (DI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef float SFtype __attribute__ ((mode (SF))); +typedef float DFtype __attribute__ ((mode (DF))); + +SFtype __floatundisf (UDItype); + +SFtype +__floatundisf (UDItype u) +{ + /* Protect against double-rounding error. + Represent any low-order bits, that might be truncated by a bit that + won't be lost. The bit can go in anywhere below the rounding position + of SFTYPE. A fixed mask and bit position handles all usual + configurations. */ + if (53 < (sizeof (DItype) * 8) + && 53 > ((sizeof (DItype) * 8) - 53 + 24)) + { + if (u >= ((UDItype) 1 << 53)) + { + if ((UDItype) u & (((UDItype) 1 << (sizeof (DItype) * 8 - 53)) - 1)) + { + u &= ~ (((UDItype) 1 << (sizeof (DItype) * 8 - 53)) - 1); + u |= (UDItype) 1 << (sizeof (DItype) * 8 - 53); + } + } + } + /* Do the calculation in a wider type so that we don't lose any of + the precision of the high word while multiplying it. */ + DFtype f = (USItype) (u >> (sizeof (USItype) * 8)); + f *= 0x1p32f; + f += (USItype) u; + return (SFtype) f; +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003260519.o2Q5JrVn048192>