Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 10 Dec 2019 14:35:58 -0500
From: Rich Felker <>
To: Stefan Kanthak <>
Subject: Re: More patches for math subtree

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.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.