summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2004-04-12 20:49:36 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2004-04-12 20:49:36 (GMT)
commitdfe9639c9bd2ec7a331a35a2d6de6dde833621c5 (patch)
treec2133b5c3bad3037483d69692a2709d07c6cff4d /src
parent7a73740dfd87a69b960992907a317c5d12e2cc55 (diff)
downloadhdf5-dfe9639c9bd2ec7a331a35a2d6de6dde833621c5.zip
hdf5-dfe9639c9bd2ec7a331a35a2d6de6dde833621c5.tar.gz
hdf5-dfe9639c9bd2ec7a331a35a2d6de6dde833621c5.tar.bz2
[svn-r8344] Purpose: Internal function change
Description: H5T_bit_shift wasn't general enough to handle arbitory start, length. Solution: Make it be so. Platforms tested: h5committest
Diffstat (limited to 'src')
-rw-r--r--src/H5Tbit.c41
-rw-r--r--src/H5Tconv.c8
-rw-r--r--src/H5Tpkg.h2
3 files changed, 28 insertions, 23 deletions
diff --git a/src/H5Tbit.c b/src/H5Tbit.c
index c9b2b4c..5f4cfe4 100644
--- a/src/H5Tbit.c
+++ b/src/H5Tbit.c
@@ -167,50 +167,55 @@ H5T_bit_copy (uint8_t *dst, size_t dst_offset, const uint8_t *src,
* Purpose: Simulation of hardware shifting. Shifts a bit vector
* in a way similar to shifting a variable value, like
* value <<= 3, or value >>= 16. SHIFT_DIST is positive for
- * left shift, negative for right shift.
+ * left shift, negative for right shift. The bit vector starts
+ * at OFFSET and is SIZE long.
*
* Return: void
*
* Programmer: Raymond Lu
- * Wednesday, Febuary 4, 2004
+ * Monday, April 12, 2004
*
* Modifications:
*
- * Can generalize it to handle a bit vector of any START
- * position and any SIZE.
- *
*-------------------------------------------------------------------------
*/
void
-H5T_bit_shift (uint8_t *buf, ssize_t shift_dist, size_t buf_size)
+H5T_bit_shift (uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size)
{
uint8_t *tmp_buf;
- size_t buf_size_bit = 8*buf_size;
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5T_bit_shift);
/* Sanity check */
assert(buf);
- assert(buf_size);
+ assert(size);
if(!shift_dist)
goto done;
- if(ABS(shift_dist) >= buf_size_bit) {
- HDmemset(buf,0,buf_size);
+ if(ABS(shift_dist) >= size) {
+ H5T_bit_set(buf, offset, size, 0);
goto done;
}
- tmp_buf = (uint8_t*)H5MM_calloc(buf_size);
+ tmp_buf = (uint8_t*)H5MM_calloc(size/8+1);
assert(tmp_buf);
/* Shift vector by making copies */
- if(shift_dist > 0) /* left shift */
- H5T_bit_copy (tmp_buf, (size_t)shift_dist, buf, 0, (size_t)(buf_size_bit-shift_dist));
- else /* right shift */
- H5T_bit_copy(tmp_buf, 0, buf, (size_t)-shift_dist, (size_t)(buf_size_bit+shift_dist));
-
- /* Copy back the vector */
- HDmemcpy(buf,tmp_buf,buf_size);
+ if(shift_dist > 0) { /* left shift */
+ /* Copy part to be shifted to a temporary buffer */
+ H5T_bit_copy (tmp_buf, 0, buf, offset, (size_t)(size-shift_dist));
+
+ /* Copy it back to the original buffer */
+ H5T_bit_copy (buf, offset+shift_dist, tmp_buf, 0, (size_t)(size-shift_dist));
+
+ /* Zero-set the left part*/
+ H5T_bit_set(buf, offset, shift_dist, 0);
+ } else { /* right shift */
+ shift_dist = - shift_dist;
+ H5T_bit_copy(tmp_buf, 0, buf, offset+shift_dist, (size_t)(size-shift_dist));
+ H5T_bit_copy (buf, offset, tmp_buf, 0, (size_t)(size-shift_dist));
+ H5T_bit_set(buf, offset+size-shift_dist, shift_dist, 0);
+ }
/* Free temporary buffer */
H5MM_xfree(tmp_buf);
diff --git a/src/H5Tconv.c b/src/H5Tconv.c
index 23c5adc..0cd615b 100644
--- a/src/H5Tconv.c
+++ b/src/H5Tconv.c
@@ -8600,7 +8600,7 @@ H5T_conv_f_i (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
* Shift mantissa part by exponent minus mantissa size(right shift),
* or by mantissa size minus exponent(left shift).
*/
- H5T_bit_shift(int_buf, (ssize_t)(expo-src.u.f.msize), buf_size);
+ H5T_bit_shift(int_buf, (ssize_t)(expo-src.u.f.msize), 0, buf_size*8);
/* Convert to integer representation if negative.
* equivalent to ~(value - 1).
@@ -8969,7 +8969,7 @@ H5T_conv_i_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
}
/* Right shift to drop off extra bits */
- H5T_bit_shift(int_buf, (ssize_t)(dst.u.f.msize-first), buf_size);
+ H5T_bit_shift(int_buf, (ssize_t)(dst.u.f.msize-first), 0, buf_size*8);
if(do_round) {
H5T_bit_inc(int_buf, 0, buf_size*8);
@@ -8989,7 +8989,7 @@ H5T_conv_i_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
/* Right shift 1 bit to let the carried 1 fit in the mantissa,
* and increment exponent by 1.
*/
- H5T_bit_shift(int_buf, -1, buf_size);
+ H5T_bit_shift(int_buf, -1, 0, buf_size*8);
expo++;
}
}
@@ -8997,7 +8997,7 @@ H5T_conv_i_f (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, hsize_t nelmts,
} else {
/* The bit sequence can fit mantissa part. Left shift to fit in from high-order of
* bit position. */
- H5T_bit_shift(int_buf, (ssize_t)(dst.u.f.msize-first), buf_size);
+ H5T_bit_shift(int_buf, (ssize_t)(dst.u.f.msize-first), 0, buf_size*8);
}
diff --git a/src/H5Tpkg.h b/src/H5Tpkg.h
index 70a4f56..e3e6226 100644
--- a/src/H5Tpkg.h
+++ b/src/H5Tpkg.h
@@ -1070,7 +1070,7 @@ H5_DLL herr_t H5T_conv_i32le_f64le(hid_t src_id, hid_t dst_id,
/* Bit twiddling functions */
H5_DLL void H5T_bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
size_t src_offset, size_t size);
-H5_DLL void H5T_bit_shift(uint8_t *buf, ssize_t shift_dist, size_t buf_size);
+H5_DLL void H5T_bit_shift(uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size);
H5_DLL void H5T_bit_set(uint8_t *buf, size_t offset, size_t size,
hbool_t value);
H5_DLL hsize_t H5T_bit_get_d(uint8_t *buf, size_t offset, size_t size);