summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-04-27 00:37:04 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-04-27 00:37:04 (GMT)
commit5e7595c546160dada7537287b724177ff24041d2 (patch)
treef6193bb01b0f7c0a8fdcfc76c4df8d3210ac7f3f
parent79a3ae8b6a2a773ec0260ce1554e6ecbaa21c948 (diff)
downloadhdf5-5e7595c546160dada7537287b724177ff24041d2.zip
hdf5-5e7595c546160dada7537287b724177ff24041d2.tar.gz
hdf5-5e7595c546160dada7537287b724177ff24041d2.tar.bz2
[svn-r18630] Description:
Fix remaining aliasing problems and enable optimizations w/gcc now. This addresses the remaining issues for Bug#1398. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.3 (amazon) in debug mode Mac OS X/32 10.6.3 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
-rw-r--r--config/gnu-flags20
-rw-r--r--src/H5Zscaleoffset.c753
2 files changed, 422 insertions, 351 deletions
diff --git a/config/gnu-flags b/config/gnu-flags
index 427b839..96db51d 100644
--- a/config/gnu-flags
+++ b/config/gnu-flags
@@ -147,23 +147,11 @@ case "$cc_vendor-$cc_version" in
gcc-2.95.[34])
PROD_CFLAGS="-O3"
;;
- gcc-4.[345]*)
- # The optimization level is reduced for gcc 4.[345] due to problems
- # with code generation for src/H5Tconv.c with the -O (same -O1)
- # optimization levels (which shows up as failures for long double
- # types -> signed char conversion in the test/dt_arith test).
- # There's either a bug in gcc or our code. Need further investigation.
- # Turn off all optimizations to allow the tests to pass for now.
- # - AKC - 2009/04/19
- PROD_CFLAGS="-O0"
+ gcc-3.*)
+ PROD_CFLAGS="-O3"
;;
- gcc-3.[0-4]*|gcc-4.[012]*)
- # The optimization level is reduced for gcc 3.* and 4.* due to problems
- # with code generation for src/H5Tconv.c with the -O2 & -O3
- # optimization levels (which shows up as failures for various integer
- # types -> long long conversions in the test/dtypes test). Perhaps
- # later versions of gcc will fix this bug... - QAK - 2003/10/20
- PROD_CFLAGS="-O"
+ gcc-4.*)
+ PROD_CFLAGS="-O3"
;;
*)
PROD_CFLAGS="-O"
diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c
index 5927713..5737702 100644
--- a/src/H5Zscaleoffset.c
+++ b/src/H5Zscaleoffset.c
@@ -35,17 +35,17 @@ typedef struct {
unsigned mem_order; /* current memory endianness order */
} parms_atomic;
-enum H5Z_scaleoffset_type {t_bad=0, t_uchar=1, t_ushort, t_uint, t_ulong, t_ulong_long,
+enum H5Z_scaleoffset_t {t_bad=0, t_uchar=1, t_ushort, t_uint, t_ulong, t_ulong_long,
t_schar, t_short, t_int, t_long, t_long_long,
t_float, t_double};
/* Local function prototypes */
static double H5Z_scaleoffset_rnd(double val);
static herr_t H5Z_can_apply_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id);
-static enum H5Z_scaleoffset_type H5Z_scaleoffset_get_type(unsigned dtype_class,
+static enum H5Z_scaleoffset_t H5Z_scaleoffset_get_type(unsigned dtype_class,
unsigned dtype_size, unsigned dtype_sign);
static herr_t H5Z_scaleoffset_set_parms_fillval(H5P_genplist_t *dcpl_plist,
- const H5T_t *type, enum H5Z_scaleoffset_type scale_type, unsigned cd_values[],
+ const H5T_t *type, enum H5Z_scaleoffset_t scale_type, unsigned cd_values[],
int need_convert, hid_t dxpl_id);
static herr_t H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id);
static size_t H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts,
@@ -53,32 +53,32 @@ static size_t H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts,
static void H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size);
static unsigned H5Z_scaleoffset_log2(unsigned long long num);
static void H5Z_scaleoffset_precompress_i(void *data, unsigned d_nelmts,
- enum H5Z_scaleoffset_type type, unsigned filavail, const void *filval_buf,
+ enum H5Z_scaleoffset_t type, unsigned filavail, const void *filval_buf,
uint32_t *minbits, unsigned long long *minval);
static void H5Z_scaleoffset_postdecompress_i(void *data, unsigned d_nelmts,
- enum H5Z_scaleoffset_type type, unsigned filavail, const void *filval_buf,
+ enum H5Z_scaleoffset_t type, unsigned filavail, const void *filval_buf,
uint32_t minbits, unsigned long long minval);
static herr_t H5Z_scaleoffset_precompress_fd(void *data, unsigned d_nelmts,
- enum H5Z_scaleoffset_type type, unsigned filavail, const void *filval_buf,
+ enum H5Z_scaleoffset_t type, unsigned filavail, const void *filval_buf,
uint32_t *minbits, unsigned long long *minval, double D_val);
static herr_t H5Z_scaleoffset_postdecompress_fd(void *data, unsigned d_nelmts,
- enum H5Z_scaleoffset_type type, unsigned filavail, const void *filval_buf,
+ enum H5Z_scaleoffset_t type, unsigned filavail, const void *filval_buf,
uint32_t minbits, unsigned long long minval, double D_val);
-static void H5Z_scaleoffset_next_byte(size_t *j, int *buf_len);
+static void H5Z_scaleoffset_next_byte(size_t *j, unsigned *buf_len);
static void H5Z_scaleoffset_decompress_one_byte(unsigned char *data, size_t data_offset,
- int k, int begin_i, unsigned char *buffer, size_t *j, int *buf_len,
- parms_atomic p, int dtype_len);
+ unsigned k, unsigned begin_i, unsigned char *buffer, size_t *j, unsigned *buf_len,
+ parms_atomic p, unsigned dtype_len);
static void H5Z_scaleoffset_compress_one_byte(unsigned char *data, size_t data_offset,
- int k, int begin_i, unsigned char *buffer, size_t *j, int *buf_len,
- parms_atomic p, int dtype_len);
+ unsigned k, unsigned begin_i, unsigned char *buffer, size_t *j, unsigned *buf_len,
+ parms_atomic p, unsigned dtype_len);
static void H5Z_scaleoffset_decompress_one_atomic(unsigned char *data, size_t data_offset,
- unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p);
+ unsigned char *buffer, size_t *j, unsigned *buf_len, parms_atomic p);
static void H5Z_scaleoffset_compress_one_atomic(unsigned char *data, size_t data_offset,
- unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p);
+ unsigned char *buffer, size_t *j, unsigned *buf_len, parms_atomic p);
static void H5Z_scaleoffset_decompress(unsigned char *data, unsigned d_nelmts,
- unsigned char *buffer, parms_atomic p);
+ unsigned char *buffer, parms_atomic p);
static void H5Z_scaleoffset_compress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer,
- size_t buffer_size, parms_atomic p);
+ size_t buffer_size, parms_atomic p);
/* This message derives from H5Z */
H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
@@ -119,15 +119,25 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
/* Store fill value in cd_values[] */
#define H5Z_scaleoffset_save_filval(type, cd_values, fill_val) \
{ \
- unsigned i; /* index */ \
+ unsigned char *fill_parm; /* Pointer to fill value parameter */ \
\
/* Store the fill value as the last entry in cd_values[] \
* Store byte by byte from least significant byte to most significant byte \
* Plenty of space left for the fill value (from index 8 to 19) \
*/ \
- for(i = 0; i < sizeof(type); i++) \
- ((unsigned char *)&cd_values[H5Z_SCALEOFFSET_PARM_FILVAL])[i] = \
- (unsigned char)((fill_val & ((type)0xff << i * 8)) >> i * 8); \
+ fill_parm = (unsigned char *)&cd_values[H5Z_SCALEOFFSET_PARM_FILVAL]; \
+ if(H5T_native_order_g == H5T_ORDER_LE) \
+ HDmemcpy(fill_parm, &fill_val, sizeof(type)); \
+ else { \
+ unsigned char *fill_buf; /* Pointer to fill value in memory */ \
+ unsigned u; /* index */ \
+ \
+ HDassert(H5T_native_order_g == H5T_ORDER_BE); \
+ \
+ fill_buf = (unsigned char *)&fill_val; \
+ for(u = 0; u < sizeof(type); u++) \
+ fill_parm[u] = fill_buf[sizeof(type) - (u + 1)]; \
+ } /* end else */ \
}
/* Set the fill value parameter in cd_values[] for unsigned integer type */
@@ -170,57 +180,54 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get fill value") \
\
/* Store the fill value as the last entry in cd_values[] */ \
- ((unsigned char *)&cd_values[H5Z_SCALEOFFSET_PARM_FILVAL])[0] = fill_val; \
+ ((unsigned char *)&cd_values[H5Z_SCALEOFFSET_PARM_FILVAL])[0] = (unsigned char)fill_val; \
}
/* Set the fill value parameter in cd_values[] for floating-point type */
#define H5Z_scaleoffset_set_filval_4(type, dcpl_plist, dt, cd_values, need_convert, dxpl_id)\
-{ \
- type fill_val; \
- \
- /* Get dataset fill value */ \
- if(H5P_get_fill_value(dcpl_plist, dt, &fill_val, dxpl_id) < 0) \
- HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get fill value") \
- \
- if(need_convert) \
- H5Z_scaleoffset_convert(&fill_val, 1, sizeof(type)); \
- \
- if(sizeof(type) == sizeof(int)) \
- H5Z_scaleoffset_save_filval(unsigned int, cd_values, *(int *)&fill_val) \
- else if(sizeof(type) == sizeof(long)) \
- H5Z_scaleoffset_save_filval(unsigned long, cd_values, *(long *)&fill_val) \
- else if(sizeof(type) == sizeof(long long)) \
- H5Z_scaleoffset_save_filval(unsigned long long, cd_values, *(long long *)&fill_val)\
- else \
- HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\
+{ \
+ type fill_val; \
+ \
+ /* Get dataset fill value */ \
+ if(H5P_get_fill_value(dcpl_plist, dt, &fill_val, dxpl_id) < 0) \
+ HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "unable to get fill value") \
+ \
+ if(need_convert) \
+ H5Z_scaleoffset_convert(&fill_val, 1, sizeof(type)); \
+ \
+ H5Z_scaleoffset_save_filval(type, cd_values, fill_val) \
}
/* Get the fill value for integer type */
-#define H5Z_scaleoffset_get_filval_1(i, type, filval_buf, filval) \
+#define H5Z_scaleoffset_get_filval_1(type, filval_buf, filval) \
{ \
- type filval_mask; \
+ const unsigned char *fill_parm; /* Pointer to fill value parameter */ \
+ \
+ /* retrieve fill value from corresponding positions of cd_values[] \
+ * retrieve them corresponding to how they are stored \
+ */ \
+ fill_parm = (const unsigned char *)filval_buf; \
+ if(H5T_native_order_g == H5T_ORDER_LE) \
+ HDmemcpy(&filval, fill_parm, sizeof(type)); \
+ else { \
+ unsigned char *fill_buf; /* Pointer to fill value in memory */ \
+ unsigned u; /* index */ \
+ \
+ HDassert(H5T_native_order_g == H5T_ORDER_BE); \
\
- /* retrieve fill value from corresponding positions of cd_values[] \
- * retrieve them corresponding to how they are stored \
- */ \
- for(i = 0; i < sizeof(type); i++) { \
- filval_mask = ((const unsigned char *)filval_buf)[i]; \
- filval_mask <<= i*8; \
- filval |= filval_mask; \
- } \
+ fill_buf = (unsigned char *)&filval; \
+ for(u = 0; u < sizeof(type); u++) \
+ fill_buf[u] = fill_parm[sizeof(type) - (u + 1)]; \
+ } /* end else */ \
}
/* Get the fill value for floating-point type */
-#define H5Z_scaleoffset_get_filval_2(i, type, filval_buf, filval) \
-{ \
- if(sizeof(type)==sizeof(int)) \
- H5Z_scaleoffset_get_filval_1(i, int, filval_buf, *(int *)&filval) \
- else if(sizeof(type)==sizeof(long)) \
- H5Z_scaleoffset_get_filval_1(i, long, filval_buf, *(long *)&filval) \
- else if(sizeof(type)==sizeof(long long)) \
- H5Z_scaleoffset_get_filval_1(i, long long, filval_buf, *(long long *)&filval) \
- else \
- HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\
+#define H5Z_scaleoffset_get_filval_2(type, filval_buf, filval) \
+{ \
+ if(sizeof(type) <= sizeof(long long)) \
+ H5Z_scaleoffset_get_filval_1(type, filval_buf, filval) \
+ else \
+ HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \
}
/* Find maximum and minimum values of a buffer with fill value defined for integer type */
@@ -315,65 +322,68 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
/* Precompress for unsigned integer type */
#define H5Z_scaleoffset_precompress_1(type, data, d_nelmts, filavail, filval_buf, minbits, minval)\
-{ \
- type *buf = data, min = 0, max = 0, span, filval = 0; unsigned i; \
- \
- if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
- H5Z_scaleoffset_get_filval_1(i, type, filval_buf, filval) \
- if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */\
- H5Z_scaleoffset_max_min_1(i, d_nelmts, buf, filval, max, min) \
- H5Z_scaleoffset_check_1(type, max, min, minbits) \
- span = max - min + 1; \
- *minbits = H5Z_scaleoffset_log2((unsigned long long)(span+1)); \
- } else /* minbits already set, only calculate min */ \
- H5Z_scaleoffset_min_1(i, d_nelmts, buf, filval, min) \
- if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
- for(i = 0; i < d_nelmts; i++) \
- buf[i] = (buf[i] == filval)?(((type)1 << *minbits) - 1):(buf[i] - min); \
- } else { /* fill value undefined */ \
- if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */\
- H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min) \
- H5Z_scaleoffset_check_1(type, max, min, minbits) \
- span = max - min + 1; \
- *minbits = H5Z_scaleoffset_log2((unsigned long long)span); \
- } else /* minbits already set, only calculate min */ \
- H5Z_scaleoffset_min_2(i, d_nelmts, buf, min) \
- if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
- for(i = 0; i < d_nelmts; i++) buf[i] -= min; \
- } \
- *minval = min; \
+{ \
+ type *buf = (type *)data, min = 0, max = 0, span, filval = 0; \
+ unsigned i; \
+ \
+ if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
+ H5Z_scaleoffset_get_filval_1(type, filval_buf, filval) \
+ if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT) { /* minbits not set yet, calculate max, min, and minbits */ \
+ H5Z_scaleoffset_max_min_1(i, d_nelmts, buf, filval, max, min) \
+ H5Z_scaleoffset_check_1(type, max, min, minbits) \
+ span = (type)(max - min + 1); \
+ *minbits = H5Z_scaleoffset_log2((unsigned long long)(span+1)); \
+ } else /* minbits already set, only calculate min */ \
+ H5Z_scaleoffset_min_1(i, d_nelmts, buf, filval, min) \
+ if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
+ for(i = 0; i < d_nelmts; i++) \
+ buf[i] = (type)((buf[i] == filval) ? (((type)1 << *minbits) - 1) : (buf[i] - min)); \
+ } else { /* fill value undefined */ \
+ if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */ \
+ H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min) \
+ H5Z_scaleoffset_check_1(type, max, min, minbits) \
+ span = (type)(max - min + 1); \
+ *minbits = H5Z_scaleoffset_log2((unsigned long long)span); \
+ } else /* minbits already set, only calculate min */ \
+ H5Z_scaleoffset_min_2(i, d_nelmts, buf, min) \
+ if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
+ for(i = 0; i < d_nelmts; i++) \
+ buf[i] = (type)(buf[i] - min); \
+ } \
+ *minval = min; \
}
/* Precompress for signed integer type */
#define H5Z_scaleoffset_precompress_2(type, data, d_nelmts, filavail, filval_buf, minbits, minval)\
{ \
- type *buf = data, min = 0, max = 0, filval = 0; \
+ type *buf = (type *)data, min = 0, max = 0, filval = 0; \
unsigned type span; unsigned i; \
\
if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
- H5Z_scaleoffset_get_filval_1(i, type, filval_buf, filval) \
- if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */\
+ H5Z_scaleoffset_get_filval_1(type, filval_buf, filval) \
+ if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT) { /* minbits not set yet, calculate max, min, and minbits */ \
H5Z_scaleoffset_max_min_1(i, d_nelmts, buf, filval, max, min) \
H5Z_scaleoffset_check_2(type, max, min, minbits) \
- span = max - min + 1; \
- *minbits = H5Z_scaleoffset_log2((unsigned long long)(span+1)); \
+ span = (unsigned type)(max - min + 1); \
+ *minbits = H5Z_scaleoffset_log2((unsigned long long)(span + 1)); \
} else /* minbits already set, only calculate min */ \
H5Z_scaleoffset_min_1(i, d_nelmts, buf, filval, min) \
- if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
+ if(*minbits != sizeof(type) * 8) /* change values if minbits != full precision */ \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (buf[i] == filval) ? (type)(((unsigned type)1 << *minbits) - 1) : (buf[i] - min); \
+ buf[i] = (type)((buf[i] == filval) ? (type)(((unsigned type)1 << *minbits) - 1) : (buf[i] - min)); \
} else { /* fill value undefined */ \
if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */\
H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min) \
H5Z_scaleoffset_check_2(type, max, min, minbits) \
- span = max - min + 1; \
+ span = (unsigned type)(max - min + 1); \
*minbits = H5Z_scaleoffset_log2((unsigned long long)span); \
} else /* minbits already set, only calculate min */ \
H5Z_scaleoffset_min_2(i, d_nelmts, buf, min) \
- if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
- for(i = 0; i < d_nelmts; i++) buf[i] -= min; \
+ if(*minbits != sizeof(type) * 8) /* change values if minbits != full precision */ \
+ for(i = 0; i < d_nelmts; i++) \
+ buf[i] = (type)(buf[i] - min); \
} \
- *minval = min; \
+ *minval = (unsigned long long)min; \
}
/* Modify values of data in precompression if fill value defined for floating-point type */
@@ -381,27 +391,27 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
{ \
if(sizeof(type)==sizeof(int)) \
for(i = 0; i < d_nelmts; i++) { \
- if(HDfabs(buf[i] - filval) < HDpow(10.0, -D_val)) \
- *(int *)&buf[i] = ((unsigned int)1 << *minbits) - 1; \
+ if(HDfabs(buf[i] - filval) < HDpow(10.0, -D_val)) \
+ *(int *)&buf[i] = (int)(((unsigned int)1 << *minbits) - 1); \
else \
*(int *)&buf[i] = H5Z_scaleoffset_rnd( \
- buf[i]*HDpow(10.0, D_val) - min*HDpow(10.0, D_val)); \
+ buf[i]*HDpow(10.0, D_val) - min*HDpow(10.0, D_val)); \
} \
else if(sizeof(type)==sizeof(long)) \
for(i = 0; i < d_nelmts; i++) { \
- if(HDfabs(buf[i] - filval) < HDpow(10.0, -D_val)) \
- *(long *)&buf[i] = ((unsigned long)1 << *minbits) - 1; \
+ if(HDfabs(buf[i] - filval) < HDpow(10.0, -D_val)) \
+ *(long *)&buf[i] = (long)(((unsigned long)1 << *minbits) - 1); \
else \
*(long *)&buf[i] = H5Z_scaleoffset_rnd( \
- buf[i]*HDpow(10.0, D_val) - min*HDpow(10.0, D_val)); \
+ buf[i]*HDpow(10.0, D_val) - min*HDpow(10.0, D_val)); \
} \
else if(sizeof(type)==sizeof(long long)) \
for(i = 0; i < d_nelmts; i++) { \
- if(HDfabs(buf[i] - filval) < HDpow(10.0, -D_val)) \
- *(long long *)&buf[i] = ((unsigned long long)1 << *minbits) - 1; \
+ if(HDfabs(buf[i] - filval) < HDpow(10.0, -D_val)) \
+ *(long long *)&buf[i] = (long long)(((unsigned long long)1 << *minbits) - 1); \
else \
*(long long *)&buf[i] = H5Z_scaleoffset_rnd( \
- buf[i]*HDpow(10.0, D_val) - min*HDpow(10.0, D_val)); \
+ buf[i]*HDpow(10.0, D_val) - min*HDpow(10.0, D_val)); \
} \
else \
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\
@@ -429,40 +439,50 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
/* Save the minimum value for floating-point type */
#define H5Z_scaleoffset_save_min(i, type, minval, min) \
{ \
- if(sizeof(type)==sizeof(int)) \
- for(i = 0; i < sizeof(int); i++) \
- ((unsigned char *)minval)[i] = (unsigned char)((*(int *)&min & ((int)0xff << i*8)) >> i*8); \
- else if(sizeof(type)==sizeof(long)) \
- for(i = 0; i < sizeof(long); i++) \
- ((unsigned char *)minval)[i] = (unsigned char)((*(long *)&min & ((long)0xff << i*8)) >> i*8); \
- else if(sizeof(type)==sizeof(long long)) \
- for(i = 0; i < sizeof(long long); i++) \
- ((unsigned char *)minval)[i] = (unsigned char)((*(long long *)&min & ((long long)0xff << i*8)) >> i*8);\
- else \
- HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\
+ if(sizeof(type) <= sizeof(long long)) { \
+ unsigned char *min_parm; /* Pointer to min value parameter */ \
+ \
+ min_parm = (unsigned char *)minval; \
+ if(H5T_native_order_g == H5T_ORDER_LE) \
+ HDmemcpy(min_parm, &min, sizeof(type)); \
+ else { \
+ unsigned char *min_buf; /* Pointer to min value in memory */ \
+ unsigned u; /* index */ \
+ \
+ HDassert(H5T_native_order_g == H5T_ORDER_BE); \
+ \
+ min_buf = (unsigned char *)&min; \
+ for(u = 0; u < sizeof(type); u++) \
+ min_parm[u] = min_buf[sizeof(type) - (u + 1)]; \
+ } /* end else */ \
+ } /* end if */ \
+ else \
+ HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \
}
/* Precompress for floating-point type using variable-minimum-bits method */
#define H5Z_scaleoffset_precompress_3(type, data, d_nelmts, filavail, filval_buf, \
minbits, minval, D_val) \
{ \
- type *buf = data, min = 0, max = 0, filval = 0; \
- unsigned long long span; unsigned i; *minval = 0; \
+ type *buf = (type *)data, min = 0, max = 0, filval = 0; \
+ unsigned long long span; \
+ unsigned i; \
\
+ *minval = 0; \
if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
- H5Z_scaleoffset_get_filval_2(i, type, filval_buf, filval) \
+ H5Z_scaleoffset_get_filval_2(type, filval_buf, filval) \
H5Z_scaleoffset_max_min_3(i, d_nelmts, buf, filval, max, min, D_val) \
H5Z_scaleoffset_check_3(i, type, max, min, minbits, D_val) \
- span = H5Z_scaleoffset_rnd(max*HDpow(10.0,D_val) - min*HDpow(10.0,D_val)) + 1; \
- *minbits = H5Z_scaleoffset_log2((unsigned long long)(span+1)); \
- if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
+ span = H5Z_scaleoffset_rnd(max * HDpow(10.0, D_val) - min * HDpow(10.0, D_val)) + 1; \
+ *minbits = H5Z_scaleoffset_log2((unsigned long long)(span + 1)); \
+ if(*minbits != sizeof(type) * 8) /* change values if minbits != full precision */ \
H5Z_scaleoffset_modify_1(i, type, buf, d_nelmts, filval, minbits, min, D_val) \
} else { /* fill value undefined */ \
H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min) \
H5Z_scaleoffset_check_3(i, type, max, min, minbits, D_val) \
- span = H5Z_scaleoffset_rnd(max*HDpow(10.0,D_val) - min*HDpow(10.0,D_val)) + 1; \
+ span = H5Z_scaleoffset_rnd(max * HDpow(10.0, D_val) - min * HDpow(10.0, D_val)) + 1; \
*minbits = H5Z_scaleoffset_log2((unsigned long long)span); \
- if(*minbits != sizeof(type)*8) /* change values if minbits != full precision */ \
+ if(*minbits != sizeof(type) * 8) /* change values if minbits != full precision */ \
H5Z_scaleoffset_modify_2(i, type, buf, d_nelmts, min, D_val) \
} \
H5Z_scaleoffset_save_min(i, type, minval, min) \
@@ -471,49 +491,56 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
/* Postdecompress for unsigned integer type */
#define H5Z_scaleoffset_postdecompress_1(type, data, d_nelmts, filavail, filval_buf, minbits, minval)\
{ \
- type *buf = data, filval = 0; unsigned i; \
+ type *buf = (type *)data, filval = 0; unsigned i; \
\
if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
- H5Z_scaleoffset_get_filval_1(i, type, filval_buf, filval) \
+ H5Z_scaleoffset_get_filval_1(type, filval_buf, filval) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (type)((buf[i] == (((type)1 << minbits) - 1))?filval:(buf[i] + minval));\
+ buf[i] = (type)((buf[i] == (((type)1 << minbits) - 1)) ? filval : (buf[i] + minval)); \
} else /* fill value undefined */ \
- for(i = 0; i < d_nelmts; i++) buf[i] += (type)(minval); \
+ for(i = 0; i < d_nelmts; i++) buf[i] = (type)(buf[i] + (type)(minval)); \
}
/* Postdecompress for signed integer type */
#define H5Z_scaleoffset_postdecompress_2(type, data, d_nelmts, filavail, filval_buf, minbits, minval)\
{ \
- type *buf = data, filval = 0; unsigned i; \
+ type *buf = (type *)data, filval = 0; \
+ unsigned i; \
\
if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
- H5Z_scaleoffset_get_filval_1(i, type, filval_buf, filval) \
+ H5Z_scaleoffset_get_filval_1(type, filval_buf, filval) \
for(i = 0; i < d_nelmts; i++) \
buf[i] = (type)(((unsigned type)buf[i] == (((unsigned type)1 << minbits) - 1)) ? filval : (buf[i] + minval));\
} else /* fill value undefined */ \
- for(i = 0; i < d_nelmts; i++) buf[i] += (type)(minval); \
+ for(i = 0; i < d_nelmts; i++) \
+ buf[i] = (type)(buf[i] + (type)(minval)); \
}
/* Retrive minimum value of floating-point type */
-#define H5Z_scaleoffset_get_min(i, type, minval, min) \
-{ \
- if(sizeof(type)==sizeof(int)) { \
- int mask; \
- for(i = 0; i < sizeof(int); i++) { \
- mask = ((unsigned char *)&minval)[i]; mask <<= i*8; *(int *)&min |= mask; \
- } \
- } else if(sizeof(type)==sizeof(long)) { \
- long mask; \
- for(i = 0; i < sizeof(long); i++) { \
- mask = ((unsigned char *)&minval)[i]; mask <<= i*8; *(long *)&min |= mask; \
- } \
- } else if(sizeof(type)==sizeof(long long)) { \
- long long mask; \
- for(i = 0; i < sizeof(long long); i++) { \
- mask = ((unsigned char *)&minval)[i]; mask <<= i*8; *(long long *)&min |= mask;\
- } \
- } else \
- HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype")\
+#define H5Z_scaleoffset_get_min(type, minval, min) \
+{ \
+ if(sizeof(type) <= sizeof(long long)) { \
+ const unsigned char *min_parm; /* Pointer to min value parameter */ \
+ \
+ /* retrieve min value from corresponding positions \
+ * retrieve them corresponding to how they are stored \
+ */ \
+ min_parm = (const unsigned char *)&minval; \
+ if(H5T_native_order_g == H5T_ORDER_LE) \
+ HDmemcpy(&min, min_parm, sizeof(type)); \
+ else { \
+ unsigned char *min_buf; /* Pointer to min value in memory */ \
+ unsigned u; /* index */ \
+ \
+ HDassert(H5T_native_order_g == H5T_ORDER_BE); \
+ \
+ min_buf = (unsigned char *)&min; \
+ for(u = 0; u < sizeof(type); u++) \
+ min_buf[u] = min_parm[sizeof(type) - (u + 1)]; \
+ } /* end else */ \
+ } /* end if */ \
+ else \
+ HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \
}
/* Modify values of data in postdecompression if fill value defined for floating-point type */
@@ -521,16 +548,16 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
{ \
if(sizeof(type)==sizeof(int)) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (*(int *)&buf[i]==(((unsigned int)1 << minbits) - 1))? \
- filval:(*(int *)&buf[i])/HDpow(10.0, D_val) + min; \
+ buf[i] = (type)((*(int *)&buf[i] == (int)(((unsigned int)1 << minbits) - 1)) ? \
+ filval : (double)(*(int *)&buf[i]) / HDpow(10.0, D_val) + min); \
else if(sizeof(type)==sizeof(long)) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (*(long *)&buf[i]==(((unsigned long)1 << minbits) - 1))? \
- filval:(*(long *)&buf[i])/HDpow(10.0, D_val) + min; \
+ buf[i] = (type)((*(long *)&buf[i] == (long)(((unsigned long)1 << minbits) - 1)) ? \
+ filval : (double)(*(long *)&buf[i]) / HDpow(10.0, D_val) + min); \
else if(sizeof(type)==sizeof(long long)) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (*(long long *)&buf[i]==(((unsigned long long)1 << minbits) - 1))? \
- filval:(*(long long *)&buf[i])/HDpow(10.0, D_val) + min; \
+ buf[i] = (type)((*(long long *)&buf[i] == (long long)(((unsigned long long)1 << minbits) - 1)) ? \
+ filval : (double)(*(long long *)&buf[i]) / HDpow(10.0, D_val) + min); \
else \
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \
}
@@ -540,13 +567,13 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
{ \
if(sizeof(type)==sizeof(int)) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (*(int *)&buf[i])/HDpow(10.0, D_val) + min; \
+ buf[i] = (type)((double)(*(int *)&buf[i]) / HDpow(10.0, D_val) + min); \
else if(sizeof(type)==sizeof(long)) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (*(long *)&buf[i])/HDpow(10.0, D_val) + min; \
+ buf[i] = (type)((double)(*(long *)&buf[i]) / HDpow(10.0, D_val) + min); \
else if(sizeof(type)==sizeof(long long)) \
for(i = 0; i < d_nelmts; i++) \
- buf[i] = (*(long long *)&buf[i])/HDpow(10.0, D_val) + min; \
+ buf[i] = (type)((double)(*(long long *)&buf[i]) / HDpow(10.0, D_val) + min); \
else \
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "cannot find matched integer dataype") \
}
@@ -555,19 +582,19 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{
#define H5Z_scaleoffset_postdecompress_3(type, data, d_nelmts, filavail, filval_buf, \
minbits, minval, D_val) \
{ \
- type *buf = data, filval = 0, min = 0; unsigned i; \
+ type *buf = (type *)data, filval = 0, min = 0; \
+ unsigned i; \
\
- H5Z_scaleoffset_get_min(i, type, minval, min) \
+ H5Z_scaleoffset_get_min(type, minval, min) \
\
if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */ \
- H5Z_scaleoffset_get_filval_2(i, type, filval_buf, filval) \
+ H5Z_scaleoffset_get_filval_2(type, filval_buf, filval) \
H5Z_scaleoffset_modify_3(i, type, buf, d_nelmts, filval, minbits, min, D_val) \
} else /* fill value undefined */ \
H5Z_scaleoffset_modify_4(i, type, buf, d_nelmts, min, D_val) \
}
-
/*-------------------------------------------------------------------------
* Function: H5Z_can_apply_scaleoffset
*
@@ -595,7 +622,7 @@ H5Z_can_apply_scaleoffset(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED spac
FUNC_ENTER_NOAPI(H5Z_can_apply_scaleoffset, FAIL)
/* Get datatype */
- if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE)))
+ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
/* Get datatype's class, for checking the "datatype class" */
@@ -638,11 +665,11 @@ done:
*
*-------------------------------------------------------------------------
*/
-static enum H5Z_scaleoffset_type
+static enum H5Z_scaleoffset_t
H5Z_scaleoffset_get_type(unsigned dtype_class, unsigned dtype_size, unsigned dtype_sign)
{
- enum H5Z_scaleoffset_type type = t_bad; /* integer type */
- enum H5Z_scaleoffset_type ret_value; /* return value */
+ enum H5Z_scaleoffset_t type = t_bad; /* integer type */
+ enum H5Z_scaleoffset_t ret_value; /* return value */
FUNC_ENTER_NOAPI_NOINIT(H5Z_scaleoffset_get_type)
@@ -698,7 +725,7 @@ done:
*/
static herr_t
H5Z_scaleoffset_set_parms_fillval(H5P_genplist_t *dcpl_plist,
- const H5T_t *type, enum H5Z_scaleoffset_type scale_type,
+ const H5T_t *type, enum H5Z_scaleoffset_t scale_type,
unsigned cd_values[], int need_convert, hid_t dxpl_id)
{
herr_t ret_value = SUCCEED; /* Return value */
@@ -763,10 +790,9 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id)
hssize_t npoints; /* Number of points in the dataspace */
H5T_class_t dtype_class; /* Datatype's class */
H5T_order_t dtype_order; /* Datatype's endianness order */
- int need_convert = FALSE; /* Flag indicating convertion of byte order */
size_t dtype_size; /* Datatype's size (in bytes) */
H5T_sign_t dtype_sign; /* Datatype's sign */
- enum H5Z_scaleoffset_type scale_type; /* Specific datatype */
+ enum H5Z_scaleoffset_t scale_type; /* Specific datatype */
H5D_fill_value_t status; /* Status of fill value in property list */
herr_t ret_value = SUCCEED; /* Return value */
@@ -777,7 +803,7 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id)
HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
/* Get datatype */
- if(NULL == (type = H5I_object_verify(type_id, H5I_DATATYPE)))
+ if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
/* Get the filter's current parameters */
@@ -809,6 +835,17 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id)
cd_values[H5Z_SCALEOFFSET_PARM_CLASS] = H5Z_SCALEOFFSET_CLS_FLOAT;
break;
+ case H5T_NO_CLASS:
+ case H5T_TIME:
+ case H5T_STRING:
+ case H5T_BITFIELD:
+ case H5T_OPAQUE:
+ case H5T_COMPOUND:
+ case H5T_REFERENCE:
+ case H5T_ENUM:
+ case H5T_VLEN:
+ case H5T_ARRAY:
+ case H5T_NCLASSES:
default:
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "datatype class not supported by scaleoffset")
} /* end switch */
@@ -835,6 +872,8 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id)
cd_values[H5Z_SCALEOFFSET_PARM_SIGN] = H5Z_SCALEOFFSET_SGN_2;
break;
+ case H5T_SGN_ERROR:
+ case H5T_NSGN:
default:
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad integer sign")
} /* end switch */
@@ -854,6 +893,9 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id)
cd_values[H5Z_SCALEOFFSET_PARM_ORDER] = H5Z_SCALEOFFSET_ORDER_BE;
break;
+ case H5T_ORDER_ERROR:
+ case H5T_ORDER_VAX:
+ case H5T_ORDER_NONE:
default:
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, FAIL, "bad datatype endianness order")
} /* end switch */
@@ -866,6 +908,8 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id)
if(status == H5D_FILL_VALUE_UNDEFINED)
cd_values[H5Z_SCALEOFFSET_PARM_FILAVAIL] = H5Z_SCALEOFFSET_FILL_UNDEFINED;
else {
+ int need_convert = FALSE; /* Flag indicating convertion of byte order */
+
cd_values[H5Z_SCALEOFFSET_PARM_FILAVAIL] = H5Z_SCALEOFFSET_FILL_DEFINED;
/* Check if memory byte order matches dataset datatype byte order */
@@ -908,8 +952,8 @@ done:
*-------------------------------------------------------------------------
*/
static size_t
-H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_values[],
- size_t nbytes, size_t *buf_size, void **buf)
+H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_values[],
+ size_t nbytes, size_t *buf_size, void **buf)
{
size_t ret_value = 0; /* return value */
size_t size_out = 0; /* size of output buffer */
@@ -922,7 +966,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
double D_val = 0.0; /* decimal scale factor */
uint32_t minbits = 0; /* minimum number of bits to store values */
unsigned long long minval= 0; /* minimum value of input buffer */
- enum H5Z_scaleoffset_type type; /* memory type corresponding to dataset datatype */
+ enum H5Z_scaleoffset_t type; /* memory type corresponding to dataset datatype */
int need_convert = FALSE; /* flag indicating convertion of byte order */
unsigned char *outbuf = NULL; /* pointer to new output buffer */
unsigned buf_offset = 21; /* buffer offset because of parameters stored in file */
@@ -947,6 +991,9 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
need_convert = TRUE;
break;
+ case H5T_ORDER_ERROR:
+ case H5T_ORDER_VAX:
+ case H5T_ORDER_NONE:
default:
HGOTO_ERROR(H5E_PLINE, H5E_BADTYPE, 0, "bad H5T_NATIVE_INT endianness order")
} /* end switch */
@@ -997,7 +1044,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
ret_value = *buf_size;
goto done;
}
- minbits = scale_factor;
+ minbits = (uint32_t)scale_factor;
}
/* prepare paramters to pass to compress/decompress functions */
@@ -1040,7 +1087,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
size_out = d_nelmts * p.size;
/* allocate memory space for decompressed buffer */
- if(NULL==(outbuf = H5MM_malloc(size_out)))
+ if(NULL == (outbuf = (unsigned char *)H5MM_malloc(size_out)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for scaleoffset decompression")
/* special case: minbits equal to full precision */
@@ -1088,7 +1135,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
}
/* output; compress */
else {
- assert(nbytes == d_nelmts * p.size);
+ HDassert(nbytes == d_nelmts * p.size);
/* before preprocess, convert to memory endianness order if needed */
if(need_convert)
@@ -1119,7 +1166,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
size_out = buf_offset + nbytes * p.minbits / (p.size * 8) + 1; /* may be 1 larger */
/* allocate memory space for compressed buffer */
- if(NULL==(outbuf = H5MM_malloc(size_out)))
+ if(NULL == (outbuf = (unsigned char *)H5MM_malloc(size_out)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "memory allocation failed for scaleoffset compression")
/* store minbits and minval in the front of output compressed buffer
@@ -1128,7 +1175,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
* 4 bytes for minbits, 1 byte for size of minval, 16 bytes for minval
*/
for(i = 0; i < 4; i++)
- ((unsigned char *)outbuf)[i] = (minbits & ((uint32_t)0xff << i*8)) >> i*8;
+ ((unsigned char *)outbuf)[i] = (unsigned char)((minbits & ((uint32_t)0xff << i*8)) >> i*8);
((unsigned char *)outbuf)[4] = sizeof(unsigned long long);
@@ -1137,11 +1184,11 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
/* special case: minbits equal to full precision */
if(minbits == p.size * 8) {
- HDmemcpy(outbuf+buf_offset, *buf, nbytes);
+ HDmemcpy(outbuf + buf_offset, *buf, nbytes);
*buf = outbuf;
outbuf = NULL;
*buf_size = size_out;
- ret_value = buf_offset+nbytes;
+ ret_value = buf_offset + nbytes;
goto done;
}
@@ -1150,7 +1197,7 @@ H5Z_filter_scaleoffset (unsigned flags, size_t cd_nelmts, const unsigned cd_valu
* all data elements have the same value
*/
if(minbits != 0)
- H5Z_scaleoffset_compress(*buf, d_nelmts, outbuf+buf_offset, size_out-buf_offset, p);
+ H5Z_scaleoffset_compress((unsigned char *)*buf, d_nelmts, outbuf + buf_offset, size_out - buf_offset, p);
}
/* free the input buffer */
@@ -1187,124 +1234,140 @@ H5Z_scaleoffset_convert(void *buf, unsigned d_nelmts, size_t dtype_size)
unsigned i, j;
unsigned char *buffer, temp;
- buffer = buf;
+ buffer = (unsigned char *)buf;
for(i = 0; i < d_nelmts * dtype_size; i += dtype_size)
- for(j = 0; j < dtype_size/2; j++) {
+ for(j = 0; j < dtype_size / 2; j++) {
/* swap pair of bytes */
- temp = buffer[i+j];
- buffer[i+j] = buffer[i+dtype_size-1-j];
- buffer[i+dtype_size-1-j] = temp;
- }
+ temp = buffer[i + j];
+ buffer[i + j] = buffer[i + dtype_size - 1 - j];
+ buffer[i + dtype_size - 1 - j] = temp;
+ } /* end for */
} /* end if */
-}
+} /* end H5Z_scaleoffset_convert() */
/* Round a floating-point value to the nearest integer value 4/19/05 */
/* rounding to the bigger absolute value if val is in the middle,
0.5 -> 1, -0.5 ->-1
5/9/05, KY */
-static double H5Z_scaleoffset_rnd(double val)
+static double
+H5Z_scaleoffset_rnd(double val)
{
- double u_val, l_val;
+ double u_val, l_val;
- u_val = HDceil(val);
- l_val = HDfloor(val);
+ u_val = HDceil(val);
+ l_val = HDfloor(val);
- if(val > 0) {
- if((u_val - val)<=(val - l_val)) return u_val;
- else return l_val;
- }
- else {
- if((val - l_val)<=(u_val - val)) return l_val;
- else return u_val;
- }
-}
+ if(val > 0) {
+ if((u_val - val) <= (val - l_val))
+ return u_val;
+ else
+ return l_val;
+ } /* end if */
+ else {
+ if((val - l_val) <= (u_val - val))
+ return l_val;
+ else
+ return u_val;
+ }
+} /* H5Z_scaleoffset_rnd() */
/* return ceiling of floating-point log2 function
* receive unsigned integer as argument 3/10/2005
*/
-static unsigned H5Z_scaleoffset_log2(unsigned long long num)
+static unsigned
+H5Z_scaleoffset_log2(unsigned long long num)
{
unsigned v = 0;
unsigned long long lower_bound = 1; /* is power of 2, largest value <= num */
unsigned long long val = num;
- while(val >>= 1) { v++; lower_bound <<= 1; }
+ while(val >>= 1) {
+ v++;
+ lower_bound <<= 1;
+ }
- if(num == lower_bound) return v;
- else return v+1;
+ if(num == lower_bound)
+ return v;
+ else
+ return v + 1;
}
/* precompress for integer type */
static void
-H5Z_scaleoffset_precompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_type type,
- unsigned filavail, const void *filval_buf, uint32_t *minbits, unsigned long long *minval)
+H5Z_scaleoffset_precompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_t type,
+ unsigned filavail, const void *filval_buf, uint32_t *minbits, unsigned long long *minval)
{
- if(type == t_uchar)
- H5Z_scaleoffset_precompress_1(unsigned char, data, d_nelmts,
+ if(type == t_uchar)
+ H5Z_scaleoffset_precompress_1(unsigned char, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_ushort)
- H5Z_scaleoffset_precompress_1(unsigned short, data, d_nelmts,
+ else if(type == t_ushort)
+ H5Z_scaleoffset_precompress_1(unsigned short, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_uint)
- H5Z_scaleoffset_precompress_1(unsigned int, data, d_nelmts,
+ else if(type == t_uint)
+ H5Z_scaleoffset_precompress_1(unsigned int, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_ulong)
- H5Z_scaleoffset_precompress_1(unsigned long, data, d_nelmts,
+ else if(type == t_ulong)
+ H5Z_scaleoffset_precompress_1(unsigned long, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_ulong_long)
- H5Z_scaleoffset_precompress_1(unsigned long long, data, d_nelmts,
+ else if(type == t_ulong_long)
+ H5Z_scaleoffset_precompress_1(unsigned long long, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_schar) {
- signed char *buf = data, min = 0, max = 0, filval = 0;
- unsigned char span; unsigned i;
-
- if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */
- H5Z_scaleoffset_get_filval_1(i, signed char, filval_buf, filval);
- if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */
- H5Z_scaleoffset_max_min_1(i, d_nelmts, buf, filval, max, min)
- if((unsigned char)(max - min) > (unsigned char)(~(unsigned char)0 - 2))
- { *minbits = sizeof(signed char)*8; return; }
- span = max - min + 1;
- *minbits = H5Z_scaleoffset_log2((unsigned long long)(span+1));
- } else /* minbits already set, only calculate min */
- H5Z_scaleoffset_min_1(i, d_nelmts, buf, filval, min)
- if(*minbits != sizeof(signed char)*8) /* change values if minbits != full precision */
- for(i = 0; i < d_nelmts; i++)
- buf[i] = (buf[i] == filval)?(((unsigned char)1 << *minbits) - 1):(buf[i] - min);
- } else { /* fill value undefined */
- if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT ) { /* minbits not set yet, calculate max, min, and minbits */
- H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min)
- if((unsigned char)(max - min) > (unsigned char)(~(unsigned char)0 - 2)) {
- *minbits = sizeof(signed char)*8;
- *minval = min; return;
- }
- span = max - min + 1;
- *minbits = H5Z_scaleoffset_log2((unsigned long long)span);
- } else /* minbits already set, only calculate min */
- H5Z_scaleoffset_min_2(i, d_nelmts, buf, min)
- if(*minbits != sizeof(signed char)*8) /* change values if minbits != full precision */
- for(i = 0; i < d_nelmts; i++) buf[i] -= min;
- }
- *minval = min;
- }
- else if(type == t_short)
- H5Z_scaleoffset_precompress_2(short, data, d_nelmts,
+ else if(type == t_schar) {
+ signed char *buf = (signed char *)data, min = 0, max = 0, filval = 0;
+ unsigned char span;
+ unsigned i;
+
+ if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */
+ H5Z_scaleoffset_get_filval_1(signed char, filval_buf, filval);
+ if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT) { /* minbits not set yet, calculate max, min, and minbits */
+ H5Z_scaleoffset_max_min_1(i, d_nelmts, buf, filval, max, min)
+ if((unsigned char)(max - min) > (unsigned char)(~(unsigned char)0 - 2)) {
+ *minbits = sizeof(signed char)*8;
+ return;
+ }
+ span = (unsigned char)(max - min + 1);
+ *minbits = H5Z_scaleoffset_log2((unsigned long long)(span+1));
+ } else /* minbits already set, only calculate min */
+ H5Z_scaleoffset_min_1(i, d_nelmts, buf, filval, min)
+ if(*minbits != sizeof(signed char)*8) /* change values if minbits != full precision */
+ for(i = 0; i < d_nelmts; i++)
+ buf[i] = (signed char)((buf[i] == filval) ? (((unsigned char)1 << *minbits) - 1) : (buf[i] - min));
+ } else { /* fill value undefined */
+ if(*minbits == H5Z_SO_INT_MINBITS_DEFAULT) { /* minbits not set yet, calculate max, min, and minbits */
+ H5Z_scaleoffset_max_min_2(i, d_nelmts, buf, max, min)
+ if((unsigned char)(max - min) > (unsigned char)(~(unsigned char)0 - 2)) {
+ *minbits = sizeof(signed char)*8;
+ *minval = (unsigned long long)min;
+ return;
+ }
+ span = (unsigned char)(max - min + 1);
+ *minbits = H5Z_scaleoffset_log2((unsigned long long)span);
+ } else /* minbits already set, only calculate min */
+ H5Z_scaleoffset_min_2(i, d_nelmts, buf, min)
+ if(*minbits != sizeof(signed char) * 8) /* change values if minbits != full precision */
+ for(i = 0; i < d_nelmts; i++)
+ buf[i] = (signed char)(buf[i] - min);
+ }
+ *minval = (unsigned long long)min;
+ }
+ else if(type == t_short)
+ H5Z_scaleoffset_precompress_2(short, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_int)
- H5Z_scaleoffset_precompress_2(int, data, d_nelmts,
+ else if(type == t_int)
+ H5Z_scaleoffset_precompress_2(int, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_long)
- H5Z_scaleoffset_precompress_2(long, data, d_nelmts,
+ else if(type == t_long)
+ H5Z_scaleoffset_precompress_2(long, data, d_nelmts,
filavail, filval_buf, minbits, minval)
- else if(type == t_long_long)
- H5Z_scaleoffset_precompress_2(long long, data, d_nelmts,
+ else if(type == t_long_long)
+ H5Z_scaleoffset_precompress_2(long long, data, d_nelmts,
filavail, filval_buf, minbits, minval)
}
/* postdecompress for integer type */
static void
-H5Z_scaleoffset_postdecompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_type type,
- unsigned filavail, const void *filval_buf, uint32_t minbits, unsigned long long minval)
+H5Z_scaleoffset_postdecompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_t type,
+ unsigned filavail, const void *filval_buf, uint32_t minbits, unsigned long long minval)
{
long long sminval = *(long long*)&minval; /* for signed integer types */
@@ -1324,14 +1387,16 @@ H5Z_scaleoffset_postdecompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleof
H5Z_scaleoffset_postdecompress_1(unsigned long long, data, d_nelmts, filavail,
filval_buf, minbits, minval)
else if(type == t_schar) {
- signed char *buf = data, filval = 0; unsigned i;
+ signed char *buf = (signed char *)data, filval = 0;
+ unsigned i;
if(filavail == H5Z_SCALEOFFSET_FILL_DEFINED) { /* fill value defined */
- H5Z_scaleoffset_get_filval_1(i, signed char, filval_buf, filval)
+ H5Z_scaleoffset_get_filval_1(signed char, filval_buf, filval)
for(i = 0; i < d_nelmts; i++)
- buf[i] = (buf[i] == (((unsigned char)1 << minbits) - 1))?filval:(buf[i] + sminval);
+ buf[i] = (signed char)((buf[i] == (((unsigned char)1 << minbits) - 1)) ? filval : (buf[i] + sminval));
} else /* fill value undefined */
- for(i = 0; i < d_nelmts; i++) buf[i] += sminval;
+ for(i = 0; i < d_nelmts; i++)
+ buf[i] = (signed char)(buf[i] + sminval);
}
else if(type == t_short)
H5Z_scaleoffset_postdecompress_2(short, data, d_nelmts, filavail,
@@ -1350,8 +1415,9 @@ H5Z_scaleoffset_postdecompress_i(void *data, unsigned d_nelmts, enum H5Z_scaleof
/* precompress for floating-point type, variable-minimum-bits method
success: non-negative, failure: negative 4/15/05 */
static herr_t
-H5Z_scaleoffset_precompress_fd(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_type type,
-unsigned filavail, const void *filval_buf, uint32_t *minbits, unsigned long long *minval, double D_val)
+H5Z_scaleoffset_precompress_fd(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_t type,
+ unsigned filavail, const void *filval_buf, uint32_t *minbits,
+ unsigned long long *minval, double D_val)
{
herr_t ret_value=SUCCEED; /* Return value */
@@ -1371,10 +1437,11 @@ done:
/* postdecompress for floating-point type, variable-minimum-bits method
success: non-negative, failure: negative 4/15/05 */
static herr_t
-H5Z_scaleoffset_postdecompress_fd(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_type type,
-unsigned filavail, const void *filval_buf, uint32_t minbits, unsigned long long minval, double D_val)
+H5Z_scaleoffset_postdecompress_fd(void *data, unsigned d_nelmts, enum H5Z_scaleoffset_t type,
+ unsigned filavail, const void *filval_buf, uint32_t minbits,
+ unsigned long long minval, double D_val)
{
- long long sminval = *(long long*)&minval; /* for signed integer types */
+ long long sminval = (long long)minval; /* for signed integer types */
herr_t ret_value=SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5Z_scaleoffset_postdecompress_fd, FAIL)
@@ -1390,16 +1457,20 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
}
-static void H5Z_scaleoffset_next_byte(size_t *j, int *buf_len)
+static void
+H5Z_scaleoffset_next_byte(size_t *j, unsigned *buf_len)
{
- ++(*j); *buf_len = 8 * sizeof(unsigned char);
+ ++(*j);
+ *buf_len = 8 * sizeof(unsigned char);
}
-static void H5Z_scaleoffset_decompress_one_byte(unsigned char *data, size_t data_offset, int k,
-int begin_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int dtype_len)
+static void
+H5Z_scaleoffset_decompress_one_byte(unsigned char *data, size_t data_offset,
+ unsigned k, unsigned begin_i, unsigned char *buffer, size_t *j, unsigned *buf_len,
+ parms_atomic p, unsigned dtype_len)
{
- int dat_len; /* dat_len is the number of bits to be copied in each data byte */
- unsigned char val; /* value to be copied in each data byte */
+ unsigned dat_len; /* dat_len is the number of bits to be copied in each data byte */
+ unsigned char val; /* value to be copied in each data byte */
/* initialize value and bits of unsigned char to be copied */
val = buffer[*j];
@@ -1409,75 +1480,82 @@ int begin_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int
dat_len = 8;
if(*buf_len > dat_len) {
- data[data_offset + k] =
- ((val >> (*buf_len - dat_len)) & ~(~0 << dat_len));
+ data[data_offset + k] = (unsigned char)((val >> (*buf_len - dat_len)) & ~(~0 << dat_len));
*buf_len -= dat_len;
- } else {
- data[data_offset + k] =
- ((val & ~(~0 << *buf_len)) << (dat_len - *buf_len));
+ } /* end if */
+ else {
+ data[data_offset + k] = (unsigned char)((val & ~(~0 << *buf_len)) << (dat_len - *buf_len));
dat_len -= *buf_len;
H5Z_scaleoffset_next_byte(j, buf_len);
- if(dat_len == 0) return;
+ if(dat_len == 0)
+ return;
val = buffer[*j];
- data[data_offset + k] |=
- ((val >> (*buf_len - dat_len)) & ~(~0 << dat_len));
+ data[data_offset + k] |= (unsigned char)((val >> (*buf_len - dat_len)) & ~(~0 << dat_len));
*buf_len -= dat_len;
- }
+ } /* end else */
}
-static void H5Z_scaleoffset_decompress_one_atomic(unsigned char *data, size_t data_offset,
- unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p)
+static void
+H5Z_scaleoffset_decompress_one_atomic(unsigned char *data, size_t data_offset,
+ unsigned char *buffer, size_t *j, unsigned *buf_len, parms_atomic p)
{
/* begin_i: the index of byte having first significant bit */
- int k, begin_i, dtype_len;
+ unsigned begin_i;
+ unsigned dtype_len;
+ int k;
- assert(p.minbits > 0);
+ HDassert(p.minbits > 0);
dtype_len = p.size * 8;
if(p.mem_order == H5Z_SCALEOFFSET_ORDER_LE) { /* little endian */
begin_i = p.size - 1 - (dtype_len - p.minbits) / 8;
- for(k = begin_i; k >= 0; k--)
- H5Z_scaleoffset_decompress_one_byte(data, data_offset, k, begin_i,
+ for(k = (int)begin_i; k >= 0; k--)
+ H5Z_scaleoffset_decompress_one_byte(data, data_offset, (unsigned)k, begin_i,
buffer, j, buf_len, p, dtype_len);
}
+ else { /* big endian */
+ HDassert(p.mem_order == H5Z_SCALEOFFSET_ORDER_BE);
- if(p.mem_order == H5Z_SCALEOFFSET_ORDER_BE) { /* big endian */
begin_i = (dtype_len - p.minbits) / 8;
- for(k = begin_i; k <= p.size - 1; k++)
- H5Z_scaleoffset_decompress_one_byte(data, data_offset, k, begin_i,
+ for(k = (int)begin_i; k <= (int)(p.size - 1); k++)
+ H5Z_scaleoffset_decompress_one_byte(data, data_offset, (unsigned)k, begin_i,
buffer, j, buf_len, p, dtype_len);
}
}
-static void H5Z_scaleoffset_decompress(unsigned char *data, unsigned d_nelmts,
- unsigned char *buffer, parms_atomic p)
+static void
+H5Z_scaleoffset_decompress(unsigned char *data, unsigned d_nelmts,
+ unsigned char *buffer, parms_atomic p)
{
- /* i: index of data, j: index of buffer,
- buf_len: number of bits to be filled in current byte */
- size_t i, j;
- int buf_len;
-
- /* must initialize to zeros */
- for(i = 0; i < d_nelmts*p.size; i++) data[i] = 0;
-
- /* initialization before the loop */
- j = 0;
- buf_len = sizeof(unsigned char) * 8;
-
- /* decompress */
- for(i = 0; i < d_nelmts; i++)
- H5Z_scaleoffset_decompress_one_atomic(data, i*p.size, buffer, &j, &buf_len, p);
+ /* i: index of data, j: index of buffer,
+ buf_len: number of bits to be filled in current byte */
+ size_t i, j;
+ unsigned buf_len;
+
+ /* must initialize to zeros */
+ for(i = 0; i < d_nelmts*p.size; i++)
+ data[i] = 0;
+
+ /* initialization before the loop */
+ j = 0;
+ buf_len = sizeof(unsigned char) * 8;
+
+ /* decompress */
+ for(i = 0; i < d_nelmts; i++)
+ H5Z_scaleoffset_decompress_one_atomic(data, i * p.size, buffer, &j, &buf_len, p);
}
-static void H5Z_scaleoffset_compress_one_byte(unsigned char *data, size_t data_offset, int k,
-int begin_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int dtype_len)
+static void
+H5Z_scaleoffset_compress_one_byte(unsigned char *data, size_t data_offset,
+ unsigned k, unsigned begin_i, unsigned char *buffer, size_t *j, unsigned *buf_len,
+ parms_atomic p, unsigned dtype_len)
{
- int dat_len; /* dat_len is the number of bits to be copied in each data byte */
- unsigned char val; /* value to be copied in each data byte */
+ unsigned dat_len; /* dat_len is the number of bits to be copied in each data byte */
+ unsigned char val; /* value to be copied in each data byte */
/* initialize value and bits of unsigned char to be copied */
val = data[data_offset + k];
@@ -1487,53 +1565,58 @@ int begin_i, unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p, int
dat_len = 8;
if(*buf_len > dat_len) {
- buffer[*j] |= (val & ~(~0 << dat_len)) << (*buf_len - dat_len);
+ buffer[*j] |= (unsigned char)((val & ~(~0 << dat_len)) << (*buf_len - dat_len));
*buf_len -= dat_len;
} else {
- buffer[*j] |= (val >> (dat_len - *buf_len)) & ~(~0 << *buf_len);
+ buffer[*j] |= (unsigned char)((val >> (dat_len - *buf_len)) & ~(~0 << *buf_len));
dat_len -= *buf_len;
H5Z_scaleoffset_next_byte(j, buf_len);
- if(dat_len == 0) return;
+ if(dat_len == 0)
+ return;
- buffer[*j] = (val & ~(~0 << dat_len)) << (*buf_len - dat_len);
+ buffer[*j] = (unsigned char)((val & ~(~0 << dat_len)) << (*buf_len - dat_len));
*buf_len -= dat_len;
- }
+ } /* end else */
}
-static void H5Z_scaleoffset_compress_one_atomic(unsigned char *data, size_t data_offset,
- unsigned char *buffer, size_t *j, int *buf_len, parms_atomic p)
+static void
+H5Z_scaleoffset_compress_one_atomic(unsigned char *data, size_t data_offset,
+ unsigned char *buffer, size_t *j, unsigned *buf_len, parms_atomic p)
{
/* begin_i: the index of byte having first significant bit */
- int k, begin_i, dtype_len;
+ unsigned begin_i;
+ unsigned dtype_len;
+ int k;
- assert(p.minbits > 0);
+ HDassert(p.minbits > 0);
dtype_len = p.size * 8;
if(p.mem_order == H5Z_SCALEOFFSET_ORDER_LE) { /* little endian */
begin_i = p.size - 1 - (dtype_len - p.minbits) / 8;
- for(k = begin_i; k >= 0; k--)
- H5Z_scaleoffset_compress_one_byte(data, data_offset, k, begin_i,
+ for(k = (int)begin_i; k >= 0; k--)
+ H5Z_scaleoffset_compress_one_byte(data, data_offset, (unsigned)k, begin_i,
buffer, j, buf_len, p, dtype_len);
}
-
- if(p.mem_order == H5Z_SCALEOFFSET_ORDER_BE) { /* big endian */
+ else { /* big endian */
+ HDassert(p.mem_order == H5Z_SCALEOFFSET_ORDER_BE);
begin_i = (dtype_len - p.minbits) / 8;
- for(k = begin_i; k <= p.size - 1; k++)
- H5Z_scaleoffset_compress_one_byte(data, data_offset, k, begin_i,
+ for(k = (int)begin_i; k <= (int)(p.size - 1); k++)
+ H5Z_scaleoffset_compress_one_byte(data, data_offset, (unsigned)k, begin_i,
buffer, j, buf_len, p, dtype_len);
}
}
-static void H5Z_scaleoffset_compress(unsigned char *data, unsigned d_nelmts, unsigned char *buffer,
- size_t buffer_size, parms_atomic p)
+static void
+H5Z_scaleoffset_compress(unsigned char *data, unsigned d_nelmts,
+ unsigned char *buffer, size_t buffer_size, parms_atomic p)
{
/* i: index of data, j: index of buffer,
buf_len: number of bits to be filled in current byte */
size_t i, j;
- int buf_len;
+ unsigned buf_len;
/* must initialize buffer to be zeros */
for(j = 0; j < buffer_size; j++)
@@ -1545,7 +1628,7 @@ static void H5Z_scaleoffset_compress(unsigned char *data, unsigned d_nelmts, uns
/* compress */
for(i = 0; i < d_nelmts; i++)
- H5Z_scaleoffset_compress_one_atomic(data, i*p.size, buffer, &j, &buf_len, p);
+ H5Z_scaleoffset_compress_one_atomic(data, i * p.size, buffer, &j, &buf_len, p);
}
#endif /* H5_HAVE_FILTER_SCALEOFFSET */