Date: Tue, 6 Jun 2000 09:31:46 +0900 (JST) From: "Daniel C. Sobral" <dcs@newsguy.com> To: "Anatoly Vorobey" <mellon@pobox.com> Cc: "Zach Brown" <zab@zabbo.net>, hackers@FreeBSD.ORG Subject: Re: Optimization Message-ID: <200006060031.JAA00841@daniel.sobral> In-Reply-To: <20000606031706.A41154@happy.checkpoint.com> from "Anatoly Vorobey" at "Jun 6, 2000 03:17:07 am"
next in thread | previous in thread | raw e-mail | index | archive | help
Unheedful of thy elder's warnings, Anatoly Vorobey wrote: > > > > > > 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 [stuff about d being a structure] It isn't. A 32 bits integer is enough to keep both values (but not a 16 one). So question is whether unmangling the stuff is more or less efficient than a second fetch almost garanteed to be cached. > 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. Assume x and y to be short, MASK to be 0xffff, and SHIFT to be 16. Though I doubt there is any gain in actually declaring any of these variables to be a short. -- Daniel C. Sobral (8-DCS) dcs@newsguy.com dcs@freebsd.org capo@there.is.no.bsdconspiracy.net The smallest worm will turn being trodden on. -- William Shakespeare, "Henry VI" 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?200006060031.JAA00841>