Harlequin RIP SDK
Harlequin standard bit and byte operations

Files

file  hqbitops.h
 Common byte and bitwise operations with optimised versions for various architectures.
 
file  hqbitvector.h
 Macros implementing bit vectors.
 

Macros

#define BYTE_LOAD16_UNSIGNED_LE(ptr_)    (uint16)(((uint8 *)(ptr_))[0] | (((uint8 *)(ptr_))[1] << 8))
 
#define BYTE_LOAD16_UNSIGNED_BE(ptr_)    (uint16)(((uint8 *)(ptr_))[1] | (((uint8 *)(ptr_))[0] << 8))
 
#define BYTE_LOAD16_UNSIGNED_PLATFORM   BYTE_LOAD16_UNSIGNED_LE
 
#define BYTE_LOAD16_SIGNED_LE(ptr_)   (int16)BYTE_LOAD16_UNSIGNED_LE(ptr_)
 
#define BYTE_LOAD16_SIGNED_BE(ptr_)   (int16)BYTE_LOAD16_UNSIGNED_BE(ptr_)
 
#define BYTE_LOAD16_SIGNED_PLATFORM   BYTE_LOAD16_SIGNED_LE
 
#define BYTE_LOAD32_UNSIGNED_LE(ptr_)
 
#define BYTE_LOAD32_UNSIGNED_BE(ptr_)
 
#define BYTE_LOAD32_UNSIGNED_PLATFORM   BYTE_LOAD32_UNSIGNED_LE
 
#define BYTE_LOAD32_SIGNED_LE(ptr_)   (int32)BYTE_LOAD32_UNSIGNED_LE(ptr_)
 
#define BYTE_LOAD32_SIGNED_BE(ptr_)   (int32)BYTE_LOAD32_UNSIGNED_BE(ptr_)
 
#define BYTE_LOAD32_SIGNED_PLATFORM   BYTE_LOAD32_SIGNED_LE
 
#define BYTE_LOAD64_UNSIGNED_LE(ptr_)
 
#define BYTE_LOAD64_UNSIGNED_BE(ptr_)
 
#define BYTE_LOAD64_UNSIGNED_PLATFORM   BYTE_LOAD64_UNSIGNED_LE
 
#define BYTE_LOAD64_SIGNED_LE(ptr_)   (int64)BYTE_LOAD64_UNSIGNED_LE(ptr_)
 
#define BYTE_LOAD64_SIGNED_BE(ptr_)   (int64)BYTE_LOAD64_UNSIGNED_BE(ptr_)
 
#define BYTE_LOAD64_SIGNED_PLATFORM   BYTE_LOAD64_SIGNED_LE
 
#define BYTE_STORE16_LE(ptr_, val_)
 
#define BYTE_STORE16_BE(ptr_, val_)
 
#define BYTE_STORE16_PLATFORM   BYTE_STORE16_LE
 
#define BYTE_STORE32_LE(ptr_, val_)
 
#define BYTE_STORE32_BE(ptr_, val_)
 
#define BYTE_STORE32_PLATFORM   BYTE_STORE32_LE
 
#define BYTE_STORE64_LE(ptr_, val_)
 
#define BYTE_STORE64_BE(ptr_, val_)
 
#define BYTE_STORE64_PLATFORM   BYTE_STORE64_LE
 
#define MASK_BYTES_1(type_)   (type_)(~(type_)0 / 0xffu)
 
#define MASK_SHORTS_1(type_)   (type_)(~(type_)0 / 0xffffu)
 
#define MASK_WORDS_1(type_)   (type_)(~(type_)0 / 0xffffffffu)
 
#define MASK_ALTERNATE_BYTES(type_)   (type_)(MASK_SHORTS_1(type_) * 0xffu)
 
#define MASK_ALTERNATE_SHORTS(type_)   (type_)(MASK_WORDS_1(type_) * 0xffffu)
 
#define BYTE_SWAP16_UNSIGNED(val_)    (uint16)((uint8)(val_) << 8 | (uint16)(val_) >> 8)
 
#define BYTE_SWAP16_UNSIGNED(val_)    _byteswap_ushort((unsigned short)(val_))
 
#define BYTE_SWAP16_SIGNED(val_)   (int16)BYTE_SWAP16_UNSIGNED(val_)
 
#define BYTE_SWAP16_PTR(ptr_)
 
#define BYTE_SWAP16_PTR(ptr_)    _swab((char *)(ptr_), (char *)(ptr_), 2)
 
#define BYTE_SWAP16_UNSIGNED_VAR(to_, from_)
 
#define BYTE_SWAP16_BUFFER(to_, from_, bytes_)
 
#define BYTE_SWAP16_BUFFER(to_, from_, bytes_)    _swab((char *)(from_), (char *)(to_), (int)(bytes_))
 
#define BYTE_SWAP32_UNSIGNED(val_)
 
#define BYTE_SWAP32_UNSIGNED(val_)    _byteswap_ulong((unsigned long)(val_))
 
#define BYTE_SWAP32_SIGNED(val_)   (int32)BYTE_SWAP32_UNSIGNED(val_)
 
#define BYTE_SWAP32_PTR(ptr_)
 
#define BYTE_SWAP32_PTR(ptr_)
 
#define BYTE_SWAP32_UNSIGNED_VAR(to_, from_)
 
#define BYTE_SWAP32_BUFFER(to_, from_, bytes_)
 
#define BYTE_SWAP32_BUFFER_UNALIGNED(to_, from_, bytes_)
 
#define BYTE_SWAP32_BUFFER_UNALIGNED   BYTE_SWAP32_BUFFER
 
#define BYTE_SWAP64_UNSIGNED(val_)
 
#define BYTE_SWAP64_UNSIGNED(val_)    _byteswap_uint64((unsigned __int64)(val_))
 
#define BYTE_SWAP64_SIGNED(val_)   (int64)BYTE_SWAP64_UNSIGNED(val_)
 
#define BYTE_SWAP64_PTR(ptr_)
 
#define BYTE_SWAP64_PTR(ptr_)
 
#define BYTE_SWAP64_UNSIGNED_VAR(to_, from_)
 
#define BYTE_SWAP64_BUFFER(to_, from_, bytes_)
 
#define BYTE_SWAP64_BUFFER_UNALIGNED(to_, from_, bytes_)
 
#define BYTE_SWAP64_BUFFER_UNALIGNED   BYTE_SWAP64_BUFFER
 
#define SIGN32_NEG(x)   -(int32)((uint32)((int32)(x)) >> 31)
 
#define SIGN32_NEG(x)   ((int32)(x) >> 31)
 
#define SIGN64_NEG(x)   -(int64)((uint64)((int64)(x)) >> 63)
 
#define SIGN64_NEG(x)   ((int64)(x) >> 63)
 
#define SIGN32(x)   (SIGN32_NEG(x) - SIGN32_NEG(-(x)))
 
#define SIGN64(x)   (SIGN64_NEG(x) - SIGN64_NEG(-(x)))
 
#define BIT_ROTATE32_LEFT(to_, from_, shift_)
 
#define BIT_ROTATE32_LEFT(to_, from_, shift_)
 
#define BIT_ROTATE32_RIGHT(to_, from_, shift_)
 
#define BIT_ROTATE32_RIGHT(to_, from_, shift_)
 
#define BIT_ROTATE32_LEFT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE32_LEFT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE32_RIGHT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE32_RIGHT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE64_LEFT(to_, from_, shift_)
 
#define BIT_ROTATE64_LEFT(to_, from_, shift_)
 
