On Jan 5, 2009, at 19:02, Ludovic Courtès wrote:
Alas, there's no portable way that I know of to ask the compiler to
align double cells on 8-byte boundaries so that Guile actually
recognizes them as cells. GCC's `aligned' attribute does the job, but
is not portable. So this can't be committed, unless someone comes up
with a bright idea. :-)
There's no portable way, but it might be a bit more likely to happen
if you try something like:
union {
scm_t_cell cell[2];
double d_for_alignment;
long long ll_for_alignment;
}
... and use &c_name##_raw_cell.cell. Try it on a few compilers and
see what happens to the alignment (or if scm_t_cell[2] is already
sufficiently aligned).
It's still no guarantee, but I think most systems will align either
double or long long strictly enough. And you could use __aligned__
conditionally, too, for more than just GCC. There are alignment
pragma directives available in a number of compilers, but using them
with macros may not be practical. (Unfortunately for installed
headers you should probably use compiler predefined macro tests rather
than autoconf tests, since two compilers could be used on one system.)
If that all fails and the compiler winds up giving you weak alignment,
perhaps you could have something in the SCM_SNARF_INIT'ed code to
check for that case, and make a properly-aligned copy if the original
is not already sufficiently aligned, and update the static variable
before using it. Code it right and the compiler's optimizer may just
throw away most of the code on most machines where the alignment is
known to be correct. Then the code works whether or not the compiler
gives you the alignment you want, and when it does (which should be
most of the time) you win on performance...
Ken