From 4f3d64fd3d539fbe2cc80a5bbe872c7f6970b1b2 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Thu, 10 Mar 2005 16:49:28 -0500 Subject: [svn-r10180] Purpose: New way to do conversion test from floating-point to integer. Description: This is the 3rd step of change conversion test. This checkin is only for conversion from floating-point to integer. Solution: The source buffer is filled in with normalized and denormalized floating-point values. For the normalized values, it starts from FLT(DBL, or LDBL)_MIN, multiplied by 10(10000 for double, 100000000 for long double) for the next value, until reaches to FLT_MAX. For denormalized values, the exponent part is always 0. Mantissa part starts with 000...001, 000...011, 000...111, until reaches to 111...111. The same is with negative values. Platforms tested: h5committest and fuss. --- test/dtypes.c | 193 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 143 insertions(+), 50 deletions(-) diff --git a/test/dtypes.c b/test/dtypes.c index 77a0446..d984105 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -118,7 +118,7 @@ static int num_opaque_conversions_g = 0; #define aligned_malloc(Z) ((void*)((char*)HDmalloc(ALIGNMENT+Z)+ALIGNMENT)) #define aligned_free(M) HDfree((char*)(M)-ALIGNMENT) -/* Initialize source buffer of integer for integer->integer conversion test. +/* Initialize source buffer of integer for integer->integer and integer->floating-point conversion test. * This algorithm is mainly to avoid any casting and comparison between source and destination types * for compiler, because we're testing conversions. */ #define INIT_INTEGER(TYPE, SRC_MAX, SRC_MIN, SRC_SIZE, DST_SIZE, SRC_PREC, BUF, SAVED, NELMTS) \ @@ -169,6 +169,129 @@ static int num_opaque_conversions_g = 0; } \ } +/* Change a buffer's byte order from big endian to little endian. It's mainly for library's + * bit operations which handle only little endian order. + */ +#define CHANGE_ORDER(EBUF, EORDER, ESIZE) \ +{ \ + if (H5T_ORDER_BE==EORDER) { \ + int m; \ + unsigned char mediator; \ + size_t half_size = ESIZE/2; \ + for (m=0; m=100 && SRC_MAX_10_EXP<400) { /*for double*/ \ + factor = 2; \ + multiply = 10000; \ + } else { /*for long double*/ \ + factor = 3; \ + multiply = 100000000; \ + } \ + \ + /*The number of values if multiplied by 10 for each step.*/ \ + num_norm = (SRC_MAX_10_EXP - SRC_MIN_10_EXP); \ + /*Reduce the number of values by 2^factor. MULTIPLY=10^(2^factor). Using this algorithm \ + *instead of arithmatic operation to avoid any conversion*/ \ + num_norm >>= factor; \ + \ + /*Total number of values*/ \ + NELMTS = 2 * /*both positive and negative*/ \ + (num_norm + /*number of normalized values*/ \ + 1 + /*maximal normalized value*/ \ + SRC_MANT_DIG - 1); /*number of denormalized values*/ \ + \ + /* Allocate buffers */ \ + BUF = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE)); \ + SAVED = (unsigned char*)aligned_malloc(NELMTS*MAX(SRC_SIZE, DST_SIZE)); \ + tmp1 = (unsigned char*)malloc(SRC_SIZE); \ + tmp2 = (unsigned char*)malloc(SRC_SIZE); \ + \ + buf_p = BUF; \ + saved_p = SAVED; \ + \ + /*Normalized values*/ \ + value1 = SRC_MIN; \ + value2 = -SRC_MIN; \ + for(n=0; n-SRC_MAX) { /*negative*/ \ + memcpy(buf_p, &value2, SRC_SIZE); \ + memcpy(saved_p, &value2, SRC_SIZE); \ + value2 *= multiply; \ + buf_p += SRC_SIZE; \ + saved_p += SRC_SIZE; \ + } \ + } \ + \ + value1 = SRC_MAX; /*maximal value*/ \ + memcpy(buf_p, &value1, SRC_SIZE); \ + memcpy(saved_p, &value1, SRC_SIZE); \ + buf_p += SRC_SIZE; \ + saved_p += SRC_SIZE; \ + \ + value2 = -SRC_MAX; /*negative value*/ \ + memcpy(buf_p, &value2, SRC_SIZE); \ + memcpy(saved_p, &value2, SRC_SIZE); \ + buf_p += SRC_SIZE; \ + saved_p += SRC_SIZE; \ + \ + /*Denormalized values. Exponent is 0. Let mantissa starts from 00000001, 00000011, \ + *00000111,..., until 11111111.*/ \ + memset(tmp1, 0, SRC_SIZE); \ + memset(tmp2, 0, SRC_SIZE); \ + H5T_bit_set (tmp2, SRC_PREC-1, 1, TRUE); /*the negative value*/ \ + for(n=0; n