aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-20 07:01:54 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-20 07:01:54 +0100
commit465b01edc815c64b2025d6412fcebacd72edde36 (patch)
treef705491306a79d667c5d5667178913ca1970c168 /src
parentm (diff)
downloadalgorithms-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 'src')
-rw-r--r--src/algorithms/bits/Bits.java18
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
}