Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 7 Dec 2017 12:09:23 +1100 (AEDT)
From: Damian McGuckin <>
Subject: Re: remquo - underlying logic

On Wed, 6 Dec 2017, Szabolcs Nagy wrote:

> it's not clear to me how you use fma (x-(int)(x/y)*y ?), but efficient 
> fma instruction is not available on all targets and the software 
> implementation can be very slow. and i suspect such approach would break 
> fenv correctness.

Quite likely. Besides, my testing was flawed and FMA is NOT the answer I 
thought it was.

> (musl is compiled with -std=c99 so x*y+z is not contracted to fma(x,y,z) 
> automatically when the instruction is available, you have to add 
> -ffp-contract=fast if that's what you want, but it might break some code 
> in musl that relies on exact arithmetics, most math code should work 
> either way though.)

For a lot of reasons, FMA is not the answer.

That said, over that range, I am experimenting using a simplistic form of 
double-double arithmetic for that calculation.

Would you agree that when

 	(int) (x / y) < 2^52

the computation (int) (x / y) is accurate to within epsilon, i.e. if it
should be at most be incorrect by +/- 1.?

If so, and using the same sort of logic that log.c uses to split the 
calculation of

 	k * log(2.0)

into a high and low component, or maybe into 4 components, would you agree 
that it is possible to come up with an accurate computation of

 	x - y * (int) (x / y)

It should be much quicker than long division.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer

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.