lib: packing: replace bit_reverse() with bitrev8()
Remove bit_reverse() function. Instead use bitrev8() from linux/bitrev.h + bitshift. Reduces code-repetition. Signed-off-by: Uladzislau Koshchanka <koshchanka@gmail.com> Link: https://lore.kernel.org/r/20221210004423.32332-1-koshchanka@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
93e637a37b
commit
1280d4b76f
|
@ -24,6 +24,7 @@ config LINEAR_RANGES
|
||||||
|
|
||||||
config PACKING
|
config PACKING
|
||||||
bool "Generic bitfield packing and unpacking"
|
bool "Generic bitfield packing and unpacking"
|
||||||
|
select BITREVERSE
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
This option provides the packing() helper function, which permits
|
This option provides the packing() helper function, which permits
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <linux/bitops.h>
|
#include <linux/bitops.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
#include <linux/bitrev.h>
|
||||||
|
|
||||||
static int get_le_offset(int offset)
|
static int get_le_offset(int offset)
|
||||||
{
|
{
|
||||||
|
@ -29,19 +30,6 @@ static int get_reverse_lsw32_offset(int offset, size_t len)
|
||||||
return word_index * 4 + offset;
|
return word_index * 4 + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 bit_reverse(u64 val, unsigned int width)
|
|
||||||
{
|
|
||||||
u64 new_val = 0;
|
|
||||||
unsigned int bit;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
for (i = 0; i < width; i++) {
|
|
||||||
bit = (val & (1 << i)) != 0;
|
|
||||||
new_val |= (bit << (width - i - 1));
|
|
||||||
}
|
|
||||||
return new_val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void adjust_for_msb_right_quirk(u64 *to_write, int *box_start_bit,
|
static void adjust_for_msb_right_quirk(u64 *to_write, int *box_start_bit,
|
||||||
int *box_end_bit, u8 *box_mask)
|
int *box_end_bit, u8 *box_mask)
|
||||||
{
|
{
|
||||||
|
@ -49,7 +37,7 @@ static void adjust_for_msb_right_quirk(u64 *to_write, int *box_start_bit,
|
||||||
int new_box_start_bit, new_box_end_bit;
|
int new_box_start_bit, new_box_end_bit;
|
||||||
|
|
||||||
*to_write >>= *box_end_bit;
|
*to_write >>= *box_end_bit;
|
||||||
*to_write = bit_reverse(*to_write, box_bit_width);
|
*to_write = bitrev8(*to_write) >> (8 - box_bit_width);
|
||||||
*to_write <<= *box_end_bit;
|
*to_write <<= *box_end_bit;
|
||||||
|
|
||||||
new_box_end_bit = box_bit_width - *box_start_bit - 1;
|
new_box_end_bit = box_bit_width - *box_start_bit - 1;
|
||||||
|
|
Loading…
Reference in New Issue