From 33dcdecaa14dc1f4d326cf2ff11e7684c448e924 Mon Sep 17 00:00:00 2001 From: "Guillermo J. Rozas" Date: Mon, 20 Jan 1992 22:05:11 +0000 Subject: [PATCH] Fix some minor bugs and accomodate some random compilers. --- v7/src/microcode/wsize.c | 192 ++++++++++++++++++++++++--------------- 1 file changed, 119 insertions(+), 73 deletions(-) diff --git a/v7/src/microcode/wsize.c b/v7/src/microcode/wsize.c index 165eb3c5b..a9c3bd610 100644 --- a/v7/src/microcode/wsize.c +++ b/v7/src/microcode/wsize.c @@ -1,6 +1,8 @@ /* -*-C-*- -Copyright (c) 1989 Massachusetts Institute of Technology +$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/wsize.c,v 9.31 1992/01/20 22:05:11 jinx Exp $ + +Copyright (c) 1989-1992 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and @@ -29,12 +31,11 @@ there shall be no use of the name of the Massachusetts Institute of Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. */ - -/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/wsize.c,v 9.30 1990/09/08 00:09:38 cph Rel $ */ #include #include #include +#include #ifndef TYPE_CODE_LENGTH /* This MUST match object.h */ @@ -49,19 +50,53 @@ MIT in each case. */ #define true 1 extern int errno; -extern char *malloc(); -extern free(); +extern char * malloc(); +extern free (); + +/* The following hanky-panky courtesy of some buggy compilers. */ + +int +mul (x, y) + int x; int y; +{ + return (x * y); +} + +double +itod (n) + int n; +{ + return ((double) (mul (n, 1))); +} + +double +power (base, expo) + double base; + unsigned expo; +{ + double result = (itod (1)); + while (expo != 0) + { + if ((expo & 1) == 1) + { + result *= base; + expo -= 1; + } + else + { + base *= base; + expo >>= 1; + } + } + return (result); +} /* Some machines do not set ERANGE by default. */ /* This attempts to fix this. */ -#ifdef celerity -#define hack_signal -#endif - -#ifdef hack_signal +#ifdef SIGFPE -#define setup_error() signal(SIGFPE, range_error) +# define setup_error() signal(SIGFPE, range_error) void range_error() @@ -70,9 +105,12 @@ range_error() errno = ERANGE; return; } -#else -#define setup_error() -#endif + +#else /* not SIGFPE */ + +# define setup_error() + +#endif /* SIGFPE */ /* Force program data to be relatively large. */ @@ -94,79 +132,82 @@ struct double_probe { main() { - double accum[3], delta, dtemp; + double accum[3], delta, dtemp, zero, one, two; int count, expt_size, char_size, mant_size, double_size, extra; unsigned long to_be_shifted; unsigned bogus; - char buffer[sizeof(long)]; - char *temp; + struct { long pad; char real_buffer[sizeof(long)]; } padding_buf; + char * buffer, * temp; boolean confused; + buffer = &padding_buf.real_buffer[0]; confused = false; - setup_error(); + setup_error (); - printf("/%c CSCHEME configuration parameters. %c/\n", '*', '*'); - printf("/%c REMINDER: Insert these definitions in config.h. %c/\n\n", - '*', '*'); + printf ("/%c CSCHEME configuration parameters. %c/\n", '*', '*'); + printf ("/%c REMINDER: Insert these definitions in config.h. %c/\n\n", + '*', '*'); - printf("/%c REMINDER: Change the following definitions! %c/\n", - '*', '*'); - printf("#define MACHINE_TYPE \"Unknown machine, fix config.h\"\n"); - printf("#define FASL_INTERNAL_FORMAT FASL_UNKNOWN\n\n"); + printf ("/%c REMINDER: Change the following definitions! %c/\n", + '*', '*'); + printf ("#define MACHINE_TYPE \"Unknown machine, fix config.h\"\n"); + printf ("#define FASL_INTERNAL_FORMAT FASL_UNKNOWN\n\n"); if ((((int) 'a') == ASCII_LOWER_A) && (((int) 'A') == ASCII_UPPER_A)) { - printf("/%c The ASCII character set is used. %c/\n", '*', '*'); + printf ("/%c The ASCII character set is used. %c/\n", '*', '*'); } else { - printf("/%c The ASCII character set is NOT used. %c/\n", '*', '*'); - printf("/%c REMINDER: Change the following definition! %c/\n", - '*', '*'); + printf ("/%c The ASCII character set is NOT used. %c/\n", '*', '*'); + printf ("/%c REMINDER: Change the following definition! %c/\n", + '*', '*'); } - for(bogus = ((unsigned) -1), count = 0; - bogus != 0; - count += 1) + for (bogus = ((unsigned) -1), count = 0; + bogus != 0; + count += 1) + { bogus >>= 1; + } - char_size = count / (sizeof(unsigned)); + char_size = (count / (sizeof(unsigned))); - temp = malloc(MEM_SIZE*sizeof(long)); + temp = (malloc (MEM_SIZE * (sizeof(long)))); if (temp == NULL) { confused = true; - printf("/%c CONFUSION: Could not allocate %d Objects. %c/\n", - '*', MEM_SIZE, '*'); - printf("/%c Will not assume that the Heap is in Low Memory. %c/\n", - '*', '*'); + printf ("/%c CONFUSION: Could not allocate %d Objects. %c/\n", + '*', MEM_SIZE, '*'); + printf ("/%c Will not assume that the Heap is in Low Memory. %c/\n", + '*', '*'); } else { - count = free(temp); + count = (free (temp)); if (((unsigned long) temp) < (1 << ((char_size * sizeof(long)) - TYPE_CODE_LENGTH))) - printf("#define HEAP_IN_LOW_MEMORY 1\n"); + printf ("#define HEAP_IN_LOW_MEMORY 1\n"); else - printf("/%c Heap is not in Low Memory. %c/\n", '*', '*'); + printf ("/%c Heap is not in Low Memory. %c/\n", '*', '*'); } to_be_shifted = -1; if ((to_be_shifted >> 1) == to_be_shifted) { - printf("/%c unsigned longs use arithmetic shifting. %c/\n", '*', '*'); - printf("#define UNSIGNED_SHIFT_BUG\n"); + printf ("/%c unsigned longs use arithmetic shifting. %c/\n", '*', '*'); + printf ("#define UNSIGNED_SHIFT_BUG\n"); } else { - printf("/%c unsigned longs use logical shifting. %c/\n", '*', '*'); + printf ("/%c unsigned longs use logical shifting. %c/\n", '*', '*'); } - if (sizeof(long) == sizeof(char)) + if ((sizeof(long)) == (sizeof(char))) { - printf("/%c sizeof(long) == sizeof(char); no byte order problems! %c/\n", - '*', '*'); + printf ("/%c sizeof(long) == sizeof(char); no byte order problems! %c/\n", + '*', '*'); } else { @@ -187,33 +228,38 @@ main() double_size = (char_size*sizeof(double)); - printf("#define CHAR_BIT %d\n", - char_size); + printf ("#define CHAR_BIT %d\n", + char_size); if (sizeof(struct double_probe) == (sizeof(double) + sizeof(long))) { - printf("/%c Flonums have no special alignment constraints. %c/\n", - '*', '*'); + printf ("/%c Flonums have no special alignment constraints. %c/\n", + '*', '*'); } else if ((sizeof(struct double_probe) != (2 * sizeof(double))) || ((sizeof(double) % sizeof(long)) != 0)) { confused = true; - printf("/%c CONFUSION: Can't determine float alignment constraints! %c/\n", - '*', '*'); - printf("/%c Please define FLOATING_ALIGNMENT by hand. %c/\n", '*', '*'); + printf ("/%c CONFUSION: Can't determine float alignment constraints! %c/\n", + '*', '*'); + printf ("/%c Please define FLOATING_ALIGNMENT by hand. %c/\n", '*', '*'); } else { - printf("#define FLOATING_ALIGNMENT 0x%lx\n", (sizeof(double)-1)); + printf ("#define FLOATING_ALIGNMENT 0x%lx\n", (sizeof(double)-1)); } mant_size = 1; - accum[0] = 1.0; - accum[1] = 0.0; - delta = 0.5; - while(true) + zero = (itod (0)); + one = (itod (1)); + two = (itod (2)); + + accum[0] = one; + accum[1] = zero; + delta = (one / two); + + while (true) { accum[2] = accum[1]; accum[1] = (accum[0] + delta); @@ -221,44 +267,44 @@ main() (accum[2] == accum[1]) || (mant_size == double_size)) break; - delta = (delta / ((double) 2.0)); + delta = (delta / two); mant_size += 1; } - printf("#define FLONUM_MANTISSA_BITS %d\n", mant_size); + printf ("#define FLONUM_MANTISSA_BITS %d\n", mant_size); - for(errno = 0, expt_size = 0, bogus = 1, dtemp = 0.0; - ((errno != ERANGE) && (expt_size <= double_size)); - expt_size += 1, bogus <<= 1) + for (errno = 0, expt_size = 0, bogus = 1, dtemp = zero; + ((errno != ERANGE) && (expt_size <= double_size)); + expt_size += 1, bogus <<= 1) { delta = dtemp; - dtemp = pow(((double) 2.0), ((double) bogus)); + dtemp = (power (two, bogus)); if (dtemp == delta) break; } expt_size -= 1; - printf("#define FLONUM_EXPT_SIZE %d\n", expt_size); - printf("#define MAX_FLONUM_EXPONENT %d\n", ((1 << expt_size) - 1)); + printf ("#define FLONUM_EXPT_SIZE %d\n", expt_size); + printf ("#define MAX_FLONUM_EXPONENT %d\n", ((1 << expt_size) - 1)); extra = ((2 + expt_size + mant_size) - double_size); if (extra > 1) { confused = true; - printf("/%c CONFUSION: Can't determine floating parameters! %c/\n", - '*', '*'); - printf("/%c Please fix above three parameters by hand. %c/\n", '*', '*'); + printf ("/%c CONFUSION: Can't determine floating parameters! %c/\n", + '*', '*'); + printf ("/%c Please fix above three parameters by hand. %c/\n", '*', '*'); } else { - printf("/%c Floating point representation %s hidden bit. %c/\n", '*', - ((extra == 1) ? "uses" : "does not use"), '*'); + printf ("/%c Floating point representation %s hidden bit. %c/\n", '*', + ((extra == 1) ? "uses" : "does not use"), '*'); } if (confused) { - fprintf(stderr, "Please examine carefully the \"confused\" parameters.\n"); + fprintf (stderr, "Please examine carefully the \"confused\" parameters.\n"); exit(1); } return; -- 2.25.1