Date: Tue, 6 Jun 2000 03:17:07 +0300 From: Anatoly Vorobey <mellon@pobox.com> To: Zach Brown <zab@zabbo.net> Cc: hackers@freebsd.org Subject: Re: Optimization Message-ID: <20000606031706.A41154@happy.checkpoint.com> In-Reply-To: <20000605170742.C9146@mrnutty.zabbo.net>; from zab@zabbo.net on Mon, Jun 05, 2000 at 05:07:42PM -0700 References: <200006052347.IAA00583@daniel.sobral> <20000606025717.A40896@happy.checkpoint.com> <20000605170742.C9146@mrnutty.zabbo.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jun 05, 2000 at 05:07:42PM -0700, Zach Brown wrote: > On Tue, Jun 06, 2000 at 02:57:18AM +0300, Anatoly Vorobey 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 > > Don't forget the effects of caching. If x/y are always referenced > together, and memory is slow slow slow (on, say, any processor made in > the last few years) then the cost of unmushing the data in the cpu > could be much cheaper than the cost of going to memory to get x and y > from different tables. On the other hand, if the array is properly aligned, getting x will get the whole dword (qword, etc.) into the cache, and CPU won't have to run to the memory for y. Another problem with B is that I'm not sure the compiler will be smart enough to squeeze a structure into a register if it fits there, even with optimizations. Uhm, I think I'll run some tests on that, just for kicks. -- 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?20000606031706.A41154>