Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!gatech!amdcad!news From: news@amdcad.AMD.COM (Network News) Newsgroups: comp.lang.c Subject: Re: Array indexing vs. pointers... Message-ID: <23025@amdcad.AMD.COM> Date: 24 Sep 88 01:09:59 GMT References: <8809191521.AA17824@ucbvax.Berkeley.EDU> <68995@sun.uucp> <6396@batcomputer.tn.cornell.edu> Reply-To: tim@crackle.amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc., Sunnyvale CA Lines: 23 Summary: Expires: Sender: Followup-To: In article <6396@batcomputer.tn.cornell.edu> braner@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@crackle.amd.com)