#include <math.h>
#include "main/core.h" /* for MAX2, MIN2, CLAMP */
+#include "util/rounding.h" /* for _mesa_roundeven */
+#include "util/half_float.h"
#include "ir.h"
#include "glsl_types.h"
#include "program/hash_table.h"
-#if defined(_MSC_VER) && (_MSC_VER < 1800)
-static int isnormal(double x)
-{
- return _fpclass(x) == _FPCLASS_NN || _fpclass(x) == _FPCLASS_PN;
-}
-#elif defined(__SUNPRO_CC) && !defined(isnormal)
-#include <ieeefp.h>
-static int isnormal(double x)
-{
- return fpclass(x) == FP_NORMAL;
-}
-#endif
-
-#if defined(_MSC_VER)
-static double copysign(double x, double y)
-{
- return _copysign(x, y);
-}
-#endif
-
static float
dot_f(ir_constant *op0, ir_constant *op1)
{
* follows:
*
* packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
- *
- * We must first cast the float to an int, because casting a negative
- * float to a uint is undefined.
*/
- return (uint8_t) (int8_t)
- _mesa_round_to_even(CLAMP(x, -1.0f, +1.0f) * 127.0f);
+ return (uint8_t)
+ _mesa_lroundevenf(CLAMP(x, -1.0f, +1.0f) * 127.0f);
}
/**
* follows:
*
* packSnorm2x16: round(clamp(c, -1, +1) * 32767.0)
- *
- * We must first cast the float to an int, because casting a negative
- * float to a uint is undefined.
*/
- return (uint16_t) (int16_t)
- _mesa_round_to_even(CLAMP(x, -1.0f, +1.0f) * 32767.0f);
+ return (uint16_t)
+ _mesa_lroundevenf(CLAMP(x, -1.0f, +1.0f) * 32767.0f);
}
/**
*
* packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
*/
- return (uint8_t) _mesa_round_to_even(CLAMP(x, 0.0f, 1.0f) * 255.0f);
+ return (uint8_t) (int) _mesa_roundevenf(CLAMP(x, 0.0f, 1.0f) * 255.0f);
}
/**
*
* packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
*/
- return (uint16_t) _mesa_round_to_even(CLAMP(x, 0.0f, 1.0f) * 65535.0f);
+ return (uint16_t) (int)
+ _mesa_roundevenf(CLAMP(x, 0.0f, 1.0f) * 65535.0f);
}
/**
if (this->type->is_error())
return NULL;
- ir_constant *op[Elements(this->operands)] = { NULL, };
+ ir_constant *op[ARRAY_SIZE(this->operands)] = { NULL, };
ir_constant_data data;
memset(&data, 0, sizeof(data));
case ir_unop_round_even:
for (unsigned c = 0; c < op[0]->type->components(); c++) {
if (op[0]->type->base_type == GLSL_TYPE_DOUBLE)
- data.d[c] = _mesa_round_to_even(op[0]->value.d[c]);
+ data.d[c] = _mesa_roundeven(op[0]->value.d[c]);
else
- data.f[c] = _mesa_round_to_even(op[0]->value.f[c]);
+ data.f[c] = _mesa_roundevenf(op[0]->value.f[c]);
}
break;
break;
case ir_unop_sin:
- case ir_unop_sin_reduced:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
data.f[c] = sinf(op[0]->value.f[c]);
break;
case ir_unop_cos:
- case ir_unop_cos_reduced:
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
for (unsigned c = 0; c < op[0]->type->components(); c++) {
data.f[c] = cosf(op[0]->value.f[c]);
if (!isnormal(data.d[c]))
data.d[c] = copysign(0.0, op[0]->value.d[c]);
} else {
- data.f[c] = ldexp(op[0]->value.f[c], op[1]->value.i[c]);
+ data.f[c] = ldexpf(op[0]->value.f[c], op[1]->value.i[c]);
/* Flush subnormal values to zero. */
if (!isnormal(data.f[c]))
- data.f[c] = copysign(0.0f, op[0]->value.f[c]);
+ data.f[c] = copysignf(0.0f, op[0]->value.f[c]);
}
}
break;