Xmega Application Note


clz_ctz.h File Reference

CLZ/CTZ C implemetation. More...

Go to the source code of this file.

Defines

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

Functions

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

Detailed Description

CLZ/CTZ C implemetation.

Copyright (C) 2009 Atmel Corporation. All rights reserved.

Definition in file clz_ctz.h.


Define Documentation

#define clz (  )     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:
x Unsigned integer to count the leading zeros in.
Returns:
The number of leading zeros in x.

Definition at line 51 of file clz_ctz.h.

Referenced by ilog2().

#define ctz (  )     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:
x Unsigned integer to count the trailing zeros in.
Returns:
The number of trailing zeros in x.

Definition at line 138 of file clz_ctz.h.

Referenced by fifo_init_malloc(), and fifo_init_no_malloc().


Function Documentation

static __always_inline uint8_t clz16 ( uint16_t  x  )  [static]

Count leading zeros in unsigned, 16-bit integer.

For internal use only.

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

Definition at line 93 of file clz_ctz.h.

References clz8().

Referenced by clz32().

00094 {
00095         uint8_t bit = 0;
00096 
00097         if (x & 0xff00) {
00098                 x >>= 8;
00099         } else {
00100                 bit += 8;
00101         }
00102 
00103         return bit + clz8(x);
00104 }

Here is the call graph for this function:

static __always_inline uint8_t clz32 ( uint32_t  x  )  [static]

Count leading zeros in unsigned, 32-bit integer.

For internal use only.

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

Definition at line 114 of file clz_ctz.h.

References clz16().

00115 {
00116         uint8_t bit = 0;
00117 
00118         if (x & 0xffff0000) {
00119                 x >>= 16;
00120         } else {
00121                 bit += 16;
00122         }
00123 
00124         return bit + clz16(x);
00125 }

Here is the call graph for this function:

static __always_inline uint8_t clz8 ( uint8_t  x  )  [static]

Count leading zeros in unsigned, 8-bit integer.

For internal use only.

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

Definition at line 61 of file clz_ctz.h.

Referenced by clz16().

00062 {
00063         uint8_t bit = 0;
00064 
00065         if (x & 0xf0) {
00066                 x >>= 4;
00067         } else {
00068                 bit += 4;
00069         }
00070 
00071         if (x & 0x0c) {
00072                 x >>= 2;
00073         } else {
00074                 bit += 2;
00075         }
00076 
00077         if (!(x & 0x02)) {
00078                 bit++;
00079         }
00080 
00081         return bit;
00082 
00083 }

static __always_inline uint8_t ctz16 ( uint16_t  x  )  [static]

Count trailing zeros in unsigned, 16-bit integer.

For internal use only.

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

Definition at line 174 of file clz_ctz.h.

References ctz8().

Referenced by ctz32().

00175 {
00176         uint8_t bit = 0;
00177 
00178         if (!(x & 0x00ff)) {
00179                 bit += 8;
00180                 x >>= 8;
00181         }
00182 
00183         return bit + ctz8(x);
00184 }

Here is the call graph for this function:

static __always_inline uint8_t ctz32 ( uint32_t  x  )  [static]

Count trailing zeros in unsigned, 32-bit integer.

For internal use only.

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

Definition at line 194 of file clz_ctz.h.

References ctz16().

00195 {
00196         uint8_t bit = 0;
00197 
00198         if (!(x & 0x0000ffff)) {
00199                 bit += 16;
00200                 x >>= 16;
00201         }
00202 
00203         return bit + ctz16(x);
00204 }

Here is the call graph for this function:

static __always_inline uint8_t ctz8 ( uint8_t  x  )  [static]

Count trailing zeros in unsigned, 8-bit integer.

For internal use only.

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

Definition at line 148 of file clz_ctz.h.

Referenced by ctz16().

00149 {
00150         uint8_t bit = 0;
00151 
00152         if (!(x & 0x0f)) {
00153                 bit += 4;
00154                 x >>= 4;
00155         }
00156         if (!(x & 0x03)) {
00157                 bit += 2;
00158                 x >>= 2;
00159         }
00160         if (!(x & 0x01))
00161                 bit++;
00162 
00163         return bit;
00164 }

@DOC_TITLE@
Generated on Fri Oct 22 12:15:25 2010 for AVR1300 Using the Xmega ADC by doxygen 1.6.3