diff options
Diffstat (limited to 'src/H5detect.c')
-rw-r--r-- | src/H5detect.c | 303 |
1 files changed, 153 insertions, 150 deletions
diff --git a/src/H5detect.c b/src/H5detect.c index fc0570c..15736bd 100644 --- a/src/H5detect.c +++ b/src/H5detect.c @@ -73,7 +73,7 @@ static const char *FileHeader = "\n\ #define H5JMP_BUF sigjmp_buf #define H5SETJMP(buf) HDsigsetjmp(buf, 1) #define H5LONGJMP(buf, val) HDsiglongjmp(buf, val) -#define H5HAVE_SIGJMP # sigsetjmp/siglongjmp are supported. +#define H5HAVE_SIGJMP /* sigsetjmp/siglongjmp are supported. */ #elif defined(H5_HAVE_LONGJMP) #define H5JMP_BUF jmp_buf #define H5SETJMP(buf) HDsetjmp(buf) @@ -90,41 +90,41 @@ static const char *FileHeader = "\n\ * was detected. */ typedef struct detected_t { - const char *varname; - int size; /*total byte size */ - int precision; /*meaningful bits */ - int offset; /*bit offset to meaningful bits */ - int perm[32]; /*for detection of byte order */ - int is_vax; /*for vax (float & double) only */ - int sign; /*location of sign bit */ - int mpos, msize, imp;/*information about mantissa */ - int epos, esize; /*information about exponent */ - unsigned long bias; /*exponent bias for floating pt.*/ - size_t align; /*required byte alignment */ - size_t comp_align; /*alignment for structure */ + const char *varname; + unsigned int size; /* total byte size */ + unsigned int precision; /* meaningful bits */ + unsigned int offset; /* bit offset to meaningful bits */ + int perm[32]; /* for detection of byte order */ + hbool_t is_vax; /* for vax (float & double) only */ + unsigned int sign; /* location of sign bit */ + unsigned int mpos, msize, imp; /* information about mantissa */ + unsigned int epos, esize; /* information about exponent */ + unsigned long bias; /* exponent bias for floating pt */ + unsigned int align; /* required byte alignment */ + unsigned int comp_align; /* alignment for structure */ } detected_t; /* This structure holds structure alignment for pointers, hvl_t, hobj_ref_t, * hdset_reg_ref_t */ typedef struct malign_t { const char *name; - size_t comp_align; /*alignment for structure */ + unsigned int comp_align; /* alignment for structure */ } malign_t; /* global variables types detection code */ -static detected_t d_g[MAXDETECT]; -static malign_t m_g[MAXDETECT]; -static volatile int nd_g = 0, na_g = 0; +H5_GCC_DIAG_OFF(larger-than=) +static detected_t d_g[MAXDETECT]; +H5_GCC_DIAG_ON(larger-than=) +static malign_t m_g[MAXDETECT]; +static volatile int nd_g = 0, na_g = 0; static void print_results(int nd, detected_t *d, int na, malign_t *m); static void iprint(detected_t *); static int byte_cmp(int, const void *, const void *, const unsigned char *); -static int bit_cmp(int, int *, volatile void *, volatile void *, - const unsigned char *); +static unsigned int bit_cmp(unsigned int, int *, void *, void *, const unsigned char *); static void fix_order(int, int, int *, const char **); -static int imp_bit(int, int *, volatile void *, volatile void *, - const unsigned char *); -static unsigned long find_bias(int, int, int *, volatile void *); +static unsigned int imp_bit(unsigned int, int *, void *, void *, const unsigned char *); +static unsigned int find_bias(unsigned int, unsigned int, int *, void *); static void precision (detected_t*); static void print_header(void); static void detect_C89_integers(void); @@ -136,7 +136,7 @@ static void detect_C99_integers16(void); static void detect_C99_integers32(void); static void detect_C99_integers64(void); static void detect_alignments(void); -static size_t align_g[] = {1, 2, 4, 8, 16}; +static unsigned int align_g[] = {1, 2, 4, 8, 16}; static int align_status_g = 0; /* ALIGNMENT Signal Status */ static int sigbus_handler_called_g = 0; /* how many times called */ static int sigsegv_handler_called_g = 0;/* how many times called */ @@ -167,39 +167,41 @@ static H5JMP_BUF jbuf_g; static void precision (detected_t *d) { - int n; + unsigned int n; - if (0==d->msize) { - /* - * An integer. The permutation can have negative values at the - * beginning or end which represent padding of bytes. We must adjust - * the precision and offset accordingly. - */ - if (d->perm[0] < 0) { - /* - * Lower addresses are padded. - */ - for (n=0; n<d->size && d->perm[n]<0; n++) /*void*/; - d->precision = 8*(d->size-n); - d->offset = 0; - } else if (d->perm[d->size - 1] < 0) { - /* - * Higher addresses are padded. - */ - for (n=0; n<d->size && d->perm[d->size-(n+1)]; n++) /*void*/; - d->precision = 8*(d->size-n); - d->offset = 8*n; - } else { - /* - * No padding. - */ - d->precision = 8*d->size; - d->offset = 0; - } + if (0 == d->msize) { + /* + * An integer. The permutation can have negative values at the + * beginning or end which represent padding of bytes. We must adjust + * the precision and offset accordingly. + */ + if (d->perm[0] < 0) { + /* + * Lower addresses are padded. + */ + for (n = 0; n < d->size && d->perm[n] < 0; n++) + /*void*/; + d->precision = 8 * (d->size - n); + d->offset = 0; + } else if (d->perm[d->size - 1] < 0) { + /* + * Higher addresses are padded. + */ + for (n = 0; n < d->size && d->perm[d->size - (n + 1)]; n++) + /*void*/; + d->precision = 8 * (d->size - n); + d->offset = 8 * n; + } else { + /* + * No padding. + */ + d->precision = 8 * d->size; + d->offset = 0; + } } else { - /* A floating point */ - d->offset = MIN3 (d->mpos, d->epos, d->sign); - d->precision = d->msize + d->esize + 1; + /* A floating point */ + d->offset = MIN3(d->mpos, d->epos, d->sign); + d->precision = d->msize + d->esize + 1; } } @@ -251,7 +253,8 @@ precision (detected_t *d) INFO.size = sizeof(TYPE); \ \ for(_i = sizeof(DETECT_TYPE), _v = 0; _i > 0; --_i) \ - _v = (_v << 8) + _i; \ + _v = (DETECT_TYPE) ((DETECT_TYPE) (_v << 8) + (DETECT_TYPE) _i); \ + \ for(_i = 0, _x = (unsigned char *)&_v; _i < (signed)sizeof(DETECT_TYPE); _i++) { \ _j = (*_x++) - 1; \ HDassert(_j < (signed)sizeof(DETECT_TYPE)); \ @@ -290,9 +293,6 @@ precision (detected_t *d) * absence of implicit mantissa bit, and exponent bias and * initializes a detected_t structure with those properties. * - * Note: 'volatile' is used for the variables below to prevent the - * compiler from optimizing them away. - * * Return: void * * Programmer: Robb Matzke @@ -302,12 +302,12 @@ precision (detected_t *d) *------------------------------------------------------------------------- */ #define DETECT_F(TYPE,VAR,INFO) { \ - volatile TYPE _v1, _v2, _v3; \ + TYPE _v1, _v2, _v3; \ unsigned char _buf1[sizeof(TYPE)], _buf3[sizeof(TYPE)]; \ unsigned char _pad_mask[sizeof(TYPE)]; \ unsigned char _byte_mask; \ int _i, _j, _last = (-1); \ - char *_mesg; \ + const char *_mesg; \ \ HDmemset(&INFO, 0, sizeof(INFO)); \ INFO.varname = #VAR; \ @@ -326,11 +326,13 @@ precision (detected_t *d) _v1 = (TYPE)4.0L; \ HDmemcpy(_buf1, (const void *)&_v1, sizeof(TYPE)); \ for(_i = 0; _i < (int)sizeof(TYPE); _i++) \ - for(_byte_mask = (unsigned char)1; _byte_mask; _byte_mask <<= 1) { \ + for(_byte_mask = (unsigned char)1; _byte_mask; _byte_mask = (unsigned char) (_byte_mask << 1)) { \ _buf1[_i] ^= _byte_mask; \ HDmemcpy((void *)&_v2, (const void *)_buf1, sizeof(TYPE)); \ + H5_GCC_DIAG_OFF(float-equal) \ if(_v1 != _v2) \ _pad_mask[_i] |= _byte_mask; \ + H5_GCC_DIAG_ON(float-equal) \ _buf1[_i] ^= _byte_mask; \ } /* end for */ \ \ @@ -368,7 +370,7 @@ precision (detected_t *d) _v1 = (TYPE)1.0L; \ _v2 = (TYPE)1.5L; \ INFO.msize = bit_cmp (sizeof(TYPE), INFO.perm, &_v1, &_v2, _pad_mask); \ - INFO.msize += 1 + (INFO.imp?0:1) - INFO.mpos; \ + INFO.msize += 1 + (unsigned int) (INFO.imp ? 0 : 1) - INFO.mpos; \ \ /* Exponent */ \ INFO.epos = INFO.mpos + INFO.msize; \ @@ -415,14 +417,13 @@ precision (detected_t *d) TYPE x; \ } s; \ \ - COMP_ALIGN = (size_t)((char*)(&(s.x)) - (char*)(&s)); \ + COMP_ALIGN = (unsigned int)((char*)(&(s.x)) - (char*)(&s)); \ } #if defined(H5SETJMP) && defined(H5_HAVE_SIGNAL) #define ALIGNMENT(TYPE,INFO) { \ - char *volatile _buf = NULL; \ - volatile TYPE _val = 1; \ - volatile TYPE _val2; \ + char *volatile _buf = NULL; \ + TYPE _val = 1, _val2; \ volatile size_t _ano = 0; \ void (*_handler)(int) = HDsignal(SIGBUS, sigbus_handler); \ void (*_handler2)(int) = HDsignal(SIGSEGV, sigsegv_handler);\ @@ -445,8 +446,10 @@ precision (detected_t *d) else /* Little-Endian */ \ HDmemcpy(_buf+align_g[_ano]+(INFO.offset/8),((char *)&_val)+(INFO.offset/8),(size_t)(INFO.precision/8)); \ _val2 = *((TYPE*)(_buf+align_g[_ano])); \ + H5_GCC_DIAG_OFF(float-equal) \ if(_val!=_val2) \ H5LONGJMP(jbuf_g, 1); \ + H5_GCC_DIAG_ON(float-equal) \ /* End Cray Check */ \ (INFO.align)=align_g[_ano]; \ } else { \ @@ -881,63 +884,69 @@ done:\n\ static void iprint(detected_t *d) { - int i, j, k, pass; + unsigned int pass; - for (pass=(d->size-1)/4; pass>=0; --pass) { - /* - * Print the byte ordering above the bit fields. - */ - printf(" * "); - for (i=MIN(pass*4+3,d->size-1); i>=pass*4; --i) { - printf ("%4d", d->perm[i]); - if (i>pass*4) HDfputs (" ", stdout); - } + for (pass = (d->size - 1) / 4; ; --pass) { + unsigned int i, k; + /* + * Print the byte ordering above the bit fields. + */ + printf(" * "); + for (i = MIN(pass * 4 + 3, d->size - 1); i >= pass * 4; --i) { + printf("%4d", d->perm[i]); + if (i > pass * 4) HDfputs(" ", stdout); + if (!i) break; + } - /* - * Print the bit fields - */ - printf("\n * "); - for (i=MIN(pass*4+3,d->size-1), - k=MIN(pass*32+31,8*d->size-1); - i>=pass*4; --i) { - for (j=7; j>=0; --j) { - if (k==d->sign && d->msize) { - HDputchar('S'); - } else if (k>=d->epos && k<d->epos+d->esize) { - HDputchar('E'); - } else if (k>=d->mpos && k<d->mpos+d->msize) { - HDputchar('M'); - } else if (d->msize) { - HDputchar('?'); /*unknown floating point bit */ - } else if (d->sign) { - HDputchar('I'); - } else { - HDputchar('U'); - } - --k; - } - if (i>pass*4) HDputchar(' '); - } - HDputchar('\n'); + /* + * Print the bit fields + */ + printf("\n * "); + for (i = MIN(pass * 4 + 3, d->size - 1), k = MIN(pass * 32 + 31, + 8 * d->size - 1); i >= pass * 4; --i) { + unsigned int j; + + for (j = 8; j > 0; --j) { + if (k == d->sign && d->msize) { + HDputchar('S'); + } else if (k >= d->epos && k < d->epos + d->esize) { + HDputchar('E'); + } else if (k >= d->mpos && k < d->mpos + d->msize) { + HDputchar('M'); + } else if (d->msize) { + HDputchar('?'); /*unknown floating point bit */ + } else if (d->sign) { + HDputchar('I'); + } else { + HDputchar('U'); + } + --k; + } + if (i > pass * 4) HDputchar(' '); + if (!i) break; + } + HDputchar('\n'); + if (!pass) break; } /* * Is there an implicit bit in the mantissa. */ if (d->msize) { - printf(" * Implicit bit? %s\n", d->imp ? "yes" : "no"); + printf(" * Implicit bit? %s\n", d->imp ? "yes" : "no"); } /* * Alignment */ - if (0==d->align) { - printf(" * Alignment: NOT CALCULATED\n"); - } else if (1==d->align) { - printf(" * Alignment: none\n"); + if (0 == d->align) { + printf(" * Alignment: NOT CALCULATED\n"); + } else if (1 == d->align) { + printf(" * Alignment: none\n"); } else { - printf(" * Alignment: %lu\n", (unsigned long)(d->align)); + printf(" * Alignment: %lu\n", (unsigned long) (d->align)); } + } @@ -985,31 +994,25 @@ byte_cmp(int n, const void *_a, const void *_b, const unsigned char *pad_mask) * actual order to little endian. Ignores differences where * the corresponding bit in pad_mask is set to 0. * - * Return: Success: Index of first differing bit. - * - * Failure: -1 - * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Jun 13, 1996 - * - * Modifications: + * Return: Index of first differing bit. * *------------------------------------------------------------------------- */ -static int -bit_cmp(int nbytes, int *perm, volatile void *_a, volatile void *_b, - const unsigned char *pad_mask) +static unsigned int +bit_cmp(unsigned int nbytes, int *perm, void *_a, void *_b, + const unsigned char *pad_mask) { - int i, j; - volatile unsigned char *a = (volatile unsigned char *) _a; - volatile unsigned char *b = (volatile unsigned char *) _b; - unsigned char aa, bb; + unsigned int i; + unsigned char *a = (unsigned char *) _a; + unsigned char *b = (unsigned char *) _b; + unsigned char aa, bb; for (i = 0; i < nbytes; i++) { - HDassert(perm[i] < nbytes); - if ((aa = a[perm[i]] & pad_mask[perm[i]]) - != (bb = b[perm[i]] & pad_mask[perm[i]])) { + HDassert(perm[i] < (int) nbytes); + if ((aa = (unsigned char) (a[perm[i]] & pad_mask[perm[i]])) + != (bb = (unsigned char) (b[perm[i]] & pad_mask[perm[i]]))) { + unsigned int j; + for (j = 0; j < 8; j++, aa >>= 1, bb >>= 1) { if ((aa & 1) != (bb & 1)) return i * 8 + j; } @@ -1017,7 +1020,9 @@ bit_cmp(int nbytes, int *perm, volatile void *_a, volatile void *_b, HDabort(); } } - return -1; + fprintf(stderr, "INTERNAL ERROR"); + HDabort(); + return 0; } @@ -1123,21 +1128,19 @@ fix_order(int n, int last, int *perm, const char **mesg) * *------------------------------------------------------------------------- */ -static int -imp_bit(int n, int *perm, volatile void *_a, volatile void *_b, - const unsigned char *pad_mask) +static unsigned int +imp_bit(unsigned int n, int *perm, void *_a, void *_b, const unsigned char *pad_mask) { - volatile unsigned char *a = (volatile unsigned char *) _a; - volatile unsigned char *b = (volatile unsigned char *) _b; - int changed, major, minor; - int msmb; /*most significant mantissa bit */ + unsigned char *a = (unsigned char *) _a; + unsigned char *b = (unsigned char *) _b; + unsigned int changed, major, minor; + unsigned int msmb; /* most significant mantissa bit */ /* * Look for the least significant bit that has changed between * A and B. This is the least significant bit of the exponent. */ changed = bit_cmp(n, perm, a, b, pad_mask); - HDassert(changed >= 0); /* * The bit to the right (less significant) of the changed bit should @@ -1174,22 +1177,22 @@ imp_bit(int n, int *perm, volatile void *_a, volatile void *_b, * *------------------------------------------------------------------------- */ -static unsigned long -find_bias(int epos, int esize, int *perm, volatile void *_a) +static unsigned int +find_bias(unsigned int epos, unsigned int esize, int *perm, void *_a) { - unsigned char *a = (unsigned char *) _a; - unsigned char mask; - unsigned long b, shift = 0, nbits, bias = 0; + unsigned char *a = (unsigned char *) _a; + unsigned char mask; + unsigned int b, shift = 0, nbits, bias = 0; while (esize > 0) { - nbits = MIN(esize, (8 - epos % 8)); - mask = (1 << nbits) - 1; - b = (a[perm[epos / 8]] >> (epos % 8)) & mask; - bias |= b << shift; - - shift += nbits; - esize -= nbits; - epos += nbits; + nbits = MIN(esize, (8 - epos % 8)); + mask = (unsigned char) ((1 << nbits) - 1); + b = (unsigned int) (a[perm[epos / 8]] >> (epos % 8)) & mask; + bias |= b << shift; + + shift += nbits; + esize -= nbits; + epos += nbits; } return bias; } @@ -1667,7 +1670,7 @@ detect_alignments(void) static int verify_signal_handlers(int signum, void (*handler)(int)) { void (*save_handler)(int) = HDsignal(signum, handler); - int i, val; + volatile int i, val; int ntries=5; volatile int nfailures=0; volatile int nsuccesses=0; |