ppc64-fp.c revision 117395
1117395Skan/* Functions needed for soft-float on powerpc64-linux, copied from 2117395Skan libgcc2.c with macros expanded to force the use of specific types. 3117395Skan 4117395Skan Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 5117395Skan 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 6117395Skan 7117395SkanThis file is part of GCC. 8117395Skan 9117395SkanGCC is free software; you can redistribute it and/or modify it under 10117395Skanthe terms of the GNU General Public License as published by the Free 11117395SkanSoftware Foundation; either version 2, or (at your option) any later 12117395Skanversion. 13117395Skan 14117395SkanIn addition to the permissions in the GNU General Public License, the 15117395SkanFree Software Foundation gives you unlimited permission to link the 16117395Skancompiled version of this file into combinations with other programs, 17117395Skanand to distribute those combinations without any restriction coming 18117395Skanfrom the use of this file. (The General Public License restrictions 19117395Skando apply in other respects; for example, they cover modification of 20117395Skanthe file, and distribution when not linked into a combine 21117395Skanexecutable.) 22117395Skan 23117395SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 24117395SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 25117395SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26117395Skanfor more details. 27117395Skan 28117395SkanYou should have received a copy of the GNU General Public License 29117395Skanalong with GCC; see the file COPYING. If not, write to the Free 30117395SkanSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 31117395Skan02111-1307, USA. */ 32117395Skan 33117395Skan#if defined(__powerpc64__) 34117395Skan#include "fp-bit.h" 35117395Skan 36117395Skanextern DItype __fixdfdi (DFtype); 37117395Skanextern DItype __fixsfdi (SFtype); 38117395Skanextern USItype __fixunsdfsi (DFtype); 39117395Skanextern USItype __fixunssfsi (SFtype); 40117395Skanextern DFtype __floatdidf (DItype); 41117395Skanextern SFtype __floatdisf (DItype); 42117395Skan 43117395Skanstatic DItype local_fixunssfdi (SFtype); 44117395Skanstatic DItype local_fixunsdfdi (DFtype); 45117395Skan 46117395SkanDItype 47117395Skan__fixdfdi (DFtype a) 48117395Skan{ 49117395Skan if (a < 0) 50117395Skan return - local_fixunsdfdi (-a); 51117395Skan return local_fixunsdfdi (a); 52117395Skan} 53117395Skan 54117395SkanDItype 55117395Skan__fixsfdi (SFtype a) 56117395Skan{ 57117395Skan if (a < 0) 58117395Skan return - local_fixunssfdi (-a); 59117395Skan return local_fixunssfdi (a); 60117395Skan} 61117395Skan 62117395SkanUSItype 63117395Skan__fixunsdfsi (DFtype a) 64117395Skan{ 65117395Skan if (a >= - (DFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1)) 66117395Skan return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1)) 67117395Skan - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1); 68117395Skan return (SItype) a; 69117395Skan} 70117395Skan 71117395SkanUSItype 72117395Skan__fixunssfsi (SFtype a) 73117395Skan{ 74117395Skan if (a >= - (SFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1)) 75117395Skan return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1)) 76117395Skan - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1); 77117395Skan return (SItype) a; 78117395Skan} 79117395Skan 80117395SkanDFtype 81117395Skan__floatdidf (DItype u) 82117395Skan{ 83117395Skan DFtype d; 84117395Skan 85117395Skan d = (SItype) (u >> (sizeof (SItype) * 8)); 86117395Skan d *= (((UDItype) 1) << ((sizeof (SItype) * 8) / 2)); 87117395Skan d *= (((UDItype) 1) << ((sizeof (SItype) * 8) / 2)); 88117395Skan d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1)); 89117395Skan 90117395Skan return d; 91117395Skan} 92117395Skan 93117395SkanSFtype 94117395Skan__floatdisf (DItype u) 95117395Skan{ 96117395Skan DFtype f; 97117395Skan 98117395Skan if (53 < (sizeof (DItype) * 8) 99117395Skan && 53 > ((sizeof (DItype) * 8) - 53 + 24)) 100117395Skan { 101117395Skan if (! (- ((DItype) 1 << 53) < u 102117395Skan && u < ((DItype) 1 << 53))) 103117395Skan { 104117395Skan if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1)) 105117395Skan { 106117395Skan u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1); 107117395Skan u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53)); 108117395Skan } 109117395Skan } 110117395Skan } 111117395Skan f = (SItype) (u >> (sizeof (SItype) * 8)); 112117395Skan f *= (((UDItype) 1) << ((sizeof (SItype) * 8) / 2)); 113117395Skan f *= (((UDItype) 1) << ((sizeof (SItype) * 8) / 2)); 114117395Skan f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1)); 115117395Skan 116117395Skan return (SFtype) f; 117117395Skan} 118117395Skan 119117395Skan/* This version is needed to prevent recursion; fixunsdfdi in libgcc 120117395Skan calls fixdfdi, which in turn calls calls fixunsdfdi. */ 121117395Skan 122117395Skanstatic DItype 123117395Skanlocal_fixunsdfdi (DFtype a) 124117395Skan{ 125117395Skan USItype hi, lo; 126117395Skan 127117395Skan hi = a / (((UDItype) 1) << (sizeof (SItype) * 8)); 128117395Skan lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8))); 129117395Skan return ((UDItype) hi << (sizeof (SItype) * 8)) | lo; 130117395Skan} 131117395Skan 132117395Skan/* This version is needed to prevent recursion; fixunssfdi in libgcc 133117395Skan calls fixsfdi, which in turn calls calls fixunssfdi. */ 134117395Skan 135117395Skanstatic DItype 136117395Skanlocal_fixunssfdi (SFtype original_a) 137117395Skan{ 138117395Skan DFtype a = original_a; 139117395Skan USItype hi, lo; 140117395Skan 141117395Skan hi = a / (((UDItype) 1) << (sizeof (SItype) * 8)); 142117395Skan lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8))); 143117395Skan return ((UDItype) hi << (sizeof (SItype) * 8)) | lo; 144117395Skan} 145117395Skan 146117395Skan#endif /* __powerpc64__ */ 147