#define BIT_ROTATE64_RIGHT(to_, from_, shift_)
 
#define BIT_ROTATE64_RIGHT(to_, from_, shift_)
 
#define BIT_ROTATE64_LEFT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE64_LEFT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE64_RIGHT_SAFE(to_, from_, shift_)
 
#define BIT_ROTATE64_RIGHT_SAFE(to_, from_, shift_)
 
#define BIT_SHIFT32_SIGNED_RIGHT_EXPR(val_, shift_)    ((int32)((uint32)(val_) >> (shift_)) | (SIGN32_NEG(val_) << (31 ^ (shift_))))
 
#define BIT_SHIFT32_SIGNED_RIGHT_EXPR(val_, shift_)    ((int32)(val_) >> (shift_))
 
#define BIT_SHIFT32_SIGNED_RIGHT(to_, from_, shift_)
 
#define BIT_SHIFT64_SIGNED_RIGHT_EXPR(val_, shift_)    ((int64)((uint64)(val_) >> (shift_)) | (SIGN64_NEG(val_) << (63 ^ (shift_))))
 
#define BIT_SHIFT64_SIGNED_RIGHT_EXPR(val_, shift_)    ((int64)(val_) >> (shift_))
 
#define BIT_SHIFT64_SIGNED_RIGHT(to_, from_, shift_)
 
#define INLINE_MIN32(min_, a_, b_)
 
#define INLINE_MAX32(max_, a_, b_)
 
#define INLINE_MINMAX32(min_, max_, a_, b_)
 
#define INLINE_ABS32(abs_, val_)
 
#define INLINE_RANGE32(to_, from_, min_, max_)
 
#define INLINE_RANGE32_0(to_, from_, max_)
 
#define INLINE_MIN64(min_, a_, b_)
 
#define INLINE_MAX64(max_, a_, b_)
 
#define INLINE_MINMAX64(min_, max_, a_, b_)
 
#define INLINE_ABS64(abs_, val_)
 
#define INLINE_RANGE64(to_, from_, min_, max_)
 
#define INLINE_RANGE64_0(to_, from_, max_)
 
#define BIT_LOWEST_SET_32(_n_)   ((uint32)(_n_) & -(int32)(_n_))
 
#define BIT_LOWEST_CLEAR_32(_n_)   BIT_LOWEST_SET_32(~(uint32)(_n_))
 
#define BIT_AT_MOST_ONE_SET_32(_n_)   ((_n_) == BIT_LOWEST_SET_32(_n_))
 
#define BIT_EXACTLY_ONE_SET_32(_n_)   ((_n_) != 0 && BIT_AT_MOST_ONE_SET_32(_n_))
 
#define BIT_LOWEST_SET_64(_n_)   ((uint64)(_n_) & -(int64)(_n_))
 
#define BIT_LOWEST_CLEAR_64(_n_)   BIT_LOWEST_SET_64(~(uint64)(_n_))
 
#define BIT_AT_MOST_ONE_SET_64(_n_)   ((_n_) == BIT_LOWEST_SET_64(_n_))
 
#define BIT_EXACTLY_ONE_SET_64(_n_)   ((_n_) != 0 && BIT_AT_MOST_ONE_SET_64(_n_))
 
#define BIT_COUNT_TRAILING_ZEROS_32(n_, i_)
 
#define BIT_COUNT_TRAILING_ZEROS_32(n_, i_)
 
#define BIT_LOWEST_SET_INDEX_32(n_, i_)
 
#define BIT_LOWEST_SET_INDEX_32(n_, i_)
 
#define BIT_COUNT_LEADING_ZEROS_32(n_, i_)
 
#define BIT_COUNT_LEADING_ZEROS_32(n_, i_)
 
#define BIT_HIGHEST_SET_INDEX_32(n_, i_)
 
#define BIT_HIGHEST_SET_INDEX_32(n_, i_)
 
#define BIT_COUNT_TRAILING_ZEROS_64(n_, i_)
 
#define BIT_COUNT_TRAILING_ZEROS_64(n_, i_)
 
#define BIT_LOWEST_SET_INDEX_64(n_, i_)
 
#define BIT_LOWEST_SET_INDEX_64(n_, i_)
 
#define BIT_COUNT_LEADING_ZEROS_64(n_, i_)
 
#define BIT_COUNT_LEADING_ZEROS_64(n_, i_)
 
#define BIT_HIGHEST_SET_INDEX_64(n_, i_)
 
#define BIT_HIGHEST_SET_INDEX_64(n_, i_)
 

Detailed Description

Macro Definition Documentation

◆ BIT_AT_MOST_ONE_SET_32

#define BIT_AT_MOST_ONE_SET_32 (   _n_)    ((_n_) == BIT_LOWEST_SET_32(_n_))

Predicate to determine if zero or one bits are set in a 32-bit integer.

◆ BIT_AT_MOST_ONE_SET_64

#define BIT_AT_MOST_ONE_SET_64 (   _n_)    ((_n_) == BIT_LOWEST_SET_64(_n_))

Predicate to determine if zero or one bits are set in a 64-bit integer.

◆ BIT_COUNT_LEADING_ZEROS_32 [1/2]

#define BIT_COUNT_LEADING_ZEROS_32 (   n_,
  i_ 
)
Value:
MACRO_START \
uint32 _n_ = (uint32)(n_) ; \
_n_ |= _n_ >> 16 ; \
_n_ |= _n_ >> 8 ; \
_n_ |= _n_ >> 4 ; \
_n_ |= _n_ >> 2 ; \
_n_ |= _n_ >> 1 ; \
i_ = ("\040\037\200\200\005\036\200\200\200\200\004\200\020\035\200\200\200\200\200\200\200\013\003\200\200\200\011\017\025\034\001\200\200\006\200\200\200\021\200\200\200\014\200\200\012\026\002\007\200\022\200\015\200\027\010\023\016\030\024\031\032\033\000\200"[(_n_ * 0x7ef3ae3u) >> 26]) ; \
MACRO_END
unsigned int uint32
32-bit unsigned integer
Definition: hqtypes.h:126

The number of leading zeros in a 32-bit integer. The count is set to 32 if there are no bits set on input. This is equivalent to 31-BIT_HIGHEST_SET_INDEX_32().

◆ BIT_COUNT_LEADING_ZEROS_32 [2/2]

#define BIT_COUNT_LEADING_ZEROS_32 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanReverse(&_r_, (unsigned long)(n_)) ? 31 - _r_ : 32 ; \
MACRO_END

The number of leading zeros in a 32-bit integer. The count is set to 32 if there are no bits set on input. This is equivalent to 31-BIT_HIGHEST_SET_INDEX_32().

◆ BIT_COUNT_LEADING_ZEROS_64 [1/2]

#define BIT_COUNT_LEADING_ZEROS_64 (   n_,
  i_ 
)
Value:
MACRO_START \
uint64 _n_ = (uint64)(n_) ; \
_n_ |= _n_ >> 32 ; \
_n_ |= _n_ >> 16 ; \
_n_ |= _n_ >> 8 ; \
_n_ |= _n_ >> 4 ; \
_n_ |= _n_ >> 2 ; \
_n_ |= _n_ >> 1 ; \
i_ = ("\100\077\005\200\200\076\004\200\200\200\200\200\040\075\003\200\200\200\200\200\200\014\200\200\200\200\021\037\055\074\002\200\200\200\200\200\200\023\200\200\200\200\200\200\013\047\200\200\200\200\200\200\200\032\011\020\027\036\045\054\063\073\001\200\006\200\200\200\200\041\200\200\200\015\200\200\022\056\200\200\200\024\200\200\200\050\200\200\200\033\012\030\046\064\200\007\200\042\200\016\200\057\200\025\200\051\200\034\031\065\010\043\017\060\026\052\035\066\044\061\053\067\062\070\071\072\000\200"[(_n_ * UINT64(0x3fbe7af1dba72e1)) >> 57]) ; \
MACRO_END
unsigned uint64
64-bit unsigned integer
Definition: hqtypes.h:136

