Commit f12db36c authored by Matthias Braun's avatar Matthias Braun
Browse files

rename some constants to avoid clashes with system headers

parent e67a1b64
......@@ -31,11 +31,6 @@
#include "error.h"
#include <math.h>
/* undef some reused constants defined by math.h */
#ifdef NAN
# undef NAN
#endif
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
......@@ -134,13 +129,13 @@ static void *pack(const fp_value *int_float, void *packed)
shift_val = (char*) alloca(value_size);
switch ((value_class_t)int_float->desc.clss) {
case NAN:
case FC_NAN:
val_buffer = (fp_value*) alloca(calc_buffer_size);
fc_get_qnan(&int_float->desc, val_buffer);
int_float = val_buffer;
break;
case INF:
case FC_INF:
val_buffer = (fp_value*) alloca(calc_buffer_size);
fc_get_plusinf(&int_float->desc, val_buffer);
val_buffer->sign = int_float->sign;
......@@ -202,7 +197,7 @@ static int normalize(const fp_value *in_val, fp_value *out_val, int sticky)
out_val->desc = in_val->desc;
}
out_val->desc.clss = NORMAL;
out_val->desc.clss = FC_NORMAL;
/* mantissa all zeros, so zero exponent (because of explicit one) */
if (hsb == ROUNDING_BITS + in_val->desc.mantissa_size) {
......@@ -248,7 +243,7 @@ static int normalize(const fp_value *in_val, fp_value *out_val, int sticky)
/* denormalized means exponent of zero */
sc_val_from_ulong(0, _exp(out_val));
out_val->desc.clss = SUBNORMAL;
out_val->desc.clss = FC_SUBNORMAL;
}
/* perform rounding by adding a value that clears the guard bit and the round bit
......@@ -294,24 +289,24 @@ static int normalize(const fp_value *in_val, fp_value *out_val, int sticky)
}
/* could have rounded down to zero */
if (sc_is_zero(_mant(out_val)) && (out_val->desc.clss == SUBNORMAL))
out_val->desc.clss = ZERO;
if (sc_is_zero(_mant(out_val)) && (out_val->desc.clss == FC_SUBNORMAL))
out_val->desc.clss = FC_ZERO;
/* check for rounding overflow */
hsb = ROUNDING_BITS + out_val->desc.mantissa_size - sc_get_highest_set_bit(_mant(out_val)) - 1;
if ((out_val->desc.clss != SUBNORMAL) && (hsb < -1)) {
if ((out_val->desc.clss != FC_SUBNORMAL) && (hsb < -1)) {
sc_val_from_ulong(1, temp);
_shift_right(_mant(out_val), temp, _mant(out_val));
if (exact && sc_had_carry())
exact = 0;
sc_add(_exp(out_val), temp, _exp(out_val));
} else if ((out_val->desc.clss == SUBNORMAL) && (hsb == -1)) {
} else if ((out_val->desc.clss == FC_SUBNORMAL) && (hsb == -1)) {
/* overflow caused the mantissa to be normal again,
* so adapt the exponent accordingly */
sc_val_from_ulong(1, temp);
sc_add(_exp(out_val), temp, _exp(out_val));
out_val->desc.clss = NORMAL;
out_val->desc.clss = FC_NORMAL;
}
/* no further rounding is needed, because rounding overflow means
* the carry of the original rounding was propagated all the way
......@@ -343,7 +338,7 @@ static int normalize(const fp_value *in_val, fp_value *out_val, int sticky)
switch (rounding_mode) {
case FC_TONEAREST:
case FC_TOPOSITIVE:
out_val->desc.clss = INF;
out_val->desc.clss = FC_INF;
break;
case FC_TONEGATIVE:
......@@ -355,7 +350,7 @@ static int normalize(const fp_value *in_val, fp_value *out_val, int sticky)
switch (rounding_mode) {
case FC_TONEAREST:
case FC_TONEGATIVE:
out_val->desc.clss = INF;
out_val->desc.clss = FC_INF;
break;
case FC_TOPOSITIVE:
......@@ -373,12 +368,12 @@ static int normalize(const fp_value *in_val, fp_value *out_val, int sticky)
*/
#define handle_NAN(a, b, result) \
do { \
if (a->desc.clss == NAN) { \
if (a->desc.clss == FC_NAN) { \
if (a != result) memcpy(result, a, calc_buffer_size); \
fc_exact = 0; \
return; \
} \
if (b->desc.clss == NAN) { \
if (b->desc.clss == FC_NAN) { \
if (b != result) memcpy(result, b, calc_buffer_size); \
fc_exact = 0; \
return; \
......@@ -409,7 +404,7 @@ static void _fadd(const fp_value *a, const fp_value *b, fp_value *result)
sign = a->sign ^ b->sign;
/* produce NaN on inf - inf */
if (sign && (a->desc.clss == INF) && (b->desc.clss == INF)) {
if (sign && (a->desc.clss == FC_INF) && (b->desc.clss == FC_INF)) {
fc_exact = 0;
fc_get_qnan(&a->desc, result);
return;
......@@ -447,17 +442,17 @@ static void _fadd(const fp_value *a, const fp_value *b, fp_value *result)
result->sign = res_sign;
/* sign has been taken care of, check for special cases */
if (a->desc.clss == ZERO || b->desc.clss == INF) {
if (a->desc.clss == FC_ZERO || b->desc.clss == FC_INF) {
if (b != result)
memcpy(result, b, calc_buffer_size);
fc_exact = b->desc.clss == NORMAL;
fc_exact = b->desc.clss == FC_NORMAL;
result->sign = res_sign;
return;
}
if (b->desc.clss == ZERO || a->desc.clss == INF) {
if (b->desc.clss == FC_ZERO || a->desc.clss == FC_INF) {
if (a != result)
memcpy(result, a, calc_buffer_size);
fc_exact = a->desc.clss == NORMAL;
fc_exact = a->desc.clss == FC_NORMAL;
result->sign = res_sign;
return;
}
......@@ -465,7 +460,7 @@ static void _fadd(const fp_value *a, const fp_value *b, fp_value *result)
/* shift the smaller value to the right to align the radix point */
/* subnormals have their radix point shifted to the right,
* take care of this first */
if ((b->desc.clss == SUBNORMAL) && (a->desc.clss != SUBNORMAL)) {
if ((b->desc.clss == FC_SUBNORMAL) && (a->desc.clss != FC_SUBNORMAL)) {
sc_val_from_ulong(1, temp);
sc_sub(exp_diff, temp, exp_diff);
}
......@@ -494,7 +489,7 @@ static void _fadd(const fp_value *a, const fp_value *b, fp_value *result)
/* _normalize expects a 'normal' radix point, adding two subnormals
* results in a subnormal radix point -> shifting before normalizing */
if ((a->desc.clss == SUBNORMAL) && (b->desc.clss == SUBNORMAL)) {
if ((a->desc.clss == FC_SUBNORMAL) && (b->desc.clss == FC_SUBNORMAL)) {
sc_val_from_ulong(1, NULL);
_shift_left(_mant(result), sc_get_buffer(), _mant(result));
}
......@@ -526,8 +521,8 @@ static void _fmul(const fp_value *a, const fp_value *b, fp_value *result)
result->sign = res_sign = a->sign ^ b->sign;
/* produce NaN on 0 * inf */
if (a->desc.clss == ZERO) {
if (b->desc.clss == INF) {
if (a->desc.clss == FC_ZERO) {
if (b->desc.clss == FC_INF) {
fc_get_qnan(&a->desc, result);
fc_exact = 0;
} else {
......@@ -537,8 +532,8 @@ static void _fmul(const fp_value *a, const fp_value *b, fp_value *result)
}
return;
}
if (b->desc.clss == ZERO) {
if (a->desc.clss == INF) {
if (b->desc.clss == FC_ZERO) {
if (a->desc.clss == FC_INF) {
fc_get_qnan(&a->desc, result);
fc_exact = 0;
} else {
......@@ -549,14 +544,14 @@ static void _fmul(const fp_value *a, const fp_value *b, fp_value *result)
return;
}
if (a->desc.clss == INF) {
if (a->desc.clss == FC_INF) {
fc_exact = 0;
if (a != result)
memcpy(result, a, calc_buffer_size);
result->sign = res_sign;
return;
}
if (b->desc.clss == INF) {
if (b->desc.clss == FC_INF) {
fc_exact = 0;
if (b != result)
memcpy(result, b, calc_buffer_size);
......@@ -571,7 +566,7 @@ static void _fmul(const fp_value *a, const fp_value *b, fp_value *result)
sc_sub(_exp(result), temp, _exp(result));
/* mixed normal, subnormal values introduce an error of 1, correct it */
if ((a->desc.clss == SUBNORMAL) ^ (b->desc.clss == SUBNORMAL)) {
if ((a->desc.clss == FC_SUBNORMAL) ^ (b->desc.clss == FC_SUBNORMAL)) {
sc_val_from_ulong(1, temp);
sc_add(_exp(result), temp, _exp(result));
}
......@@ -613,9 +608,9 @@ static void _fdiv(const fp_value *a, const fp_value *b, fp_value *result)
result->sign = res_sign = a->sign ^ b->sign;
/* produce NAN on 0/0 and inf/inf */
if (a->desc.clss == ZERO) {
if (b->desc.clss == ZERO) {
/* produce FC_NAN on 0/0 and inf/inf */
if (a->desc.clss == FC_ZERO) {
if (b->desc.clss == FC_ZERO) {
/* 0/0 -> NaN */
fc_get_qnan(&a->desc, result);
fc_exact = 0;
......@@ -628,9 +623,9 @@ static void _fdiv(const fp_value *a, const fp_value *b, fp_value *result)
return;
}
if (b->desc.clss == INF) {
if (b->desc.clss == FC_INF) {
fc_exact = 0;
if (a->desc.clss == INF) {
if (a->desc.clss == FC_INF) {
/* inf/inf -> NaN */
fc_get_qnan(&a->desc, result);
} else {
......@@ -638,12 +633,12 @@ static void _fdiv(const fp_value *a, const fp_value *b, fp_value *result)
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
result->desc.clss = ZERO;
result->desc.clss = FC_ZERO;
}
return;
}
if (a->desc.clss == INF) {
if (a->desc.clss == FC_INF) {
fc_exact = 0;
/* inf/x -> inf */
if (a != result)
......@@ -651,7 +646,7 @@ static void _fdiv(const fp_value *a, const fp_value *b, fp_value *result)
result->sign = res_sign;
return;
}
if (b->desc.clss == ZERO) {
if (b->desc.clss == FC_ZERO) {
fc_exact = 0;
/* division by zero */
if (result->sign)
......@@ -667,7 +662,7 @@ static void _fdiv(const fp_value *a, const fp_value *b, fp_value *result)
sc_add(_exp(result), temp, _exp(result));
/* mixed normal, subnormal values introduce an error of 1, correct it */
if ((a->desc.clss == SUBNORMAL) ^ (b->desc.clss == SUBNORMAL)) {
if ((a->desc.clss == FC_SUBNORMAL) ^ (b->desc.clss == FC_SUBNORMAL)) {
sc_val_from_ulong(1, temp);
sc_add(_exp(result), temp, _exp(result));
}
......@@ -770,7 +765,7 @@ static void _trunc(const fp_value *a, fp_value *result)
sc_val_from_ulong(0, NULL);
_save_result(_exp(result));
_save_result(_mant(result));
result->desc.clss = ZERO;
result->desc.clss = FC_ZERO;
return;
}
......@@ -828,7 +823,7 @@ void *fc_val_from_str(const char *str, size_t len, const ieee_descriptor_t *desc
tmp_desc.exponent_size = 15;
tmp_desc.mantissa_size = 63;
tmp_desc.explicit_one = 1;
tmp_desc.clss = NORMAL;
tmp_desc.clss = FC_NORMAL;
fc_val_from_ieee754(val, &tmp_desc, tmp);
return fc_cast(tmp, desc, (fp_value*) result);
......@@ -877,11 +872,11 @@ fp_value *fc_val_from_ieee754(long double l, const ieee_descriptor_t *desc, fp_v
/* sign and flag suffice to identify NaN or inf, no exponent/mantissa
* encoding is needed. the function can return immediately in these cases */
if (isnan(l)) {
result->desc.clss = NAN;
result->desc.clss = FC_NAN;
TRACEPRINTF(("val_from_float resulted in NAN\n"));
return result;
} else if (isinf(l)) {
result->desc.clss = INF;
result->desc.clss = FC_INF;
TRACEPRINTF(("val_from_float resulted in %sINF\n", (result->sign == 1) ? "-" : ""));
return result;
}
......@@ -951,12 +946,12 @@ long double fc_val_to_ieee754(const fp_value *val)
desc.exponent_size = 11;
desc.mantissa_size = 52;
desc.explicit_one = 0;
desc.clss = NORMAL;
desc.clss = FC_NORMAL;
#else
desc.exponent_size = 15;
desc.mantissa_size = 63;
desc.explicit_one = 1;
desc.clss = NORMAL;
desc.clss = FC_NORMAL;
#endif
mantissa_size = desc.mantissa_size + desc.explicit_one;
......@@ -1014,13 +1009,13 @@ fp_value *fc_cast(const fp_value *value, const ieee_descriptor_t *desc, fp_value
return result;
}
if (value->desc.clss == NAN) {
if (value->desc.clss == FC_NAN) {
if (sc_get_highest_set_bit(_mant(value)) == value->desc.mantissa_size + 1)
return fc_get_qnan(desc, result);
else
return fc_get_snan(desc, result);
}
else if (value->desc.clss == INF) {
else if (value->desc.clss == FC_INF) {
if (value->sign == 0)
return fc_get_plusinf(desc, result);
else
......@@ -1046,7 +1041,7 @@ fp_value *fc_cast(const fp_value *value, const ieee_descriptor_t *desc, fp_value
sc_add(_exp(value), temp, _exp(result));
/* _normalize expects normalized radix point */
if (value->desc.clss == SUBNORMAL) {
if (value->desc.clss == FC_SUBNORMAL) {
sc_val_from_ulong(1, NULL);
_shift_left(_mant(value), sc_get_buffer(), _mant(result));
} else if (value != result) {
......@@ -1067,7 +1062,7 @@ fp_value *fc_get_max(const ieee_descriptor_t *desc, fp_value *result)
result->desc.exponent_size = desc->exponent_size;
result->desc.mantissa_size = desc->mantissa_size;
result->desc.explicit_one = desc->explicit_one;
result->desc.clss = NORMAL;
result->desc.clss = FC_NORMAL;
result->sign = 0;
......@@ -1097,7 +1092,7 @@ fp_value *fc_get_snan(const ieee_descriptor_t *desc, fp_value *result)
result->desc.exponent_size = desc->exponent_size;
result->desc.mantissa_size = desc->mantissa_size;
result->desc.explicit_one = desc->explicit_one;
result->desc.clss = NAN;
result->desc.clss = FC_NAN;
result->sign = 0;
......@@ -1116,7 +1111,7 @@ fp_value *fc_get_qnan(const ieee_descriptor_t *desc, fp_value *result)
result->desc.exponent_size = desc->exponent_size;
result->desc.mantissa_size = desc->mantissa_size;
result->desc.explicit_one = desc->explicit_one;
result->desc.clss = NAN;
result->desc.clss = FC_NAN;
result->sign = 0;
......@@ -1140,7 +1135,7 @@ fp_value *fc_get_plusinf(const ieee_descriptor_t *desc, fp_value *result)
result->desc.exponent_size = desc->exponent_size;
result->desc.mantissa_size = desc->mantissa_size;
result->desc.explicit_one = desc->explicit_one;
result->desc.clss = INF;
result->desc.clss = FC_INF;
result->sign = 0;
......@@ -1174,14 +1169,14 @@ int fc_comp(const fp_value *val_a, const fp_value *val_b)
* Unordered if NaN or equal
*/
if (val_a == val_b)
return val_a->desc.clss == NAN ? 2 : 0;
return val_a->desc.clss == FC_NAN ? 2 : 0;
/* unordered if one is a NaN */
if (val_a->desc.clss == NAN || val_b->desc.clss == NAN)
if (val_a->desc.clss == FC_NAN || val_b->desc.clss == FC_NAN)
return 2;
/* zero is equal independent of sign */
if ((val_a->desc.clss == ZERO) && (val_b->desc.clss == ZERO))
if ((val_a->desc.clss == FC_ZERO) && (val_b->desc.clss == FC_ZERO))
return 0;
/* different signs make compare easy */
......@@ -1191,13 +1186,13 @@ int fc_comp(const fp_value *val_a, const fp_value *val_b)
mul = val_a->sign ? -1 : 1;
/* both infinity means equality */
if ((val_a->desc.clss == INF) && (val_b->desc.clss == INF))
if ((val_a->desc.clss == FC_INF) && (val_b->desc.clss == FC_INF))
return 0;
/* infinity is bigger than the rest */
if (val_a->desc.clss == INF)
if (val_a->desc.clss == FC_INF)
return 1 * mul;
if (val_b->desc.clss == INF)
if (val_b->desc.clss == FC_INF)
return -1 * mul;
/* check first exponent, that mantissa if equal */
......@@ -1215,7 +1210,7 @@ int fc_comp(const fp_value *val_a, const fp_value *val_b)
int fc_is_zero(const fp_value *a)
{
return a->desc.clss == ZERO;
return a->desc.clss == FC_ZERO;
}
int fc_is_negative(const fp_value *a)
......@@ -1225,17 +1220,17 @@ int fc_is_negative(const fp_value *a)
int fc_is_inf(const fp_value *a)
{
return a->desc.clss == INF;
return a->desc.clss == FC_INF;
}
int fc_is_nan(const fp_value *a)
{
return a->desc.clss == NAN;
return a->desc.clss == FC_NAN;
}
int fc_is_subnormal(const fp_value *a)
{
return a->desc.clss == SUBNORMAL;
return a->desc.clss == FC_SUBNORMAL;
}
char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base)
......@@ -1248,13 +1243,13 @@ char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base)
switch (base) {
case FC_DEC:
switch ((value_class_t)val->desc.clss) {
case INF:
case FC_INF:
snprintf(buf, buflen, "%cINF", val->sign ? '-' : '+');
break;
case NAN:
case FC_NAN:
snprintf(buf, buflen, "NaN");
break;
case ZERO:
case FC_ZERO:
snprintf(buf, buflen, "0.0");
break;
default:
......@@ -1266,13 +1261,13 @@ char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base)
case FC_HEX:
switch ((value_class_t)val->desc.clss) {
case INF:
case FC_INF:
snprintf(buf, buflen, "%cINF", val->sign ? '-' : '+');
break;
case NAN:
snprintf(buf, buflen, "NAN");
case FC_NAN:
snprintf(buf, buflen, "NaN");
break;
case ZERO:
case FC_ZERO:
snprintf(buf, buflen, "0.0");
break;
default:
......@@ -1324,9 +1319,9 @@ int fc_can_lossless_conv_to(const fp_value *value, const ieee_descriptor_t *desc
/* handle some special cases first */
switch (value->desc.clss) {
case ZERO:
case INF:
case NAN:
case FC_ZERO:
case FC_INF:
case FC_NAN:
return 1;
default:
break;
......@@ -1498,7 +1493,7 @@ fp_value *fc_rnd(const fp_value *a, fp_value *result)
*/
int fc_flt2int(const fp_value *a, void *result, ir_mode *dst_mode)
{
if (a->desc.clss == NORMAL) {
if (a->desc.clss == FC_NORMAL) {
int exp_bias = (1 << (a->desc.exponent_size - 1)) - 1;
int exp_val = sc_val_to_long(_exp(a)) - exp_bias;
int shift, highest;
......@@ -1554,7 +1549,7 @@ int fc_flt2int(const fp_value *a, void *result, ir_mode *dst_mode)
return 1;
}
else if (a->desc.clss == ZERO) {
else if (a->desc.clss == FC_ZERO) {
sc_zero(result);
return 1;
}
......
......@@ -51,11 +51,11 @@ typedef enum {
* possible float states
*/
typedef enum {
NORMAL, /**< normal representation, implicit 1 */
ZERO, /**< +/-0 */
SUBNORMAL, /**< denormals, implicit 0 */
INF, /**< +/-oo */
NAN, /**< Not A Number */
FC_NORMAL, /**< normal representation, implicit 1 */
FC_ZERO, /**< +/-0 */
FC_SUBNORMAL, /**< denormals, implicit 0 */
FC_INF, /**< +/-oo */
FC_NAN, /**< Not A Number */
} value_class_t;
/**
......
......@@ -101,16 +101,16 @@ static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP;
static int no_float = 0;
/** IEEE-754r half precision */
static const ieee_descriptor_t half_desc = { 5, 10, 0, NORMAL };
static const ieee_descriptor_t half_desc = { 5, 10, 0, FC_NORMAL };
/** IEEE-754 single precision */
static const ieee_descriptor_t single_desc = { 8, 23, 0, NORMAL };
static const ieee_descriptor_t single_desc = { 8, 23, 0, FC_NORMAL };
/** IEEE-754 double precision */
static const ieee_descriptor_t double_desc = { 11, 52, 0, NORMAL };
static const ieee_descriptor_t double_desc = { 11, 52, 0, FC_NORMAL };
/** Intel x87 extended precision */
static const ieee_descriptor_t extended_desc = { 15, 63, 1, NORMAL };
static const ieee_descriptor_t extended_desc = { 15, 63, 1, FC_NORMAL };
/** IEEE-754r quad precision */
static const ieee_descriptor_t quad_desc = { 15, 112, 0, NORMAL };
static const ieee_descriptor_t quad_desc = { 15, 112, 0, FC_NORMAL };
/****************************************************************************
* private functions
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment