[ltt-dev] [PATCH 2/4] add a definition for fls() for ARM, taken from the linux kernel

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Tue Feb 22 17:31:49 EST 2011


* Mathieu Desnoyers (mathieu.desnoyers at efficios.com) wrote:
> * Jason Wessel (jason.wessel at windriver.com) wrote:
> > Insert the definition from the linux kernel along with the copyright
> > attribution for the fls() operation for ARM.
> 
> You could instead use my own clean room reimplementation at:
> 
> http://git.efficios.com/?p=babeltrace.git;a=blob;f=tests/test-bitfield.c
> 
> (for LGPLv2.1 licensing concerns)

Actually, I just imported in into the UST git tree. I'll merge your other
patches, thanks !

Mathieu

> 
> The header of this file states "GPL", but I give you my blessing to relicense
> the arch-agnostic fls() implementation as LGPL for UST.
> 
> If you don't feel like recoding the arm-specific fls, we can leave it out and
> just use the arch-agnostic version for now.
> 
> Thanks,
> 
> Mathieu
> 
> > 
> > Signed-off-by: Jason Wessel <jason.wessel at windriver.com>
> > ---
> >  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
> > 
> 
> -- 
> Mathieu Desnoyers
> Operating System Efficiency R&D Consultant
> EfficiOS Inc.
> http://www.efficios.com

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




More information about the lttng-dev mailing list