[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
This commit is contained in:
Quincey Koziol 2004-01-31 10:28:40 -05:00
parent eb4cc0556c
commit 6cf56ca817
5 changed files with 29 additions and 16 deletions

View File

@ -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)];

View File

@ -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;

View File

@ -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 */

View File

@ -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;

View File

@ -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 */