From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/15102 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] math: move i386 sqrt to C Date: Wed, 8 Jan 2020 02:26:41 -0500 Message-ID: <20200108072641.GR30412@brightrain.aerifal.cx> References: <20200107130605.7618-1-amonakov@ispras.ru> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="218177"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-15118-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 08 08:27:32 2020 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.89) (envelope-from ) id 1ip5k1-000nE3-T2 for gllmg-musl@m.gmane.org; Wed, 08 Jan 2020 08:26:58 +0100 Original-Received: (qmail 13391 invoked by uid 550); 8 Jan 2020 07:26:55 -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 13371 invoked from network); 8 Jan 2020 07:26:54 -0000 Content-Disposition: inline In-Reply-To: <20200107130605.7618-1-amonakov@ispras.ru> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:15102 Archived-At: On Tue, Jan 07, 2020 at 04:06:05PM +0300, Alexander Monakov wrote: > --- > Since union ldshape does not have a dedicated field for 32 least significant > bits of the x87 long double mantissa, keeping the original approach with > > ux.i.m -= (fpsr & 0x200) - 0x100; > > would lead to a 64-bit subtraction that is not trivial for the compiler to > optimize to 32-bit subtraction as done in the original assembly. Therefore > I have elected to change the approach and use > > ux.i.m ^= (fpsr & 0x200) + 0x200; > > which is easier to optimize to a 32-bit rather than 64-bit xor. > > Thoughts? I think it looks like a good change. Ideally the compiler would see, since the branch was taken where the low bits are 0x400, that subtracting a value less than 0x400 can't borrow from the high 32 bits. But I don't think current compilers do such range/value analysis, and it doesn't seem like there are anny downsides to your approach anyway. Rich