모두의 코드
POPCNT (Intel x86/64 assembly instruction)

작성일 : 2020-09-01 이 글은 29 번 읽혔습니다.

POPCNT

Return the Count of Number of Bits Set to 1

참고 사항

아래 표를 해석하는 방법은 x86-64 명령어 레퍼런스 읽는 법 글을 참조하시기 바랍니다.

OpcodeInstructionOp/
En
64-Bit
Mode
Compat/
Leg Mode
Description
F3 0F B8 /rPOPCNT r16 r/m16RMValidValidPOPCNT on r/m16
F3 0F B8 /rPOPCNT r32 r/m32RMValidValidPOPCNT on r/m32
F3 REX.W 0F B8 /rPOPCNT r64 r/m64RMValidN.E.POPCNT on r/m64

Instruction Operand Encoding

Op/EnOperand 1Operand 2Operand 3Operand 4
RMModRM:reg (w)ModRM:r/m (r)NANA

Description

This instruction calculates the number of bits set to 1 in the second operand (source) and returns the count in the first operand (a destination register).

Operation

Count = 0;
For (i=0; i < OperandSize; i++) 
{   IF (SRC[ i] = 1) // i'th bit
          THEN Count++; FI;
}
DEST <-  Count;

Flags Affected

OF, SF, ZF, AF, CF, PF are all cleared. ZF is set if SRC = 0, otherwise ZF is cleared.

Intel C/C++ Compiler Intrinsic Equivalent

POPCNT : int _mm_popcnt_u32(unsigned int a);
POPCNT : int64_t _mm_popcnt_u64(unsigned __int64 a);

Protected Mode Exceptions

#GP(0)

  • If a memory operand effective address is outside the CS, DS, ES, FS or GS segments.

#SS(0)

  • If a memory operand effective address is outside the SS segment limit.

#PF

  • (fault-code) For a page fault.

#AC(0)

  • If an unaligned memory reference is made while the current privilege level is 3 and alignment checking is enabled.

#UD

  • If CPUID.01H:ECX.POPCNT [Bit 23] = 0.

  • If LOCK prefix is used.

Real-Address Mode Exceptions

#GP(0)

  • If any part of the operand lies outside of the effective address space from 0 to 0FFFFH.

#SS(0)

  • If a memory operand effective address is outside the SS segment limit.

#UD

  • If CPUID.01H:ECX.POPCNT [Bit 23] = 0.

  • If LOCK prefix is used.

Virtual 8086 Mode Exceptions

#GP(0) If any part of the operand lies outside of the effective address space from 0 to 0FFFFH.

#SS(0) If a memory operand effective address is outside the SS segment limit.

#PF (fault-code) For a page fault.

#AC(0) If an unaligned memory reference is made while alignment checking is enabled.

#UD If CPUID.01H:ECX.POPCNT [Bit 23] = 0.

If LOCK prefix is used.

Compatibility Mode Exceptions

Same exceptions as in Protected Mode.

64-Bit Mode Exceptions

#GP(0)

  • If the memory address is in a non-canonical form.

#SS(0)

  • If a memory address referencing the SS segment is in a non-canonical form.

#PF

  • (fault-code) For a page fault.

#AC(0)

  • If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.

#UD

  • If CPUID.01H:ECX.POPCNT [Bit 23] = 0.

  • If LOCK prefix is used.

첫 댓글을 달아주세요!
프로필 사진 없음
강좌에 관련 없이 궁금한 내용은 여기를 사용해주세요