diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-01-20 07:06:30 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-01-20 07:06:30 +0100 |
commit | 8623a0bf1fb2136a32c172ee48d2ff3274ca2cef (patch) | |
tree | a8edb7b10065d2d37cdbc1f3474f00c4c28416f6 /src/algorithms/bits | |
parent | optimised parallel parity (diff) | |
download | algorithms-and-data-structures-8623a0bf1fb2136a32c172ee48d2ff3274ca2cef.tar.gz algorithms-and-data-structures-8623a0bf1fb2136a32c172ee48d2ff3274ca2cef.tar.bz2 algorithms-and-data-structures-8623a0bf1fb2136a32c172ee48d2ff3274ca2cef.tar.xz |
64-bit instructions for parity on byte
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/algorithms/bits/Bits.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/algorithms/bits/Bits.java b/src/algorithms/bits/Bits.java index 8625310..3101217 100644 --- a/src/algorithms/bits/Bits.java +++ b/src/algorithms/bits/Bits.java @@ -64,6 +64,17 @@ public class Bits private static byte[] PARITY_TABLE_256 = { £(parity-table 4 0) }; + /** + * Compute the parity of all bits in an integer, 64-bit multiply–modulus version + * + * @param value The interger + * @return The parity + */ + public static int parity_64bit(byte value) + { + return (int)(((value * 0x0101010101010101L) & 0x8040201008040201L) % 0x1FF) & 1; + } + £<for T_S in char_2 byte_1 short_2 int_4 long_8; do T=${T_S%_*} £>S=${T_S#*_} |