Date: Tue, 6 Jun 2000 02:57:18 +0300 From: Anatoly Vorobey <mellon@pobox.com> To: "Daniel C. Sobral" <dcs@newsguy.com> Cc: hackers@freebsd.org Subject: Re: Optimization Message-ID: <20000606025717.A40896@happy.checkpoint.com> In-Reply-To: <200006052347.IAA00583@daniel.sobral>; from dcs@newsguy.com on Tue, Jun 06, 2000 at 08:47:42AM %2B0900 References: <200006052347.IAA00583@daniel.sobral>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jun 06, 2000 at 08:47:42AM +0900, Daniel C. Sobral wrote: > Can someone discuss the performance trade-offs of the following two > alternative codes (and maybe suggest alternatives)? > > Problem: I need to retrieve two values from a table. > > Alternative A: > > x = table[i].x; > y = table[i].y; > > Alternative B: > > d = table[i]; > x = d & MASK; > y = d >> SHIFT; Alternative A should be much faster. The compiler should be smart enough to cache &(table[i]) in a register. OTOH I am not sure it'll be smart enough to cache a structure (d) in a register even though it might fit there. The first line of Alternative B should take roughly as much as the whole of Alternative A, and even more if the compiler is stupider (and sets up an array-copying operation to retrieve d instead of explicitly copying x and y). Of course, if table[i] includes anything else besides x and y, B is slower yet. You might want to declare x and y as register if that's alright with you. It might speed you up wrt next operations you do with x and y. -- Anatoly Vorobey, mellon@pobox.com http://pobox.com/~mellon/ "Angels can fly because they take themselves lightly" - G.K.Chesterton To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000606025717.A40896>