X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Ftv.c;h=933c55f4f0ef2447f3765d6efeb41e58dd16b063;hb=8010ed3d640a15ac18138d8a96ea61f318aae2cb;hp=dbdf9b6e0defa0acad5eb8ac52bbf8ed4c14da37;hpb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;p=libfirm diff --git a/ir/tv/tv.c b/ir/tv/tv.c index dbdf9b6e0..933c55f4f 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -36,10 +36,8 @@ #include #include #include -#ifdef HAVE_STRINGS_H -#include -#endif #include +#include #include "bitfiddle.h" #include "tv_t.h" @@ -116,8 +114,8 @@ static const ieee_descriptor_t quad_desc = { 15, 112, 0, NORMAL }; * private functions ****************************************************************************/ #ifndef NDEBUG -static int hash_val(const void *value, unsigned int length); -static int hash_tv(ir_tarval *tv); +static unsigned hash_val(const void *value, size_t length); +static unsigned hash_tv(ir_tarval *tv); static void _fail_verify(ir_tarval *tv, const char* file, int line) { /* print a memory image of the tarval and throw an assertion */ @@ -145,16 +143,16 @@ inline static void tarval_verify(ir_tarval *tv) #endif /* NDEBUG */ /** Hash a tarval. */ -static int hash_tv(ir_tarval *tv) +static unsigned hash_tv(ir_tarval *tv) { - return (PTR_TO_INT(tv->value) ^ PTR_TO_INT(tv->mode)) + tv->length; + return (unsigned)((PTR_TO_INT(tv->value) ^ PTR_TO_INT(tv->mode)) + tv->length); } /** Hash a value. Treat it as a byte array. */ -static int hash_val(const void *value, unsigned int length) +static unsigned hash_val(const void *value, size_t length) { - unsigned int i; - unsigned int hash = 0; + size_t i; + unsigned hash = 0; /* scramble the byte - array */ for (i = 0; i < length; ++i) { @@ -190,7 +188,7 @@ static int cmp_tv(const void *p1, const void *p2, size_t n) } /** finds tarval with value/mode or creates new tarval */ -static ir_tarval *get_tarval(const void *value, int length, ir_mode *mode) +static ir_tarval *get_tarval(const void *value, size_t length, ir_mode *mode) { ir_tarval tv; @@ -217,7 +215,7 @@ static ir_tarval *get_tarval(const void *value, int length, ir_mode *mode) /** * handle overflow */ -static ir_tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) +static ir_tarval *get_tarval_overflow(const void *value, size_t length, ir_mode *mode) { char *temp; @@ -480,7 +478,7 @@ long get_tarval_long(ir_tarval* tv) return sc_val_to_long(tv->value); } -ir_tarval *new_tarval_from_double(long double d, ir_mode *mode) +ir_tarval *new_tarval_from_long_double(long double d, ir_mode *mode) { const ieee_descriptor_t *desc; @@ -490,6 +488,11 @@ ir_tarval *new_tarval_from_double(long double d, ir_mode *mode) return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode); } +ir_tarval *new_tarval_from_double(double d, ir_mode *mode) +{ + return new_tarval_from_long_double(d, mode); +} + /* returns non-zero if can be converted to double */ int tarval_is_double(ir_tarval *tv) { @@ -498,13 +501,18 @@ int tarval_is_double(ir_tarval *tv) return (get_mode_sort(tv->mode) == irms_float_number); } -long double get_tarval_double(ir_tarval *tv) +long double get_tarval_long_double(ir_tarval *tv) { assert(tarval_is_double(tv)); return fc_val_to_ieee754((const fp_value*) tv->value); } +double get_tarval_double(ir_tarval *tv) +{ + return get_tarval_long_double(tv); +} + /* * Access routines for tarval fields ======================================== @@ -848,7 +856,7 @@ int tarval_is_minus_one(ir_tarval *a) /* * comparison */ -pn_Cmp tarval_cmp(ir_tarval *a, ir_tarval *b) +ir_relation tarval_cmp(ir_tarval *a, ir_tarval *b) { carry_flag = -1; @@ -857,10 +865,10 @@ pn_Cmp tarval_cmp(ir_tarval *a, ir_tarval *b) } if (a == tarval_undefined || b == tarval_undefined) - return pn_Cmp_False; + return ir_relation_false; if (a->mode != b->mode) - return pn_Cmp_False; + return ir_relation_false; if (get_mode_n_vector_elems(a->mode) > 1) { /* vector arithmetic not implemented yet */ @@ -873,36 +881,33 @@ pn_Cmp tarval_cmp(ir_tarval *a, ir_tarval *b) case irms_memory: case irms_auxiliary: if (a == b) - return pn_Cmp_Eq; - return pn_Cmp_False; + return ir_relation_equal; + return ir_relation_false; case irms_float_number: - /* 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! */ switch (fc_comp((const fp_value*) a->value, (const fp_value*) b->value)) { - case -1: return pn_Cmp_Lt; - case 0: return pn_Cmp_Eq; - case 1: return pn_Cmp_Gt; - case 2: return pn_Cmp_Uo; - default: return pn_Cmp_False; + case -1: return ir_relation_less; + case 0: return ir_relation_equal; + case 1: return ir_relation_greater; + case 2: return ir_relation_unordered; + default: return ir_relation_false; } case irms_reference: case irms_int_number: if (a == b) - return pn_Cmp_Eq; - return sc_comp(a->value, b->value) == 1 ? pn_Cmp_Gt : pn_Cmp_Lt; + return ir_relation_equal; + return sc_comp(a->value, b->value) == 1 ? ir_relation_greater : ir_relation_less; case irms_internal_boolean: if (a == b) - return pn_Cmp_Eq; - return a == tarval_b_true ? pn_Cmp_Gt : pn_Cmp_Lt; + return ir_relation_equal; + return a == tarval_b_true ? ir_relation_greater : ir_relation_less; } - return pn_Cmp_False; + return ir_relation_false; } /* @@ -1205,46 +1210,34 @@ ir_tarval *tarval_mul(ir_tarval *a, ir_tarval *b) } /* - * floating point division - */ -ir_tarval *tarval_quo(ir_tarval *a, ir_tarval *b) -{ - assert((a->mode == b->mode) && mode_is_float(a->mode)); - - carry_flag = -1; - - if (no_float) - return tarval_bad; - - if (get_mode_n_vector_elems(a->mode) > 1) { - /* vector arithmetic not implemented yet */ - return tarval_bad; - } - - fc_div((const fp_value*) a->value, (const fp_value*) b->value, NULL); - return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), a->mode); -} - -/* - * integer division + * division * overflow is impossible, but look out for division by zero */ ir_tarval *tarval_div(ir_tarval *a, ir_tarval *b) { - assert((a->mode == b->mode) && mode_is_int(a->mode)); + ir_mode *mode = a->mode; + assert(mode == b->mode); carry_flag = -1; - if (get_mode_n_vector_elems(a->mode) > 1) { + if (get_mode_n_vector_elems(mode) > 1) { /* vector arithmetic not implemented yet */ return tarval_bad; } - /* x/0 error */ - if (b == get_mode_null(b->mode)) return tarval_bad; - /* modes of a,b are equal */ - sc_div(a->value, b->value, NULL); - return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); + if (mode_is_int(mode)) { + /* x/0 error */ + if (b == get_mode_null(mode)) + return tarval_bad; + + /* modes of a,b are equal */ + sc_div(a->value, b->value, NULL); + return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); + } else { + assert(mode_is_float(mode)); + fc_div((const fp_value*) a->value, (const fp_value*) b->value, NULL); + return get_tarval_overflow(fc_get_buffer(), fc_get_buffer_length(), mode); + } } /*