glsl: Add "built-in" functions to do neg(fp64)

v2: use mix.

Signed-off-by: Elie Tournier <elie.tournier@collabora.com>
This commit is contained in:
Elie Tournier 2017-08-08 13:55:30 +01:00 committed by Matt Turner
parent 0428951b9d
commit eac66f0248
1 changed files with 26 additions and 0 deletions

View File

@ -43,6 +43,7 @@
#version 430
#extension GL_ARB_gpu_shader_int64 : enable
#extension GL_ARB_shader_bit_encoding : enable
#extension GL_EXT_shader_integer_mix : enable
#pragma warning(off)
@ -67,3 +68,28 @@ __fabs64(uint64_t __a)
a.y &= 0x7FFFFFFFu;
return packUint2x32(a);
}
/* Returns 1 if the double-precision floating-point value `a' is a NaN;
* otherwise returns 0.
*/
bool
__is_nan(uint64_t __a)
{
uvec2 a = unpackUint2x32(__a);
return (0xFFE00000u <= (a.y<<1)) &&
((a.x != 0u) || ((a.y & 0x000FFFFFu) != 0u));
}
/* Negate value of a Float64 :
* Toggle the sign bit
*/
uint64_t
__fneg64(uint64_t __a)
{
uvec2 a = unpackUint2x32(__a);
uint t = a.y;
t ^= (1u << 31);
a.y = mix(t, a.y, __is_nan(__a));
return packUint2x32(a);
}