From mboxrd@z Thu Jan 1 00:00:00 1970 From: jason.wessel@windriver.com (Jason Wessel) Date: Tue, 22 Feb 2011 15:48:32 -0600 Subject: [ltt-dev] [PATCH 2/4] add a definition for fls() for ARM, taken from the linux kernel In-Reply-To: <1298411314-25405-2-git-send-email-jason.wessel@windriver.com> References: <1298411314-25405-1-git-send-email-jason.wessel@windriver.com> <1298411314-25405-2-git-send-email-jason.wessel@windriver.com> Message-ID: <1298411314-25405-3-git-send-email-jason.wessel@windriver.com> Insert the definition from the linux kernel along with the copyright attribution for the fls() operation for ARM. Signed-off-by: Jason Wessel --- include/ust/processor.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/include/ust/processor.h b/include/ust/processor.h index 01aa290..70e244b 100644 --- a/include/ust/processor.h +++ b/include/ust/processor.h @@ -454,6 +454,59 @@ static __inline__ int fls(unsigned int x) struct registers { }; +/* constant_fls() and fls() were take directly from the linux kernel + * sources in 2.6.37 from the file arch/arm/include/asm/bitops.h + * which had the following copyright. + * + * Copyright 1995, Russell King. + * Various bits and pieces copyrights include: + * Linus Torvalds (test_bit). + * Big endian support: Copyright 2001, Nicolas Pitre + * reworked by rmk. + */ + +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; +} + +static __inline__ int fls(unsigned int x) +{ + int ret; + + if (__builtin_constant_p(x)) + return constant_fls(x); + + asm("clz\t%0, %1" : "=r" (ret) : "r" (x) : "cc"); + ret = 32 - ret; + return ret; +} +/*------- end of source taken from linux kernel headers -------*/ + #define ARCH_COPY_ADDR(dst) "ldr "dst", =2b\n\t" \ "b 55f\n\t" \ ".ltorg\n\t" \ -- 1.6.6.2