From patchwork Mon May 23 22:18:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 12484 Received: (qmail 48509 invoked by alias); 23 May 2016 22:18:48 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 48444 invoked by uid 89); 23 May 2016 22:18:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:5201, regeneration, 7819 X-HELO: e37.co.us.ibm.com X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: murphyp@linux.vnet.ibm.com X-IBM-RcptTo: libc-alpha@sourceware.org From: "Paul E. Murphy" To: libc-alpha@sourceware.org Subject: [PATCHv3 1/3] Refactor tst-strtod-round.c Date: Mon, 23 May 2016 17:18:28 -0500 Message-Id: In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16052322-0025-0000-0000-00004110B9CE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused This file is partially generated. To make updates a little simpler, I have moved the generated code into a partially contained header to simplify regeneration. gen-tst-strtod-round.c now takes two, mandatory arguments. These arguments specify the input test data and the output destination, respectively. NOTE: I've stripped the changes to tst-strtod-round.c and tst-strtod-round-data.h. You will need to manually remove the test object, and replace it with: /* Include the generated test data. */ #include "tst-strtod-round-data.h" * stdlib/gen-tst-strtod-round.c (main): Change usage to more closely match the generated output. Add usage and compilation instructions. (string_to_fp): Add and use FILE* parameter as output target. (print_fp): Likewise. (round_str): Likewise. (round_for_all): Likewise. * stdlib/tst-strtod-round.c (tests): Move into * stdlib/tst-strtod-round-data.h: New file. --- stdlib/gen-tst-strtod-round.c | 86 +- stdlib/tst-strtod-round-data.h | 12334 ++++++++++++++++++++++++++++++++++++++ stdlib/tst-strtod-round.c | 12338 +-------------------------------------- 3 files changed, 12401 insertions(+), 12357 deletions(-) create mode 100644 stdlib/tst-strtod-round-data.h diff --git a/stdlib/gen-tst-strtod-round.c b/stdlib/gen-tst-strtod-round.c index 3ef4506..26c2ec2 100644 --- a/stdlib/gen-tst-strtod-round.c +++ b/stdlib/gen-tst-strtod-round.c @@ -17,11 +17,25 @@ License along with the GNU C Library; if not, see . */ +/* Compile this program as: + + gcc -std=gnu11 -O2 -Wall -Wextra gen-tst-strtod-round.c -lmpfr + -o gen-tst-strtod-round + + (use of current MPFR version recommended) and run it as: + + gen-tst-strtod-round tst-strtod-round-data tst-strtod-round-data.h + + The output file will be generated as tst-strtod-round-data.h +*/ + + #define _GNU_SOURCE #include #include #include #include +#include #include /* Work around incorrect ternary value from mpfr_strtofr @@ -47,16 +61,17 @@ string_to_fp (mpfr_t f, const char *s, mpfr_rnd_t rnd) } static void -print_fp (mpfr_t f, const char *suffix, const char *suffix2) +print_fp (FILE *fout, mpfr_t f, const char *suffix, const char *suffix2) { if (mpfr_inf_p (f)) - mpfr_printf ("\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "", suffix2); + mpfr_fprintf (fout, "\t%sINFINITY%s", mpfr_signbit (f) ? "-" : "", + suffix2); else - mpfr_printf ("\t%Ra%s%s", f, suffix, suffix2); + mpfr_fprintf (fout, "\t%Ra%s%s", f, suffix, suffix2); } static void -round_str (const char *s, const char *suffix, +round_str (FILE *fout, const char *s, const char *suffix, int prec, int emin, int emax, bool ibm_ld) { mpfr_t f; @@ -78,19 +93,19 @@ round_str (const char *s, const char *suffix, r = 1; mpfr_clear (max_value); } - mpfr_printf ("\t%s,\n", r ? "false" : "true"); - print_fp (f, suffix, ",\n"); + mpfr_fprintf (fout, "\t%s,\n", r ? "false" : "true"); + print_fp (fout, f, suffix, ",\n"); string_to_fp (f, s, MPFR_RNDN); - print_fp (f, suffix, ",\n"); + print_fp (fout, f, suffix, ",\n"); string_to_fp (f, s, MPFR_RNDZ); - print_fp (f, suffix, ",\n"); + print_fp (fout, f, suffix, ",\n"); string_to_fp (f, s, MPFR_RNDU); - print_fp (f, suffix, ""); + print_fp (fout, f, suffix, ""); mpfr_clear (f); } static void -round_for_all (const char *s) +round_for_all (FILE *fout, const char *s) { static const struct fmt { const char *suffix; @@ -109,39 +124,68 @@ round_for_all (const char *s) { "L", 106, -1073, 1024, true }, { "L", 113, -16493, 16384, false }, }; - mpfr_printf (" TEST (\""); + mpfr_fprintf (fout, " TEST (\""); const char *p; for (p = s; *p; p++) { - putchar (*p); + fputc (*p, fout); if ((p - s) % 60 == 59 && p[1]) - mpfr_printf ("\"\n\t\""); + mpfr_fprintf (fout, "\"\n\t\""); } - mpfr_printf ("\",\n"); + mpfr_fprintf (fout, "\",\n"); int i; for (i = 0; i < 7; i++) { - round_str (s, formats[i].suffix, formats[i].prec, + round_str (fout, s, formats[i].suffix, formats[i].prec, formats[i].emin, formats[i].emax, formats[i].ibm_ld); if (i < 6) - mpfr_printf (",\n"); + mpfr_fprintf (fout, ",\n"); } - mpfr_printf ("),\n"); + mpfr_fprintf (fout, "),\n"); } int -main (void) +main (int argc, char **argv) { char *p = NULL; size_t len; ssize_t nbytes; - while ((nbytes = getline (&p, &len, stdin)) != -1) + FILE *fin, *fout; + char *fin_name = argv[1]; + char *fout_name = argv[2]; + + if (argc < 3) + { + fprintf (stderr, "Usage: %s [input] [output]\n", basename (argv[0])); + return EXIT_FAILURE; + } + + fin = fopen (fin_name, "r"); + if (fin == NULL) + { + perror ("Could not open input for reading"); + return EXIT_FAILURE; + } + + fout = fopen (fout_name, "w"); + if (fout == NULL) + { + perror ("Could not open output for writing"); + return EXIT_FAILURE; + } + + fprintf (fout, "/* This file was generated by %s from %s. */\n", + __FILE__, fin_name); + fputs ("static const struct test tests[] = {\n", fout); + while ((nbytes = getline (&p, &len, fin)) != -1) { if (p[nbytes - 1] == '\n') p[nbytes - 1] = 0; - round_for_all (p); + round_for_all (fout, p); free (p); p = NULL; } - return 0; + fputs ("};\n", fout); + + return EXIT_SUCCESS; }