Conjecture::BitOverlay Class Reference

#include <BitOverlay.h>

Inheritance diagram for Conjecture::BitOverlay:

Conjecture::Root Conjecture::BitInfo List of all members.

Detailed Description

Hyper-low-level bit analysis.

******************************************************************

This class provides a variety of routines for analyzing the bits within a 32-bit value.

There are both static and instance versions of each method.

An "on" bit is 1, an "off" bit is 0.

IMPORTANT: This class can be used as simply a collection of static methods, OR it can be used as an "overlay", a means of adding semantics and functionality to an arbitrary integer. However, in order for it to be an overlay, NO VIRTUAL METHODS! We do not want a vtbl here! Includes parents, of course. Because of this, statically typing a variable as BitOverlay and assigning it an instance of the subclass BitInfo is NOT recommended.

FUTURE WORK: Analyze http://graphics.stanford.edu/~seander/bithacks.html and incorporate useful methods from there into this class!

See Also: BitOverlay64


Public Types

typedef unsigned int Layout
typedef int BitPos
typedef unsigned BitCount

Public Member Functions

 BitOverlay (Layout data)
Layout bits () const
BitPos findFirstHigh () const
BitPos findFirstLow () const
BitCount popc () const
std::string str () const
BitCount regions (int *largest=NULL, int *all=NULL) const

Static Public Member Functions

static BitPos FindFirstHigh (Layout val)
static BitPos FindFirstHighSlow (Layout val)
static BitPos FindFirstLow (Layout val)
static int _bx (Layout x)
static BitCount PopCount (Layout val)
static BitCount PopCountSlow (Layout val)
static std::string Str (Layout val)
static BitCount Regions (Layout val, int *largest=NULL, int *all=NULL)
static void Test (int argc=0, const char *argv[]=NULL)

Static Public Attributes

static const BitPos npos = 255

Protected Member Functions

void bitsIs (const Layout &bits)


Member Typedef Documentation

typedef unsigned Conjecture::BitOverlay::BitCount
 

A type for use in methods that return a bit count.

typedef int Conjecture::BitOverlay::BitPos
 

A bit position.

Bit position 0 is the lowest-order bit, and bit position 31 is the highest-order-bit. The special value 'npos' is used to represent "not present", and is outside the 0-31 range.

NOTE: Although this type could be described using a single byte (the maximum bit position possible is 31, after all), it is defined as an 'int' because 'char' types get printed out as chars, not integers, when used in '<<' debugging operators. If size becomes relevant, it can be changed to 'unsigned char'.

FUTURE FIX: A better name for this type should be found!

typedef unsigned int Conjecture::BitOverlay::Layout
 

The type describing the underlying value being analyzed.

A typedef to make a BitOverlay64 implementation look as similar as possible to BitOverlay (and to make potential transitioning to a template implementation easier).


Member Function Documentation

static int Conjecture::BitOverlay::_bx Layout  x  )  [inline, static]
 

Population Count: Returns the number of "on" bits.

BitOverlay::BitPos Conjecture::BitOverlay::FindFirstHigh Layout  val  )  [static]
 

Returns the bit position of the most-significant "on" bit.

NOTE: Some chipsets have a 'find-first-set' (ffs) instruction that implements this. I've renamed it because I want to distinguish ffh and ffl.

BitOverlay::BitPos Conjecture::BitOverlay::FindFirstLow Layout  val  )  [static]
 

Returns the bit position of the least-significant "on" bit.

BitOverlay::BitCount Conjecture::BitOverlay::Regions Layout  val,
int *  largest = NULL,
int *  all = NULL
[static]
 

Returns number of "regions" of contiguous "on" pixels.

Parameters:
val The sequence of bits to analyze
largest If non-null, it is assigned the length of the largest region.
all If non-null, a pre-allocated array of size 16+, into which the sizes of each region are placed (may also encode start-bit-position).

string Conjecture::BitOverlay::Str Layout  val  )  [static]
 

String representation of 'val' as a binary number.

Currently always returns a string of length 32. Future extensions may add an optional arg specifying when we can truncate (could use FFS to establish minimum length).

void Conjecture::BitOverlay::Test int  argc = 0,
const char *  argv[] = NULL
[static]
 

The Unit-testing method

Reimplemented in Conjecture::BitInfo.


The documentation for this class was generated from the following files:
Generated on Thu Jun 15 19:56:12 2006 for Conjecture by  doxygen 1.4.6