summaryrefslogtreecommitdiffstats
path: root/src/H5Tbit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Tbit.c')
-rw-r--r--src/H5Tbit.c138
1 files changed, 62 insertions, 76 deletions
diff --git a/src/H5Tbit.c b/src/H5Tbit.c
index c6c1777..0d8103a 100644
--- a/src/H5Tbit.c
+++ b/src/H5Tbit.c
@@ -16,17 +16,14 @@
* the bytes are in little-endian order.
*/
-#include "H5Tmodule.h" /* This source code file is part of the H5T module */
+#include "H5Tmodule.h" /* This source code file is part of the H5T module */
+#include "H5private.h" /*generic functions */
+#include "H5Eprivate.h" /*error handling */
+#include "H5MMprivate.h" /* Memory management */
+#include "H5Tpkg.h" /*data-type functions */
+#include "H5WBprivate.h" /* Wrapped Buffers */
-#include "H5private.h" /*generic functions */
-#include "H5Eprivate.h" /*error handling */
-#include "H5MMprivate.h" /* Memory management */
-#include "H5Tpkg.h" /*data-type functions */
-#include "H5WBprivate.h" /* Wrapped Buffers */
-
-
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_copy
*
@@ -37,12 +34,11 @@
*-------------------------------------------------------------------------
*/
void
-H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
- size_t src_offset, size_t size)
+H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src, size_t src_offset, size_t size)
{
- size_t shift;
- size_t mask_lo, mask_hi;
- size_t s_idx, d_idx;
+ size_t shift;
+ size_t mask_lo, mask_hi;
+ size_t s_idx, d_idx;
FUNC_ENTER_PACKAGE_NOERR
@@ -71,9 +67,9 @@ H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
*/
while (src_offset && size > 0) {
size_t nbits = MIN3(size, 8 - dst_offset, 8 - src_offset);
- size_t mask = ((size_t)1 << nbits) - 1;
+ size_t mask = ((size_t)1 << nbits) - 1;
- dst[d_idx] &= (uint8_t)~(mask << dst_offset);
+ dst[d_idx] &= (uint8_t) ~(mask << dst_offset);
dst[d_idx] = (uint8_t)(dst[d_idx] | (((src[s_idx] >> src_offset) & (uint8_t)mask) << dst_offset));
src_offset += nbits;
@@ -111,7 +107,7 @@ H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
* bits). SHIFT is three since the source must be shifted right three bits
* to line up with the destination.
*/
- shift = dst_offset;
+ shift = dst_offset;
mask_lo = ((size_t)1 << (8 - shift)) - 1;
mask_hi = (~mask_lo) & 0xff;
@@ -128,8 +124,8 @@ H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
/* Finish up */
while (size > 0) {
- size_t nbits = (size_t)MIN3 (size, 8 - dst_offset, 8 - src_offset);
- size_t mask = ((size_t)1 << nbits) - 1;
+ size_t nbits = (size_t)MIN3(size, 8 - dst_offset, 8 - src_offset);
+ size_t mask = ((size_t)1 << nbits) - 1;
dst[d_idx] &= (uint8_t)(~(mask << dst_offset));
dst[d_idx] = (uint8_t)(dst[d_idx] | (((src[s_idx] >> src_offset) & (uint8_t)mask) << dst_offset));
@@ -152,7 +148,6 @@ H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
FUNC_LEAVE_NOAPI_VOID
} /* end H5T__bit_copy() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_shift
*
@@ -173,9 +168,9 @@ H5T__bit_copy(uint8_t *dst, size_t dst_offset, const uint8_t *src,
herr_t
H5T__bit_shift(uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size)
{
- uint8_t tmp_buf[512]; /* Temporary buffer */
- H5WB_t *wb = NULL; /* Wrapped buffer for temporary buffer */
- herr_t ret_value = SUCCEED; /* Return value */
+ uint8_t tmp_buf[512]; /* Temporary buffer */
+ H5WB_t *wb = NULL; /* Wrapped buffer for temporary buffer */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
@@ -189,7 +184,7 @@ H5T__bit_shift(uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size)
if (abs_shift_dist >= size)
H5T__bit_set(buf, offset, size, 0);
else {
- size_t buf_size = (size / 8) + 1; /* Size of shift buffer needed */
+ size_t buf_size = (size / 8) + 1; /* Size of shift buffer needed */
uint8_t *shift_buf; /* Pointer to shift buffer */
/* Wrap the local buffer for serialized header info */
@@ -217,7 +212,7 @@ H5T__bit_shift(uint8_t *buf, ssize_t shift_dist, size_t offset, size_t size)
H5T__bit_set(buf, offset + size - abs_shift_dist, abs_shift_dist, 0);
}
} /* end else */
- } /* end if */
+ } /* end if */
done:
/* Release resources */
@@ -227,7 +222,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T__bit_shift() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_get_d
*
@@ -244,24 +238,24 @@ done:
uint64_t
H5T__bit_get_d(uint8_t *buf, size_t offset, size_t size)
{
- uint64_t val = 0;
- size_t i, hs;
- uint64_t ret_value = 0; /* Return value */
+ uint64_t val = 0;
+ size_t i, hs;
+ uint64_t ret_value = 0; /* Return value */
FUNC_ENTER_PACKAGE_NOERR
HDassert(8 * sizeof(val) >= size);
- H5T__bit_copy((uint8_t*)&val, (size_t)0, buf, offset, size);
- switch(H5T_native_order_g) {
+ H5T__bit_copy((uint8_t *)&val, (size_t)0, buf, offset, size);
+ switch (H5T_native_order_g) {
case H5T_ORDER_LE:
break;
case H5T_ORDER_BE:
for (i = 0, hs = sizeof(val) / 2; i < hs; i++) {
- uint8_t tmp = ((uint8_t*)&val)[i];
- ((uint8_t*)&val)[i] = ((uint8_t*)&val)[sizeof(val) - (i + 1)];
- ((uint8_t*)&val)[sizeof(val) - (i + 1)] = tmp;
+ uint8_t tmp = ((uint8_t *)&val)[i];
+ ((uint8_t *)&val)[i] = ((uint8_t *)&val)[sizeof(val) - (i + 1)];
+ ((uint8_t *)&val)[sizeof(val) - (i + 1)] = tmp;
}
break;
@@ -281,7 +275,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T__bit_get_d() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_set_d
*
@@ -294,20 +287,20 @@ done:
void
H5T__bit_set_d(uint8_t *buf, size_t offset, size_t size, uint64_t val)
{
- size_t i, hs;
+ size_t i, hs;
FUNC_ENTER_PACKAGE_NOERR
HDassert(8 * sizeof(val) >= size);
- switch(H5T_native_order_g) {
+ switch (H5T_native_order_g) {
case H5T_ORDER_LE:
break;
case H5T_ORDER_BE:
for (i = 0, hs = sizeof(val) / 2; i < hs; i++) {
- uint8_t tmp = ((uint8_t *)&val)[i];
- ((uint8_t *)&val)[i] = ((uint8_t *)&val)[sizeof(val) - (i + 1)];
+ uint8_t tmp = ((uint8_t *)&val)[i];
+ ((uint8_t *)&val)[i] = ((uint8_t *)&val)[sizeof(val) - (i + 1)];
((uint8_t *)&val)[sizeof(val) - (i + 1)] = tmp;
}
break;
@@ -320,12 +313,11 @@ H5T__bit_set_d(uint8_t *buf, size_t offset, size_t size, uint64_t val)
HDabort();
}
- H5T__bit_copy(buf, offset, (uint8_t*)&val, (size_t)0, size);
+ H5T__bit_copy(buf, offset, (uint8_t *)&val, (size_t)0, size);
FUNC_LEAVE_NOAPI_VOID
} /* end H5T__bit_set_d() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_set
*
@@ -339,7 +331,7 @@ H5T__bit_set_d(uint8_t *buf, size_t offset, size_t size, uint64_t val)
void
H5T__bit_set(uint8_t *buf, size_t offset, size_t size, hbool_t value)
{
- int idx;
+ int idx;
FUNC_ENTER_PACKAGE_NOERR
@@ -349,8 +341,8 @@ H5T__bit_set(uint8_t *buf, size_t offset, size_t size, hbool_t value)
/* The first partial byte */
if (size && offset % 8) {
- size_t nbits = MIN(size, 8 - offset);
- unsigned mask = ((unsigned)1 << nbits) - 1;
+ size_t nbits = MIN(size, 8 - offset);
+ unsigned mask = ((unsigned)1 << nbits) - 1;
if (value)
buf[idx] = (uint8_t)(buf[idx] | (mask << offset));
@@ -378,7 +370,6 @@ H5T__bit_set(uint8_t *buf, size_t offset, size_t size, hbool_t value)
FUNC_LEAVE_NOAPI_VOID
} /* end H5T__bit_set() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_find
*
@@ -397,13 +388,12 @@ H5T__bit_set(uint8_t *buf, size_t offset, size_t size, hbool_t value)
*-------------------------------------------------------------------------
*/
ssize_t
-H5T__bit_find(uint8_t *buf, size_t offset, size_t size, H5T_sdir_t direction,
- hbool_t value)
+H5T__bit_find(uint8_t *buf, size_t offset, size_t size, H5T_sdir_t direction, hbool_t value)
{
- ssize_t base = (ssize_t)offset;
- ssize_t idx, i;
- size_t iu;
- ssize_t ret_value = (-1); /* Return value */
+ ssize_t base = (ssize_t)offset;
+ ssize_t idx, i;
+ size_t iu;
+ ssize_t ret_value = (-1); /* Return value */
/* Use FUNC_ENTER_PACKAGE_NOERR here to avoid performance issues */
FUNC_ENTER_PACKAGE_NOERR
@@ -486,7 +476,6 @@ done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T__bit_find() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_inc
*
@@ -500,9 +489,9 @@ done:
hbool_t
H5T__bit_inc(uint8_t *buf, size_t start, size_t size)
{
- size_t idx = start / 8;
- unsigned carry = 1;
- unsigned acc, mask;
+ size_t idx = start / 8;
+ unsigned carry = 1;
+ unsigned acc, mask;
/* Use FUNC_ENTER_PACKAGE_NOERR here to avoid performance issues */
FUNC_ENTER_PACKAGE_NOERR
@@ -513,7 +502,7 @@ H5T__bit_inc(uint8_t *buf, size_t start, size_t size)
/* The first partial byte */
if (start) {
- if(size + start < 8)
+ if (size + start < 8)
mask = ((unsigned)1 << size) - 1;
else
mask = ((unsigned)1 << (8 - start)) - 1;
@@ -531,7 +520,7 @@ H5T__bit_inc(uint8_t *buf, size_t start, size_t size)
while (carry && size >= 8) {
acc = buf[idx];
acc++;
- carry = acc & 0x100;
+ carry = acc & 0x100;
buf[idx] = (uint8_t)(acc & 0xff);
idx++;
size -= 8;
@@ -540,7 +529,7 @@ H5T__bit_inc(uint8_t *buf, size_t start, size_t size)
/* The last bits */
if (carry && size > 0) {
mask = ((unsigned)1 << size) - 1;
- acc = buf[idx] & mask;
+ acc = buf[idx] & mask;
acc++;
carry = acc & ((unsigned)1 << size);
buf[idx] &= (uint8_t)(~mask);
@@ -550,7 +539,6 @@ H5T__bit_inc(uint8_t *buf, size_t start, size_t size)
FUNC_LEAVE_NOAPI(carry ? TRUE : FALSE)
} /* end H5T__bit_inc() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_dec
*
@@ -565,10 +553,10 @@ H5T__bit_inc(uint8_t *buf, size_t start, size_t size)
hbool_t
H5T__bit_dec(uint8_t *buf, size_t start, size_t size)
{
- size_t idx = start / 8;
- size_t pos = start % 8;
- uint8_t tmp;
- unsigned borrow = 0;
+ size_t idx = start / 8;
+ size_t pos = start % 8;
+ uint8_t tmp;
+ unsigned borrow = 0;
/* Use FUNC_ENTER_PACKAGE_NOERR here to avoid performance issues */
FUNC_ENTER_PACKAGE_NOERR
@@ -617,18 +605,17 @@ H5T__bit_dec(uint8_t *buf, size_t start, size_t size)
* and get 10111100. A bit is borrowed from 6th bit(buf[idx]>>6=00000010, tmp>>6=00000011,
* not equal). We need to put this bit back by increment 1000000.
*/
- tmp = buf[idx];
+ tmp = buf[idx];
buf[idx] = (uint8_t)(buf[idx] - (1 << pos));
if ((buf[idx] >> (pos + size)) != tmp >> (pos + size)) {
buf[idx] = (uint8_t)(buf[idx] + (1 << (pos + size)));
- borrow = 1;
+ borrow = 1;
}
}
FUNC_LEAVE_NOAPI(borrow ? TRUE : FALSE)
} /* end H5T__bit_dec() */
-
/*-------------------------------------------------------------------------
* Function: H5T__bit_neg
*
@@ -642,9 +629,9 @@ H5T__bit_dec(uint8_t *buf, size_t start, size_t size)
void
H5T__bit_neg(uint8_t *buf, size_t start, size_t size)
{
- size_t idx = start / 8;
- size_t pos = start % 8;
- uint8_t tmp[1];
+ size_t idx = start / 8;
+ size_t pos = start % 8;
+ uint8_t tmp[1];
/* Use FUNC_ENTER_PACKAGE_NOERR here to avoid performance issues */
FUNC_ENTER_PACKAGE_NOERR
@@ -656,30 +643,29 @@ H5T__bit_neg(uint8_t *buf, size_t start, size_t size)
tmp[0] = (uint8_t)~buf[idx];
/* Simply copy the negated bit field back to the original byte */
- if((size + start - 1) / 8 > idx) { /*bit sequence doesn't end in the same byte as starts*/
- H5T__bit_copy(&(buf[idx]), pos, tmp, pos, (8-pos));
+ if ((size + start - 1) / 8 > idx) { /*bit sequence doesn't end in the same byte as starts*/
+ H5T__bit_copy(&(buf[idx]), pos, tmp, pos, (8 - pos));
idx++;
size -= (8 - pos);
/* The middle bytes */
- while(size >= 8) {
- buf[idx] = (uint8_t)~(buf[idx]);
+ while (size >= 8) {
+ buf[idx] = (uint8_t) ~(buf[idx]);
idx++;
size -= 8;
}
/* The last partial byte */
- if(size > 0) {
+ if (size > 0) {
/* Similar to the first byte case, where sequence ends in the same byte as starts */
tmp[0] = (uint8_t)~buf[idx];
H5T__bit_copy(&(buf[idx]), (size_t)0, tmp, (size_t)0, size);
}
}
- else {
+ else {
/* bit sequence ends in the same byte as starts */
H5T__bit_copy(&(buf[idx]), pos, tmp, pos, size);
}
FUNC_LEAVE_NOAPI_VOID
} /* end H5T__bit_neg() */
-