U-boot-V2:ARM: Introduce additional bitops
Subsystems (3)
Menon
PATCH 2/9 U-boot-V2:ARM: Introduce additional bitops
Add linux-like bitops definitions - this is based on 2.6.25 rc5 kernel
--- arch/arm/lib/Makefile | 1 arch/arm/lib/findbit.S | 181 +++++++++++++++++++++++++++++++++++++++++++++++ include/asm-arm/bitops.h | 86 +++++++++++++++++++++- 3 files changed, 265 insertions(+), 3 deletions(-)
arch/arm/lib/findbit.S 2008-06-17 17:01:06.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +181 -0
@@ -0,0 +1,181 @@ +/** + * @file + * @brief common bitops + */ +/* + * Originally from Linux kernel + * arch/arm/lib/findbit.S + * + * Copyright (C) 1995-2000 Russell King + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 16th March 2001 - John Ripley <[email protected]> + * Fixed so that "size" is an exclusive not an inclusive quantity. + * All users of these functions expect exclusive sizes, and may + * also call with zero size. + * Reworked by rmk. + */ + .text + +/* + * Purpose : Find a 'zero' bit + * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit); + */ + .globl _find_first_zero_bit_le; +_find_first_zero_bit_le: + teq r1, #0 + beq 3f + mov r2, #0 +1: ldrb r3, [r0, r2, lsr #3] + eors r3, r3, #0xff @ invert bits + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + +/* + * Purpose : Find next 'zero' bit + * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, + * int offset) + */ + .globl _find_next_zero_bit_le; +_find_next_zero_bit_le: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + ldrb r3, [r0, r2, lsr #3] + eor r3, r3, #0xff @ now looking for a 1 bit + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + +/* + * Purpose : Find a 'one' bit + * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit) + */ + .globl _find_first_bit_le; +_find_first_bit_le: + teq r1, #0 + beq 3f + mov r2, #0 +1: ldrb r3, [r0, r2, lsr #3] + movs r3, r3 + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + +/* + * Purpose : Find next 'one' bit + * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, + * int offset) + */ + .globl _find_next_bit_le; +_find_next_bit_le: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + ldrb r3, [r0, r2, lsr #3] + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + +#ifdef __ARMEB__ + + .globl _find_first_zero_bit_be; +_find_first_zero_bit_be: + teq r1, #0 + beq 3f + mov r2, #0 +1: eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + eors r3, r3, #0xff @ invert bits + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + + .globl _find_next_zero_bit_be; +_find_next_zero_bit_be: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + eor r3, r3, #0xff @ now looking for a 1 bit + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + + .globl _find_first_bit_be; +_find_first_bit_be: + teq r1, #0 + beq 3f + mov r2, #0 +1: eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + movs r3, r3 + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + + .globl _find_next_bit_be; +_find_next_bit_be: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + +#endif + +/* + * One or more bits in the LSB of r3 are assumed to be set. + */ +.L_found: +#if __LINUX_ARM_ARCH__ >= 5 + rsb r1, r3, #0 + and r3, r3, r1 + clz r3, r3 + rsb r3, r3, #31 + add r0, r2, r3 +#else + tst r3, #0x0f + addeq r2, r2, #4 + movne r3, r3, lsl #4 + tst r3, #0x30 + addeq r2, r2, #2 + movne r3, r3, lsl #2 + tst r3, #0x40 + addeq r2, r2, #1 + mov r0, r2 +#endif + mov pc, lr +
arch/arm/lib/Makefile 2008-06-17 17:01:06.000000000 -0500 renamed from arch/arm/lib/Makefile 2008-06-17 16:52:31.000000000 -0500 +1 -0
@@ -8,6 +8,7 @@ obj-y += _udivsi3.o obj-y += _umodsi3.o obj-y += _lshrdi3.o +obj-y += findbit.o obj-y += arm.o obj-$(CONFIG_MODULES) += module.o extra-$(CONFIG_GENERIC_LINKER_SCRIPT) += u-boot.lds
include/asm-arm/bitops.h 2008-06-17 17:01:06.000000000 -0500 renamed from include/asm-arm/bitops.h 2008-06-17 16:52:31.000000000 -0500 +83 -3
104 lines not on this page · raw message
PATCH 2/9 U-boot-V2:ARM: Introduce additional bitops
Quoted 1 line · Nishanth
Add linux-like bitops definitions - this is based on 2.6.25 rc5 kernel
I haven't looked at it, but I guess you need these for the following patches. It would be better to first introduce generic bitops. Otherwise we end up with i2c only working on arm.
Sascha
Quoted 319 lines
Signed-off-by Nishanth Menon <[email protected]>--- arch/arm/lib/Makefile | 1 arch/arm/lib/findbit.S | 181 +++++++++++++++++++++++++++++++++++++++++++++++ include/asm-arm/bitops.h | 86 +++++++++++++++++++++- 3 files changed, 265 insertions(+), 3 deletions(-)Index:
u-boot-v2.git/arch/arm/lib/findbit.S
===================================================================arch/arm/lib/findbit.S 2008-06-17 17:01:06.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +181
-0@@ -0,0 +1,181 @@ +/** + * @file + * @brief common bitops + */ +/* + * Originally from Linux kernel + * arch/arm/lib/findbit.S + * + * Copyright (C) 1995-2000 Russell King + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 16th March 2001 - John Ripley <[email protected]> + * Fixed so that "size" is an exclusive not an inclusive quantity. + * All users of these functions expect exclusive sizes, and may + * also call with zero size. + * Reworked by rmk. + */ + .text + +/* + * Purpose : Find a 'zero' bit + * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit); + */ + .globl _find_first_zero_bit_le; +_find_first_zero_bit_le: + teq r1, #0 + beq 3f + mov r2, #0 +1: ldrb r3, [r0, r2, lsr #3] + eors r3, r3, #0xff @ invert bits + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + +/* + * Purpose : Find next 'zero' bit + * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, + * int offset) + */ + .globl _find_next_zero_bit_le; +_find_next_zero_bit_le: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + ldrb r3, [r0, r2, lsr #3] + eor r3, r3, #0xff @ now looking for a 1 bit + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + +/* + * Purpose : Find a 'one' bit + * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit) + */ + .globl _find_first_bit_le; +_find_first_bit_le: + teq r1, #0 + beq 3f + mov r2, #0 +1: ldrb r3, [r0, r2, lsr #3] + movs r3, r3 + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + +/* + * Purpose : Find next 'one' bit + * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, + * int offset) + */ + .globl _find_next_bit_le; +_find_next_bit_le: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + ldrb r3, [r0, r2, lsr #3] + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + +#ifdef __ARMEB__ + + .globl _find_first_zero_bit_be; +_find_first_zero_bit_be: + teq r1, #0 + beq 3f + mov r2, #0 +1: eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + eors r3, r3, #0xff @ invert bits + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + + .globl _find_next_zero_bit_be; +_find_next_zero_bit_be: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + eor r3, r3, #0xff @ now looking for a 1 bit + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + + .globl _find_first_bit_be; +_find_first_bit_be: + teq r1, #0 + beq 3f + mov r2, #0 +1: eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + movs r3, r3 + bne .L_found @ any now set - found zero bit + add r2, r2, #8 @ next bit pointer +2: cmp r2, r1 @ any more? + blo 1b +3: mov r0, r1 @ no free bits + mov pc, lr + + .globl _find_next_bit_be; +_find_next_bit_be: + teq r1, #0 + beq 3b + ands ip, r2, #7 + beq 1b @ If new byte, goto old routine + eor r3, r2, #0x18 @ big endian byte ordering + ldrb r3, [r0, r3, lsr #3] + movs r3, r3, lsr ip @ shift off unused bits + bne .L_found + orr r2, r2, #7 @ if zero, then no bits here + add r2, r2, #1 @ align bit pointer + b 2b @ loop for next bit + +#endif + +/* + * One or more bits in the LSB of r3 are assumed to be set. + */ +.L_found: +#if __LINUX_ARM_ARCH__ >= 5 + rsb r1, r3, #0 + and r3, r3, r1 + clz r3, r3 + rsb r3, r3, #31 + add r0, r2, r3 +#else + tst r3, #0x0f + addeq r2, r2, #4 + movne r3, r3, lsl #4 + tst r3, #0x30 + addeq r2, r2, #2 + movne r3, r3, lsl #2 + tst r3, #0x40 + addeq r2, r2, #1 + mov r0, r2 +#endif + mov pc, lr +Index: u-boot-v2.git/arch/arm/lib/Makefile
===================================================================arch/arm/lib/Makefile 2008-06-17 17:01:06.000000000 -0500 renamed from arch/arm/lib/Makefile 2008-06-17 16:52:31.000000000 -0500 +1
-0@@ -8,6 +8,7 @@ obj-y += _udivsi3.o obj-y += _umodsi3.o obj-y += _lshrdi3.o +obj-y += findbit.o obj-y += arm.o obj-$(CONFIG_MODULES) += module.o extra-$(CONFIG_GENERIC_LINKER_SCRIPT) += u-boot.ldsIndex:
u-boot-v2.git/include/asm-arm/bitops.h
===================================================================include/asm-arm/bitops.h 2008-06-17 17:01:06.000000000 -0500 renamed from include/asm-arm/bitops.h 2008-06-17 16:52:31.000000000 -0500 +83
-3@@ -75,9 +75,6 @@ return oldval & mask; } -extern int find_first_zero_bit(void * addr, unsigned size); -extern int find_next_zero_bit(void * addr, int size, int offset); - /* * This routine doesn't need to be atomic. */@@ -86,6 +83,44 @@ return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7)); } + + + +#ifndef __ARMEB__ +/* + * These are the little endian definitions. + */ +extern int _find_first_zero_bit_le(const void *p, unsigned size); +extern int _find_next_zero_bit_le(const void *p, int size, int offset); +extern int _find_first_bit_le(const unsigned long *p, unsigned size); +extern int _find_next_bit_le(const unsigned long *p, int size, int offset); +#define find_first_zero_bit(p, sz) _find_first_zero_bit_le(p, sz) +#define find_next_zero_bit(p, sz, off) _find_next_zero_bit_le(p, sz, off) +#define find_first_bit(p, sz) _find_first_bit_le(p, sz) +#define find_next_bit(p, sz, off) _find_next_bit_le(p, sz, off) + +#define WORD_BITOFF_TO_LE(x) ((x)) + +#else + +/* + * These are the big endian definitions. + */ +extern int _find_first_zero_bit_be(const void *p, unsigned size); +extern int _find_next_zero_bit_be(const void *p, int size, int offset); +extern int _find_first_bit_be(const unsigned long *p, unsigned size); +extern int _find_next_bit_be(const unsigned long *p, int size, int offset); +#define find_first_zero_bit(p, sz) _find_first_zero_bit_be(p, sz) +#define find_next_zero_bit(p, sz, off) _find_next_zero_bit_be(p, sz, off) +#define find_first_bit(p, sz) _find_first_bit_be(p, sz) +#define find_next_bit(p, sz, off) _find_next_bit_be(p, sz, off) + +#define WORD_BITOFF_TO_LE(x) ((x) ^ 0x18) + +#endif + +#if (defined(__LINUX_ARM_ARCH__) && (__LINUX_ARM_ARCH__ < 5)) + /* * ffz = Find First Zero in word. Undefined if no zero exists, * so code should check against ~0UL first..@@ -112,6 +147,51 @@ #define ffs(x) generic_ffs(x) +#else + +static inline int constant_fls(int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xffff0000u)) { + x <<= 16; + r -= 16; + } + if (!(x & 0xff000000u)) { + x <<= 8; + r -= 8; + } + if (!(x & 0xf0000000u)) { + x <<= 4; + r -= 4; + } + if (!(x & 0xc0000000u)) { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000u)) { + x <<= 1; + r -= 1; + } + return r; +} + +/* + * On ARMv5 and above those functions can be implemented around + * the clz instruction for much better code efficiency. + */ + +#define fls(x) \ + (__builtin_constant_p(x) ? constant_fls(x) : \ + ({ int __r; asm("clz\t%0, %1" : "=r"(__r) : "r"(x) : "cc"); 32-__r; })) +#define ffs(x) ({ unsigned long __t = (x); fls(__t &-__t); }) +#define __ffs(x) (ffs(x) - 1) +#define ffz(x) __ffs(~(x)) + +#endif + /* * hweightN: returns the hamming weight (i.e. the number * of bits set) of a N-bit word
Signature · 4 lines
Pengutronix e.K. - Linux Solutions for Science and Industry ----------------------------------------------------------- Kontakt-Informationen finden Sie im Header dieser Mail oder auf der Webseite -> http://www.pengutronix.de/impressum/ <-
Menon
PATCH 2/9 U-boot-V2:ARM: Introduce additional bitops
Sascha,
Quoted 8 lines
-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, June 18, 2008 10:31 AM
To: Menon, Nishanth
Cc: Kamat, Nishant; u-boot-users at lists.sourceforge.net; Laurent Desnogues; philip.balister at gmail.com; dirk.behme at googlemail.com
Subject: Re: [Patch 2/9] U-boot-V2:ARM: Introduce additional bitops
Quoted 6 lines
Quoted 1 line · Nishanth
Add linux-like bitops definitions - this is based on 2.6.25 rc5 kernel
I haven't looked at it, but I guess you need these for the following patches. It would be better to first introduce generic bitops. Otherwise we end up with i2c only working on arm.
Would you have a proposal for it? I am not familiar with ppc and other archs :( I can help on ARM side of things.
Regards,
Nishanth Menon
PATCH 2/9 U-boot-V2:ARM: Introduce additional bitops
Quoted 9 lines · Nishanth
Sascha,
Quoted 8 lines
-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, June 18, 2008 10:31 AM
To: Menon, Nishanth
Cc: Kamat, Nishant; u-boot-users at lists.sourceforge.net; Laurent Desnogues; philip.balister at gmail.com; dirk.behme at googlemail.com
Subject: Re: [Patch 2/9] U-boot-V2:ARM: Introduce additional bitops
Quoted 7 lines
Quoted 6 lines · Nishanth
Quoted 1 line
Add linux-like bitops definitions - this is based on 2.6.25 rc5 kernel
I haven't looked at it, but I guess you need these for the following patches. It would be better to first introduce generic bitops. Otherwise we end up with i2c only working on arm.
Would you have a proposal for it? I am not familiar with ppc and other archs :( I can help on ARM side of things.
In the kernel are generic bitops, #ifdefed with CONFIG_GENERIC_XXX
Regards,
Sascha
Signature · 4 lines
Pengutronix e.K. - Linux Solutions for Science and Industry ----------------------------------------------------------- Kontakt-Informationen finden Sie im Header dieser Mail oder auf der Webseite -> http://www.pengutronix.de/impressum/ <-
Menon
PATCH 1/3 U-Boot-V2: Bitops cleanup: introduce asm-generic bitops
Sascha,
The following 3 patches are for cleaning up the bitops
Quoted 10 lines
-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, June 18, 2008 10:51 AM
To: Menon, Nishanth
Cc: Kamat, Nishant; u-boot-users at lists.sourceforge.net; Laurent Desnogues; philip.balister at gmail.com; dirk.behme at googlemail.com
Subject: Re: [Patch 2/9] U-boot-V2:ARM: Introduce additional bitopsIn the kernel are generic bitops, #ifdefed with
CONFIG_GENERIC_XXX
This introduces selected generic bitop files from kernel. We don't need minix, ext2, sched or lock based bitops. Those have been dropped.
--- include/asm-generic/bitops/__ffs.h | 43 ++++++++++++++++ include/asm-generic/bitops/__fls.h | 43 ++++++++++++++++ include/asm-generic/bitops/ffs.h | 41 +++++++++++++++ include/asm-generic/bitops/ffz.h | 12 ++++ include/asm-generic/bitops/find.h | 15 +++++ include/asm-generic/bitops/fls.h | 41 +++++++++++++++ include/asm-generic/bitops/fls64.h | 36 +++++++++++++ include/asm-generic/bitops/hweight.h | 35 +++++++++++++ include/asm-generic/bitops/ops.h | 91 +++++++++++++++++++++++++++++++++++ 9 files changed, 357 insertions(+)
include/asm-generic/bitops/__ffs.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +43 -0
@@ -0,0 +1,43 @@ +#ifndef _ASM_GENERIC_BITOPS___FFS_H_ +#define _ASM_GENERIC_BITOPS___FFS_H_ + +#include <asm/types.h> + +/** + * __ffs - find first bit in word. + * @word: The word to search + * + * Undefined if no bit exists, so code should check against 0 first. + */ +static inline unsigned long __ffs(unsigned long word) +{ + int num = 0; + +#if BITS_PER_LONG == 64 + if ((word & 0xffffffff) == 0) { + num += 32; + word >>= 32; + } +#endif + if ((word & 0xffff) == 0) { + num += 16; + word >>= 16; + } + if ((word & 0xff) == 0) { + num += 8; + word >>= 8; + } + if ((word & 0xf) == 0) { + num += 4; + word >>= 4; + } + if ((word & 0x3) == 0) { + num += 2; + word >>= 2; + } + if ((word & 0x1) == 0) + num += 1; + return num; +} + +#endif /* _ASM_GENERIC_BITOPS___FFS_H_ */
include/asm-generic/bitops/__fls.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +43 -0
43 lines not on this page · raw message
include/asm-generic/bitops/ffs.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +41 -0
41 lines not on this page · raw message
include/asm-generic/bitops/ffz.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +12 -0
@@ -0,0 +1,12 @@ +#ifndef _ASM_GENERIC_BITOPS_FFZ_H_ +#define _ASM_GENERIC_BITOPS_FFZ_H_ + +/* + * ffz - find first zero in word. + * @word: The word to search + * + * Undefined if no zero exists, so code should check against ~0UL first. + */ +#define ffz(x) __ffs(~(x)) + +#endif /* _ASM_GENERIC_BITOPS_FFZ_H_ */
include/asm-generic/bitops/find.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +15 -0
@@ -0,0 +1,15 @@ +#ifndef _ASM_GENERIC_BITOPS_FIND_H_ +#define _ASM_GENERIC_BITOPS_FIND_H_ + +#ifndef CONFIG_GENERIC_FIND_NEXT_BIT +extern unsigned long find_next_bit(const unsigned long *addr, unsigned long + size, unsigned long offset); + +extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned + long size, unsigned long offset); +#endif + +#define find_first_bit(addr, size) find_next_bit((addr), (size), 0) +#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0) + +#endif /*_ASM_GENERIC_BITOPS_FIND_H_ */
include/asm-generic/bitops/fls.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +41 -0
41 lines not on this page · raw message
include/asm-generic/bitops/fls64.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +36 -0
@@ -0,0 +1,36 @@ +#ifndef _ASM_GENERIC_BITOPS_FLS64_H_ +#define _ASM_GENERIC_BITOPS_FLS64_H_ + +#include <asm/types.h> + +/** + * fls64 - find last set bit in a 64-bit word + * @x: the word to search + * + * This is defined in a similar way as the libc and compiler builtin + * ffsll, but returns the position of the most significant set bit. + * + * fls64(value) returns 0 if value is 0 or the position of the last + * set bit if value is nonzero. The last (most significant) bit is + * at position 64. + */ +#if BITS_PER_LONG == 32 +static inline int fls64(__u64 x) +{ + __u32 h = x >> 32; + if (h) + return fls(h) + 32; + return fls(x); +} +#elif BITS_PER_LONG == 64 +static inline int fls64(__u64 x) +{ + if (x == 0) + return 0; + return __fls(x) + 1; +} +#else +#error BITS_PER_LONG not 32 or 64 +#endif + +#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */
include/asm-generic/bitops/hweight.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +35 -0
@@ -0,0 +1,35 @@ +#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ +#define _ASM_GENERIC_BITOPS_HWEIGHT_H_ + +#include <asm/types.h> + +/* + * hweightN: returns the hamming weight (i.e. the number + * of bits set) of a N-bit word + */ + +static inline unsigned int hweight32(unsigned int w) +{ + unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555); + res = (res & 0x33333333) + ((res >> 2) & 0x33333333); + res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F); + res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF); + return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF); +} + +static inline unsigned int hweight16(unsigned int w) +{ + unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555); + res = (res & 0x3333) + ((res >> 2) & 0x3333); + res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F); + return (res & 0x00FF) + ((res >> 8) & 0x00FF); +} + +static inline unsigned int hweight8(unsigned int w) +{ + unsigned int res = (w & 0x55) + ((w >> 1) & 0x55); + res = (res & 0x33) + ((res >> 2) & 0x33); + return (res & 0x0F) + ((res >> 4) & 0x0F); +} + +#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
include/asm-generic/bitops/ops.h 2008-06-19 01:06:03.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +91 -0
91 lines not on this page · raw message
PATCH 1/3 U-Boot-V2: Bitops cleanup: introduce asm-generic bitops
Quoted 12 lines · Nishanth
Sascha,
The following 3 patches are for cleaning up the bitopsQuoted 10 lines
-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, June 18, 2008 10:51 AM
To: Menon, Nishanth
Cc: Kamat, Nishant; u-boot-users at lists.sourceforge.net; Laurent Desnogues; philip.balister at gmail.com; dirk.behme at googlemail.com
Subject: Re: [Patch 2/9] U-boot-V2:ARM: Introduce additional bitopsIn the kernel are generic bitops, #ifdefed with
CONFIG_GENERIC_XXX
Again, either leave the above crap out entirely or place it below the triple-dash line.
Quoted 1 line
This introduces selected generic bitop files from kernel. We don't need minix, ext2, sched or lock based bitops. Those have been dropped.
Line wrap the log message at 70 or 72.
Quoted 5 lines
Signed-off-by Nishanth Menon <[email protected]>--- include/asm-generic/bitops/__ffs.h | 43 ++++++++++++++++ include/asm-generic/bitops/__fls.h | 43 ++++++++++++++++
Thanks,
jdl
Menon
PATCH 2/3 U-Boot-V2: Bitops cleanup: cleanup ARM bitops
In reply to Sascha HauerCleanup of ARM bitops functions. Introduce the findbits.S which allows for optimized algo.
--- arch/arm/lib/Makefile | 1 arch/arm/lib/findbit.S | 181 +++++++++++++++++++++++++++++++++++++++++++++++ include/asm-arm/bitops.h | 133 +++++++++++++++++++++++----------- 3 files changed, 273 insertions(+), 42 deletions(-)
arch/arm/lib/Makefile 2008-06-19 00:54:17.000000000 -0500 renamed from arch/arm/lib/Makefile 2008-06-19 00:52:51.000000000 -0500 +1 -0
@@ -8,6 +8,7 @@ obj-y += _udivsi3.o obj-y += _umodsi3.o obj-y += _lshrdi3.o +obj-y += findbit.o obj-y += arm.o obj-$(CONFIG_MODULES) += module.o extra-$(CONFIG_GENERIC_LINKER_SCRIPT) += u-boot.lds
arch/arm/lib/findbit.S 2008-06-19 00:54:17.000000000 -0500 renamed from dev/null 1970-01-01 00:00:00.000000000 +0000 +181 -0
181 lines not on this page · raw message
include/asm-arm/bitops.h 2008-06-19 00:54:30.000000000 -0500 renamed from include/asm-arm/bitops.h 2008-06-19 00:52:51.000000000 -0500 +91 -42
189 lines not on this page · raw message
Menon
PATCH 3/3 U-Boot-V2: Bitops cleanup: cleanup rest of generic_xxx functions
In reply to Sascha HauerUse the asm-generic/bitops/xyz.h instead of using generic_xyz functions.
--- include/asm-blackfin/bitops.h | 18 +--------- include/asm-m68k/bitops.h | 18 +--------- include/asm-ppc/bitops.h | 9 ----- include/linux/bitops.h | 71 ++++-------------------------------------- 4 files changed, 12 insertions(+), 104 deletions(-)
include/asm-blackfin/bitops.h 2008-06-19 00:51:52.000000000 -0500 renamed from include/asm-blackfin/bitops.h 2008-06-19 00:50:37.000000000 -0500 +2 -16
@@ -268,22 +268,8 @@ return result + ffz(tmp); } -/* - * ffs: find first bit set. This is defined the same way as - * the libc and compiler builtin ffs routines, therefore - * differs in spirit from the above ffz (man ffs). - */ - -#define ffs(x) generic_ffs(x) - -/* - * hweightN: returns the hamming weight (i.e. the number - * of bits set) of a N-bit word - */ - -#define hweight32(x) generic_hweight32(x) -#define hweight16(x) generic_hweight16(x) -#define hweight8(x) generic_hweight8(x) +#include <asm-generic/bitops/ffs.h> +#include <asm-generic/bitops/hweight.h> static __inline__ int ext2_set_bit(int nr, volatile void *addr) {
include/asm-m68k/bitops.h 2008-06-19 00:51:52.000000000 -0500 renamed from include/asm-m68k/bitops.h 2008-06-19 00:50:13.000000000 -0500 +2 -16
@@ -122,22 +122,8 @@ return k; } -/* - * ffs: find first bit set. This is defined the same way as - * the libc and compiler builtin ffs routines, therefore - * differs in spirit from the above ffz (man ffs). - */ - -#define ffs(x) generic_ffs(x) - -/* - * hweightN: returns the hamming weight (i.e. the number - * of bits set) of a N-bit word - */ - -#define hweight32(x) generic_hweight32(x) -#define hweight16(x) generic_hweight16(x) -#define hweight8(x) generic_hweight8(x) +#include <asm-generic/bitops/ffs.h> +#include <asm-generic/bitops/hweight.h> #define ext2_set_bit test_and_set_bit #define ext2_clear_bit test_and_clear_bit
include/linux/bitops.h 2008-06-19 00:52:34.000000000 -0500 renamed from include/linux/bitops.h 2008-06-19 00:50:13.000000000 -0500 +7 -64
77 lines not on this page · raw message
include/asm-ppc/bitops.h 2008-06-19 00:51:52.000000000 -0500 renamed from include/asm-ppc/bitops.h 2008-06-19 00:50:37.000000000 -0500 +1 -8
@@ -178,14 +178,7 @@ return __ilog2(x & -x) + 1; } -/* - * hweightN: returns the hamming weight (i.e. the number - * of bits set) of a N-bit word - */ - -#define hweight32(x) generic_hweight32(x) -#define hweight16(x) generic_hweight16(x) -#define hweight8(x) generic_hweight8(x) +#include <asm-generic/bitops/hweight.h> #endif /* __U_BOOT__ */