The number of leading zeros in a 64-bit integer. The count is set to 64 if there are no bits set on input. This is equivalent to 63-BIT_HIGHEST_SET_INDEX_64().

◆ BIT_COUNT_LEADING_ZEROS_64 [2/2]

#define BIT_COUNT_LEADING_ZEROS_64 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanReverse64(&_r_, (unsigned __int64)(n_)) ? 63 - _r_ : 64 ; \
MACRO_END

The number of leading zeros in a 64-bit integer. The count is set to 64 if there are no bits set on input. This is equivalent to 63-BIT_HIGHEST_SET_INDEX_64().

◆ BIT_COUNT_TRAILING_ZEROS_32 [1/2]

#define BIT_COUNT_TRAILING_ZEROS_32 (   n_,
  i_ 
)
Value:
MACRO_START \
i_ = ("\040\000\200\001\200\200\033\002\200\200\200\200\034\200\020\003\200\200\200\200\200\200\200\025\035\200\200\200\027\021\013\004\037\200\200\032\200\200\200\017\200\200\200\024\200\200\026\012\036\031\200\016\200\023\200\011\030\015\022\010\014\007\006\005"[(BIT_LOWEST_SET_32(n_) * 0x7ef3ae3u) >> 26]) ; \
MACRO_END
#define BIT_LOWEST_SET_32(_n_)
Definition: hqbitops.h:830

The number of trailing zeros in a 32-bit integer. The count is set to 32 if there are no bits set on input. Apart from the zero case, this is the same as BIT_LOWEST_SET_INDEX_32().

◆ BIT_COUNT_TRAILING_ZEROS_32 [2/2]

#define BIT_COUNT_TRAILING_ZEROS_32 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanForward(&_r_, (unsigned long)(n_)) ? _r_ : 32 ; \
MACRO_END

The number of trailing zeros in a 32-bit integer. The count is set to 32 if there are no bits set on input. Apart from the zero case, this is the same as BIT_LOWEST_SET_INDEX_32().

◆ BIT_COUNT_TRAILING_ZEROS_64 [1/2]

#define BIT_COUNT_TRAILING_ZEROS_64 (   n_,
  i_ 
)
Value:
MACRO_START \
i_ = ("\100\000\200\001\073\200\200\002\074\200\200\200\200\200\040\003\075\200\200\200\200\200\200\064\200\200\200\200\057\041\023\004\076\200\200\200\200\200\200\055\200\200\200\200\200\200\065\031\200\200\200\200\200\200\200\046\067\060\051\042\033\024\015\005\077\200\072\200\200\200\200\037\200\200\200\063\200\200\056\022\200\200\200\054\200\200\200\030\200\200\200\045\066\050\032\014\200\071\200\036\200\062\200\021\200\053\200\027\200\044\047\013\070\035\061\020\052\026\043\012\034\017\025\011\016\010\007\006"[(BIT_LOWEST_SET_64(n_) * UINT64(0x3fbe7af1dba72e1)) >> 57]) ; \
MACRO_END
#define BIT_LOWEST_SET_64(_n_)
Definition: hqbitops.h:842

The number of trailing zeros in a 64-bit integer. The count is set to 64 if there are no bits set on input. Apart from the zero case, this is the same as BIT_LOWEST_SET_INDEX_64().

◆ BIT_COUNT_TRAILING_ZEROS_64 [2/2]

#define BIT_COUNT_TRAILING_ZEROS_64 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanForward64(&_r_, (unsigned __int64)(n_)) ? _r_ : 64 ; \
MACRO_END

The number of trailing zeros in a 64-bit integer. The count is set to 64 if there are no bits set on input. Apart from the zero case, this is the same as BIT_LOWEST_SET_INDEX_64().

◆ BIT_EXACTLY_ONE_SET_32

#define BIT_EXACTLY_ONE_SET_32 (   _n_)    ((_n_) != 0 && BIT_AT_MOST_ONE_SET_32(_n_))

Predicate to determine if one bit is set in a 32-bit integer.

◆ BIT_EXACTLY_ONE_SET_64

#define BIT_EXACTLY_ONE_SET_64 (   _n_)    ((_n_) != 0 && BIT_AT_MOST_ONE_SET_64(_n_))

Predicate to determine if one bit is set in a 64-bit integer.

◆ BIT_HIGHEST_SET_INDEX_32 [1/2]

#define BIT_HIGHEST_SET_INDEX_32 (   n_,
  i_ 
)
Value:
i_ = 31 - i_ ; \
MACRO_END
#define BIT_COUNT_LEADING_ZEROS_32(n_, i_)
Definition: hqbitops.h:943

Index of most significant bit set of a 32-bit integer. The index is set to -1 if there are no bits set on input. This is equivalent to 31-BIT_COUNT_LEADING_ZEROS_32().

◆ BIT_HIGHEST_SET_INDEX_32 [2/2]

#define BIT_HIGHEST_SET_INDEX_32 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanReverse(&_r_, (unsigned long)(n_)) ? _r_ : -1 ; \
MACRO_END

Index of most significant bit set of a 32-bit integer. The index is set to -1 if there are no bits set on input. This is equivalent to 31-BIT_COUNT_LEADING_ZEROS_32().

◆ BIT_HIGHEST_SET_INDEX_64 [1/2]

#define BIT_HIGHEST_SET_INDEX_64 (   n_,
  i_ 
)
Value:
i_ = 63 - i_ ; \
MACRO_END
#define BIT_COUNT_LEADING_ZEROS_64(n_, i_)
Definition: hqbitops.h:972

Index of most significant bit set of a 64-bit integer. The index is set to -1 if there are no bits set on input. This is equivalent to 63-BIT_COUNT_LEADING_ZEROS_64().

◆ BIT_HIGHEST_SET_INDEX_64 [2/2]

#define BIT_HIGHEST_SET_INDEX_64 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanReverse64(&_r_, (unsigned __int64)(n_)) ? _r_ : -1 ; \
MACRO_END

Index of most significant bit set of a 64-bit integer. The index is set to -1 if there are no bits set on input. This is equivalent to 63-BIT_COUNT_LEADING_ZEROS_64().

◆ BIT_LOWEST_CLEAR_32

#define BIT_LOWEST_CLEAR_32 (   _n_)    BIT_LOWEST_SET_32(~(uint32)(_n_))

Masks to the least significant bit clear for 32-bit integers.

◆ BIT_LOWEST_CLEAR_64

#define BIT_LOWEST_CLEAR_64 (   _n_)    BIT_LOWEST_SET_64(~(uint64)(_n_))

Masks to the least significant bit clear for 64-bit integers.

◆ BIT_LOWEST_SET_32

#define BIT_LOWEST_SET_32 (   _n_)    ((uint32)(_n_) & -(int32)(_n_))

Masks to the least significant bit set for 32-bit integers.

◆ BIT_LOWEST_SET_64

#define BIT_LOWEST_SET_64 (   _n_)    ((uint64)(_n_) & -(int64)(_n_))

Masks to the least significant bit set for 64-bit integers.

◆ BIT_LOWEST_SET_INDEX_32 [1/2]

