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

Richard A. O'Keefe ok at atlas.otago.ac.nz
Thu Feb 8 14:46:40 AEDT 2001


Fergus Henderson provided a packing example from the Mercury compiler.
	:- type decl_flags ---> decl_flags(
		access :: access,		% public/private/protected
		per_instance :: per_instance,	% one_copy/per_instance
		virtuality :: virtuality,	% virtual/non_virtual
		finality :: finality,		% final/overridable (funcs only)
		constness :: constness,		% const/modifiable  (data only)
		abstractness :: abstractness	% abstract/concrete
	).
	
access       has 4 cases (2 bits)
per_instance has 2 cases (1 bit)	
virtuality   has 2 cases (1 bit)
finality     has 2 cases (1 bit)
constness    has 2 cases (1 bit)
abstractness has 2 cases (1 bit)
--------------------------------
Total                     7 bits.

Presumably the record would take 6 words (192 bits) without packing.
However, the packing could be tighter yet.  'finality' and 'constness'
are never meaningful at the same time, so only 6 bits are needed.

We note that the fields are not in fact independent.  In Java, it is not
possible for a "one copy" (static) field or method to be virtual, so
per_instance and virtuality together are a SINGLE aspect with three possible
values, not 4.  Merging fields *as appropriate to the problem*, we find

access       has 4 cases (2 bits)
stat_virt    has 3 cases (2 bits) static/nonstatic/virtual
finality     has 2 cases (1 bit)  (final data? or final method?)
abstractness has 2 cases (1 bit)

So we have three versions to compare:

Pack to bit  level:   6 bits required.
Pack to byte level:  32 bits (4 separate bytes) required.
Pack to word level: 192 bits (4 words * 32 bits) required.

I was arguing _against_ packing to the bit level.
That is not the same as arguing against packing;
I was arguing _for_ packing to the byte level.

Packing to the byte level would give us one 32-bit word for this information;
it would be a substantial space saving while still permitting fast compact
code.  As a single-word object, it would of course be unboxed.

So I think that FOR THIS CASE byte-level packing would probably be best.
It would save _enough_ memory to be useful, without any performance
penalty.

--------------------------------------------------------------------------
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