patches/glibc/2.3.6/210-glibc-fp-byteorder.patch
changeset 744 4bf8448536d5
parent 743 0bdbc96fecc0
child 745 e445c00d134d
     1.1 --- a/patches/glibc/2.3.6/210-glibc-fp-byteorder.patch	Mon Jul 28 11:43:29 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,205 +0,0 @@
     1.4 -Taken from http://sources.redhat.com/ml/crossgcc/2004-02/msg00104.html
     1.5 -Author: addsub@eyou.com
     1.6 -Target: ARM
     1.7 -
     1.8 -Fixes http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/920501-8.c
     1.9 -and makes printf("%f", 1.0) work.
    1.10 -
    1.11 -Lennert Buytenhek wrote in http://sources.redhat.com/ml/crossgcc/2004-09/msg00115.html :
    1.12 - It ... fixes the 'printf("%f\n", 0.5); prints 0.000000' and general 'floating point
    1.13 - is broken' on my big-endian hardfloat FPA ARM platform. ...
    1.14 - It's definitely needed for hardfloat.  So I'd think it's needed for
    1.15 - big-endian systems in any case, and for VFP on little-endian systems
    1.16 - too.  Someone would have to verify that though.
    1.17 -
    1.18 -Lennert Buytenhek wrote in http://sources.redhat.com/ml/crossgcc/2004-09/msg00123.html
    1.19 - I just had a look at glibc-20040830, and [this patch] is still needed and useful
    1.20 - for this version.  glibc-20040830 out-of-the-box still contains the
    1.21 - following wrong assumptions:
    1.22 - - sysdeps/arm/bits/endian.h: float word order is big endian (which it is
    1.23 -   not on vfp systems)
    1.24 - - sysdeps/arm/gmp-mparam.h: IEEE doubles are mixed endian (which they
    1.25 -   are not on big endian systems, neither on vfp systems)
    1.26 - - sysdeps/arm/ieee754.h: IEEE doubles are in little endian byte order
    1.27 -   (which they are not on big endian systems)
    1.28 - [This patch] seems the right solution for all of these issues.
    1.29 -
    1.30 -Dimitry Andric wrote in http://sources.redhat.com/ml/crossgcc/2004-09/msg00132.html :
    1.31 - It's even needed for glibc CVS, AFAICS.
    1.32 - The patch hunk which modifies glibc.new/sysdeps/arm/bits/endian.h
    1.33 - (currently at version 1.4) is only needed for proper VFP operation.
    1.34 - But the hunk which modifies sysdeps/arm/gmp-mparam.h, and the hunk
    1.35 - that deletes sysdeps/arm/ieee754.h (yes, this IS correct), are needed
    1.36 - for proper operation of *any* FP model on big endian ARM.
    1.37 -
    1.38 -See also discussion in followups to
    1.39 -http://sources.redhat.com/ml/crossgcc/2004-05/msg00245.html)
    1.40 -
    1.41 -Message-ID: <276985760.37584@eyou.com>
    1.42 -Received: from unknown (HELO eyou.com) (172.16.2.2)
    1.43 - by 0.0.0.0 with SMTP; Tue, 17 Feb 2004 10:42:40 +0800
    1.44 -Received: (qmail 8238 invoked by uid 65534); 17 Feb 2004 10:42:38 +0800
    1.45 -Date: 17 Feb 2004 10:42:38 +0800
    1.46 -Message-ID: <20040217104238.8237.qmail@eyou.com>
    1.47 -From: "add" <addsub@eyou.com>
    1.48 -To: dank@kegel.com
    1.49 -Reply-To: "add" <addsub@eyou.com>
    1.50 -Subject: Re:&nbsp;&nbsp;&nbsp;problem&nbsp;while&nbsp;building&nbsp;arm&nbsp;vfp&nbsp;softfloat&nbsp;gcc&nbsp;`
    1.51 -
    1.52 -Hi, Dan, This is a patch I applied to my glibc-2.3.2, then my softfloat
    1.53 -toolchain can printf("%f\n",1.0). So you may have a try of this
    1.54 -
    1.55 -
    1.56 -diff -uNrp glibc.old/sysdeps/arm/bits/endian.h glibc.new/sysdeps/arm/bits/endian.h
    1.57 ---- glibc.old/sysdeps/arm/bits/endian.h	1999-04-12 11:59:13.000000000 -0400
    1.58 -+++ glibc.new/sysdeps/arm/bits/endian.h	2004-02-12 09:15:13.000000000 -0500
    1.59 -@@ -9,4 +9,9 @@
    1.60 - #else
    1.61 - #define __BYTE_ORDER __LITTLE_ENDIAN
    1.62 - #endif
    1.63 -+
    1.64 -+#ifdef __VFP_FP__
    1.65 -+#define __FLOAT_WORD_ORDER __BYTE_ORDER
    1.66 -+#else
    1.67 - #define __FLOAT_WORD_ORDER __BIG_ENDIAN
    1.68 -+#endif
    1.69 -diff -uNrp glibc.old/sysdeps/arm/gmp-mparam.h glibc.new/sysdeps/arm/gmp-mparam.h
    1.70 ---- glibc.old/sysdeps/arm/gmp-mparam.h	2001-07-07 15:21:19.000000000 -0400
    1.71 -+++ glibc.new/sysdeps/arm/gmp-mparam.h	2004-02-12 09:15:13.000000000 -0500
    1.72 -@@ -26,5 +26,13 @@ MA 02111-1307, USA. */
    1.73 - #define BITS_PER_SHORTINT 16
    1.74 - #define BITS_PER_CHAR 8
    1.75 - 
    1.76 --#define IEEE_DOUBLE_BIG_ENDIAN 0
    1.77 --#define IEEE_DOUBLE_MIXED_ENDIAN 1
    1.78 -+#if defined(__ARMEB__)
    1.79 -+# define IEEE_DOUBLE_MIXED_ENDIAN 0
    1.80 -+# define IEEE_DOUBLE_BIG_ENDIAN 1
    1.81 -+#elif defined(__VFP_FP__)
    1.82 -+# define IEEE_DOUBLE_MIXED_ENDIAN 0
    1.83 -+# define IEEE_DOUBLE_BIG_ENDIAN 0
    1.84 -+#else
    1.85 -+# define IEEE_DOUBLE_BIG_ENDIAN 0
    1.86 -+# define IEEE_DOUBLE_MIXED_ENDIAN 1
    1.87 -+#endif
    1.88 -diff -uNrp glibc.old/sysdeps/arm/ieee754.h glibc.new/sysdeps/arm/ieee754.h
    1.89 ---- glibc.old/sysdeps/arm/ieee754.h	2001-07-07 15:21:19.000000000 -0400
    1.90 -+++ glibc.new/sysdeps/arm/ieee754.h	1969-12-31 19:00:00.000000000 -0500
    1.91 -@@ -1,115 +0,0 @@
    1.92 --/* Copyright (C) 1992, 1995, 1996, 1998 Free Software Foundation, Inc.
    1.93 --   This file is part of the GNU C Library.
    1.94 --
    1.95 --   The GNU C Library is free software; you can redistribute it and/or
    1.96 --   modify it under the terms of the GNU Lesser General Public
    1.97 --   License as published by the Free Software Foundation; either
    1.98 --   version 2.1 of the License, or (at your option) any later version.
    1.99 --
   1.100 --   The GNU C Library is distributed in the hope that it will be useful,
   1.101 --   but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.102 --   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   1.103 --   Lesser General Public License for more details.
   1.104 --
   1.105 --   You should have received a copy of the GNU Lesser General Public
   1.106 --   License along with the GNU C Library; if not, write to the Free
   1.107 --   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   1.108 --   02111-1307 USA.  */
   1.109 --
   1.110 --#ifndef _IEEE754_H
   1.111 --
   1.112 --#define _IEEE754_H 1
   1.113 --#include <features.h>
   1.114 --
   1.115 --#include <endian.h>
   1.116 --
   1.117 --__BEGIN_DECLS
   1.118 --
   1.119 --union ieee754_float
   1.120 --  {
   1.121 --    float f;
   1.122 --
   1.123 --    /* This is the IEEE 754 single-precision format.  */
   1.124 --    struct
   1.125 --      {
   1.126 --	unsigned int mantissa:23;
   1.127 --	unsigned int exponent:8;
   1.128 --	unsigned int negative:1;
   1.129 --      } ieee;
   1.130 --
   1.131 --    /* This format makes it easier to see if a NaN is a signalling NaN.  */
   1.132 --    struct
   1.133 --      {
   1.134 --	unsigned int mantissa:22;
   1.135 --	unsigned int quiet_nan:1;
   1.136 --	unsigned int exponent:8;
   1.137 --	unsigned int negative:1;
   1.138 --      } ieee_nan;
   1.139 --  };
   1.140 --
   1.141 --#define IEEE754_FLOAT_BIAS	0x7f /* Added to exponent.  */
   1.142 --
   1.143 --
   1.144 --union ieee754_double
   1.145 --  {
   1.146 --    double d;
   1.147 --
   1.148 --    /* This is the IEEE 754 double-precision format.  */
   1.149 --    struct
   1.150 --      {
   1.151 --	unsigned int mantissa0:20;
   1.152 --	unsigned int exponent:11;
   1.153 --	unsigned int negative:1;
   1.154 --	unsigned int mantissa1:32;
   1.155 --      } ieee;
   1.156 --
   1.157 --    /* This format makes it easier to see if a NaN is a signalling NaN.  */
   1.158 --    struct
   1.159 --      {
   1.160 --	unsigned int mantissa0:19;
   1.161 --	unsigned int quiet_nan:1;
   1.162 --	unsigned int exponent:11;
   1.163 --	unsigned int negative:1;
   1.164 --	unsigned int mantissa1:32;
   1.165 --      } ieee_nan;
   1.166 --  };
   1.167 --
   1.168 --#define IEEE754_DOUBLE_BIAS	0x3ff /* Added to exponent.  */
   1.169 --
   1.170 --
   1.171 --/* The following two structures are correct for `new' floating point systems but
   1.172 --   wrong for the old FPPC.  The only solution seems to be to avoid their use on
   1.173 --   old hardware.  */
   1.174 --
   1.175 --union ieee854_long_double
   1.176 --  {
   1.177 --    long double d;
   1.178 --
   1.179 --    /* This is the IEEE 854 double-extended-precision format.  */
   1.180 --    struct
   1.181 --      {
   1.182 --	unsigned int exponent:15;
   1.183 --	unsigned int empty:16;
   1.184 --	unsigned int negative:1;
   1.185 --	unsigned int mantissa1:32;
   1.186 --	unsigned int mantissa0:32;
   1.187 --      } ieee;
   1.188 --
   1.189 --    /* This is for NaNs in the IEEE 854 double-extended-precision format.  */
   1.190 --    struct
   1.191 --      {
   1.192 --	unsigned int exponent:15;
   1.193 --	unsigned int empty:16;
   1.194 --	unsigned int negative:1;
   1.195 --	unsigned int mantissa1:32;
   1.196 --	unsigned int mantissa0:30;
   1.197 --	unsigned int quiet_nan:1;
   1.198 --	unsigned int one:1;
   1.199 --      } ieee_nan;
   1.200 --  };
   1.201 --
   1.202 --#define IEEE854_LONG_DOUBLE_BIAS 0x3fff
   1.203 --
   1.204 --__END_DECLS
   1.205 --
   1.206 --#endif /* ieee754.h */
   1.207 -
   1.208 -Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>