From owner-freebsd-hackers Mon Jun 5 17:30:47 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from peach.ocn.ne.jp (peach.ocn.ne.jp [210.145.254.87]) by hub.freebsd.org (Postfix) with ESMTP id 7B20437BE81 for ; Mon, 5 Jun 2000 17:30:41 -0700 (PDT) (envelope-from dcs@newsguy.com) Received: from daniel.sobral (p06-dn01kiryunisiki.gunma.ocn.ne.jp [211.0.245.7]) by peach.ocn.ne.jp (8.9.1a/OCN/) with ESMTP id JAA19754; Tue, 6 Jun 2000 09:30:38 +0900 (JST) Received: (from dcs@localhost) by daniel.sobral (8.9.3/8.9.3) id JAA00841; Tue, 6 Jun 2000 09:31:46 +0900 (JST) (envelope-from dcs) From: "Daniel C. Sobral" Message-Id: <200006060031.JAA00841@daniel.sobral> Subject: Re: Optimization In-Reply-To: <20000606031706.A41154@happy.checkpoint.com> from "Anatoly Vorobey" at "Jun 6, 2000 03:17:07 am" To: "Anatoly Vorobey" Date: Tue, 6 Jun 2000 09:31:46 +0900 (JST) Cc: "Zach Brown" , hackers@FreeBSD.ORG Disclaimer: Klaatu Barada Nikto! X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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