From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12130 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Do not use 64 bit division if possible Date: Sat, 25 Nov 2017 19:59:16 -0500 Message-ID: <20171126005916.GS1627@brightrain.aerifal.cx> References: <424674f0-8460-7807-7366-a87d8588e8bc@davidgf.es> <9716E0B3-B86C-4CFF-8636-6DE4BAA0D716@mac.com> <5575a0c9-0f53-f8e7-e0dc-6c1ff2b594f7@davidgf.es> <20171125235333.GQ1627@brightrain.aerifal.cx> <796e366e-f321-25a3-78e7-8a3800e62eeb@davidgf.es> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1511657973 17182 195.159.176.226 (26 Nov 2017 00:59:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 26 Nov 2017 00:59:33 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12146-gllmg-musl=m.gmane.org@lists.openwall.com Sun Nov 26 01:59:29 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eIlI7-00047Q-Hk for gllmg-musl@m.gmane.org; Sun, 26 Nov 2017 01:59:27 +0100 Original-Received: (qmail 30569 invoked by uid 550); 26 Nov 2017 00:59:29 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30548 invoked from network); 26 Nov 2017 00:59:28 -0000 Content-Disposition: inline In-Reply-To: <796e366e-f321-25a3-78e7-8a3800e62eeb@davidgf.es> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12130 Archived-At: On Sun, Nov 26, 2017 at 01:49:09AM +0100, David Guillen Fandos wrote: > Hey, > > Wow that's an awesome optimization (the a&-a), didn't know gcc was > smart enough to figure that out by itself :D It doesn't seem to be doing any optimizing for me. What it *should* do is optimize the div to ctz+shift. BTW please don't top-reply; it makes threads hard to follow and hard to meaningfully reply to inline. Rich > I just realized that PAGE_SIZE seems indeed to be defined to a > constant for some architectures, did not notice since I was running > on MIPS which has a page size different for each uarch. > > I'd say the (a&-a) is a very simple optimization and we should use > it, since it adds almost no complexity and sames some cycles and > some .text bytes, which is sometimes a bit tight. > > Something like this? Doesn't hurt constants, improves some arches :) > > diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c > index b8b761d0..aa9fc9d1 100644 > --- a/src/conf/sysconf.c > +++ b/src/conf/sysconf.c > @@ -206,7 +206,7 @@ long sysconf(int name) > if (name==_SC_PHYS_PAGES) mem = si.totalram; > else mem = si.freeram + si.bufferram; > mem *= si.mem_unit; > - mem /= PAGE_SIZE; > + mem /= (unsigned)(PAGE_SIZE & -PAGE_SIZE); > return (mem > LONG_MAX) ? LONG_MAX : mem; > case JT_ZERO & 255: > return 0;