Decode performance: speed up the BIT_MASK macro

This commit is contained in:
Shahram Najm 2018-01-08 16:11:43 +00:00
parent 7b8a4f4f31
commit c8ace53907
2 changed files with 10 additions and 3 deletions

View File

@ -156,7 +156,7 @@ char* grib_decode_string(const unsigned char* bitStream, long *bitOffset, size_t
/* A mask with x least-significant bits set, possibly 0 or >=32 */
/* -1UL is 1111111... in every bit in binary representation */
#define BIT_MASK(x) \
(((x) >= max_nbits) ? \
(((x) == max_nbits) ? \
(unsigned long) -1UL : (1UL << (x)) - 1)
/**
* decode a value consisting of nbits from an octet-bitstream to long-representation

View File

@ -12,6 +12,13 @@
* Enrico Fucile - 19.06.2007 *
* *
***************************************************************************/
/* A mask with x least-significant bits set, possibly 0 or >=32 */
/* -1UL is 1111111... in every bit in binary representation */
#define BIT_MASK1(x) \
(((x) >= max_nbits) ? \
(unsigned long) -1UL : (1UL << (x)) - 1)
/**
* decode an array of n_vals values from a octet-stream
*
@ -24,7 +31,7 @@
int grib_decode_long_array(const unsigned char* p, long *bitp, long bitsPerValue,
size_t n_vals,long* val)
{
unsigned long mask = BIT_MASK(bitsPerValue);
unsigned long mask = BIT_MASK1(bitsPerValue);
/* pi: position of bitp in p[]. >>3 == /8 */
long pi = *bitp / 8;
@ -119,7 +126,7 @@ int grib_decode_double_array(const unsigned char* p, long *bitp, long bitsPerVal
}
else
{
unsigned long mask = BIT_MASK(bitsPerValue);
unsigned long mask = BIT_MASK1(bitsPerValue);
/* pi: position of bitp in p[]. >>3 == /8 */
long pi = *bitp / 8;