#define BIT_LOWEST_SET_INDEX_32 (   n_,
  i_ 
)
Value:
MACRO_START \
i_ = (signed char)("\377\000\200\001\200\200\033\002\200\200\200\200\034\200\020\003\200\200\200\200\200\200\200\025\035\200\200\200\027\021\013\004\037\200\200\032\200\200\200\017\200\200\200\024\200\200\026\012\036\031\200\016\200\023\200\011\030\015\022\010\014\007\006\005"[(BIT_LOWEST_SET_32(n_) * 0x7ef3ae3u) >> 26]) ; \
MACRO_END

Index of least significant bit set of a 32 bit integer. The index is set to -1 if there are no bits set on input. Apart from the zero case, this is the same as BIT_COUNT_TRAILING_ZEROS_32().

◆ BIT_LOWEST_SET_INDEX_32 [2/2]

#define BIT_LOWEST_SET_INDEX_32 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanForward(&_r_, (unsigned long)(n_)) ? _r_ : -1 ; \
MACRO_END

Index of least significant bit set of a 32 bit integer. The index is set to -1 if there are no bits set on input. Apart from the zero case, this is the same as BIT_COUNT_TRAILING_ZEROS_32().

◆ BIT_LOWEST_SET_INDEX_64 [1/2]

#define BIT_LOWEST_SET_INDEX_64 (   n_,
  i_ 
)
Value:
MACRO_START \
i_ = (signed char)("\377\000\200\001\073\200\200\002\074\200\200\200\200\200\040\003\075\200\200\200\200\200\200\064\200\200\200\200\057\041\023\004\076\200\200\200\200\200\200\055\200\200\200\200\200\200\065\031\200\200\200\200\200\200\200\046\067\060\051\042\033\024\015\005\077\200\072\200\200\200\200\037\200\200\200\063\200\200\056\022\200\200\200\054\200\200\200\030\200\200\200\045\066\050\032\014\200\071\200\036\200\062\200\021\200\053\200\027\200\044\047\013\070\035\061\020\052\026\043\012\034\017\025\011\016\010\007\006"[(BIT_LOWEST_SET_64(n_) * UINT64(0x3fbe7af1dba72e1)) >> 57]) ; \
MACRO_END

Index of least significant bit set of a 64 bit integer. The index is set to -1 if there are no bits set on input. Apart from the zero case, this is the same as BIT_COUNT_TRAILING_ZEROS_64().

◆ BIT_LOWEST_SET_INDEX_64 [2/2]

#define BIT_LOWEST_SET_INDEX_64 (   n_,
  i_ 
)
Value:
MACRO_START \
unsigned long _r_ ; \
i_ = _BitScanForward64(&_r_, (unsigned __int64)(n_)) ? _r_ : -1 ; \
MACRO_END

Index of least significant bit set of a 64 bit integer. The index is set to -1 if there are no bits set on input. Apart from the zero case, this is the same as BIT_COUNT_TRAILING_ZEROS_64().

◆ BIT_ROTATE32_LEFT [1/2]

#define BIT_ROTATE32_LEFT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = ((from_) << (shift_)) | ((uint32)(from_) >> (32 - (shift_))) ; \
MACRO_END

Rotate bits left in a 32-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE32_LEFT [2/2]

#define BIT_ROTATE32_LEFT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotl((uint32)(from_), (shift_)) ; \
MACRO_END

Rotate bits left in a 32-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE32_LEFT_SAFE [1/2]

#define BIT_ROTATE32_LEFT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
if ( (shift_) != 0 ) \
BIT_ROTATE32_LEFT((to_), (from_), (shift_)) ; \
else \
(to_) = (from_) ; \
MACRO_END

Rotate bits left in a 32-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE32_LEFT_SAFE [2/2]

#define BIT_ROTATE32_LEFT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotl((uint32)(from_), (shift_)) ; \
MACRO_END

Rotate bits left in a 32-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE32_RIGHT [1/2]

#define BIT_ROTATE32_RIGHT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = ((from_) >> (shift_)) | ((uint32)(from_) << (32 - (shift_))) ; \
MACRO_END

Rotate bits right in a 32-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE32_RIGHT [2/2]

#define BIT_ROTATE32_RIGHT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotr((uint32)(from_), (shift_)) ; \
MACRO_END

Rotate bits right in a 32-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE32_RIGHT_SAFE [1/2]

#define BIT_ROTATE32_RIGHT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
if ( (shift_) != 0 ) \
BIT_ROTATE32_RIGHT((to_), (from_), (shift_)) ; \
else \
(to_) = (from_) ; \
MACRO_END

Rotate bits left in a 32-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE32_RIGHT_SAFE [2/2]

#define BIT_ROTATE32_RIGHT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotr((uint32)(from_), (shift_)) ; \
MACRO_END

Rotate bits left in a 32-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE64_LEFT [1/2]

#define BIT_ROTATE64_LEFT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = ((from_) << (shift_)) | ((uint64)(from_) >> (64 - (shift_))) ; \
MACRO_END

Rotate bits left in a 64-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE64_LEFT [2/2]

#define BIT_ROTATE64_LEFT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotl64((uint64)(from_), (shift_)) ; \
MACRO_END

Rotate bits left in a 64-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE64_LEFT_SAFE [1/2]

#define BIT_ROTATE64_LEFT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
if ( (shift_) != 0 ) \
BIT_ROTATE64_LEFT((to_), (from_), (shift_)) ; \
else \
(to_) = (from_) ; \
MACRO_END

Rotate bits left in a 64-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE64_LEFT_SAFE [2/2]

#define BIT_ROTATE64_LEFT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotl64((uint64)(from_), (shift_)) ; \
MACRO_END

Rotate bits left in a 64-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE64_RIGHT [1/2]

#define BIT_ROTATE64_RIGHT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = ((uint64)(from_) >> (shift_)) | ((uint64)(from_) << (64 - (shift_))) ; \
MACRO_END

Rotate bits right in a 64-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE64_RIGHT [2/2]

#define BIT_ROTATE64_RIGHT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotr64((uint64)(from_), (shift_)) ; \
MACRO_END

Rotate bits right in a 64-bit value. This is NOT safe for zero shifts.

◆ BIT_ROTATE64_RIGHT_SAFE [1/2]

#define BIT_ROTATE64_RIGHT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
if ( (shift_) != 0 ) \
BIT_ROTATE64_RIGHT((to_), (from_), (shift_)) ; \
else \
(to_) = (from_) ; \
MACRO_END

Rotate bits left in a 64-bit value. This IS safe for zero shifts.

◆ BIT_ROTATE64_RIGHT_SAFE [2/2]

#define BIT_ROTATE64_RIGHT_SAFE (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
(to_) = _rotr64((uint64)(from_), (shift_)) ; \
MACRO_END

Rotate bits left in a 64-bit value. This IS safe for zero shifts.

◆ BIT_SHIFT32_SIGNED_RIGHT

#define BIT_SHIFT32_SIGNED_RIGHT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
int32 _f_ = (int32)(from_) ; \
(to_) = BIT_SHIFT32_SIGNED_RIGHT_EXPR(_f_, (shift_)) ; \
MACRO_END
#define BIT_SHIFT32_SIGNED_RIGHT_EXPR(val_, shift_)
Definition: hqbitops.h:700
signed int int32
32-bit signed integer
Definition: hqtypes.h:122

Arithmetic shift right in a 32-bit value. This is safe for zero shifts (because the left shift of the negative sign by 31 ^ shift will set the same sign bit as is currently set).

