CPU_CntTrailZerosXX

Description

Counts the number of contiguous, least-significant, trailing zero bits in a data value. If available on the targeted architecture an alternate optimized implementation can be defined.

Files

cpu_core.h/cpu_core.c

Prototypes

          CPU_DATA  CPU_CntTrailZeros (CPU_DATA  val);
           
          CPU_DATA  CPU_CntTrailZeros08 (CPU_INT08U  val);
          CPU_DATA  CPU_CntTrailZeros16 (CPU_INT16U  val);
          CPU_DATA  CPU_CntTrailZeros32 (CPU_INT32U  val);
          CPU_DATA  CPU_CntTrailZeros64 (CPU_INT64U  val);


Arguments

val

Data value to count trailing zero bits.

Returned Value

Number of contiguous, least-significant, trailing zero bits in val.

Required Configuration

CPU_CntTrailZeros() available and implemented in cpu_core.c if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT is not #define'd in cpu_cfg.h (or cpu.h), but should be implemented in cpu_a.asm (or cpu_a.s) if CPU_CFG_TRAIL_ZEROS_ASM_PRESENT is #define'd in cpu_cfg.h (or cpu.h). Refer to Core Library Configuration for details.

Each CPU_CntTrailZerosXX() is available and implemented in cpu_core.c based on CPU_CFG_DATA_SIZE_MAX configuration as #define'd in cpu.h :

Functions available according to CPU_CFG_DATA_SIZE_MAX:

CPU_CntTrailZero08() = CPU_WORD_SIZE_08
CPU_CntTrailZero16() = CPU_WORD_SIZE_16
CPU_CntTrailZero32() = CPU_WORD_SIZE_32
CPU_CntTrailZero64() = CPU_WORD_SIZE_64

Notes / Warnings

  1. For non-zero values, the returned number of contiguous, least-significant, trailing zero bits is also equivalent to the bit position of the least-significant set bit.

Example Usage

          CPU_DATA  val;
          CPU_DATA  nbr_trail_zeros;
           
          val             = 0x0643A718;
          nbr_trail_zeros = CPU_CntTrailZeros(val);
          nbr_trail_zeros = CPU_CntTrailZeros08((CPU_INT08U)val);
          nbr_trail_zeros = CPU_CntTrailZeros16((CPU_INT16U)val);
          nbr_trail_zeros = CPU_CntTrailZeros32((CPU_INT32U)val);
          nbr_trail_zeros = CPU_CntTrailZeros64((CPU_INT64U)val);