[m-dev.] Re: pragma fact_table

Fergus Henderson fjh at cs.mu.oz.au
Wed Feb 19 14:27:56 AEDT 1997


David Matthew OVERTON, you wrote:
> 
> For the case when index is a pointer, is it guaranteed to be aligned
> on a word boundary (i.e. so that at least the 2 least significant bits
> are 0)?  The pointer is pointing to a struct defined as a global C
> variable, not to something on the Mercury heap.

This is not guaranteed by ANSI C.  However, it's true for most
compilers, including (as far as I am aware) all ports of gcc,
presuming the struct contains at least one field that will force
sufficient alignment, e.g. a pointer, an `Integer', or a `Word'.
Also, we already assume this in quite a bit of our code.

To get the best of both worlds you need to use conditional compilation
(which is what we do in the other code that makes this assumption.)
Currently the use of tag bits can be turned off by setting
NUM_TAG_BITS == 0.  So you need to test for that.  In fact
your code uses values 0, 1, and 2, so you need two tag bits.
(Actually in your code you could make do with only one tag bit, but
that's not terribly important.)

For maximum generality, it would be nice to have a separate
compile-time flag to test on

	#if NUM_TAG_BITS >= 2  && !UNALIGNED_GLOBALS
		...
	#endif

However, implementing that properly would require changes
in quite a few places in the code, so until we actually
come across a machine on which it might be useful, don't bother.
Just test NUM_TAG_BITS.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list