public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Paul E. Murphy" <murphyp@linux.vnet.ibm.com>
To: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Cc: Joseph Myers <joseph@codesourcery.com>
Subject: [PATCH] Improve gen-libm-test.pl LIT() application
Date: Thu, 04 Aug 2016 15:06:00 -0000	[thread overview]
Message-ID: <588e39fe-e762-8f54-d793-8ba2e06eb9a2@linux.vnet.ibm.com> (raw)

When bootstrapping float128, this exposed a number of areas where
the L suffix is incorrectly applied to simple expressions when it
should be applied to each constant in the expression.

In order to stave off more macros in libm-test.inc, apply_lit is
made slightly more intelligent.  It will now split most basic
expressions and apply LIT() individually to each token.  As noted,
it is not a perfect solution, but compromises correctness,
readability, and simplicity.

The above is problematic when the L real suffix is not the most
expressive modifier, and the compiler complains (i.e ppc64) or
silently truncates a value (i.e ppc64).

	* math/gen-libm-test.pl (apply_lit): Rewrite to apply
	LIT() to individual constants in simple expressions.
	(_apply_lit): Rename replaced version, and use it to
	apply to what appears to be a token.
---
 math/gen-libm-test.pl | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/math/gen-libm-test.pl b/math/gen-libm-test.pl
index aa66e76..cb0a02b 100755
--- a/math/gen-libm-test.pl
+++ b/math/gen-libm-test.pl
@@ -163,7 +163,7 @@ sub show_exceptions {
 
 # Apply the LIT(x) macro to a literal floating point constant
 # and strip any existing suffix.
-sub apply_lit {
+sub _apply_lit {
   my ($lit) = @_;
   my $exp_re = "([+-])?[[:digit:]]+";
   # Don't wrap something that does not look like a:
@@ -180,6 +180,44 @@ sub apply_lit {
   return "LIT (${lit})";
 }
 
+
+# Apply LIT macro to individual tokens within an
+# expression.  This is only meant to work with
+# the very simple expressions encountered like
+# A (op B)*.  It will not split all literals
+# correctly, but suffices for this usage without
+# a substantially more complex tokenizer.
+sub apply_lit {
+  my ($lit) = @_;
+  my @toks = ();
+
+  # There are some constant expressions embedded in the
+  # test cases.  To avoid writing a more complex lexer,
+  # we apply some fixups, and split based on simple
+  # operators, unfixup, then apply LIT as needed.
+
+  # This behaves poorly on inputs like 0x0e+1.0f,
+  # or MAX_EXP+1, but ultimately doesn't break
+  # anything... for now.
+  $lit =~ s/([[:xdigit:]])[pP]\+/$1,/g;
+  $lit =~ s/([[:xdigit:]])[pP]\-/$1#/g;
+  $lit =~ s/([0-9])[eE]\+/$1'/g;
+  $lit =~ s/([0-9])[eE]\-/$1"/g;
+
+  # Split into tokenish looking things
+  @toks = split (/([\*\-\+\/])/, $lit);
+
+  # Remove fixups and apply LIT() if needed.
+  foreach (@toks) {
+    $_ =~ s/,/p+/g;
+    $_ =~ s/#/p-/g;
+    $_ =~ s/'/e+/g;
+    $_ =~ s/"/e-/g;
+    $_ = _apply_lit ($_);
+  }
+  return join ('', @toks);
+}
+
 # Parse the arguments to TEST_x_y
 sub parse_args {
   my ($file, $descr, $args) = @_;
-- 
2.4.11

             reply	other threads:[~2016-08-04 15:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 15:06 Paul E. Murphy [this message]
2016-08-04 16:03 ` Carlos O'Donell
2016-08-04 16:45   ` Paul E. Murphy
2016-08-04 16:52     ` Carlos O'Donell
2016-08-04 16:52     ` Joseph Myers
2016-08-04 16:52       ` Carlos O'Donell
2016-08-04 20:44         ` Paul E. Murphy
2016-08-04 20:55           ` Joseph Myers
2016-08-05 19:44             ` Paul E. Murphy
2016-08-04 16:48 ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=588e39fe-e762-8f54-d793-8ba2e06eb9a2@linux.vnet.ibm.com \
    --to=murphyp@linux.vnet.ibm.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).