From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12132 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 20:23:11 -0500 Message-ID: <20171126012311.GT1627@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> <20171126005916.GS1627@brightrain.aerifal.cx> 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 1511659412 22096 195.159.176.226 (26 Nov 2017 01:23:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 26 Nov 2017 01:23:32 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12148-gllmg-musl=m.gmane.org@lists.openwall.com Sun Nov 26 02:23:28 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 1eIlfF-0004rf-Pd for gllmg-musl@m.gmane.org; Sun, 26 Nov 2017 02:23:21 +0100 Original-Received: (qmail 12177 invoked by uid 550); 26 Nov 2017 01:23:24 -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 12159 invoked from network); 26 Nov 2017 01:23:23 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12132 Archived-At: On Sun, Nov 26, 2017 at 02:12:58AM +0100, David Guillen Fandos wrote: > > On 26/11/17 01:59, Rich Felker wrote: > >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; > > Sorry for that, default settings you know :) > > Well the main reason is cause in MIPS it requires adding __divdi3 > which is around 1KB of code, which hey, it's not much, but why would > we need it right? It makes a difference in embedded tools with > statically linked musl. > > Thanks for your interest! If this is a real problem you're hitting, I'm interested in helping, but it seems unlikely. If your program uses printf or other common functions it will already be pulling in __divdi3 I think. Rich