◆ BIT_SHIFT32_SIGNED_RIGHT_EXPR [1/2]

#define BIT_SHIFT32_SIGNED_RIGHT_EXPR (   val_,
  shift_ 
)     ((int32)((uint32)(val_) >> (shift_)) | (SIGN32_NEG(val_) << (31 ^ (shift_))))

Arithmetic shift right in a 32-bit value, suitable for use in an expression. This is safe for zero shifts (because the left shift of the negative sign by 31 ^ shift will set the same sign bit as is currently set).

◆ BIT_SHIFT32_SIGNED_RIGHT_EXPR [2/2]

#define BIT_SHIFT32_SIGNED_RIGHT_EXPR (   val_,
  shift_ 
)     ((int32)(val_) >> (shift_))

Arithmetic shift right in a 32-bit value, suitable for use in an expression. This is safe for zero shifts (because the left shift of the negative sign by 31 ^ shift will set the same sign bit as is currently set).

◆ BIT_SHIFT64_SIGNED_RIGHT

#define BIT_SHIFT64_SIGNED_RIGHT (   to_,
  from_,
  shift_ 
)
Value:
MACRO_START \
int64 _f_ = (int64)(from_) ; \
(to_) = BIT_SHIFT64_SIGNED_RIGHT_EXPR(_f_, (shift_)) ; \
MACRO_END
#define BIT_SHIFT64_SIGNED_RIGHT_EXPR(val_, shift_)
Definition: hqbitops.h:704
signed int64
64-bit signed integer
Definition: hqtypes.h:135

Arithmetic shift right in a 64-bit value. This is safe for zero shifts (because the left shift of the negative sign by 63 ^ shift will set the same sign bit as is currently set).

◆ BIT_SHIFT64_SIGNED_RIGHT_EXPR [1/2]

#define BIT_SHIFT64_SIGNED_RIGHT_EXPR (   val_,
  shift_ 
)     ((int64)((uint64)(val_) >> (shift_)) | (SIGN64_NEG(val_) << (63 ^ (shift_))))

Arithmetic shift right in a 64-bit value, suitable for use in an expression. This is safe for zero shifts (because the left shift of the negative sign by 63 ^ shift will set the same sign bit as is currently set).

◆ BIT_SHIFT64_SIGNED_RIGHT_EXPR [2/2]

#define BIT_SHIFT64_SIGNED_RIGHT_EXPR (   val_,
  shift_ 
)     ((int64)(val_) >> (shift_))

Arithmetic shift right in a 64-bit value, suitable for use in an expression. This is safe for zero shifts (because the left shift of the negative sign by 63 ^ shift will set the same sign bit as is currently set).

◆ BYTE_LOAD16_SIGNED_BE

#define BYTE_LOAD16_SIGNED_BE (   ptr_)    (int16)BYTE_LOAD16_UNSIGNED_BE(ptr_)

Load a 16-bit signed big-endian number from memory.

◆ BYTE_LOAD16_SIGNED_LE

#define BYTE_LOAD16_SIGNED_LE (   ptr_)    (int16)BYTE_LOAD16_UNSIGNED_LE(ptr_)

Load a 16-bit signed little-endian number from memory.

◆ BYTE_LOAD16_SIGNED_PLATFORM

#define BYTE_LOAD16_SIGNED_PLATFORM   BYTE_LOAD16_SIGNED_LE

Load a 16-bit signed platform-endian number from memory.

◆ BYTE_LOAD16_UNSIGNED_BE

#define BYTE_LOAD16_UNSIGNED_BE (   ptr_)     (uint16)(((uint8 *)(ptr_))[1] | (((uint8 *)(ptr_))[0] << 8))

Load a 16-bit unsigned big-endian number from memory.

◆ BYTE_LOAD16_UNSIGNED_LE

#define BYTE_LOAD16_UNSIGNED_LE (   ptr_)     (uint16)(((uint8 *)(ptr_))[0] | (((uint8 *)(ptr_))[1] << 8))

Load a 16-bit unsigned little-endian number from memory.

◆ BYTE_LOAD16_UNSIGNED_PLATFORM

#define BYTE_LOAD16_UNSIGNED_PLATFORM   BYTE_LOAD16_UNSIGNED_LE

Load a 16-bit unsigned platform-endian number from memory.

◆ BYTE_LOAD32_SIGNED_BE

#define BYTE_LOAD32_SIGNED_BE (   ptr_)    (int32)BYTE_LOAD32_UNSIGNED_BE(ptr_)

Load a 32-bit signed big-endian number from memory.

◆ BYTE_LOAD32_SIGNED_LE

#define BYTE_LOAD32_SIGNED_LE (   ptr_)    (int32)BYTE_LOAD32_UNSIGNED_LE(ptr_)

Load a 32-bit signed little-endian number from memory.

◆ BYTE_LOAD32_SIGNED_PLATFORM

#define BYTE_LOAD32_SIGNED_PLATFORM   BYTE_LOAD32_SIGNED_LE

Load a 32-bit signed platform-endian number from memory.

◆ BYTE_LOAD32_UNSIGNED_BE

#define BYTE_LOAD32_UNSIGNED_BE (   ptr_)
Value:
((uint32)(((uint8 *)(ptr_))[3]) | \
((uint32)(((uint8 *)(ptr_))[2]) << 8) | \
((uint32)(((uint8 *)(ptr_))[1]) << 16) | \
((uint32)(((uint8 *)(ptr_))[0]) << 24))
unsigned char uint8
8-bit unsigned integer
Definition: hqtypes.h:124

Load a 32-bit unsigned big-endian number from memory.

◆ BYTE_LOAD32_UNSIGNED_LE

#define BYTE_LOAD32_UNSIGNED_LE (   ptr_)
Value:
((uint32)(((uint8 *)(ptr_))[0]) | \
((uint32)(((uint8 *)(ptr_))[1]) << 8) | \
((uint32)(((uint8 *)(ptr_))[2]) << 16) | \
((uint32)(((uint8 *)(ptr_))[3]) << 24))

Load a 32-bit unsigned little-endian number from memory.

◆ BYTE_LOAD32_UNSIGNED_PLATFORM

#define BYTE_LOAD32_UNSIGNED_PLATFORM   BYTE_LOAD32_UNSIGNED_LE

Load a 32-bit unsigned platform-endian number from memory.

◆ BYTE_LOAD64_SIGNED_BE

#define BYTE_LOAD64_SIGNED_BE (   ptr_)    (int64)BYTE_LOAD64_UNSIGNED_BE(ptr_)

Load a 64-bit signed big-endian number from memory.

◆ BYTE_LOAD64_SIGNED_LE

#define BYTE_LOAD64_SIGNED_LE (   ptr_)    (int64)BYTE_LOAD64_UNSIGNED_LE(ptr_)

Load a 64-bit signed little-endian number from memory.

◆ BYTE_LOAD64_SIGNED_PLATFORM

#define BYTE_LOAD64_SIGNED_PLATFORM   BYTE_LOAD64_SIGNED_LE

Load a 64-bit signed platform-endian number from memory.

◆ BYTE_LOAD64_UNSIGNED_BE

#define BYTE_LOAD64_UNSIGNED_BE (   ptr_)
Value:
((uint64)(((uint8 *)(ptr_))[7]) | \
((uint64)(((uint8 *)(ptr_))[6]) << 8) | \
((uint64)(((uint8 *)(ptr_))[5]) << 16) | \
((uint64)(((uint8 *)(ptr_))[4]) << 24) | \
((uint64)(((uint8 *)(ptr_))[3]) << 32) | \
((uint64)(((uint8 *)(ptr_))[2]) << 40) | \
((uint64)(((uint8 *)(ptr_))[1]) << 48) | \
((uint64)(((uint8 *)(ptr_))[0]) << 56))

