Functional syntax (Was: RE: [mercury-users] Hi, and determini sm)

Richard A. O'Keefe ok at atlas.otago.ac.nz
Wed Feb 7 10:41:43 AEDT 2001


Ralph Becket <rbeck at microsoft.com> wrote:
	...
	if the compiler could work out that a given type's values only
	occupied n bits (either by observation or a promise from the
	programmer) then it could do bit-packing.
	
	I suspect this would net a tidy performance improvement in many
	programs.

My experience using bit-fields in C suggests the opposite.
Any time that fetching/storing a field requires more than a simple
memory reference instruction, performance suffers.
Packing to the byte level is fine, especially if the compiler
re-orders fields in descending order of alignment
(double[8] > int[4] > short[2] > char[1], to use C terminology).

Of course, it all depends on how much data you have.  If packing your
data tightly means that you stop thrashing VM, you'd better do it; if
packing your data tightly means that you don't have many L2 cache
misses, it's a good idea.

The only good use of C bit-fields I've seen recently in application-level
code was a program that would have needed >1GB without, and can just
squeeze into a 256MB machine with packing.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list