summaryrefslogtreecommitdiffstats
path: root/src/H5Tbit.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-06-30 21:30:28 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-06-30 21:30:28 (GMT)
commit1b3a1f8014b630208013c7a18cfe8e7c0539e161 (patch)
tree442600fb6f75f8dbde490f48d2a8ccba7c823164 /src/H5Tbit.c
parent030d46c078b7ef61468703dabb4861212ecb13ca (diff)
downloadhdf5-1b3a1f8014b630208013c7a18cfe8e7c0539e161.zip
hdf5-1b3a1f8014b630208013c7a18cfe8e7c0539e161.tar.gz
hdf5-1b3a1f8014b630208013c7a18cfe8e7c0539e161.tar.bz2
[svn-r437] Changes since 19980612
---------------------- ./src/H5Tbit.c ./src/H5Tpkg.h Fixed a bug in H5T_bit_copy(). Added H5T_bit_get_d() and H5T_bit_set_d() which treat portions of a bit vector as an unsigned integer. Added H5T_bit_inc() that increments part of a bit vector and returns an indication of overflow. ./src/H5Tconv.c ./src/H5Tpkg.h ./test/dtypes.c Added a slow general floating point conversion which works so far on Intel, MIPS, and DEC but the test is turned off because a cast from double to float will cause a SIGFPE on some systems if an overflow occurs. Added fast hardware conversions between native floating point types. This function is also subject to the SIGFPE problem. ./src/H5detect.c Removed the exponent bias adjustment when the significand isn't normalized. This is now handled in the conversion functions instead. ./src/H5T.c Register new conversion functions. Plugged a memory leak in the library termination code. ./RELEASE Added a list of major changes since the first alpha. ./src/H5.c ./src/H5private.h ./src/H5A.c ./src/H5AC.c ./src/H5D.c ./src/H5Ffamily.c ./src/H5Fistore.c ./src/H5G.c ./src/H5Gprivate.h ./src/H5HG.c ./src/H5O.c ./src/H5T.c ./src/H5Tbit.c ./src/H5Tconv.c Fixed various compiler warnings on Irix64. ./src/H5MM.c Added PABLO_MASK to this file. ./test/chunk.c Removed a warning about memcpy().
Diffstat (limited to 'src/H5Tbit.c')
-rw-r--r--src/H5Tbit.c176
1 files changed, 168 insertions, 8 deletions
diff --git a/src/H5Tbit.c b/src/H5Tbit.c
index b9a830d..d80c8b3 100644
--- a/src/H5Tbit.c
+++ b/src/H5Tbit.c
@@ -11,8 +11,15 @@
*/
#define H5T_PACKAGE
#include <H5private.h>
+#include <H5Eprivate.h>
+#include <H5Iprivate.h>
#include <H5Tpkg.h>
+/* Interface initialization */
+#define PABLO_MASK H5Tbit_mask
+static intn interface_initialize_g = FALSE;
+#define INTERFACE_INIT NULL
+
/*-------------------------------------------------------------------------
* Function: H5T_bit_copy
@@ -40,8 +47,8 @@ H5T_bit_copy (uint8 *dst, size_t dst_offset, const uint8 *src,
* Normalize the offset to be a byte number and a bit offset within that
* byte.
*/
- s_idx = src_offset / 8;
- d_idx = dst_offset / 8;
+ s_idx = (intn)src_offset / 8;
+ d_idx = (intn)dst_offset / 8;
src_offset %= 8;
dst_offset %= 8;
@@ -62,7 +69,7 @@ H5T_bit_copy (uint8 *dst, size_t dst_offset, const uint8 *src,
* dst[d_idx+1] dst[d_idx]
*/
while (src_offset && size>0) {
- unsigned nbits = MIN3 (size, 8-dst_offset, 8-src_offset);
+ unsigned nbits = (unsigned)MIN3 (size, 8-dst_offset, 8-src_offset);
unsigned mask = (1<<nbits) - 1;
dst[d_idx] &= ~(mask<<dst_offset);
@@ -102,9 +109,9 @@ H5T_bit_copy (uint8 *dst, size_t dst_offset, const uint8 *src,
* bits). SHIFT is three since the source must be shifted right three bits
* to line up with the destination.
*/
- shift = dst_offset;
+ shift = (intn)dst_offset;
mask_lo = (1<<(8-shift))-1;
- mask_hi = ~mask_lo;
+ mask_hi = (~mask_lo) & 0xff;
for (/*void*/; size>8; size-=8, d_idx++, s_idx++) {
if (shift) {
@@ -119,7 +126,7 @@ H5T_bit_copy (uint8 *dst, size_t dst_offset, const uint8 *src,
/* Finish up */
while (size>0) {
- unsigned nbits = MIN3 (size, 8-dst_offset, 8-src_offset);
+ unsigned nbits = (unsigned)MIN3 (size, 8-dst_offset, 8-src_offset);
unsigned mask = (1<<nbits) - 1;
dst[d_idx] &= ~(mask<<dst_offset);
@@ -141,6 +148,94 @@ H5T_bit_copy (uint8 *dst, size_t dst_offset, const uint8 *src,
/*-------------------------------------------------------------------------
+ * Function: H5T_bit_get_d
+ *
+ * Purpose: Return a small bit sequence as a number.
+ *
+ * Return: Success: The bit sequence interpretted as an unsigned
+ * integer.
+ *
+ * Failure: 0
+ *
+ * Programmer: Robb Matzke
+ * Tuesday, June 23, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hsize_t
+H5T_bit_get_d (uint8 *buf, size_t offset, size_t size)
+{
+ hsize_t val=0;
+ size_t i, hs;
+
+ FUNC_ENTER (H5T_bit_get_d, 0);
+ assert (8*sizeof(val)>=size);
+
+ H5T_bit_copy ((uint8*)&val, 0, buf, offset, size);
+ switch (((H5T_t*)(H5I_object(H5T_NATIVE_INT_g)))->u.atomic.order) {
+ case H5T_ORDER_LE:
+ break;
+
+ case H5T_ORDER_BE:
+ for (i=0, hs=sizeof(val)/2; i<hs; i++) {
+ uint8 tmp = ((uint8*)&val)[i];
+ ((uint8*)&val)[i] = ((uint8*)&val)[sizeof(val)-(i+1)];
+ ((uint8*)&val)[sizeof(val)-(i+1)] = tmp;
+ }
+ break;
+
+ default:
+ abort ();
+ }
+
+ FUNC_LEAVE (val);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_bit_set_d
+ *
+ * Purpose: Sets part of a bit vector to the specified unsigned value.
+ *
+ * Return: void
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, June 24, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+void
+H5T_bit_set_d (uint8 *buf, size_t offset, size_t size, hsize_t val)
+{
+ size_t i, hs;
+
+ assert (8*sizeof(val)>=size);
+
+ switch (((H5T_t*)(H5I_object(H5T_NATIVE_INT_g)))->u.atomic.order) {
+ case H5T_ORDER_LE:
+ break;
+
+ case H5T_ORDER_BE:
+ for (i=0, hs=sizeof(val)/2; i<hs; i++) {
+ uint8 tmp = ((uint8*)&val)[i];
+ ((uint8*)&val)[i] = ((uint8*)&val)[sizeof(val)-(i+1)];
+ ((uint8*)&val)[sizeof(val)-(i+1)] = tmp;
+ }
+ break;
+
+ default:
+ abort ();
+ }
+
+ H5T_bit_copy (buf, offset, (uint8*)&val, 0, size);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: H5T_bit_set
*
* Purpose: Sets or clears bits in a contiguous region of a vector
@@ -161,7 +256,7 @@ H5T_bit_set (uint8 *buf, size_t offset, size_t size, hbool_t value)
intn idx;
/* Normalize */
- idx = offset / 8;
+ idx = (intn)offset / 8;
offset %= 8;
/* The first partial byte */
@@ -217,7 +312,7 @@ ssize_t
H5T_bit_find (uint8 *buf, size_t offset, size_t size, H5T_sdir_t direction,
hbool_t value)
{
- size_t base=offset;
+ ssize_t base=(ssize_t)offset;
ssize_t idx, i;
/* Some functions call this with value=TRUE */
@@ -300,3 +395,68 @@ H5T_bit_find (uint8 *buf, size_t offset, size_t size, H5T_sdir_t direction,
return -1;
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5T_bit_inc
+ *
+ * Purpose: Increment part of a bit field by adding 1.
+ *
+ * Return: Success: The carry-out value, one if overflow zero
+ * otherwise.
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Robb Matzke
+ * Friday, June 26, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hbool_t
+H5T_bit_inc(uint8 *buf, size_t start, size_t size)
+{
+ size_t idx = start / 8;
+ unsigned carry = 1;
+ unsigned acc, mask;
+
+ assert(buf);
+ start %= 8;
+
+ /* The first partial byte */
+ if (start) {
+ if (size+start<8) mask = (1<<size)-1;
+ else mask = (1<<(8-start))-1;
+ acc = (buf[idx]>>start) & mask;
+ acc += 1;
+ carry = acc & (1<<MIN(size, 8-start));
+ buf[idx] &= ~(mask<<start);
+ buf[idx] |= (acc & mask) << start;
+ size -= MIN(size, 8-start);
+ start=0;
+ idx++;
+ }
+
+ /* The middle */
+ while (carry && size>=8) {
+ acc = buf[idx];
+ acc += 1;
+ carry = acc & 0x100;
+ buf[idx] = acc & 0xff;
+ idx++;
+ size -= 8;
+ }
+
+ /* The last bits */
+ if (carry && size>0) {
+ mask = (1<<size)-1;
+ acc = buf[idx] & mask;
+ acc += 1;
+ carry = acc & (1<<size);
+ buf[idx] &= ~mask;
+ buf[idx] |= acc & mask;
+ }
+
+ return carry ? TRUE : FALSE;
+}