Load a 64-bit unsigned big-endian number from memory.

◆ BYTE_LOAD64_UNSIGNED_LE

#define BYTE_LOAD64_UNSIGNED_LE (   ptr_)
Value:
((uint64)(((uint8 *)(ptr_))[0]) | \
((uint64)(((uint8 *)(ptr_))[1]) << 8) | \
((uint64)(((uint8 *)(ptr_))[2]) << 16) | \
((uint64)(((uint8 *)(ptr_))[3]) << 24) | \
((uint64)(((uint8 *)(ptr_))[4]) << 32) | \
((uint64)(((uint8 *)(ptr_))[5]) << 40) | \
((uint64)(((uint8 *)(ptr_))[6]) << 48) | \
((uint64)(((uint8 *)(ptr_))[7]) << 56))

Load a 64-bit unsigned little-endian number from memory.

◆ BYTE_LOAD64_UNSIGNED_PLATFORM

#define BYTE_LOAD64_UNSIGNED_PLATFORM   BYTE_LOAD64_UNSIGNED_LE

Load a 64-bit unsigned platform-endian number from memory.

◆ BYTE_STORE16_BE

#define BYTE_STORE16_BE (   ptr_,
  val_ 
)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint16 _val_ = (uint16)(val_) ; \
_ptr_[1] = (uint8)_val_ ; \
_ptr_[0] = (uint8)(_val_ >> 8) ; \
MACRO_END
unsigned short uint16
16-bit unsigned integer
Definition: hqtypes.h:125

Store a 16-bit big-endian number to memory.

◆ BYTE_STORE16_LE

#define BYTE_STORE16_LE (   ptr_,
  val_ 
)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint16 _val_ = (uint16)(val_) ; \
_ptr_[0] = (uint8)_val_ ; \
_ptr_[1] = (uint8)(_val_ >> 8) ; \
MACRO_END

Store a 16-bit little-endian number to memory.

◆ BYTE_STORE16_PLATFORM

#define BYTE_STORE16_PLATFORM   BYTE_STORE16_LE

Store a 16-bit platform-endian number to memory.

◆ BYTE_STORE32_BE

#define BYTE_STORE32_BE (   ptr_,
  val_ 
)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint32 _val_ = (uint32)(val_) ; \
_ptr_[3] = (uint8)_val_ ; \
_ptr_[2] = (uint8)(_val_ >> 8) ; \
_ptr_[1] = (uint8)(_val_ >> 16) ; \
_ptr_[0] = (uint8)(_val_ >> 24) ; \
MACRO_END

Store a 32-bit big-endian number to memory.

◆ BYTE_STORE32_LE

#define BYTE_STORE32_LE (   ptr_,
  val_ 
)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint32 _val_ = (uint32)(val_) ; \
_ptr_[0] = (uint8)_val_ ; \
_ptr_[1] = (uint8)(_val_ >> 8) ; \
_ptr_[2] = (uint8)(_val_ >> 16) ; \
_ptr_[3] = (uint8)(_val_ >> 24) ; \
MACRO_END

Store a 32-bit little-endian number to memory.

◆ BYTE_STORE32_PLATFORM

#define BYTE_STORE32_PLATFORM   BYTE_STORE32_LE

Store a 32-bit platform-endian number to memory.

◆ BYTE_STORE64_BE

#define BYTE_STORE64_BE (   ptr_,
  val_ 
)

Store a 64-bit big-endian number to memory.

◆ BYTE_STORE64_LE

#define BYTE_STORE64_LE (   ptr_,
  val_ 
)

Store a 64-bit little-endian number to memory.

◆ BYTE_STORE64_PLATFORM

#define BYTE_STORE64_PLATFORM   BYTE_STORE64_LE

Store a 64-bit platform-endian number to memory.

◆ BYTE_SWAP16_BUFFER [1/2]

#define BYTE_SWAP16_BUFFER (   to_,
  from_,
  bytes_ 
)

Swap multiple 16-bit values in a buffer. Source and destination buffers can be the same.

◆ BYTE_SWAP16_BUFFER [2/2]

#define BYTE_SWAP16_BUFFER (   to_,
  from_,
  bytes_ 
)     _swab((char *)(from_), (char *)(to_), (int)(bytes_))

Swap multiple 16-bit values in a buffer. Source and destination buffers can be the same.

◆ BYTE_SWAP16_PTR [1/2]

#define BYTE_SWAP16_PTR (   ptr_)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint8 _tmp_ = _ptr_[0] ; \
_ptr_[0] = _ptr_[1] ; \
_ptr_[1] = _tmp_ ; \
MACRO_END

Swap bytes in a 16-bit value in memory.

◆ BYTE_SWAP16_PTR [2/2]

#define BYTE_SWAP16_PTR (   ptr_)     _swab((char *)(ptr_), (char *)(ptr_), 2)

Swap bytes in a 16-bit value in memory.

◆ BYTE_SWAP16_SIGNED

#define BYTE_SWAP16_SIGNED (   val_)    (int16)BYTE_SWAP16_UNSIGNED(val_)

Swap bytes in a 16-bit value, returning a signed 16-bit value.

◆ BYTE_SWAP16_UNSIGNED [1/2]

#define BYTE_SWAP16_UNSIGNED (   val_)     (uint16)((uint8)(val_) << 8 | (uint16)(val_) >> 8)

Swap bytes in a 16-bit value, returning an unsigned 16-bit value.

◆ BYTE_SWAP16_UNSIGNED [2/2]

#define BYTE_SWAP16_UNSIGNED (   val_)     _byteswap_ushort((unsigned short)(val_))

Swap bytes in a 16-bit value, returning an unsigned 16-bit value.

◆ BYTE_SWAP16_UNSIGNED_VAR

#define BYTE_SWAP16_UNSIGNED_VAR (   to_,
  from_ 
)
Value:
MACRO_START \
uint16 _tmp_ = (uint16)(from_) ; \
to_ = (uint16)((_tmp_ << 8) | (_tmp_ >> 8)) ; \
MACRO_END

Swap bytes in a 16-bit value in a variable.

◆ BYTE_SWAP32_BUFFER

#define BYTE_SWAP32_BUFFER (   to_,
  from_,
  bytes_ 
)

Swap multiple 32-bit values in a buffer. Source and destination buffers can be the same.

◆ BYTE_SWAP32_BUFFER_UNALIGNED [1/2]

#define BYTE_SWAP32_BUFFER_UNALIGNED (   to_,
  from_,
  bytes_ 
)

Swap multiple 32-bit values in a buffer, which may be unaligned. Source and destination buffers can be the same.

◆ BYTE_SWAP32_BUFFER_UNALIGNED [2/2]

#define BYTE_SWAP32_BUFFER_UNALIGNED   BYTE_SWAP32_BUFFER

Swap multiple 32-bit values in a buffer, which may be unaligned. Source and destination buffers can be the same.

◆ BYTE_SWAP32_PTR [1/2]

#define BYTE_SWAP32_PTR (   ptr_)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint8 _tmp_ = _ptr_[0] ; \
_ptr_[0] = _ptr_[3] ; \
_ptr_[3] = _tmp_ ; \
_tmp_ = _ptr_[1] ; \
_ptr_[1] = _ptr_[2] ; \
_ptr_[2] = _tmp_ ; \
MACRO_END

Swap bytes in a 32-bit value in memory.

