From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/654 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: correctly rounded sqrt Date: Thu, 15 Mar 2012 06:30:11 +0100 Message-ID: <20120315053011.GK5728@port70.net> References: <20120314165604.GF5728@port70.net> <20120314190123.GH5728@port70.net> <20120315014647.GI5728@port70.net> <20120315032304.GJ5728@port70.net> <20120315050748.GC184@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1331789426 12925 80.91.229.3 (15 Mar 2012 05:30:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 15 Mar 2012 05:30:26 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-655-gllmg-musl=m.gmane.org@lists.openwall.com Thu Mar 15 06:30:26 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1S83GZ-00038z-Re for gllmg-musl@plane.gmane.org; Thu, 15 Mar 2012 06:30:23 +0100 Original-Received: (qmail 10078 invoked by uid 550); 15 Mar 2012 05:30:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 10070 invoked from network); 15 Mar 2012 05:30:23 -0000 Content-Disposition: inline In-Reply-To: <20120315050748.GC184@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:654 Archived-At: * Rich Felker [2012-03-15 01:07:48 -0400]: > Here's the asm version based on fpu status word. I'm not sure if it's > safe for non-default rounding modes but otherwise it should be > correct. up,down,zero rounding should be ok we change ..xxx|10000.. into one of ..xxx|10100.. ..xxx|01100.. and both of them round the same way with ru,rd,rz > .global sqrt > .type sqrt,@function > sqrt: fldl 4(%esp) > fsqrt > fstsw %ax > sub $12,%esp > fld %st(0) > fstpt (%esp) > mov (%esp),%ecx > and $0x7ff,%ecx > cmp $0x400,%ecx > jnz 1f > and $0x200,%eax > sub $0x100,%eax > sub %eax,(%esp) here you modify the return value even if it was nan eg c99 F.9 recommends no nan modifications if ((y & 0x7fff<<64) == 0x7fff<<64) ... > fstp %st(0) > fldt (%esp) > 1: add $12,%esp > fstpl 4(%esp) > fldl 4(%esp) > ret