[U-Boot] [PATCH 6/8] lib: import bitrev library from linux kernel

Mike Dunn mikedunn at newsguy.com
Mon Apr 8 18:46:26 CEST 2013


On 04/07/2013 11:23 PM, Marek Vasut wrote:
> Dear Mike Dunn,
> 
>> This patch adds the bitrev library from the linux kernel.  This is a simple
>> algorithm that uses an 8 bit look-up table to reverse the bits in data
>> types of 8, 16, or 32 bit widths.  The docg4 nand flash driver uses it.
>>
>> Signed-off-by: Mike Dunn <mikedunn at newsguy.com>
>> ---
>>  include/linux/bitrev.h |   16 +++++++++++++
>>  lib/Makefile           |    1 +
>>  lib/bitrev.c           |   56
>> ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73
>> insertions(+), 0 deletions(-)
>>  create mode 100644 include/linux/bitrev.h
>>  create mode 100644 lib/bitrev.c
>>
>> diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h
>> new file mode 100644
>> index 0000000..7ffe03f
>> --- /dev/null
>> +++ b/include/linux/bitrev.h
>> @@ -0,0 +1,16 @@
>> +#ifndef _LINUX_BITREV_H
>> +#define _LINUX_BITREV_H
>> +
>> +#include <linux/types.h>
>> +
>> +extern u8 const byte_rev_table[256];
>> +
>> +static inline u8 bitrev8(u8 byte)
>> +{
>> +	return byte_rev_table[byte];
>> +}
>> +
>> +extern u16 bitrev16(u16 in);
>> +extern u32 bitrev32(u32 in);
> 
> Do we really need to expose the array and use so many externs here?



Yeah, I don't know why the function prototypes were given the 'extern'
specifier.  This is how it is in the kernel.  They aren't necessary.

As for the table... if the bitrev8() function is moved to bitrev.c, the table
need not be extern.  But if I'm not mistaken, bitrev8() is in the header so that
it can be inlined by the compiler.  So for the sake of performance I think the
extern is appropriate for the table.

Thanks Marek,
Mike



More information about the U-Boot mailing list