Packing booleans?

Nathan Sidwell nathan@codesourcery.com
Wed May 4 12:57:00 GMT 2005


Mattias Karlsson wrote:
> On Wed, 4 May 2005, Nathan Sidwell wrote:
> 
>> Sam Lauber wrote:
>>
>>> Would it be possible to have a -fpack-bools option that packs 
>>> booleans into
>>> the smallest form possible (8 booleans -> 1 8-bit reg, etc.) into a 
>>> register
>>> (or memory, as the case may be)?
>>
>>
>> why would you want to do this?  Seems to me you might save up to 7 bytes
>> of data memory at a vastly greater expansion of code size and reduction
>> in performance.
> 
> 
> Unless you are using an architecture with btst, bset, bclr instructions.

True, they'd have to have memory operands to be a win though. Otherwise it'd
be a
	load
	bset
	store
or
	load
	btst
sequence, rather than
	store
or
	load

Of course, one might be able to amortize the load and store over several
bit operations, but you'd still end up with at least one extra instruction
over not packing, and that will cost you 4 bytes (or thereabouts).

If this were being done at the level of register allocation, why would
one need a user visible option?  'Just' rearrange the register file to look
like a set of single bit registers overlaid on a more conventional register
file.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



More information about the Gcc mailing list