Subject: Re: 2s complement
To: Terry Moore <>
From: Chapman Flack <>
List: tech-kern
Date: 01/07/2006 10:27:30
Terry Moore wrote:
> [Is bitstr.h used in the kernel?  Or is this off-topic?  If so, I 
> apologize.]

I was considering using it in the kernel, hence my choice of list;
I'll add my apologies if it's considered OT.

zvrba wrote:

> The Hacker's Delight book has 7 pages dedicated to various ways of
> computing the "number of leading/trailing zeros" functions. For a given
> bitstring of arbitrary length, one would first find the first nonzero
> word, and then techniques from HD can be applied. One suggested

Neat ... several are completely branch-free, which beats anything I've
done in the past. :o

Terry's question is to the point: bitstring manipulations are common in
systems code, and bitstring.h does offer convenience and clarity, so if
there's a question whether bitstring.h is used in the kernel, is that
because coders needing bitstrings have looked at its implementation and
decided to forgo its convenience and clarity and do many pieces of
custom code?  (I don't know the answer, just wondering aloud.)

If so, maybe the number of people choosing to do without bitstring.h
could never be brought all the way to zero, for the reasons Terry
mentioned, but maybe if people looked in bitstring.h and said, ok,
that's an implementation roughly as good as what I would write as
a matter of course, and I don't have to write it, then maybe it
/would/ be used more often in the kernel, except for the most demanding
hand optimized spots.