no noalias not negligible

Chris Torek chris at mimsy.UUCP
Sat May 21 14:38:02 AEST 1988


One I forgot: inline expansion.  The latest GCC compilers have inline
functions, and `inline' is easy to add to a C compiler (although the
resulting langauge is not C).  daxpy is certainly short enough to write
in line:

	inline void
	daxpy(int n, double a, double *x, double *y) {
		int i;
		for (i = 0; i < n; i++) y[i] += a * x[i];
	}

or (as short as I can make it :-) )

	inline void daxpy(int n, double a, double *x, double *y)
		{ while (--n >= 0) *y++ += a * *x++; }

To stick to C proper, although it introduces possible name collisions,
and makes daxpy() not an expression,

	#define daxpy(n, a, x, y) do { \
		register int daxpy_n = n; \
		register double daxpy_a = a, *daxpy_x = x, *daxpy_y = y; \
		while (--daxpy_n >= 0) *daxpy_y++ += a * *daxpy_x++; \
	} while (0)

The resulting expansion (either from the cleaner but nonstandard
`inline void' versions, or the macro version) will likely not only run
faster (no subroutine call overhead) but also be in a place where the
optimiser can see whether there are aliasing problems.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list