◆ BYTE_SWAP32_PTR [2/2]

#define BYTE_SWAP32_PTR (   ptr_)
Value:
MACRO_START \
uint32 *_ptr_ = (uint32 *)(ptr_) ; \
BYTE_SWAP32_UNSIGNED_VAR(_ptr_[0], _ptr_[0]) ; \
MACRO_END

Swap bytes in a 32-bit value in memory.

◆ BYTE_SWAP32_SIGNED

#define BYTE_SWAP32_SIGNED (   val_)    (int32)BYTE_SWAP32_UNSIGNED(val_)

Swap bytes in a 32-bit value, returning a signed 32-bit value.

◆ BYTE_SWAP32_UNSIGNED [1/2]

#define BYTE_SWAP32_UNSIGNED (   val_)
Value:
(uint32)((uint32)(val_) << 24 | (uint32)(val_) >> 24 | \
((uint32)(val_) & 0xff00u) << 8 | (((uint32)(val_) >> 8) & 0xff00u))

Swap bytes in a 32-bit value, returning an unsigned 32-bit value.

◆ BYTE_SWAP32_UNSIGNED [2/2]

#define BYTE_SWAP32_UNSIGNED (   val_)     _byteswap_ulong((unsigned long)(val_))

Swap bytes in a 32-bit value, returning an unsigned 32-bit value.

◆ BYTE_SWAP32_UNSIGNED_VAR

#define BYTE_SWAP32_UNSIGNED_VAR (   to_,
  from_ 
)
Value:
MACRO_START \
uint32 _tmp_ = (uint32)(from_) ; \
_tmp_ = (_tmp_ << 16) | (_tmp_ >> 16) ; \
to_ = (((_tmp_ & MASK_ALTERNATE_BYTES(uint32)) << 8) | \
((_tmp_ >> 8) & MASK_ALTERNATE_BYTES(uint32))) ; \
MACRO_END
#define MASK_ALTERNATE_BYTES(type_)
Definition: hqbitops.h:255

Swap bytes in a 32-bit value in a variable.

◆ BYTE_SWAP64_BUFFER

#define BYTE_SWAP64_BUFFER (   to_,
  from_,
  bytes_ 
)

Swap multiple 64-bit values in a buffer. Source and destination buffers can be the same.

◆ BYTE_SWAP64_BUFFER_UNALIGNED [1/2]

#define BYTE_SWAP64_BUFFER_UNALIGNED (   to_,
  from_,
  bytes_ 
)

Swap multiple 64-bit values in a buffer, which may be unaligned. Source and destination buffers can be the same.

◆ BYTE_SWAP64_BUFFER_UNALIGNED [2/2]

#define BYTE_SWAP64_BUFFER_UNALIGNED   BYTE_SWAP64_BUFFER

Swap multiple 64-bit values in a buffer, which may be unaligned. Source and destination buffers can be the same.

◆ BYTE_SWAP64_PTR [1/2]

#define BYTE_SWAP64_PTR (   ptr_)
Value:
MACRO_START \
uint8 *_ptr_ = (uint8 *)(ptr_) ; \
uint64 _tmp_ = BYTE_LOAD64_UNSIGNED_LE(_ptr_) ; \
BYTE_STORE64_BE(_ptr_, _tmp_) ; \
MACRO_END
#define BYTE_LOAD64_UNSIGNED_LE(ptr_)
Definition: hqbitops.h:107

Swap bytes in a 64-bit value in memory.

◆ BYTE_SWAP64_PTR [2/2]

#define BYTE_SWAP64_PTR (   ptr_)
Value:
MACRO_START \
uint64 *_ptr_ = (uint64 *)(ptr_) ; \
BYTE_SWAP64_UNSIGNED_VAR(_ptr_[0], _ptr_[0]) ; \
MACRO_END

Swap bytes in a 64-bit value in memory.

◆ BYTE_SWAP64_SIGNED

#define BYTE_SWAP64_SIGNED (   val_)    (int64)BYTE_SWAP64_UNSIGNED(val_)

Swap bytes in a 64-bit value, returning a signed 64-bit value.

◆ BYTE_SWAP64_UNSIGNED [1/2]

#define BYTE_SWAP64_UNSIGNED (   val_)
Value:
(uint64)((uint64)(val_) << 56 | (uint64)(val_) >> 56 | \
((uint64)(val_) & 0xff00u) << 40 | \
(((uint64)(val_) >> 40) & 0xff00u) | \
((uint64)(val_) & 0xff0000u) << 24 | \
(((uint64)(val_) >> 24) & 0xff0000u) | \
((uint64)(val_) & 0xff000000u) << 8 | \
(((uint64)(val_) >> 8) & 0xff000000u))

Swap bytes in a 64-bit value, returning an unsigned 64-bit value.

◆ BYTE_SWAP64_UNSIGNED [2/2]

#define BYTE_SWAP64_UNSIGNED (   val_)     _byteswap_uint64((unsigned __int64)(val_))

Swap bytes in a 64-bit value, returning an unsigned 64-bit value.

◆ BYTE_SWAP64_UNSIGNED_VAR

#define BYTE_SWAP64_UNSIGNED_VAR (   to_,
  from_ 
)
Value:
MACRO_START \
uint64 _tmp_ = (uint64)(from_) ; \
_tmp_ = (_tmp_ << 32) | (_tmp_ >> 32) ; \
_tmp_ = (((_tmp_ & MASK_ALTERNATE_SHORTS(uint64)) << 16) | \
((_tmp_ >> 16) & MASK_ALTERNATE_SHORTS(uint64))) ; \
to_ = (((_tmp_ & MASK_ALTERNATE_BYTES(uint64)) << 8) | \
((_tmp_ >> 8) & MASK_ALTERNATE_BYTES(uint64))) ; \
MACRO_END
#define MASK_ALTERNATE_SHORTS(type_)
Definition: hqbitops.h:258

Swap bytes in a 64-bit value in a variable.

◆ INLINE_ABS32

#define INLINE_ABS32 (   abs_,
  val_ 
)
Value:
MACRO_START \
int32 _s_ = SIGN32_NEG(val_); \
(abs_) = ((int32)(val_) ^ _s_) - _s_ ; \
MACRO_END
#define SIGN32_NEG(x)
Definition: hqbitops.h:524

Get the absolute value of a 32-bit integer without branches.

◆ INLINE_ABS64

#define INLINE_ABS64 (   abs_,
  val_ 
)
Value:
MACRO_START \
int64 _s_ = SIGN64_NEG(val_); \
(abs_) = ((int64)(val_) ^ _s_) - _s_ ; \
MACRO_END
#define SIGN64_NEG(x)
Definition: hqbitops.h:527

Get the absolute value of a 64-bit integer without branches.

◆ INLINE_MAX32

#define INLINE_MAX32 (   max_,
  a_,
  b_ 
)
Value:
MACRO_START \
int32 _d_ = (b_) - (a_) ; \
HQASSERT((a_) > (b_) ? _d_ < 0 : _d_ >= 0, \
"Difference between integers too large for in-line max") ; \
_d_ &= SIGN32_NEG(_d_) ; \
(max_) = (b_) - _d_ ; \
MACRO_END

Get the maximum of two 32-bit integers without branches. This only works when the absolute difference between the values is less than MAXINT32.

◆ INLINE_MAX64

#define INLINE_MAX64 (   max_,
  a_,
  b_ 
)
Value:
MACRO_START \
int64 _d_ = (b_) - (a_) ; \
HQASSERT((a_) > (b_) ? _d_ < 0 : _d_ >= 0, \
"Difference between integers too large for in-line max") ; \
_d_ &= SIGN64_NEG(_d_) ; \
(max_) = (b_) - _d_ ; \
MACRO_END

