Array indexing vs. pointers...

Network News news at amdcad.AMD.COM
Sat Sep 24 11:09:59 AEST 1988


In article <6396 at batcomputer.tn.cornell.edu> braner at tcgould.tn.cornell.edu (Moshe Braner) writes:
| []
| 
| I was surprised by the results of some experiments I ran on a Gould box
| and on the Inmos Transputer.  In both cases the speed of bumping pointers
| turned out to be similar to, or even slower than, using array indexing.
| This is not too surprising for a[i], but even holds for a[i][j], where
| the indexing involves a _multiplication_!!!  (I was comparing indexing
| to with double-indirection, i.e. p[i][j] where p is a pointer to an array
| of pointers to rows of the matrix, and also to with *p++ where p is a
| pointer to an element inside a row.)  It turns out that while on
| some machines (e.g., 68000) multiplication is an order of magnitude
| slower than addition or shifts, on some other machines (e.g., the
| transputer) multiplication is just as fast as an addition!

I don't think so.  Rather, it is probable that the "multiplication" is
optimized via strength reduction into a series of shifts and adds.  If
this series is small, it may be faster than a load (indirection), which
would be the reason why array indexing may be faster than two-level
indirection in this case. 
	-- Tim Olson
	Advanced Micro Devices
	(tim at crackle.amd.com)



More information about the Comp.lang.c mailing list