no noalias not negligible - a difference between C and Fortran - long

T. William Wells bill at proxftl.UUCP
Thu Jun 2 22:59:10 AEST 1988


In article <7879 at alice.UUCP>, ark at alice.UUCP writes:
>       daxpy(n, da, dx, dy)
>               register double *dx, *dy, da;
>               int n;
>       {
>               register double *dylim = dy + n;
>
>               do *dy += da * *dx++;
>               while (++dy <= dylim);
>       }

If you go this far, you should do this:

	daxpy(n, da, dx, dy)
		register double *dx, *dy, da;
		int n;
	{
		register double *dylim = dy + n;

		do *dy++ += da * *dx++;
		while (dy <= dylim);
	}

[If n is the number of elements in dy, shouldn't the test be a <, not a <=?]

The only difference is moving the ++ from the test condition to the
assignment. For some machines (680?0 ?, VAX ?), this might give slightly
better results because it may be possible to use an addressing mode to
accomplish the increment. Also, the register variables should be ordered dy
and dx instead of dx and dy, this might not make any difference here, but had
these register variables been the second and third, this would have made a
minor difference (on an 80?86, for example).



More information about the Comp.lang.c mailing list