From 465b01edc815c64b2025d6412fcebacd72edde36 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 20 Jan 2014 07:01:54 +0100 Subject: optimised parallel parity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/algorithms/bits/Bits.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 } -- cgit v1.2.3-70-g09d2