Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

Counts the number of contiguous, most-significant, leading 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 / Specific CPU/compiler cpu_a.asm

Prototypes

Code Block
languagecpp
          CPU_DATA  CPU_CntLeadZeros (CPU_DATA  val);
           
          CPU_DATA  CPU_CntLeadZeros08 (CPU_INT08U  val);
          CPU_DATA  CPU_CntLeadZeros16 (CPU_INT16U  val);
          CPU_DATA  CPU_CntLeadZeros32 (CPU_INT32U  val);
          CPU_DATA  CPU_CntLeadZeros64 (CPU_INT64U  val);


Arguments

val

Data value to count leading zero bits.

Returned Value

Number of contiguous, most-significant, leading zero bits in val.

Required Configuration

CPU_CntLeadZeros()is available and implemented in cpu_core.c if CPU_CFG_LEAD_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_LEAD_ZEROS_ASM_PRESENT is #define'd in cpu_cfg.h (or cpu.h). Refer to Core Library Configuration for details.

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

...

CPU_CntLeadZero08() = CPU_WORD_SIZE_08
CPU_CntLeadZero16() = CPU_WORD_SIZE_16
CPU_CntLeadZero32() = CPU_WORD_SIZE_32
CPU_CntLeadZero64() = CPU_WORD_SIZE_64

Notes / Warnings

None.

Example Usage

Code Block
languagecpp
          CPU_DATA  val;
          CPU_DATA  nbr_lead_zeros;
           
          val            = 0x0643A718;
          nbr_lead_zeros = CPU_CntLeadZeros(val);
          nbr_lead_zeros = CPU_CntLeadZeros08((CPU_INT08U)val);
          nbr_lead_zeros = CPU_CntLeadZeros16((CPU_INT16U)val);
          nbr_lead_zeros = CPU_CntLeadZeros32((CPU_INT32U)val);
          nbr_lead_zeros = CPU_CntLeadZeros64((CPU_INT64U)val);