Atmel Software Framework

clz_ctz.h File Reference

CLZ/CTZ C implementation.

Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.

Macros

#define clz(x)   compiler_demux_size(sizeof(x), clz, (x))
 Count leading zeros in unsigned integer. More...
 
#define ctz(x)   compiler_demux_size(sizeof(x), ctz, (x))
 Count trailing zeros in unsigned integer. More...
 

Functions

static __always_inline uint8_t clz16 (uint16_t x)
 Count leading zeros in unsigned, 16-bit integer. More...
 
static __always_inline uint8_t clz32 (uint32_t x)
 Count leading zeros in unsigned, 32-bit integer. More...
 
static __always_inline uint8_t clz8 (uint8_t x)
 Count leading zeros in unsigned, 8-bit integer. More...
 
static __always_inline uint8_t ctz16 (uint16_t x)
 Count trailing zeros in unsigned, 16-bit integer. More...
 
static __always_inline uint8_t ctz32 (uint32_t x)
 Count trailing zeros in unsigned, 32-bit integer. More...
 
static __always_inline uint8_t ctz8 (uint8_t x)
 Count trailing zeros in unsigned, 8-bit integer. More...
 

#define clz (   x)    compiler_demux_size(sizeof(x), clz, (x))

Count leading zeros in unsigned integer.

This macro takes unsigned integers of any size, and evaluates to a call to the clz-function for its size. These functions count the number of zeros, starting with the MSB, before a one occurs in the integer.

Parameters
xUnsigned integer to count the leading zeros in.
Returns
The number of leading zeros in x.

Referenced by ilog2().

#define ctz (   x)    compiler_demux_size(sizeof(x), ctz, (x))

Count trailing zeros in unsigned integer.

This macro takes unsigned integers of any size, and evaluates to a call to the ctz-function for its size. These functions count the number of zeros, starting with the LSB, before a one occurs in the integer.

Parameters
xUnsigned integer to count the trailing zeros in.
Returns
The number of trailing zeros in x.

static __always_inline uint8_t clz16 ( uint16_t  x)
static

Count leading zeros in unsigned, 16-bit integer.

Parameters
xUnsigned word to count the leading zeros in.
Returns
The number of leading zeros in x.

References clz8().

Referenced by clz32().

static __always_inline uint8_t clz32 ( uint32_t  x)
static

Count leading zeros in unsigned, 32-bit integer.

Parameters
xUnsigned double word to count the leading zeros in.
Returns
The number of leading zeros in x.

References clz16().

static __always_inline uint8_t clz8 ( uint8_t  x)
static

Count leading zeros in unsigned, 8-bit integer.

Parameters
xUnsigned byte to count the leading zeros in.
Returns
The number of leading zeros in x.

Referenced by clz16().

static __always_inline uint8_t ctz16 ( uint16_t  x)
static

Count trailing zeros in unsigned, 16-bit integer.

Parameters
xUnsigned word to count the trailing zeros in.
Returns
The number of trailing zeros in x.

References ctz8().

Referenced by ctz32().

static __always_inline uint8_t ctz32 ( uint32_t  x)
static

Count trailing zeros in unsigned, 32-bit integer.

Parameters
xUnsigned double word to count the trailing zeros in.
Returns
The number of trailing zeros in x.

References ctz16().

static __always_inline uint8_t ctz8 ( uint8_t  x)
static

Count trailing zeros in unsigned, 8-bit integer.

Parameters
xUnsigned byte to count the trailing zeros in.
Returns
The number of leading zeros in x.

Referenced by ctz16().