Get the maximum of two 64-bit integers without branches. This only works when the absolute difference between the values is less than MAXINT64.

◆ INLINE_MIN32

#define INLINE_MIN32 (   min_,
  a_,
  b_ 
)
Value:
MACRO_START \
int32 _d_ = (b_) - (a_) ; \
HQASSERT((a_) > (b_) ? _d_ < 0 : _d_ >= 0, \
"Difference between integers too large for in-line min") ; \
_d_ &= SIGN32_NEG(_d_) ; \
(min_) = (a_) + _d_ ; \
MACRO_END

Get the minimum of two 32-bit integers without branches. This only works when the absolute difference between the values is less than MAXINT32.

◆ INLINE_MIN64

#define INLINE_MIN64 (   min_,
  a_,
  b_ 
)
Value:
MACRO_START \
int64 _d_ = (b_) - (a_) ; \
HQASSERT((a_) > (b_) ? _d_ < 0 : _d_ >= 0, \
"Difference between integers too large for in-line min") ; \
_d_ &= SIGN64_NEG(_d_) ; \
(min_) = (a_) + _d_ ; \
MACRO_END

Get the minimum of two 64-bit integers without branches. This only works when the absolute difference between the values is less than MAXINT64.

◆ INLINE_MINMAX32

#define INLINE_MINMAX32 (   min_,
  max_,
  a_,
  b_ 
)
Value:
MACRO_START \
int32 _d_ = (b_) - (a_) ; \
HQASSERT((a_) > (b_) ? _d_ < 0 : _d_ >= 0, \
"Difference between integers too large for in-line minmax") ; \
_d_ &= SIGN32_NEG(_d_) ; \
(min_) = (a_) + _d_ ; \
(max_) = (b_) - _d_ ; \
MACRO_END

Get the minimum and maximum of two 32-bit integers without branches. This only works when the absolute difference between the values is less than MAXINT32.

◆ INLINE_MINMAX64

#define INLINE_MINMAX64 (   min_,
  max_,
  a_,
  b_ 
)
Value:
MACRO_START \
int64 _d_ = (b_) - (a_) ; \
HQASSERT((a_) > (b_) ? _d_ < 0 : _d_ >= 0, \
"Difference between integers too large for in-line minmax") ; \
_d_ &= SIGN64_NEG(_d_) ; \
(min_) = (a_) + _d_ ; \
(max_) = (b_) - _d_ ; \
MACRO_END

Get the minimum and maximum of two 64-bit integers without branches. This only works when the absolute difference between the values is less than MAXINT64.

◆ INLINE_RANGE32

#define INLINE_RANGE32 (   to_,
  from_,
  min_,
  max_ 
)
Value:
MACRO_START \
int32 _t_ ; \
HQASSERT((min_) <= (max_), "Range clip limits out of order") ; \
INLINE_MIN32(_t_, (from_), (max_)) ; \
INLINE_MAX32((to_), _t_, (min_)) ; \
MACRO_END

Range clip a 32-bit integer to minimum and maximum limits. This only works when the absolute difference between the values is less than MAXINT32.

◆ INLINE_RANGE32_0

#define INLINE_RANGE32_0 (   to_,
  from_,
  max_ 
)
Value:
MACRO_START \
int32 _t_ = (int32)(from_) ; \
HQASSERT((max_) >= 0, "Range clip limit too small") ; \
_t_ &= (int32)((uint32)_t_ >> 31) - 1 ; /* t = max(0,t) */ \
INLINE_MIN32((to_), _t_, (max_)) ; \
MACRO_END

Range clip a 32-bit integer to (0,maximum) limits.

◆ INLINE_RANGE64

#define INLINE_RANGE64 (   to_,
  from_,
  min_,
  max_ 
)
Value:
MACRO_START \
int64 _t_ ; \
HQASSERT((min_) <= (max_), "Range clip limits out of order") ; \
INLINE_MIN64(_t_, (from_), (max_)) ; \
INLINE_MAX64((to_), _t_, (min_)) ; \
MACRO_END

Range clip a 64-bit integer to minimum and maximum limits. This only works when the absolute difference between the values is less than MAXINT64.

◆ INLINE_RANGE64_0

#define INLINE_RANGE64_0 (   to_,
  from_,
  max_ 
)
Value:
MACRO_START \
int64 _t_ = (int64)(from_) ; \
HQASSERT((max_) >= 0, "Range clip limit too small") ; \
_t_ &= (int64)((uint64)_t_ >> 63) - 1 ; /* t = max(0,t) */ \
INLINE_MIN64((to_), _t_, (max_)) ; \
MACRO_END

Range clip a 64-bit integer to (0,maximum) limits.

◆ MASK_ALTERNATE_BYTES

#define MASK_ALTERNATE_BYTES (   type_)    (type_)(MASK_SHORTS_1(type_) * 0xffu)

Alternating bytes in an unsigned type set to 0x00,0xff.

◆ MASK_ALTERNATE_SHORTS

#define MASK_ALTERNATE_SHORTS (   type_)    (type_)(MASK_WORDS_1(type_) * 0xffffu)

Alternating shorts in an unsigned type set to 0x0000,0xffff.

◆ MASK_BYTES_1

#define MASK_BYTES_1 (   type_)    (type_)(~(type_)0 / 0xffu)

All bytes in an unsigned type set to 0x01.

◆ MASK_SHORTS_1

#define MASK_SHORTS_1 (   type_)    (type_)(~(type_)0 / 0xffffu)

All shorts in an unsigned type set to 0x0001.

◆ MASK_WORDS_1

#define MASK_WORDS_1 (   type_)    (type_)(~(type_)0 / 0xffffffffu)

All words in an unsigned type set to 0x00000001.

◆ SIGN32

#define SIGN32 (   x)    (SIGN32_NEG(x) - SIGN32_NEG(-(x)))

Extract the sign of a 32-bit integer as -1, 0, or +1.

◆ SIGN32_NEG [1/2]

#define SIGN32_NEG (   x)    -(int32)((uint32)((int32)(x)) >> 31)

Extract the sign bit, returning 0 for non-negative 32-bit numbers and -1 for negative numbers. This is useful as a mask. The casts around the macro parameter are to ensure sign extension from any supplied integer.

◆ SIGN32_NEG [2/2]

#define SIGN32_NEG (   x)    ((int32)(x) >> 31)

Extract the sign bit, returning 0 for non-negative 32-bit numbers and -1 for negative numbers. This is useful as a mask. The casts around the macro parameter are to ensure sign extension from any supplied integer.

◆ SIGN64

#define SIGN64 (   x)    (SIGN64_NEG(x) - SIGN64_NEG(-(x)))

Extract the sign of a 64-bit integer as -1, 0, or +1.

◆ SIGN64_NEG [1/2]

#define SIGN64_NEG (   x)    -(int64)((uint64)((int64)(x)) >> 63)

Extract the sign bit, returning 0 for non-negative 64-bit numbers and -1 for negative numbers. This is useful as a mask. The casts around the macro parameter are to ensure sign extension from any supplied integer.

◆ SIGN64_NEG [2/2]

#define SIGN64_NEG (   x)    ((int64)(x) >> 63)

Extract the sign bit, returning 0 for non-negative 64-bit numbers and -1 for negative numbers. This is useful as a mask. The casts around the macro parameter are to ensure sign extension from any supplied integer.