return hash;
}
+static int cmp_tv(const void *p1, const void *p2, size_t n) {
+ const tarval *tv1 = p1;
+ const tarval *tv2 = p2;
+ (void) n;
+
+ assert(tv1->kind == k_tarval);
+ assert(tv2->kind == k_tarval);
+ if(tv1->mode < tv2->mode)
+ return -1;
+ if(tv1->mode > tv2->mode)
+ return 1;
+ if(tv1->length < tv2->length)
+ return -1;
+ if(tv1->length > tv2->length)
+ return 1;
+ if(tv1->value < tv2->value)
+ return -1;
+ if(tv1->value > tv2->value)
+ return 1;
+
+ return 0;
+}
+
/** finds tarval with value/mode or creates new tarval */
static tarval *get_tarval(const void *value, int length, ir_mode *mode) {
tarval tv;
return pn_Cmp_False;
case irms_float_number:
- if (no_float)
- return pn_Cmp_False;
+ /* it should be safe to enable this even if other arithmetic is disabled */
+ /*if (no_float)
+ return pn_Cmp_False;*/
/*
* BEWARE: we cannot compare a == b here, because
* a NaN is always Unordered to any other value, even to itself!
res = fc_rnd(src->value, NULL);
break;
default:
- assert(0);
+ panic("Unsupported float to int conversion mode in tarval_convert_to()");
break;
}
buffer = alloca(sc_get_buffer_length());
return get_tarval_overflow(buffer, a->length, a->mode);
case irms_float_number:
- if(no_float)
- return tarval_bad;
+ /* it should be safe to enable this even if other arithmetic is disabled */
+ /*if (no_float)
+ return tarval_bad;*/
fc_neg(a->value, NULL);
return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode);
return get_tarval_overflow(buffer, a->length, a->mode);
case irms_float_number:
- if(no_float)
+ if (no_float)
return tarval_bad;
fc_add(a->value, b->value, NULL);
return get_tarval_overflow(buffer, a->length, a->mode);
case irms_float_number:
- if(no_float)
+ if (no_float)
return tarval_bad;
fc_sub(a->value, b->value, NULL);
return get_tarval_overflow(buffer, a->length, a->mode);
case irms_float_number:
- if(no_float)
+ if (no_float)
return tarval_bad;
fc_mul(a->value, b->value, NULL);
assert(b);
assert((a->mode == b->mode) && mode_is_float(a->mode));
- if(no_float)
+ if (no_float)
return tarval_bad;
if (get_mode_n_vector_elems(a->mode) > 1) {
return a;
case irms_float_number:
- if(no_float)
- return tarval_bad;
+ /* it should be safe to enable this even if other arithmetic is disabled */
+ /*if (no_float)
+ return tarval_bad;*/
if (fc_comp(a->value, get_mode_null(a->mode)->value) == -1) {
fc_neg(a->value, NULL);
* carry flag of the last operation
*/
int tarval_carry(void) {
+ panic("tarval_carry() requetsed: not implemented on all operations");
return sc_had_carry();
}
return fc_get_exponent(tv->value);
}
+/*
+ * Check if the tarval can be converted to the given mode without
+ * precision loss.
+ */
+int tarval_ieee754_can_conv_lossless(tarval *tv, ir_mode *mode) {
+ char exp_size, mant_size;
+ switch (get_mode_size_bits(mode)) {
+ case 32:
+ exp_size = 8; mant_size = 23;
+ break;
+ case 64:
+ exp_size = 11; mant_size = 52;
+ break;
+ case 80:
+ case 96:
+ exp_size = 15; mant_size = 64;
+ break;
+ default:
+ panic("Unsupported mode in tarval_ieee754_can_conv_lossless()");
+ return 0;
+ }
+ return fc_can_lossless_conv_to(tv->value, exp_size, mant_size);
+}
+
/* Set the immediate precision for IEEE-754 results. */
unsigned tarval_ieee754_set_immediate_precision(unsigned bits) {
return fc_set_immediate_precision(bits);
/* initialize the sets holding the tarvals with a comparison function and
* an initial size, which is the expected number of constants */
- tarvals = new_set(memcmp, N_CONSTANTS);
+ tarvals = new_set(cmp_tv, N_CONSTANTS);
values = new_set(memcmp, N_CONSTANTS);
/* init strcalc with precision of 68 to support floating point values with 64
* bit mantissa (needs extra bits for rounding and overflow) */