diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-01-20 07:01:54 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-01-20 07:01:54 +0100 |
commit | 465b01edc815c64b2025d6412fcebacd72edde36 (patch) | |
tree | f705491306a79d667c5d5667178913ca1970c168 /src | |
parent | m (diff) | |
download | algorithms-and-data-structures-465b01edc815c64b2025d6412fcebacd72edde36.tar.gz algorithms-and-data-structures-465b01edc815c64b2025d6412fcebacd72edde36.tar.bz2 algorithms-and-data-structures-465b01edc815c64b2025d6412fcebacd72edde36.tar.xz |
optimised parallel parity
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/algorithms/bits/Bits.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/algorithms/bits/Bits.java b/src/algorithms/bits/Bits.java index 3dfeca4..8625310 100644 --- a/src/algorithms/bits/Bits.java +++ b/src/algorithms/bits/Bits.java @@ -314,6 +314,24 @@ public class Bits value ^= value >> 8; return PARITY_TABLE_256[(int)value]; } + + /** + * Compute the parity of all bits in an integer, optimised parallel version + * + * @param value The interger + * @return The parity + */ + public static int parity_optimised_parallel(£{T} value) + { +£>(( $S > 4 )) && + value ^= value >> 32; +£>(( $S > 2 )) && + value ^= value >> 16; +£>(( $S > 1 )) && + value ^= value >> 8; + value ^= value >> 4; + return (0x6996 >> (value & 15)) & 1; + } £>done } |