From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/15110 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 sqrtf to C Date: Thu, 9 Jan 2020 17:00:14 -0500 Message-ID: <20200109220014.GX30412@brightrain.aerifal.cx> References: <20200106174346.6489-1-amonakov@ispras.ru> <20200109170002.GW30412@brightrain.aerifal.cx> <20200109210003.GO23985@port70.net> 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="106889"; 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-15126-gllmg-musl=m.gmane-mx.org@lists.openwall.com Thu Jan 09 23:01:16 2020 Return-path: Envelope-to: gllmg-musl@m.gmane-mx.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1ipfqy-0017aH-3a for gllmg-musl@m.gmane-mx.org; Thu, 09 Jan 2020 23:00:32 +0100 Original-Received: (qmail 30152 invoked by uid 550); 9 Jan 2020 22:00:27 -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 30134 invoked from network); 9 Jan 2020 22:00:26 -0000 Content-Disposition: inline In-Reply-To: <20200109210003.GO23985@port70.net> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:15110 Archived-At: On Thu, Jan 09, 2020 at 10:00:06PM +0100, Szabolcs Nagy wrote: > > If we want to ensure correct rounding (important for sqrt[f]) even on > > broken compilers (some ppl use gcc 3.x, and pcc may be broken too?) > > perhaps we should just do the store from asm too? > > that would be a bit safer, but then correct compiler would > store twice i think. If you did something like: float y = expr_with_excess_precision; __asm__( "" : "+m"(y)); return y; then I think you'd get just one store and one load, as intended. It seems to work as intended here. Oddly though my local gcc (7.3) is gratuitously pushing/popping a single gpr to align stack to 8 (but not 16) despite being a leaf function. No idea why. > it's hard to get excited about this > issue: it only matters on m68k and i386 which are not the > main targets for new float code (and old code had to deal > with this and bigger brokenness already). Indeed, but context of present thread is getting rid of the i386 asm files so it's relevant here. > > Note that eval_as_float only helps if -ffloat-store is used, which is > > a nasty hack and also nonconforming, arguably worse than the behavior > > without it, so we should probably drop use of that as a fallback, and > > use fp_barrier[f] instead if needed. > > i think -ffloat-store almost always drops excess precision > including returns and assignments, so with that no > annotation is needed. but yes the way the annotation is > defined now is not useful against broken compilers or > non-standard excess precision setting, in glibc the > annotation is defined differently (with inline asm). I was thinking in the context of wanting to remove from configure the: || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; } which is probably doing more harm than good. Do you know if there are things that'd break if we did that? I think eval_as_float should probably be defined as fp_barrierf to make it safe in your code, conditional on FLT_EVAL_METHOD>0 (and likewise >1 for eval_as_double). Rich