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.

See Also: BitOverlay64


Public Types

typedef unsigned int Layout
typedef int BitPos
typedef unsigned BitCount
 A type for use in methods that return a bit count.

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 FindFirstLow (Layout val)
 Returns the bit position of the least-significant "on" bit.
static BitCount PopC (Layout val)
 Population Count: Returns the number of "on" bits.
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)
 The Unit-testing method.

Static Public Attributes

static const BitPos npos = 255

Protected Member Functions

void bitsIs (const Layout &bits)


Member Typedef Documentation

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

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::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).


The documentation for this class was generated from the following files:
Generated on Mon Jun 12 20:27:18 2006 for Conjecture by  doxygen 1.4.6