/* check for exponent overflow */
sc_val_from_ulong((1 << out_val->desc.exponent_size) - 1, temp);
- if (sc_comp(_exp(out_val), temp) != -1) {
+ if (sc_comp(_exp(out_val), temp) != ir_relation_less) {
/* exponent overflow, reaction depends on rounding method:
*
* mode | sign of value | result
* (+/- 0 ?) */
if (sign && sc_val_to_long(exp_diff) == 0) {
switch (sc_comp(_mant(a), _mant(b))) {
- case 1: /* a > b */
+ case ir_relation_greater: /* a > b */
res_sign = a->sign; /* abs(a) is bigger and a is negative */
break;
- case 0: /* a == b */
+ case ir_relation_equal: /* a == b */
res_sign = (rounding_mode == FC_TONEGATIVE);
break;
- case -1: /* a < b */
+ case ir_relation_less: /* a < b */
res_sign = b->sign; /* abs(b) is bigger and b is negative */
break;
default:
- /* can't be reached */
- res_sign = 0;
- break;
+ panic("invalid comparison result");
}
}
else
}
if (sign) {
- if (sc_comp(_mant(a), temp) == -1)
+ if (sc_comp(_mant(a), temp) == ir_relation_less)
sc_sub(temp, _mant(a), _mant(result));
else
sc_sub(_mant(a), temp, _mant(result));
return ir_relation_less ^ mul;
/* check first exponent, that mantissa if equal */
- int rel = sc_comp(_exp(val_a), _exp(val_b));
- if (rel == 0)
+ ir_relation rel = sc_comp(_exp(val_a), _exp(val_b));
+ if (rel == ir_relation_equal)
rel = sc_comp(_mant(val_a), _mant(val_b));
-
- switch (rel) {
- case -1: return ir_relation_less ^ mul;
- case 0: return ir_relation_equal;
- case 1: return ir_relation_greater ^ mul;
- default: panic("invalid comparison result");
- }
+ if (rel != ir_relation_equal)
+ rel ^= mul;
+ return rel;
}
int fc_is_zero(const fp_value *a)
if (result == NULL) result = calc_buffer;
/* make the value with the bigger exponent the first one */
- if (sc_comp(_exp(a), _exp(b)) == -1)
+ if (sc_comp(_exp(a), _exp(b)) == ir_relation_less)
_fadd(b, a, result);
else
_fadd(a, b, result);
temp = (fp_value*) alloca(calc_buffer_size);
memcpy(temp, b, calc_buffer_size);
temp->sign = !b->sign;
- if (sc_comp(_exp(a), _exp(temp)) == -1)
+ if (sc_comp(_exp(a), _exp(temp)) == ir_relation_less)
_fadd(temp, a, result);
else
_fadd(a, temp, result);
memset(rem, SC_0, calc_buffer_size);
/* if the divisor is zero this won't work (quot is zero) */
- if (sc_comp(divisor, quot) == 0) assert(0 && "division by zero!");
+ assert(sc_comp(divisor, quot) != ir_relation_equal && "division by zero!");
/* if the dividend is zero result is zero (quot is zero) */
- if (sc_comp(dividend, quot) == 0)
+ if (sc_comp(dividend, quot) == ir_relation_equal)
return;
if (do_sign(dividend) == -1) {
/* if divisor >= dividend division is easy
* (remember these are absolute values) */
switch (sc_comp(dividend, divisor)) {
- case 0: /* dividend == divisor */
+ case ir_relation_equal: /* dividend == divisor */
quot[0] = SC_1;
goto end;
- case -1: /* dividend < divisor */
+ case ir_relation_less: /* dividend < divisor */
memcpy(rem, dividend, calc_buffer_size);
goto end;
do_push(dividend[c_dividend], rem);
do_push(SC_0, quot);
- if (sc_comp(rem, divisor) != -1) { /* remainder >= divisor */
+ if (sc_comp(rem, divisor) != ir_relation_less) { /* remainder >= divisor */
/* subtract until the remainder becomes negative, this should
* be faster than comparing remainder with divisor */
do_add(rem, minus_divisor, rem);
*pos = SC_0;
}
-int sc_comp(const void* value1, const void* value2)
+ir_relation sc_comp(void const* const value1, void const* const value2)
{
int counter = calc_buffer_size - 1;
const char *val1 = (const char *)value1;
/* compare signs first:
* the loop below can only compare values of the same sign! */
if (do_sign(val1) != do_sign(val2))
- return (do_sign(val1) == 1)?(1):(-1);
+ return do_sign(val1) == 1 ? ir_relation_greater : ir_relation_less;
/* loop until two digits differ, the values are equal if there
* are no such two digits */
while (val1[counter] == val2[counter]) {
counter--;
- if (counter < 0) return 0;
+ if (counter < 0) return ir_relation_equal;
}
/* the leftmost digit is the most significant, so this returns
* the correct result.
* This implies the digit enum is ordered */
- return (val1[counter] > val2[counter]) ? (1) : (-1);
+ return val1[counter] > val2[counter] ? ir_relation_greater : ir_relation_less;
}
int sc_get_highest_set_bit(const void *value)
/**
* Compares val1 and val2
*/
-int sc_comp(const void *val1, const void *val2);
+ir_relation sc_comp(void const *val1, void const *val2);
int sc_get_highest_set_bit(const void *value);
int sc_get_lowest_set_bit(const void *value);
return get_tarval(temp, length, mode);
case irms_int_number:
- if (sc_comp(value, get_mode_max(mode)->value) == 1) {
+ if (sc_comp(value, get_mode_max(mode)->value) == ir_relation_greater) {
switch (tarval_get_integer_overflow_mode()) {
case TV_OVERFLOW_SATURATE:
return get_mode_max(mode);
return get_tarval(value, length, mode);
}
}
- if (sc_comp(value, get_mode_min(mode)->value) == -1) {
+ if (sc_comp(value, get_mode_min(mode)->value) == ir_relation_less) {
switch (tarval_get_integer_overflow_mode()) {
case TV_OVERFLOW_SATURATE:
return get_mode_min(mode);
if (get_mode_size_bits(tv->mode) > (int) (sizeof(long) << 3)) {
/* the value might be too big to fit in a long */
sc_max_from_bits(sizeof(long) << 3, 0, NULL);
- if (sc_comp(sc_get_buffer(), tv->value) == -1) {
+ if (sc_comp(sc_get_buffer(), tv->value) == ir_relation_less) {
/* really doesn't fit */
return 0;
}
case irms_int_number:
if (!mode_is_signed(a->mode)) return 0;
else
- return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0;
+ return sc_comp(a->value, get_mode_null(a->mode)->value) == ir_relation_less ? 1 : 0;
case irms_float_number:
return fc_is_negative((const fp_value*) a->value);
case irms_int_number:
if (a == b)
return ir_relation_equal;
- return sc_comp(a->value, b->value) == 1 ? ir_relation_greater : ir_relation_less;
+ return sc_comp(a->value, b->value);
case irms_internal_boolean:
if (a == b)
switch (get_mode_sort(a->mode)) {
case irms_int_number:
- if (sc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
+ if (sc_comp(a->value, get_mode_null(a->mode)->value) == ir_relation_less) {
buffer = (char*) alloca(sc_get_buffer_length());
sc_neg(a->value, buffer);
return get_tarval_overflow(buffer, a->length, a->mode);