Boost logo

Boost :

From: François Duranleau (duranlef_at_[hidden])
Date: 2007-02-01 10:03:48


On Wed, 31 Jan 2007, Art Stamness wrote:

>> On Jan 31, 2007, at 4:21 PM, me22 wrote:
>>
>>> On 1/31/07, Art Stamness <artstamness_at_[hidden]> wrote:
>>
>>> However, what's the main advantage of your code over
>>> Boost.Dynamic_Bitset and std::bitset? It seems (from a quick look)
>>> that your bit_array is close to std::bitset and your bit_vector is
>>> close to at least one of dynamic_bitset and vector<bool> (the latter
>>> being specialised for packing).
>>
>> True, these types are similar to the std::bitset /
>> boost::dynamic_bitset / std::vector<bool> in that they are used to
>> represent bit data. However they have a very different operational
>> semantic. These types are intended to model bit containers for
>> arbitrary logic functions. Things that are commonly found when
>> modeling hardware systems ( you can find why i do this under the
>> "Motivation" section ).
>>
>> For instance, taking 4 bits from one type and 4 bits from another,
>> doing a logical exclusive-or on those bits, and placing it in 4
>> bits of a third type is a 1 line operation.
>>
>> c.select(15,12) = a.select(7,4) ^ b.select(3,0) ; // a,b,c can all
>> be bit_array / bit_vector / bit_container ( adapted type )
>>
>> This very closely mimics what is found in hardware description
>> languages ( which is my background ) .
>>
>> c[15:12] = a[7:4] ^ b[3:0] ; // Same operation in Verilog
>>
>> This library is intended to provide fixed , and resizable types,
>> that can be used to model n-bit long logical operations in a clear
>> semantic description, while also providing some STL container like
>> interface for use with STL algorithm.
>>
>> The above listed operations would be very difficult to do with any
>> of the 3 listed types.

How about writing bit container algorithms instead of new bit containers?
Taking the 'select' example, we could write:

select(c,15,12) = select(a,7,4) ^ select(b,3.0)

The 'select' algorithm would return a view for a range of bits. Thus we
would only need to write those algorithms plus some view classes, and it
could work with any already existing bit containers. It could be possible
to specialize the views for certain types of containers if it could
optimize some operations (I don't know).

-- 
François Duranleau
LIGUM, Université de Montréal

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk