Re: [PATCH 4/6] Implement a general log2 facility in the kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Luck, Tony <[email protected]> wrote:

> > This facility provides three entry points:
> > 
> > 	log2()		Log base 2 of u32
> > 	ll_log2()	Log base 2 of u64
> > 	long_log2()	Log base 2 of unsigned long
> 
> The names are rather counter-intuitive. "ll" sounds like "long long", so
> why does it opearte on *unsigned* 64-bit?  Ditto for "long_log2()".
> Perhaps they should be log2_u32(), log2_u64(), etc.

Well, given that you can't represent a log of a negative number, I'm not sure
it matters.

Note that long_log2() already exists and is of arch-dependent size.

> Even better if someone can come up with the right pre-processor magic
> using sizeof/typeof so that you could just use "log2(any type)"

I then end up with 32 of these per usage if I pass in a definite 32-bit value:

	warning: comparison is always false due to limited range of data type

because of the:

		n >= (1ULL << 63) ? 63 :	\
		n >= (1ULL << 62) ? 62 :	\
		n >= (1ULL << 61) ? 61 :	\
	...

in ll_log2().

David
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux