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

Roland Scheidegger sroland at vmware.com
Tue Jan 29 14:41:57 UTC 2019


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.

Roland


> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Csroland%40vmware.com%7Cab4bc9f7d353406d07fd08d685c9b366%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636843498692106809&sdata=X5iJUwgPjhoiZYqrzSd%2FE1vhRrBthXVt21eFBigWjjM%3D&reserved=0
> 



More information about the mesa-dev mailing list