From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/15112 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 21:07:47 -0500 Message-ID: <20200110020747.GY30412@brightrain.aerifal.cx> References: <20200106174346.6489-1-amonakov@ispras.ru> <20200109170002.GW30412@brightrain.aerifal.cx> <20200109210003.GO23985@port70.net> <20200109220014.GX30412@brightrain.aerifal.cx> <20200109231858.GP23985@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="82746"; 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-15128-gllmg-musl=m.gmane-mx.org@lists.openwall.com Fri Jan 10 03:10:25 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 1ipjiV-0014jj-Vf for gllmg-musl@m.gmane-mx.org; Fri, 10 Jan 2020 03:08:04 +0100 Original-Received: (qmail 3086 invoked by uid 550); 10 Jan 2020 02:07:59 -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 2044 invoked from network); 10 Jan 2020 02:07:59 -0000 Content-Disposition: inline In-Reply-To: <20200109231858.GP23985@port70.net> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:15112 Archived-At: On Fri, Jan 10, 2020 at 12:18:58AM +0100, Szabolcs Nagy wrote: > * Rich Felker [2020-01-09 17:00:14 -0500]: > > On Thu, Jan 09, 2020 at 10:00:06PM +0100, Szabolcs Nagy wrote: > > > > 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). > > i think -fexcess-precision=standard was introduced in > gcc 4.5 and to get reliable behaviour before that we > needed -ffloat-store. I don't think the behavior was "reliable" with -ffloat-store; it's wrong with respect to the defined meaning of FLT_EVAL_METHOD. > since we had -ffloat-store i turned off the volatile > hacks in commit 6d3f1a39c14b12026df84f386875b094e3652990 > and later completely removed the annotations in commit > 9b0fcb441a44456c7b071c7cdaf90403f81ec05a Thanks for these references. > on new compilers -fexcess-precision=standard is used, > but that turned out to do too many stores on the fdlibm > code (which is why glibc kept using =fast), so in commit > e216951f509b71da193da2fc63e25b998740d58b i started using > float_t and double_t to get fast code in standard mode. > (of course this made things worse for -ffloat-store). This was the right thing to do, and I think it largely but not entirely eliminates the need for caring about how the compiler handles this, except in a few cases. It could probably be eliminated in more. For example the argument reduction code cited above could use the right constants for double_t rather than double to avoid the need to store/load to drop excess precision. > i think we would need to add back the old annotations > to make old compilers safe without -ffloat-store. > (fdlibm often raises fenv exceptions via a final rounding > before return, those could be often handled more cleanly > by __math_oflow etc helpers, but since it was not designed > for inline errno handling some normal return paths can > raise fp exceptions too and thus need eval_as_* annotation). I think I asked you before, but from a standpoint of fenv stuff, I'm confused why the eval_as_* things are useful at all; it looks like you would need fp_barrier* to ensure they're actually evaluated (e.g. in the presence of LTO with a compiler that doesn't honor fenv right). But I think it's also useful to distinguish between possibility of wrong exceptions being raised, which is a rather minor issue since some widely-used compilers don't even support fenv reasonably at at all, and the possibility of wrong values being returned for functions where the result is required to be correctly rounded. I would deem it a serious problem for sqrt[f] or fma[f] to return the wrong value when compiled with gcc3 or pcc. I don't think I would particularly care if exceptions failed to be raised properly when compiled with gcc3 or pcc, though. So I probably would like to ensure that, whatever code we end up with in i386 sqrt[f].c, it it ends up working even if the compiler does not handle excess precision correctly. Rich