From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id 305B93858C52; Fri, 23 Sep 2022 08:52:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305B93858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663923163; bh=FaRitvmze/UjF2wP8gXZjJl5eqjXsW2r/9m8NHYHKt0=; h=From:To:Subject:Date:From; b=oj2bE6IVrFvDvu7vmyaTQZ7nwHFSXodu88cj2Un84RpcmS5x9QTfgPhdgX22JIofP ZGpvIE5YmkGSUScxJ9Dg1rxZHmuMGW5XKJk8RmKx2wPYecSGFKjvKvEejo/5UeX97z 9/NiLKsP7sIYmMYDFcHWHm6F30jOXabYZCTfh4MU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2808] frange: dump hex values when dumping FP numbers. X-Act-Checkin: gcc X-Git-Author: Aldy Hernandez X-Git-Refname: refs/heads/master X-Git-Oldrev: 651625728520b5e1d926f0e12018c96f3fe18b22 X-Git-Newrev: 0706262498bc5d206330c08414df0c780a0c3141 Message-Id: <20220923085243.305B93858C52@sourceware.org> Date: Fri, 23 Sep 2022 08:52:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0706262498bc5d206330c08414df0c780a0c3141 commit r13-2808-g0706262498bc5d206330c08414df0c780a0c3141 Author: Aldy Hernandez Date: Thu Sep 22 18:07:03 2022 +0200 frange: dump hex values when dumping FP numbers. It has been suggested that if we start bumping numbers by an ULP when calculating open ranges (for example the numbers less than 3.0) that dumping these will become increasingly harder to read, and instead we should opt for the hex representation. I still find the floating point representation easier to read for most numbers, but perhaps we could have both? With this patch this is the representation for [15.0, 20.0]: [frange] float [1.5e+1 (0x0.fp+4), 2.0e+1 (0x0.ap+5)] Would you find this useful, or should we stick to the hex representation only? Tested on x86-64 Linux. gcc/ChangeLog: * value-range-pretty-print.cc (vrange_printer::print_real_value): New. (vrange_printer::visit): Call print_real_value. * value-range-pretty-print.h: New print_real_value. Diff: --- gcc/value-range-pretty-print.cc | 19 +++++++++++++++---- gcc/value-range-pretty-print.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc index eb7442229ba..8cbe97b76fd 100644 --- a/gcc/value-range-pretty-print.cc +++ b/gcc/value-range-pretty-print.cc @@ -117,6 +117,19 @@ vrange_printer::print_irange_bitmasks (const irange &r) const pp_string (pp, buf); } +void +vrange_printer::print_real_value (tree type, const REAL_VALUE_TYPE &r) const +{ + char s[100]; + real_to_decimal_for_mode (s, &r, sizeof (s), 0, 1, TYPE_MODE (type)); + pp_string (pp, s); + if (!DECIMAL_FLOAT_TYPE_P (type)) + { + real_to_hexadecimal (s, &r, sizeof (s), 0, 1); + pp_printf (pp, " (%s)", s); + } +} + // Print an frange. void @@ -141,11 +154,9 @@ vrange_printer::visit (const frange &r) const bool has_endpoints = !r.known_isnan (); if (has_endpoints) { - dump_generic_node (pp, - build_real (type, r.lower_bound ()), 0, TDF_NONE, false); + print_real_value (type, r.lower_bound ()); pp_string (pp, ", "); - dump_generic_node (pp, - build_real (type, r.upper_bound ()), 0, TDF_NONE, false); + print_real_value (type, r.upper_bound ()); } pp_character (pp, ']'); print_frange_nan (r); diff --git a/gcc/value-range-pretty-print.h b/gcc/value-range-pretty-print.h index 20c26598fe7..a9ae5a7b4cc 100644 --- a/gcc/value-range-pretty-print.h +++ b/gcc/value-range-pretty-print.h @@ -32,6 +32,7 @@ private: void print_irange_bound (const wide_int &w, tree type) const; void print_irange_bitmasks (const irange &) const; void print_frange_nan (const frange &) const; + void print_real_value (tree type, const REAL_VALUE_TYPE &r) const; pretty_printer *pp; };