mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Stefan Kanthak <stefan.kanthak@nexgo.de>
Cc: musl@lists.openwall.com
Subject: Re: More patches for math subtree
Date: Tue, 10 Dec 2019 14:35:58 -0500	[thread overview]
Message-ID: <20191210193558.GK1666@brightrain.aerifal.cx> (raw)
In-Reply-To: <2C3325A208DA4260A1A0F7B4517D6DFA@H270>

On Tue, Dec 10, 2019 at 05:57:55PM +0100, Stefan Kanthak wrote:
> Some more optimisations: the current implementations of ceil(), floor()
> and trunc() for i386 change the rounding control using fldcw instructions,
> which are SLOW; these patches provide faster and smaller branch-free (!)
> implementations.
> 
> JFTR: I'm NOT subscribed to your mailing list, so CC: me in replies!
> 
> --- -/src/math/i386/floor.s
> +++ +/src/math/i386/floor.s
> @@ -1,67 +1,26 @@
>  .global floorf
>  .type floorf,@function
>  floorf:
>          flds 4(%esp)
>          jmp 1f
>  
>  .global floorl
>  .type floorl,@function
>  floorl:
>          fldt 4(%esp)
>          jmp 1f
>  
>  .global floor
>  .type floor,@function
>  floor:
>          fldl 4(%esp)
> +1:      fld %st(0)
> +        frndint
> +        fxch %st(1)
> +        fucomip %st(1),%st(0)
> +        fld1
> +        fldz
> +        fcmovb %st(1),%st(0)
           ^^^^^^

fcmovb is not in the baseline ISA. Otherwise, I *think* the idea of
this patch looks good, provided I'm not missing anything with respect
to how status flags are affected.

As noted in the other email (sorry about not CC'ing you before; I've
got you on CC now), I really want to get rid of all these .s files in
favor of __asm__ statements with proper constraints in C source files.
That makes them inlineable with LTO, and makes it possible for the
compiler to select to use an instruction like fcmovb conditionally
based on the targeted ISA level rather than having to do a .S file
with hard-coded preprocessor conditionals. It also precludes x87 stack
imbalance bugs like CVE-2019-14697, which make me really wary of
manual changes to these files.

Would you be interested in working on converting over the files you
want to optimize (or even others too) to that form at the same time as
doing the optimizations? It would really help with review process and
with improving the overall code state.

Rich


  reply	other threads:[~2019-12-10 19:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 16:57 Stefan Kanthak
2019-12-10 19:35 ` Rich Felker [this message]
2019-12-10 21:32   ` Stefan Kanthak
2019-12-10 22:17     ` Rich Felker
2019-12-11  1:13       ` Rosen Penev
2019-12-11  9:53       ` Stefan Kanthak
2019-12-11 10:28         ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191210193558.GK1666@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=stefan.kanthak@nexgo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).