[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Problems with double-word alignment on hppa and sparc



On Tue, Nov 27, 2007 at 12:29:53PM +0100, Uwe Steinmann wrote:
<upstream says>
I've looked into this a bit, and I'm not sure it can be fixed very
easily.  The OCaml bindings for libgsl avoid some expensive copy
operations by making the assumption that the platform can accept double
arrays aligned on word boundaries.  Apparently hppa and sparc don't
provide this capability.
</upstream says>

sparc doesn't? I ran the attached test program on my Ultra 5 and it succesfully completed. If sparc didn't allow this, then the program would fail on the "ok" line with a SIGBUS. This might be different in 64-bit mode, but since most Debian programs are compiled in 32-bit mode, this shouldn't matter.

I cannot speak for hppa, since I don't own one.

Well, is there really no hope for fixing this? This appears to
be a more general problem and maybe somebody has solved it already.

Remove the #error directive, and see if it works. Also, advise upstream that the C standard does not allow the assumption they made, and please chastise them. If it doesn't work, then you're out of luck; sparc does not provide in-kernel fixups of unaligned traps. (On Debian buildds, fixups of unaligned traps are disabled even on architectures that support them, due to the insane performance penalty they create.)

What puzzles me is the fact, that libocamlgsl-ocaml compiles without
errors. The gsl bindings shipped with orpie are the same version as
libocamlgsl-ocaml, though not all files are present.

Unaligned access is not a compile-time problem, so you have to run the program to see if it fails. The way I would suggest handling this case is not to use #error directives, but instead to run a comprehensive testsuite and see if it fails; if not, you're probably free of any unaligned accesses. If the bindings really make the assumptions you say they do, then there is a 2**(-n) (n being the number of copies avoided) probability that you will pass a testsuite when there is an unaligned access.

--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
a typesetting engine: http://crustytoothpaste.ath.cx/~bmc/code/thwack
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
#include <stdio.h>
#include <stdint.h>

int main(void)
{
	double arr[2] = {0.0, 0.0};
	long *p;
	double *q;
	uintptr_t ph;

	printf("sizeof(long) == %d\n", sizeof(*p));
	printf("sizeof(double) == %d\n", sizeof(*q));
	p = arr;
	p++;
	q = p;
	ph = (uintptr_t)q;
	printf("arr == %p\np   == %p\nq   == %p\n", arr, p, q);
	printf("q&7 == %ld\n", ph&7);
	printf("ok: *q == %f\n", *q);

	return 0;
}

Attachment: signature.asc
Description: Digital signature


Reply to: