From patchwork Wed Oct 25 16:17:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Weigand X-Patchwork-Id: 23817 Received: (qmail 94138 invoked by alias); 25 Oct 2017 16:17:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 94100 invoked by uid 89); 25 Oct 2017 16:17:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Oct 2017 16:17:22 +0000 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9PGHJex086336 for ; Wed, 25 Oct 2017 12:17:20 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dtvgmd7u7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 25 Oct 2017 12:17:19 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Oct 2017 17:17:09 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 25 Oct 2017 17:17:07 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9PGH7eN11403504 for ; Wed, 25 Oct 2017 16:17:07 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 097C84C050 for ; Wed, 25 Oct 2017 17:12:45 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E40EE4C046 for ; Wed, 25 Oct 2017 17:12:44 +0100 (BST) Received: from oc3748833570.ibm.com (unknown [9.152.213.178]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Wed, 25 Oct 2017 17:12:44 +0100 (BST) Received: by oc3748833570.ibm.com (Postfix, from userid 1000) id 1DD56D807F1; Wed, 25 Oct 2017 18:17:07 +0200 (CEST) Subject: [RFC v2][8/9] Target FP: Remove unused floating-point routines To: gdb-patches@sourceware.org Date: Wed, 25 Oct 2017 18:17:07 +0200 (CEST) From: "Ulrich Weigand" MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17102516-0040-0000-0000-000003E6CDEA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102516-0041-0000-0000-000025E93F0E Message-Id: <20171025161707.1DD56D807F1@oc3748833570.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-25_10:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710250216 [RFC v2][8/9] Target FP: Remove unused floating-point routines This patch removes the following routines, which now have no remaining users in GDB: - extract_typed_floating - store_typed_floating - convert_typed_floating - decimal_from_doublest - decimal_to_doublest - value_as_double - unpack_double - value_from_double - value_from_decfloat This completes removal of DOUBLEST from all files except doublest.{c,h} and target-float.c. Bye, Ulrich ChangeLog: * doublest.c: Do not include "gdbtypes.h". (extract_typed_floating): Remove. (store_typed_floating): Remove. (convert_typed_floating): Remove. * doublest.h (struct type): Remove. (DOUBLEST_PRINT_FORMAT): Remove. (DOUBLEST_SCAN_FORMAT): Remove. (extract_typed_floating): Remove. (store_typed_floating): Remove. (convert_typed_floating): Remove. * dfp.c (decimal_from_doublest): Remove. (decimal_to_doublest): Remove. * dfp.h: Do not include "doublest.h". (decimal_from_doublest): Remove. (decimal_to_doublest): Remove. * value.c: Do not include "doublest.h" and "dfp.h". (value_as_double): Remove. (unpack_double): Remove. (value_from_double): Remove. (value_from_decfloat): Remove. * value.h: Do not include "doublest.h". (value_as_double): Remove. (unpack_double): Remove. (value_from_double): Remove. (value_from_decfloat): Remove. Index: binutils-gdb/gdb/doublest.c =================================================================== --- binutils-gdb.orig/gdb/doublest.c +++ binutils-gdb/gdb/doublest.c @@ -26,7 +26,6 @@ #include "defs.h" #include "doublest.h" #include "floatformat.h" -#include "gdbtypes.h" #include /* ldexp */ #include @@ -897,95 +896,3 @@ floatformat_from_string (const struct fl floatformat_from_doublest (fmt, &doub, out); return true; } - -/* Extract a floating-point number of type TYPE from a target-order - byte-stream at ADDR. Returns the value as type DOUBLEST. */ - -DOUBLEST -extract_typed_floating (const void *addr, const struct type *type) -{ - const struct floatformat *fmt = floatformat_from_type (type); - DOUBLEST retval; - - floatformat_to_doublest (fmt, addr, &retval); - return retval; -} - -/* Store VAL as a floating-point number of type TYPE to a target-order - byte-stream at ADDR. */ - -void -store_typed_floating (void *addr, const struct type *type, DOUBLEST val) -{ - const struct floatformat *fmt = floatformat_from_type (type); - - /* FIXME: kettenis/2001-10-28: It is debatable whether we should - zero out any remaining bytes in the target buffer when TYPE is - longer than the actual underlying floating-point format. Perhaps - we should store a fixed bitpattern in those remaining bytes, - instead of zero, or perhaps we shouldn't touch those remaining - bytes at all. - - NOTE: cagney/2001-10-28: With the way things currently work, it - isn't a good idea to leave the end bits undefined. This is - because GDB writes out the entire sizeof() bits of the - floating-point type even though the value might only be stored - in, and the target processor may only refer to, the first N < - TYPE_LENGTH (type) bits. If the end of the buffer wasn't - initialized, GDB would write undefined data to the target. An - errant program, refering to that undefined data, would then - become non-deterministic. - - See also the function convert_typed_floating below. */ - memset (addr, 0, TYPE_LENGTH (type)); - - floatformat_from_doublest (fmt, &val, addr); -} - -/* Convert a floating-point number of type FROM_TYPE from a - target-order byte-stream at FROM to a floating-point number of type - TO_TYPE, and store it to a target-order byte-stream at TO. */ - -void -convert_typed_floating (const void *from, const struct type *from_type, - void *to, const struct type *to_type) -{ - const struct floatformat *from_fmt = floatformat_from_type (from_type); - const struct floatformat *to_fmt = floatformat_from_type (to_type); - - if (from_fmt == NULL || to_fmt == NULL) - { - /* If we don't know the floating-point format of FROM_TYPE or - TO_TYPE, there's not much we can do. We might make the - assumption that if the length of FROM_TYPE and TO_TYPE match, - their floating-point format would match too, but that - assumption might be wrong on targets that support - floating-point types that only differ in endianness for - example. So we warn instead, and zero out the target buffer. */ - warning (_("Can't convert floating-point number to desired type.")); - memset (to, 0, TYPE_LENGTH (to_type)); - } - else if (from_fmt == to_fmt) - { - /* We're in business. The floating-point format of FROM_TYPE - and TO_TYPE match. However, even though the floating-point - format matches, the length of the type might still be - different. Make sure we don't overrun any buffers. See - comment in store_typed_floating for a discussion about - zeroing out remaining bytes in the target buffer. */ - memset (to, 0, TYPE_LENGTH (to_type)); - memcpy (to, from, std::min (TYPE_LENGTH (from_type), - TYPE_LENGTH (to_type))); - } - else - { - /* The floating-point types don't match. The best we can do - (apart from simulating the target FPU) is converting to the - widest floating-point type supported by the host, and then - again to the desired type. */ - DOUBLEST d; - - floatformat_to_doublest (from_fmt, from, &d); - floatformat_from_doublest (to_fmt, &d, to); - } -} Index: binutils-gdb/gdb/doublest.h =================================================================== --- binutils-gdb.orig/gdb/doublest.h +++ binutils-gdb/gdb/doublest.h @@ -20,7 +20,6 @@ #ifndef DOUBLEST_H #define DOUBLEST_H -struct type; struct floatformat; /* Use `long double' if the host compiler supports it. (Note that this is not @@ -35,12 +34,8 @@ struct floatformat; #if (defined HAVE_LONG_DOUBLE && defined PRINTF_HAS_LONG_DOUBLE \ && defined SCANF_HAS_LONG_DOUBLE) typedef long double DOUBLEST; -# define DOUBLEST_PRINT_FORMAT "Lg" -# define DOUBLEST_SCAN_FORMAT "Lg" #else typedef double DOUBLEST; -# define DOUBLEST_PRINT_FORMAT "g" -# define DOUBLEST_SCAN_FORMAT "lg" /* If we can't scan or print long double, we don't want to use it anywhere. */ # undef HAVE_LONG_DOUBLE @@ -81,12 +76,4 @@ extern bool floatformat_from_string (con extern size_t floatformat_totalsize_bytes (const struct floatformat *fmt); -extern DOUBLEST extract_typed_floating (const void *addr, - const struct type *type); -extern void store_typed_floating (void *addr, const struct type *type, - DOUBLEST val); -extern void convert_typed_floating (const void *from, - const struct type *from_type, - void *to, const struct type *to_type); - #endif Index: binutils-gdb/gdb/dfp.c =================================================================== --- binutils-gdb.orig/gdb/dfp.c +++ binutils-gdb/gdb/dfp.c @@ -268,29 +268,6 @@ decimal_to_longest (const gdb_byte *from return strtoll (str.c_str (), NULL, 10); } -/* Converts a value of a float type to a decimal float of - specified LEN bytes. - - This is an ugly way to do the conversion, but libdecnumber does - not offer a direct way to do it. */ -void -decimal_from_doublest (DOUBLEST from, - gdb_byte *to, int len, enum bfd_endian byte_order) -{ - std::string str = string_printf ("%.30" DOUBLEST_PRINT_FORMAT, from); - decimal_from_string (to, len, byte_order, str); -} - -/* Converts a decimal float of LEN bytes to a double value. */ -DOUBLEST -decimal_to_doublest (const gdb_byte *from, int len, enum bfd_endian byte_order) -{ - /* This is an ugly way to do the conversion, but libdecnumber does - not offer a direct way to do it. */ - std::string str = decimal_to_string (from, len, byte_order); - return strtod (str.c_str (), NULL); -} - /* Perform operation OP with operands X and Y with sizes LEN_X and LEN_Y and byte orders BYTE_ORDER_X and BYTE_ORDER_Y, and store value in RESULT with size LEN_RESULT and byte order BYTE_ORDER_RESULT. */ Index: binutils-gdb/gdb/dfp.h =================================================================== --- binutils-gdb.orig/gdb/dfp.h +++ binutils-gdb/gdb/dfp.h @@ -25,7 +25,6 @@ #ifndef DFP_H #define DFP_H -#include "doublest.h" /* For DOUBLEST. */ #include "expression.h" /* For enum exp_opcode. */ extern std::string decimal_to_string (const gdb_byte *, int, enum bfd_endian, @@ -38,10 +37,6 @@ extern void decimal_from_ulongest (ULONG int len, enum bfd_endian byte_order); extern LONGEST decimal_to_longest (const gdb_byte *from, int len, enum bfd_endian byte_order); -extern void decimal_from_doublest (DOUBLEST from, gdb_byte *to, - int len, enum bfd_endian byte_order); -extern DOUBLEST decimal_to_doublest (const gdb_byte *from, int len, - enum bfd_endian byte_order); extern void decimal_binop (enum exp_opcode, const gdb_byte *, int, enum bfd_endian, const gdb_byte *, int, enum bfd_endian, Index: binutils-gdb/gdb/value.c =================================================================== --- binutils-gdb.orig/gdb/value.c +++ binutils-gdb/gdb/value.c @@ -28,10 +28,8 @@ #include "target.h" #include "language.h" #include "demangle.h" -#include "doublest.h" #include "regcache.h" #include "block.h" -#include "dfp.h" #include "target-float.h" #include "objfiles.h" #include "valprint.h" @@ -2764,18 +2762,6 @@ value_as_long (struct value *val) return unpack_long (value_type (val), value_contents (val)); } -DOUBLEST -value_as_double (struct value *val) -{ - DOUBLEST foo; - int inv; - - foo = unpack_double (value_type (val), value_contents (val), &inv); - if (inv) - error (_("Invalid floating value found in program.")); - return foo; -} - /* Extract a value as a C pointer. Does not deallocate the value. Note that val's type may not actually be a pointer; value_as_long handles all the cases. */ @@ -2938,49 +2924,6 @@ unpack_long (struct type *type, const gd return 0; /* Placate lint. */ } -/* Return a double value from the specified type and address. - INVP points to an int which is set to 0 for valid value, - 1 for invalid value (bad float format). In either case, - the returned double is OK to use. Argument is in target - format, result is in host format. */ - -DOUBLEST -unpack_double (struct type *type, const gdb_byte *valaddr, int *invp) -{ - enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); - enum type_code code; - int len; - int nosign; - - *invp = 0; /* Assume valid. */ - type = check_typedef (type); - code = TYPE_CODE (type); - len = TYPE_LENGTH (type); - nosign = TYPE_UNSIGNED (type); - if (code == TYPE_CODE_FLT) - { - if (!target_float_is_valid (valaddr, type)) - { - *invp = 1; - return 0.0; - } - - return extract_typed_floating (valaddr, type); - } - else if (code == TYPE_CODE_DECFLOAT) - return decimal_to_doublest (valaddr, len, byte_order); - else if (nosign) - { - /* Unsigned -- be sure we compensate for signed LONGEST. */ - return (ULONGEST) unpack_long (type, valaddr); - } - else - { - /* Signed -- we are OK with unpack_long. */ - return unpack_long (type, valaddr); - } -} - /* Unpack raw data (copied from debugee, target byte order) at VALADDR as a CORE_ADDR, assuming the raw data is described by type TYPE. We don't assume any alignment for the raw data. Return value is in @@ -3693,32 +3636,6 @@ value_from_contents (struct type *type, return result; } -struct value * -value_from_double (struct type *type, DOUBLEST num) -{ - struct value *val = allocate_value (type); - struct type *base_type = check_typedef (type); - enum type_code code = TYPE_CODE (base_type); - - if (code == TYPE_CODE_FLT) - { - store_typed_floating (value_contents_raw (val), base_type, num); - } - else - error (_("Unexpected type encountered for floating constant.")); - - return val; -} - -struct value * -value_from_decfloat (struct type *type, const gdb_byte *dec) -{ - struct value *val = allocate_value (type); - - memcpy (value_contents_raw (val), dec, TYPE_LENGTH (type)); - return val; -} - /* Extract a value from the history file. Input will be of the form $digits or $$digits. See block comment above 'write_dollar_variable' for details. */ Index: binutils-gdb/gdb/value.h =================================================================== --- binutils-gdb.orig/gdb/value.h +++ binutils-gdb/gdb/value.h @@ -20,7 +20,6 @@ #if !defined (VALUE_H) #define VALUE_H 1 -#include "doublest.h" #include "frame.h" /* For struct frame_id. */ struct block; @@ -613,12 +612,9 @@ extern int print_address_demangle (const extern bool is_floating_value (struct value *val); extern LONGEST value_as_long (struct value *val); -extern DOUBLEST value_as_double (struct value *val); extern CORE_ADDR value_as_address (struct value *val); extern LONGEST unpack_long (struct type *type, const gdb_byte *valaddr); -extern DOUBLEST unpack_double (struct type *type, const gdb_byte *valaddr, - int *invp); extern CORE_ADDR unpack_pointer (struct type *type, const gdb_byte *valaddr); extern LONGEST unpack_field_as_long (struct type *type, @@ -644,9 +640,6 @@ extern void pack_long (gdb_byte *buf, st extern struct value *value_from_longest (struct type *type, LONGEST num); extern struct value *value_from_ulongest (struct type *type, ULONGEST num); extern struct value *value_from_pointer (struct type *type, CORE_ADDR addr); -extern struct value *value_from_double (struct type *type, DOUBLEST num); -extern struct value *value_from_decfloat (struct type *type, - const gdb_byte *decbytes); extern struct value *value_from_history_ref (const char *, const char **); extern struct value *value_from_component (struct value *, struct type *, LONGEST);