diff options
author | Sven Eckelmann <sven.eckelmann@gmx.de> | 2010-09-05 01:58:22 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-09-05 00:29:43 -0700 |
commit | 8bb22a38d6083d751075829e84421b139dabb460 (patch) | |
tree | 57eb1115dafe8cec963efa662e9c9c72033f1c30 /drivers/staging/batman-adv/bitarray.c | |
parent | 556c83ece8e8a897d7cad23315407ecd1a195fce (diff) | |
download | op-kernel-dev-8bb22a38d6083d751075829e84421b139dabb460.zip op-kernel-dev-8bb22a38d6083d751075829e84421b139dabb460.tar.gz |
Staging: batman-adv: Calculate hamming weight using optimized kernel functions
The Kernighan algorithm is not able to calculate the number of set bits
in parallel and the compiler cannot replace it with optimized
instructions.
The kernel provides specialised functions for each cpu which can either
use a software implementation or hardware instruction depending on the
target cpu.
Reported-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/batman-adv/bitarray.c')
-rw-r--r-- | drivers/staging/batman-adv/bitarray.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/staging/batman-adv/bitarray.c b/drivers/staging/batman-adv/bitarray.c index dd4193c..9dbaf1e 100644 --- a/drivers/staging/batman-adv/bitarray.c +++ b/drivers/staging/batman-adv/bitarray.c @@ -22,6 +22,8 @@ #include "main.h" #include "bitarray.h" +#include <linux/bitops.h> + /* returns true if the corresponding bit in the given seq_bits indicates true * and curr_seqno is within range of last_seqno */ uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno, @@ -187,21 +189,14 @@ char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff, } /* count the hamming weight, how many good packets did we receive? just count - * the 1's. The inner loop uses the Kernighan algorithm, see - * http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan + * the 1's. */ int bit_packet_count(TYPE_OF_WORD *seq_bits) { int i, hamming = 0; - TYPE_OF_WORD word; - for (i = 0; i < NUM_WORDS; i++) { - word = seq_bits[i]; + for (i = 0; i < NUM_WORDS; i++) + hamming += hweight_long(seq_bits[i]); - while (word) { - word &= word-1; - hamming++; - } - } return hamming; } |