diff options
author | Juergen Beisert <j.beisert@pengutronix.de> | 2009-04-23 13:22:52 +0000 |
---|---|---|
committer | Juergen Beisert <j.beisert@pengutronix.de> | 2009-04-23 13:22:52 +0000 |
commit | 00a59ebaedd229d17425ba1da7216cdf7a94315e (patch) | |
tree | 1d8d93c3f3a2baf8cbd809ed0cf673838290705b | |
parent | 51c3dd7aa8b42fa7b66f03b44f8a998df3066013 (diff) | |
download | floatings-00a59ebaedd229d17425ba1da7216cdf7a94315e.tar.gz floatings-00a59ebaedd229d17425ba1da7216cdf7a94315e.tar.xz |
making pi8 more useable for automatic tests
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/pi8.c | 137 |
2 files changed, 85 insertions, 54 deletions
diff --git a/configure.ac b/configure.ac index 88a7f13..b8751b5 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([floatings], [1.0.0], [bugs@pengutronix.de]) +AC_INIT([floatings], [1.1.0], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_SRCDIR([src/float_bench.c]) AC_CANONICAL_BUILD @@ -57,14 +57,20 @@ 33 minutes and 54 seconds. */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/time.h> +#include <unistd.h> #define SHOWTIME +#define DEFAULT_DIGIT_COUNT 2000 + #if defined USEFPU #define BASE 1000000000L @@ -85,7 +91,7 @@ typedef long int INDEXER; SHORT *pi, *powers, *term; -INDEXER size; +INDEXER size = DEFAULT_DIGIT_COUNT; void OutDig(int dig) @@ -219,67 +225,92 @@ void arctan(int multiplier, int denom, int sign) } } -int main(int argc, char *argv[]) +static void usage(const char *prg, FILE *out) { - INDEXER x; - struct timeval start, stop, diff; - - if (argc != 2) - { - fprintf(stderr, "I need to know how many digits to compute.\n"); - exit(EXIT_FAILURE); - } - - size = atol(argv[1]); - if (size <= 0L) - { - fprintf(stderr, "Invalid argument.\n"); - exit(EXIT_FAILURE); - } - - size = ((size + BASEDIGITS - 1) / BASEDIGITS) + 1; - - pi = malloc(sizeof(SHORT) * size); - powers = malloc(sizeof(SHORT) * size); - term = malloc(sizeof(SHORT) * size); - - if ((pi == NULL) || (powers == NULL) || (term == NULL)) - { - fprintf(stderr, "Unable to allocate enough memory.\n"); - exit(EXIT_FAILURE); - } - - for (x = 0; x < size; x++) - pi[x] = 0; + fprintf(out, "usage: %s [options]\n", prg); + fprintf(out, " options are:\n"); + fprintf(out, " '-c count' digits to compute. Default is %ld, should not be 0.\n", size); + fprintf(out, " '-q' be quiet, do not emit pi\n"); + fprintf(out, " '-v' print program version and exit\n"); + fprintf(out, " '-h' print this help and exit\n"); +} - gettimeofday(&start, NULL); +int main(int argc, char *argv[]) +{ + INDEXER x; + int quiet = 0, c; + struct timeval start, stop, diff; + + /* handle command line options first */ + while (1) { + c = getopt(argc, argv, "c:qhv"); + if (c == -1) + break; + + switch (c) { + case 'c': + size = atoi(optarg); /* digits to compute */ + break; + case 'q': + quiet = 1; + break; + case 'h': + usage(argv[0], stdout); + exit(EXIT_SUCCESS); + case 'v': + printf("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION); + exit(EXIT_SUCCESS); + } + } + + if (! size) { + usage(argv[0], stderr); + exit(EXIT_FAILURE); + } + + size = ((size + BASEDIGITS - 1) / BASEDIGITS) + 1; + + pi = malloc(sizeof(SHORT) * size); + powers = malloc(sizeof(SHORT) * size); + term = malloc(sizeof(SHORT) * size); + + if ((pi == NULL) || (powers == NULL) || (term == NULL)) { + fprintf(stderr, "Unable to allocate enough memory.\n"); + exit(EXIT_FAILURE); + } + + for (x = 0; x < size; x++) + pi[x] = 0; + + gettimeofday(&start, NULL); #if defined ARC3 - arctan(8, 3, 1); - arctan(4, 7, 1); + arctan(8, 3, 1); + arctan(4, 7, 1); #elif defined ARC5 - arctan(16, 5, 1); - arctan(4, 70, -1); - arctan(4, 99, 1); + arctan(16, 5, 1); + arctan(4, 70, -1); + arctan(4, 99, 1); #elif defined ARC4 - arctan(12, 4, 1); - arctan(4, 20, 1); - arctan(4, 1985, 1); + arctan(12, 4, 1); + arctan(4, 20, 1); + arctan(4, 1985, 1); #elif defined ARC10 - arctan(32, 10, 1); - arctan(4, 239, -1); - arctan(16, 515, -1); + arctan(32, 10, 1); + arctan(4, 239, -1); + arctan(16, 515, -1); #else /* Machin formula */ - arctan(16, 5, 1); - arctan(4, 239, -1); + arctan(16, 5, 1); + arctan(4, 239, -1); #endif - gettimeofday(&stop, NULL); - Print(pi); - - timersub(&stop, &start, &diff); - printf("\nCalculation time %ldsec %ldusec\n", diff.tv_sec, diff.tv_usec); - - return EXIT_SUCCESS; + gettimeofday(&stop, NULL); + if (!quiet) + Print(pi); + + timersub(&stop, &start, &diff); + printf("\nTime (s): %ld.%ld\n", diff.tv_sec, diff.tv_usec); + + return EXIT_SUCCESS; } |