summaryrefslogtreecommitdiffstats
path: root/src/H5detect.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-12-14 16:19:21 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-12-14 16:19:21 (GMT)
commit28e684b0af6f181b2a1acc662d6ed2cc67ca97fb (patch)
treea5d6954568d8cca7a313dbb92c623a1cf9ec88eb /src/H5detect.c
parent16b789409def33adf5a64ba0adaeaf6204a20dad (diff)
downloadhdf5-28e684b0af6f181b2a1acc662d6ed2cc67ca97fb.zip
hdf5-28e684b0af6f181b2a1acc662d6ed2cc67ca97fb.tar.gz
hdf5-28e684b0af6f181b2a1acc662d6ed2cc67ca97fb.tar.bz2
[svn-r968] Changes since 19981207
---------------------- ./MANIFEST Added tcompound2.{dmp,h5} and tdset2.{dmp,h5} used by the h5toh4 testing. ./configure.in ./configure [REGENERATED] ./src/H5config.h.in [REGENERATED] Added check for <sys/timeb.h> for Win32. Determines sizeof(char) just so we have a complete list of type sizes defined as preprocessor symbols. ./src/H5detect.c ./src/H5T.c ./src/H5Tpkg.h Detects alignment constraints. In order for this to work the operating system must not correct unaligned data (for instance, on the DEC Alpha one might need to say `uac p sigbus' before running H5detect). ./src/H5private.h Includes <signal.h> because it's needed by H5detect.c to detect alignment constraints. ./src/H5Tconv.c Added extra checks to all hardware conversion functions so they align data when necessary before the conversion. This slows down the conversions somewhat but they're still much faster than the software conversions. ./test/dtypes.c By setting a constant at the top of the source you can test conversions where the data is aligned on various byte boundaries. By setting a constant at the top of the source you can simulate architectures that have alignment constraints on architectures that don't. Changed typo SIZEOF_LDOUBLE to SIZEOF_LONG_DOUBLE in a few places.
Diffstat (limited to 'src/H5detect.c')
-rw-r--r--src/H5detect.c167
1 files changed, 62 insertions, 105 deletions
diff --git a/src/H5detect.c b/src/H5detect.c
index bf97452..ae1ecb2 100644
--- a/src/H5detect.c
+++ b/src/H5detect.c
@@ -39,19 +39,19 @@ static const char *FileHeader = "\n\
*/
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];
- int sign;
- int mpos, msize, imp;
- int epos, esize;
- unsigned long bias;
+ int size; /*total byte size */
+ int precision; /*meaningful bits */
+ int offset; /*bit offset to meaningful bits */
+ int perm[32]; /*byte order */
+ 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 */
} detected_t;
static void print_results(int nd, detected_t *d);
static void iprint(detected_t *);
-static void print_known_formats(detected_t *);
static int byte_cmp(int, void *, void *);
static int bit_cmp(int, int *, void *, void *);
static void fix_order(int, int, int, int *, const char **);
@@ -59,6 +59,7 @@ static int imp_bit(int, int *, void *, void *);
static unsigned long find_bias(int, int, int *, void *);
static void precision (detected_t*);
static void print_header(void);
+static size_t align_g[] = {1, 2, 4, 8, 16};
/*-------------------------------------------------------------------------
@@ -114,58 +115,7 @@ precision (detected_t *d)
}
}
-
-/*-------------------------------------------------------------------------
- * For convenience, we place here in a table descriptions of all
- * architectures we've seen so far. That way we can print a description
- * of the system on which the program is run. We place the system name
- * in the VARNAME field.
- *-------------------------------------------------------------------------
- */
-#define LE {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \
- 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}
-#define LE_1 LE
-#define LE_2 LE
-#define LE_4 LE
-#define LE_8 LE
-
-#define BE_1 {0}
-#define BE_2 {1,0}
-#define BE_4 {3,2,1,0}
-#define BE_8 {7,6,5,4,3,2,1,0}
-#define INTEGER 0,0,0,0,0,0,0
-
-static detected_t Known[] =
-{
- /* Single-byte quantities */
- {"Byte addressable",
- 1, 8, 0, LE_1, INTEGER},
-
- /* Little-endian integer */
- {"Little-endian",
- 2, 16, 0, LE_2, INTEGER},
- {"Little-endian",
- 4, 32, 0, LE_4, INTEGER},
-
- /* Big-endian integer */
- {"Big-endian",
- 2, 16, 0, BE_2, INTEGER},
- {"Big-endian",
- 4, 32, 0, BE_4, INTEGER},
-
- /* Little-endian IEEE floating-point */
- {"Little-endian IEEE",
- 4, 32, 0, LE_4, 31, 0, 23, 1, 23, 8, 127},
- {"Little-endian IEEE",
- 8, 64, 0, LE_8, 63, 0, 52, 1, 52, 11, 1023},
-
- /* Big-endian IEEE floating-point */
- {"Big-endian IEEE",
- 4, 32, 0, BE_4, 31, 0, 23, 1, 23, 8, 127},
- {"Big-endian IEEE",
- 8, 64, 0, BE_8, 63, 0, 52, 1, 52, 11, 1023},
-};
/*-------------------------------------------------------------------------
* Function: DETECT_I
@@ -210,6 +160,7 @@ static detected_t Known[] =
INFO.perm[_i] = _j; \
} \
INFO.sign = ('U'!=*(#VAR)); \
+ ALIGNMENT(TYPE, INFO.align); \
precision (&(INFO)); \
}
@@ -286,8 +237,47 @@ static detected_t Known[] =
\
_v1 = 1.0; \
INFO.bias = find_bias (INFO.epos, INFO.esize, INFO.perm, &_v1); \
+ ALIGNMENT(TYPE, INFO.align); \
precision (&(INFO)); \
}
+
+#define ALIGNMENT(TYPE,ALIGN) { \
+ char *_buf=malloc(sizeof(TYPE)+align_g[NELMTS(align_g)-1]); \
+ TYPE _val=0; \
+ size_t _ano; \
+ pid_t _child; \
+ int _status; \
+ \
+ for (_ano=0; _ano<NELMTS(align_g); _ano++) { \
+ fflush(stdout); \
+ fflush(stderr); \
+ if (0==(_child=fork())) { \
+ _val = *((TYPE*)(_buf+align_g[_ano])); \
+ exit(0); \
+ } else if (_child<0) { \
+ perror("fork"); \
+ exit(1); \
+ } \
+ if (waitpid(_child, &_status, 0)<0) { \
+ perror("waitpid"); \
+ exit(1); \
+ } \
+ if (WIFEXITED(_status) && 0==WEXITSTATUS(_status)) { \
+ ALIGN=align_g[_ano]; \
+ break; \
+ } \
+ if (WIFSIGNALED(_status) && SIGBUS==WTERMSIG(_status)) { \
+ continue; \
+ } \
+ _ano=NELMTS(align_g); \
+ break; \
+ } \
+ if (_ano>=NELMTS(align_g)) { \
+ ALIGN=0; \
+ fprintf(stderr, "unable to calculate alignment for %s\n", #TYPE); \
+ } \
+}
+
/*-------------------------------------------------------------------------
* Function: print_results
@@ -346,8 +336,7 @@ H5T_native_open (void)\n\
/* Print a comment to describe this section of definitions. */
printf("\n /*\n");
- iprint(d + i);
- print_known_formats(d + i);
+ iprint(d+i);
printf(" */\n");
/* The part common to fixed and floating types */
@@ -404,6 +393,8 @@ H5T_native_open (void)\n\
\"failure\");\n\
}\n",
d[i].varname);
+ printf(" H5T_NATIVE_%s_ALIGN_g = %lu;\n",
+ d[i].varname, (unsigned long)(d[i].align));
}
printf(" FUNC_LEAVE (SUCCEED);\n}\n");
@@ -475,50 +466,16 @@ iprint(detected_t *d)
if (d->msize) {
printf(" * Implicit bit? %s\n", d->imp ? "yes" : "no");
}
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: print_known_formats
- *
- * Purpose: Prints archetecture names for the specified format
- * description, if any.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * matzke@llnl.gov
- * Jun 13, 1996
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-print_known_formats(detected_t *d)
-{
-
- int i, j, diff;
- int n = sizeof(Known) / sizeof(Known[0]);
-
- for (i=0; i<n; i++) {
- if (d->size != Known[i].size) continue;
- if (d->precision != Known[i].precision) continue;
- if (d->offset != Known[i].offset) continue;
- for (j = diff = 0; !diff && j < d->size; j++) {
- if (d->perm[j] != Known[i].perm[j]) diff = 1;
- }
- if (diff) continue;
- /* if (d->sign != Known[i].sign) continue; */
- if (d->mpos != Known[i].mpos) continue;
- if (d->msize != Known[i].msize) continue;
- if (d->imp != Known[i].imp) continue;
- if (d->epos != Known[i].epos) continue;
- if (d->esize != Known[i].esize) continue;
- if (d->bias != Known[i].bias) continue;
-
- printf(" * %s\n", Known[i].varname);
+ /*
+ * Alignment
+ */
+ if (0==d->align) {
+ printf(" * Alignment: NOT CALCULATED\n");
+ } else if (1==d->align) {
+ printf(" * Alignment: none\n");
+ } else {
+ printf(" * Alignemtn: %lu\n", (unsigned long)(d->align));
}
}