• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Math
      • 100-theorems
      • Arithmetic
      • Bit-vectors
        • Sparseint
        • Bitops
          • Bitops/merge
          • Bitops-compatibility
          • Bitops-books
          • Logbitp-reasoning
          • Bitops/signed-byte-p
          • Fast-part-select
          • Bitops/integer-length
          • Bitops/extra-defs
          • Install-bit
          • Trailing-0-count
          • Bitops/defaults
          • Logbitp-mismatch
          • Trailing-1-count
          • Bitops/rotate
          • Bitops/equal-by-logbitp
          • Bitops/ash-bounds
          • Bitops/fast-logrev
          • Limited-shifts
          • Bitops/part-select
          • Bitops/parity
            • Parity
            • Parity4
            • Parity32
              • Fast-parity
            • Bitops/saturate
            • Bitops/part-install
            • Bitops/logbitp-bounds
            • Bitops/ihsext-basics
            • Bitops/fast-rotate
            • Bitops/fast-logext
            • Bitops/ihs-extensions
          • Bv
          • Ihs
          • Rtl
        • Algebra
      • Testing-utilities
    • Bitops/parity

    Parity32

    Optimized version of (parity 32 x).

    Signature
    (parity32 x) → *

    The basic idea is from Sean Anderson's bit twiddling hacks page, except that we don't use a lookup table at the end. See parity4 for details about why we don't do that.

    Definitions and Theorems

    Function: parity32$inline

    (defun parity32$inline (x)
     (declare (type (unsigned-byte 32) x))
     (let ((__function__ 'parity32))
      (declare (ignorable __function__))
      (mbe :logic (parity 32 x)
           :exec
           (b* ((x (the (unsigned-byte 32)
                        (logxor x
                                (the (unsigned-byte 32) (ash x -16)))))
                (x (the (unsigned-byte 32)
                        (logxor x (the (unsigned-byte 32) (ash x -8)))))
                (x (the (unsigned-byte 32)
                        (logxor x (the (unsigned-byte 32) (ash x -4)))))
                (x (the (unsigned-byte 32)
                        (logxor x (the (unsigned-byte 32) (ash x -2)))))
                (x (the (unsigned-byte 32)
                        (logxor x
                                (the (unsigned-byte 32) (ash x -1))))))
             (the (unsigned-byte 1) (logand 1 x))))))