summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-01-31 15:28:40 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-01-31 15:28:40 (GMT)
commit6cf56ca817ccba7b8c956cffee208ec624921b12 (patch)
treee30ab953bdfc4d332ea6c0af192f8ae4893931b3
parenteb4cc0556c390deaa9f21710d95f5690932221d9 (diff)
downloadhdf5-6cf56ca817ccba7b8c956cffee208ec624921b12.zip
hdf5-6cf56ca817ccba7b8c956cffee208ec624921b12.tar.gz
hdf5-6cf56ca817ccba7b8c956cffee208ec624921b12.tar.bz2
[svn-r8136] Purpose:
Optimization Description: Speed up various parts of the library by setting a global variable for the endianness of the machine at library startup and use that variable instead of repeatedly querying the endianness of the native int datatype. Platforms tested: IBM p690 (copper) too minor to require h5committest
-rw-r--r--src/H5T.c15
-rw-r--r--src/H5Tbit.c4
-rw-r--r--src/H5Tconv.c8
-rw-r--r--src/H5Tpkg.h3
-rw-r--r--src/H5detect.c15
5 files changed, 29 insertions, 16 deletions
diff --git a/src/H5T.c b/src/H5T.c
index 6f670b0..f10752d 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -241,6 +241,9 @@ static struct {
H5T_soft_t *soft; /*unsorted array of soft conversions */
} H5T_g;
+/* The native endianess of the platform */
+H5T_order_t H5T_native_order_g = H5T_ORDER_ERROR;
+
/* The overflow handler */
H5T_overflow_t H5T_overflow_g = NULL;
@@ -514,7 +517,7 @@ H5T_init_inf(void)
dst = &dst_p->u.atomic;
/* Check that we can re-order the bytes correctly */
- if (H5T_ORDER_LE!=dst->order && H5T_ORDER_BE!=dst->order)
+ if (H5T_ORDER_LE!=H5T_native_order_g && H5T_ORDER_BE!=H5T_native_order_g)
HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
/* +Inf */
@@ -524,7 +527,7 @@ H5T_init_inf(void)
H5T_bit_set (d, dst->u.f.mpos, dst->u.f.msize, FALSE);
/* Swap the bytes if the machine architecture is big-endian */
- if (H5T_ORDER_BE==dst->order) {
+ if (H5T_ORDER_BE==H5T_native_order_g) {
half_size = dst_p->size/2;
for (u=0; u<half_size; u++) {
uint8_t tmp = d[dst_p->size-(u+1)];
@@ -540,7 +543,7 @@ H5T_init_inf(void)
H5T_bit_set (d, dst->u.f.mpos, dst->u.f.msize, FALSE);
/* Swap the bytes if the machine architecture is big-endian */
- if (H5T_ORDER_BE==dst->order) {
+ if (H5T_ORDER_BE==H5T_native_order_g) {
half_size = dst_p->size/2;
for (u=0; u<half_size; u++) {
uint8_t tmp = d[dst_p->size-(u+1)];
@@ -555,7 +558,7 @@ H5T_init_inf(void)
dst = &dst_p->u.atomic;
/* Check that we can re-order the bytes correctly */
- if (H5T_ORDER_LE!=dst->order && H5T_ORDER_BE!=dst->order)
+ if (H5T_ORDER_LE!=H5T_native_order_g && H5T_ORDER_BE!=H5T_native_order_g)
HGOTO_ERROR (H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order");
/* +Inf */
@@ -565,7 +568,7 @@ H5T_init_inf(void)
H5T_bit_set (d, dst->u.f.mpos, dst->u.f.msize, FALSE);
/* Swap the bytes if the machine architecture is big-endian */
- if (H5T_ORDER_BE==dst->order) {
+ if (H5T_ORDER_BE==H5T_native_order_g) {
half_size = dst_p->size/2;
for (u=0; u<half_size; u++) {
uint8_t tmp = d[dst_p->size-(u+1)];
@@ -581,7 +584,7 @@ H5T_init_inf(void)
H5T_bit_set (d, dst->u.f.mpos, dst->u.f.msize, FALSE);
/* Swap the bytes if the machine architecture is big-endian */
- if (H5T_ORDER_BE==dst->order) {
+ if (H5T_ORDER_BE==H5T_native_order_g) {
half_size = dst_p->size/2;
for (u=0; u<half_size; u++) {
uint8_t tmp = d[dst_p->size-(u+1)];
diff --git a/src/H5Tbit.c b/src/H5Tbit.c
index f6e36c7..157da5d 100644
--- a/src/H5Tbit.c
+++ b/src/H5Tbit.c
@@ -189,7 +189,7 @@ H5T_bit_get_d (uint8_t *buf, size_t offset, size_t size)
assert (8*sizeof(val)>=size);
H5T_bit_copy ((uint8_t*)&val, 0, buf, offset, size);
- switch (((H5T_t*)(H5I_object(H5T_NATIVE_INT_g)))->u.atomic.order) {
+ switch (H5T_native_order_g) {
case H5T_ORDER_LE:
break;
@@ -234,7 +234,7 @@ H5T_bit_set_d (uint8_t *buf, size_t offset, size_t size, hsize_t val)
assert (8*sizeof(val)>=size);
- switch (((H5T_t*)(H5I_object(H5T_NATIVE_INT_g)))->u.atomic.order) {
+ switch (H5T_native_order_g) {
case H5T_ORDER_LE:
break;
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index 7c7b505..862c19a 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -683,15 +683,9 @@ H5T_conv_order_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
/* Check for "no op" reference conversion */
if(src->type==H5T_REFERENCE) {
- H5T_t *native_int; /* Native integer datatype */
-
/* Sanity check */
assert(dst->type==H5T_REFERENCE);
- /* Get pointer to native integer type */
- if (NULL==(native_int=H5I_object(H5T_NATIVE_INT_g)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype object");
-
/* Check if we are on a little-endian machine (the order that
* the addresses in the file must be) and just get out now, there
* is no need to convert the object reference. Yes, this is
@@ -701,7 +695,7 @@ H5T_conv_order_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
* "native" hobj_ref_t datatype and I think that would break a
* lot of existing programs. -QAK
*/
- if(native_int->u.atomic.order == H5T_ORDER_LE)
+ if(H5T_native_order_g == H5T_ORDER_LE)
break;
} /* end if */
diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h
index d87cc2f..a01d995 100644
--- a/src/H5Tpkg.h
+++ b/src/H5Tpkg.h
@@ -232,6 +232,9 @@ typedef enum H5T_sdir_t {
H5T_BIT_MSB /*search msb toward lsb */
} H5T_sdir_t;
+/* The native endianess of the platform */
+H5_DLLVAR H5T_order_t H5T_native_order_g;
+
/* The overflow handler */
H5_DLLVAR H5T_overflow_t H5T_overflow_g;
diff --git a/src/H5detect.c b/src/H5detect.c
index 670aed1..f3a5588 100644
--- a/src/H5detect.c
+++ b/src/H5detect.c
@@ -479,7 +479,7 @@ sigbus_handler(int UNUSED signo)
static void
print_results(int nd, detected_t *d, int na, malign_t *misc_align)
{
-
+ int byte_order;
int i, j;
/* Include files */
@@ -523,6 +523,18 @@ H5TN_init_interface(void)\n\
\n\
FUNC_ENTER_NOAPI(H5TN_init_interface, FAIL);\n");
+ /* The native endianess of this machine */
+ /* (Use the byte-order of a reasonably large type) */
+ for (i = 0; i < nd; i++)
+ if(d[i].size>1) {
+ byte_order=d[i].perm[0];
+ break;
+ } /* end if */
+ printf("\n\
+ /* Set the native order for this machine */\n\
+ H5T_native_order_g = H5T_ORDER_%s;\n",
+ byte_order ? "BE" : "LE"); /*byte order */
+
for (i = 0; i < nd; i++) {
/* Print a comment to describe this section of definitions. */
@@ -548,6 +560,7 @@ H5TN_init_interface(void)\n\
d[i].perm[0] ? "BE" : "LE", /*byte order */
d[i].offset, /*offset */
d[i].precision); /*precision */
+ assert(d[i].size<2 || (d[i].perm[0]>0)==(byte_order>0)); /* Double-check that byte-order doesn't change */
if (0 == d[i].msize) {
/* The part unique to fixed point types */