binutils-gdb/gdb/testsuite/gdb.base/floatn.c

49 lines
1.2 KiB
C
Raw Normal View History

Support 128-bit IEEE floating-point types on Intel and Power Now that all the prerequisites are in place, this commit finally adds support for handling the __float128 type on Intel and Power, by providing appropriate platform-specific versions of the floatformat_for_type callback. Since at this point we do not yet have any indication in the debug info to distinguish different floating-point formats of the same length, we simply use the type name as hint. Types named "__float128" get the IEEE format. In addition to handling "__float128" itself, we also recognize "_Float128" and (on Power) "_Float64x", as well as the complex versions of those. (As pointed out by Joseph Myers, starting with GCC 7, __float128 is just a typedef for _Float128 -- but it's good to handle this anyway.) A new test case does some simple verification that the format is decoded correctly, using both __float128 and "long double" to make sure using both in the same file still works. Another new test verifies handling of the _FloatN and _FloatNx types supported by GCC 7, as well as the complex versions of those types. Note that this still only supports basic format decoding and encoding. We do not yet support the GNU extension 'g' suffix for __float128 constants. In addition, since all *arithmetic* on floating-point values is still performed in native host "long double" arithmetic, if that format is not able to encode all target __float128 values, we may get incorrect results. (To fix this would require implementing fully synthetic target floating- point arithmetic along the lines of GCC's real.c, presumably using MPFR.) gdb/ChangeLog: * i386-tdep.c (i386_floatformat_for_type): New function. (i386_gdbarch_init): Install it. * ppc-linux-tdep.c (ppc_floatformat_for_type): New function. (ppc_linux_init_abi): Install it. gdb/testsuite/ChangeLog: * gdb.base/float128.c: New file. * gdb.base/float128.exp: Likewise. * gdb.base/floatn.c: Likewise. * gdb.base/floatn.exp: Likewise. Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
2016-09-06 17:33:15 +02:00
/* This testcase is part of GDB, the GNU debugger.
Copyright 2016-2017 Free Software Foundation, Inc.
Support 128-bit IEEE floating-point types on Intel and Power Now that all the prerequisites are in place, this commit finally adds support for handling the __float128 type on Intel and Power, by providing appropriate platform-specific versions of the floatformat_for_type callback. Since at this point we do not yet have any indication in the debug info to distinguish different floating-point formats of the same length, we simply use the type name as hint. Types named "__float128" get the IEEE format. In addition to handling "__float128" itself, we also recognize "_Float128" and (on Power) "_Float64x", as well as the complex versions of those. (As pointed out by Joseph Myers, starting with GCC 7, __float128 is just a typedef for _Float128 -- but it's good to handle this anyway.) A new test case does some simple verification that the format is decoded correctly, using both __float128 and "long double" to make sure using both in the same file still works. Another new test verifies handling of the _FloatN and _FloatNx types supported by GCC 7, as well as the complex versions of those types. Note that this still only supports basic format decoding and encoding. We do not yet support the GNU extension 'g' suffix for __float128 constants. In addition, since all *arithmetic* on floating-point values is still performed in native host "long double" arithmetic, if that format is not able to encode all target __float128 values, we may get incorrect results. (To fix this would require implementing fully synthetic target floating- point arithmetic along the lines of GCC's real.c, presumably using MPFR.) gdb/ChangeLog: * i386-tdep.c (i386_floatformat_for_type): New function. (i386_gdbarch_init): Install it. * ppc-linux-tdep.c (ppc_floatformat_for_type): New function. (ppc_linux_init_abi): Install it. gdb/testsuite/ChangeLog: * gdb.base/float128.c: New file. * gdb.base/float128.exp: Likewise. * gdb.base/floatn.c: Likewise. * gdb.base/floatn.exp: Likewise. Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
2016-09-06 17:33:15 +02:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
_Float32 f32;
_Float64 f64;
_Float128 f128;
_Float32x f32x;
_Float64x f64x;
_Complex _Float32 c32;
_Complex _Float64 c64;
_Complex _Float128 c128;
_Complex _Float32x c32x;
_Complex _Float64x c64x;
int main()
{
f32 = 1.5f32;
f64 = 2.25f64;
f128 = 3.375f128;
f32x = 10.5f32x;
f64x = 20.25f64x;
c32 = 1.5f32 + 1.0if;
c64 = 2.25f64 + 1.0if;
c128 = 3.375f128 + 1.0if;
c32x = 10.5f32x + 1.0if;
c64x = 20.25f64x + 1.0if;
return 0;
}