From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12198 Path: news.gmane.org!.POSTED!not-for-mail From: Damian McGuckin Newsgroups: gmane.linux.lib.musl.general Subject: Re: remquo - underlying logic Date: Mon, 4 Dec 2017 19:10:17 +1100 (AEDT) Message-ID: References: <20171130185956.GS15263@port70.net> <20171130211713.GT15263@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1512375038 2723 195.159.176.226 (4 Dec 2017 08:10:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 4 Dec 2017 08:10:38 +0000 (UTC) User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) To: musl@lists.openwall.com Original-X-From: musl-return-12214-gllmg-musl=m.gmane.org@lists.openwall.com Mon Dec 04 09:10:34 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 1eLlpd-0000F1-Se for gllmg-musl@m.gmane.org; Mon, 04 Dec 2017 09:10:29 +0100 Original-Received: (qmail 26609 invoked by uid 550); 4 Dec 2017 08:10:33 -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 26584 invoked from network); 4 Dec 2017 08:10:33 -0000 X-Authentication-Warning: key0.esi.com.au: damianm owned process doing -bs In-Reply-To: <20171130211713.GT15263@port70.net> Xref: news.gmane.org gmane.linux.lib.musl.general:12198 Archived-At: Floats are not going to be faster for remquo(x, y, &q) except for a very small range where 1 < x / y < 1000 (or so) But I was hoping for only a moderate overhead. And John Reiser mentioned > The range of a floating-point exponent will limit the applicability. No. > Packing and unpacking floating-point format (logb, scalb, etc.) are > non-trivial costs, as are mucking around with NaN, +inf, -inf, > denormals, etc. Not really. > The "big-O" efficiency is the same: find the difference in exponents, > scale both operands to have the same exponent, The above are trivial compared to the operation where you > perform "ordinary long division" with the number of steps equal to the > difference in exponents; take care to preserve enough precision. This is the killer. On a Xeon, the floating point alternative is generally a factor of 4-6 worse. Actually, in the domain y * 2^(p) < x < 2^(w-1) where w is the word size in bits, the penalty is higher still, about 10. but after that it drops down to a factor of 4 and increases slowly to a factor of 6 where the difference in exponents is the same as the bias of the exponent. I must admit that I found the penalty incredible. A bit scary that faking floating point is so much faster, although admittedly with quite simple operations. The only thing is that the code is infinitely more readable, an important but not the dominant concern. An interesting exercise, albiet a bit fruitless. Regards - Damian Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037 Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here Views & opinions here are mine and not those of any past or present employer