Skip to content

Commit 1280d4b

Browse files
Uladzislau Koshchankakuba-moo
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 93e637a commit 1280d4b

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

lib/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ config LINEAR_RANGES
2424

2525
config PACKING
2626
bool "Generic bitfield packing and unpacking"
27+
select BITREVERSE
2728
default n
2829
help
2930
This option provides the packing() helper function, which permits

lib/packing.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/bitops.h>
88
#include <linux/errno.h>
99
#include <linux/types.h>
10+
#include <linux/bitrev.h>
1011

1112
static int get_le_offset(int offset)
1213
{
@@ -29,27 +30,14 @@ static int get_reverse_lsw32_offset(int offset, size_t len)
2930
return word_index * 4 + offset;
3031
}
3132

32-
static u64 bit_reverse(u64 val, unsigned int width)
33-
{
34-
u64 new_val = 0;
35-
unsigned int bit;
36-
unsigned int i;
37-
38-
for (i = 0; i < width; i++) {
39-
bit = (val & (1 << i)) != 0;
40-
new_val |= (bit << (width - i - 1));
41-
}
42-
return new_val;
43-
}
44-
4533
static void adjust_for_msb_right_quirk(u64 *to_write, int *box_start_bit,
4634
int *box_end_bit, u8 *box_mask)
4735
{
4836
int box_bit_width = *box_start_bit - *box_end_bit + 1;
4937
int new_box_start_bit, new_box_end_bit;
5038

5139
*to_write >>= *box_end_bit;
52-
*to_write = bit_reverse(*to_write, box_bit_width);
40+
*to_write = bitrev8(*to_write) >> (8 - box_bit_width);
5341
*to_write <<= *box_end_bit;
5442

5543
new_box_end_bit = box_bit_width - *box_start_bit - 1;

0 commit comments

Comments
 (0)