[Get Parity of 32-bit word]                           [Assembler][/][80386]

There is sometimes need to get the parity of a 32-bit word. This is one
solution:

;
; get parity of 32 bit word
;
; input:
;   eax = word to get parity from
;
; output:
;   flags (parity flag)
;
; destroys:
;   eax,ebx
;

        mov     ebx,eax
        shr     eax,16
        xor     eax,ebx
        xor     al,ah
        jp      Parity          ; 4 cycles if correctly predicted

For 16-bit code SHLD (4 cycles?) seems to be equivalent to MOV (2) + SHR
(2), and better on 386/486 cpus:

;
; get parity of 32 bit word
;
; input:
;   eax = word to get parity from
;
; output:
;   flags (parity flag)
;
; destroys:
;   eax,ebx
;

        shld    ebx,eax,16
        xor     ax,bx
        xor     al,ah
        jp      Parity          ; 6 cycles in 16-bit mode?

                                                 Gem writer: Terje Mathisen
                                                   last updated: 1998-03-16
