HP OpenVMS Systems

ask the wizard
Content starts here

ctpop, Alpha count population instruction?

» close window

The Question is:

I wonder if there is any MACRO source code or any other programming language
 code example on how to use the ctpop instruction in the Alpha architecure.

The Answer is :

  The CTPOP count population Alpha instruction is part of one of the more
  recently added Alpha instruction groups known as the count instructions
  extension (CIX), and would be an AMACRO (Alpha assembler; Macro64)
  instruction -- and not a Macro32 (VAX Macro compiler) instruction.
  This is also available to C code using the asm mechanism, as well, and
  (in recent C compilers) the _POPCNT() C built-in function.
  The OpenVMS Wizard would recommend coding a particular instruction or
  built-in with care, as this usage can lead to code-portability issues.
  For details on how to interprete the following, please see the Macro64
  documentation on the OpenVMS Freeware.
   Count Population
                CTPOP  Rb.rq,Rc.wq      ! Operate Format
                temp = 0
                FOR i FROM 0 TO 63
                  IF { Rbv<i> EQ 1 } THEN temp = temp + 1
                Rc<6:0> <- temp<6:0>
                Rc<63:7> <- 0
        Instruction Mnemonics:
                CTPOP   Count Population
                The number of ones in Rb is written to Rc.

answer written or last revised on ( 17-DEC-2003 )

» close window