Alignment blues..

Ozan Yigit oz at yetti.UUCP
Fri Mar 22 00:58:56 AEST 1985


	The mis-alingment of programs under VAXen could be
	extremely costly, as some of the other net-people have
	observed. C. J. Van Wyk, J. L. Bentley and P. J. Weinberger
	report [1] an instance where they timed the i-- and i-=1
	statements for 100,000 iterations:

	Statement			timing (in ticks)
	i--	24	18	23	25	25	22	25  etc.
	i-=1	20	23	22	22	22	22	21  etc.

	In their tests, i-=1 performed 10% better for ALL types of i.

	But, later..

	"This seemed too wonderful to be true, so we looked at the
	assembler code for the two tests. It was IDENTICAL.
	The difference arose because the second statement fell on an even
	eight-byte boundary in memory, while the first fell accross an
	eight-byte boundary. Thus, the 100,000 iterations of the first
	statement required twice as many memory fetches as those of
	second" [1]

	There are very many horror stories about MISALIGNMENT in the
	VMS world. The usual rule of thumb is to align all time-critical
	code properly.


	[1]	C. J. Van Wyk, J. L. Bentley, P. J. Weinberger,
		"Efficiency Consicerations for C programs on a 
		VAX 11/780", Technical Report CMU-CS-82-134,
		Carnegie-Mellon University, 
		Dept. of Computer Science, August 1982


	Oz	(wizard of something or another, no doubt)
	Dept. of Computer Science
	York University
	



More information about the Comp.lang.c mailing list