libusual  0.1
Functions
usual/bits.h File Reference

Bit arithmetics. More...

Functions

static bool is_power_of_2 (unsigned int n)
 Checks if integer has only one bit set.
static uint16_t rol16 (uint16_t v, int s)
 Rotate 16-bit int to left.
static uint32_t rol32 (uint32_t v, int s)
 Rotate 32-bit int to left.
static uint64_t rol64 (uint64_t v, int s)
 Rotate 64-bit int to left.
static uint16_t ror16 (uint16_t v, int s)
 Rotate 16-bit int to right.
static uint32_t ror32 (uint32_t v, int s)
 Rotate 32-bit int to right.
static uint64_t ror64 (uint64_t v, int s)
 Rotate 64-bit int to right.
static int fls (int x)
 Find last (highest) set bit, 1-based offset, 0 if arg == 0.
static int flsl (long x)
 Find last (highest) set bit, 1-based offset, 0 if arg == 0.
static int flsll (long long x)
 Find last (highest) set bit, 1-based offset, 0 if arg == 0.
static int ffs (int x)
 Find first (lowest) set bit, 1-based ofs, 0 if arg == 0.
static int ffsl (long x)
 Find first (lowest) set bit, 1-based ofs, 0 if arg == 0.
static int ffsll (long long x)
 Find first (lowest) set bit, 1-based ofs, 0 if arg == 0.
static bool safe_mul_uint (unsigned int *res_p, unsigned int a, unsigned int b)
 Multiply with overflow check for 'unsigned int'.
static bool safe_mul_ulong (unsigned long *res_p, unsigned long a, unsigned long b)
 Multiply with overflow check for 'unsigned long'.
static bool safe_mul_uint8 (uint8_t *res_p, uint8_t a, uint8_t b)
 Multiply with overflow check for 'uint8_t'.
static bool safe_mul_uint16 (uint16_t *res_p, uint16_t a, uint16_t b)
 Multiply with overflow check for 'uint16_t'.
static bool safe_mul_uint32 (uint32_t *res_p, uint32_t a, uint32_t b)
 Multiply with overflow check for 'uint32_t'.
static bool safe_mul_uint64 (uint64_t *res_p, uint64_t a, uint64_t b)
 Multiply with overflow check for 'uint64_t'.
static bool safe_mul_size (size_t *res_p, size_t a, size_t b)
 Multiply with overflow check for 'size_t'.

Detailed Description

Bit arithmetics.


Function Documentation

static bool is_power_of_2 ( unsigned int  n) [inline, static]

Checks if integer has only one bit set.

static uint16_t rol16 ( uint16_t  v,
int  s 
) [inline, static]

Rotate 16-bit int to left.

Referenced by ror16().

static uint32_t rol32 ( uint32_t  v,
int  s 
) [inline, static]

Rotate 32-bit int to left.

Referenced by ror32().

static uint64_t rol64 ( uint64_t  v,
int  s 
) [inline, static]

Rotate 64-bit int to left.

Referenced by ror64().

static uint16_t ror16 ( uint16_t  v,
int  s 
) [inline, static]

Rotate 16-bit int to right.

References rol16().

static uint32_t ror32 ( uint32_t  v,
int  s 
) [inline, static]

Rotate 32-bit int to right.

References rol32().

static uint64_t ror64 ( uint64_t  v,
int  s 
) [inline, static]

Rotate 64-bit int to right.

References rol64().

static int fls ( int  x) [inline, static]

Find last (highest) set bit, 1-based offset, 0 if arg == 0.

static int flsl ( long  x) [inline, static]

Find last (highest) set bit, 1-based offset, 0 if arg == 0.

static int flsll ( long long  x) [inline, static]

Find last (highest) set bit, 1-based offset, 0 if arg == 0.

static int ffs ( int  x) [inline, static]

Find first (lowest) set bit, 1-based ofs, 0 if arg == 0.

static int ffsl ( long  x) [inline, static]

Find first (lowest) set bit, 1-based ofs, 0 if arg == 0.

static int ffsll ( long long  x) [inline, static]

Find first (lowest) set bit, 1-based ofs, 0 if arg == 0.

static bool safe_mul_uint ( unsigned int *  res_p,
unsigned int  a,
unsigned int  b 
) [inline, static]

Multiply with overflow check for 'unsigned int'.

static bool safe_mul_ulong ( unsigned long *  res_p,
unsigned long  a,
unsigned long  b 
) [inline, static]

Multiply with overflow check for 'unsigned long'.

static bool safe_mul_uint8 ( uint8_t *  res_p,
uint8_t  a,
uint8_t  b 
) [inline, static]

Multiply with overflow check for 'uint8_t'.

static bool safe_mul_uint16 ( uint16_t *  res_p,
uint16_t  a,
uint16_t  b 
) [inline, static]

Multiply with overflow check for 'uint16_t'.

static bool safe_mul_uint32 ( uint32_t *  res_p,
uint32_t  a,
uint32_t  b 
) [inline, static]

Multiply with overflow check for 'uint32_t'.

static bool safe_mul_uint64 ( uint64_t *  res_p,
uint64_t  a,
uint64_t  b 
) [inline, static]

Multiply with overflow check for 'uint64_t'.

static bool safe_mul_size ( size_t *  res_p,
size_t  a,
size_t  b 
) [inline, static]

Multiply with overflow check for 'size_t'.