[Mesa-dev] [PATCH] nir: Optimize double-precision lower_round_even()

Erik Faye-Lund erik.faye-lund at collabora.com
Tue Jan 29 16:30:32 UTC 2019


On Tue, 2019-01-29 at 14:41 +0000, Roland Scheidegger wrote:
> Am 29.01.19 um 10:10 schrieb Erik Faye-Lund:
> > On Mon, 2019-01-28 at 09:31 -0800, Matt Turner wrote:
> > > Use the trick of adding and then subtracting 2**52 (52 is the
> > > number
> > > of
> > > explicit mantissa bits a double-precision floating-point value
> > > has)
> > > to
> > > implement round-to-even.
> > > 
> > > Cuts the number of instructions on SKL of the piglit test
> > > fs-roundEven-double.shader_test from 109 to 21.
> > 
> > Won't this approach only work for "small" values, that is values
> > equal
> > to or smaller than DBL_MAX - 2**52? Once you add 2**52, you'll get
> > infinity, and you can't subtract 2**52 away again without being
> > stuck
> > with infinity, no...
> 
> It would actually work for very large numbers in theory.
> The only numbers the magic trick won't work are those with magnitude
> between 2^52 and 2^104 (those are already integral and the add will
> cause some of them to be rounded up to another number with the sub
> not
> doing anything afterwards), for larger ones it will work again, up to
> and including inf.
> But in any case, that's what the bcsel is for, for numbers larger
> than
> 2^52 no operations are performed at all.
> 

Doh, I missed the bcsel somehow. Thanks for setting me straight.



More information about the mesa-dev mailing list