From: Michael Beck Date: Fri, 4 Apr 2003 12:27:52 +0000 (+0000) Subject: Fixed floting point computation, other small fixes X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=f2ceaaa00facf0937cad33a4ea1def4d25c1f15d;p=libfirm Fixed floting point computation, other small fixes [r1030] --- diff --git a/ir/tv/fltcalc.c b/ir/tv/fltcalc.c index f20b00e7d..46d725daa 100644 --- a/ir/tv/fltcalc.c +++ b/ir/tv/fltcalc.c @@ -26,7 +26,9 @@ ********/ static long double value; -#define CAST_IN(val) (*((long double *)((val)))) +#define CAST_IN(val) ({ long double xxx = *(long double *)(val); printf("CAST to %Lg\n", xxx); xxx; }) + +//#define CAST_IN(val) (*((long double *)((val)))) #define CAST_OUT(val) ((void *)&(val)) #define CLEAR_BUFFER() memset((char*)&value, 0, sizeof(long double)) @@ -49,6 +51,9 @@ const int fc_get_buffer_length(void) void fc_val_from_str(const char *str, unsigned int len) { + extern long double strtold(const char *str, char **end); + + printf("-> %s\n", str); CLEAR_BUFFER(); value = strtold(str, NULL); } @@ -150,6 +155,8 @@ void fc_calc(const void *a, const void *b, int opcode) break; case FC_NEG: value = -CAST_IN(a); + printf("-> NEG %Lg\n", value); + break; } } diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 0eab0eaa9..59829f5bd 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -507,20 +507,30 @@ tarval *get_tarval_nan(ir_mode *mode) { ANNOUNCE(); assert(mode); - assert(get_mode_sort(mode) == float_number); - fc_get_nan(); - return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode); + if (get_mode_sort(mode) == float_number) { + fc_get_nan(); + return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode); + } + else { + assert(0 && "tarval is not floating point"); + return tarval_bad; + } } tarval *get_tarval_inf(ir_mode *mode) { ANNOUNCE(); assert(mode); - assert(get_mode_sort(mode) == float_number); - fc_get_inf(); - return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode); + if (get_mode_sort(mode) == float_number) { + fc_get_inf(); + return get_tarval(fc_get_buffer(), fc_get_buffer_length(), mode); + } + else { + assert(0 && "tarval is not floating point"); + return tarval_bad; + } } /* @@ -545,6 +555,7 @@ int tarval_is_negative(tarval *a) default: assert(0 && "not implemented"); + return 0; } } @@ -652,6 +663,7 @@ tarval *tarval_neg(tarval *a) /* negation */ assert(mode_is_num(a->mode)); /* negation only for numerical values */ assert(mode_is_signed(a->mode)); /* negation is difficult without negative numbers, isn't it */ +printf("NEG\n"); switch (get_mode_sort(a->mode)) { case int_number: @@ -659,6 +671,7 @@ tarval *tarval_neg(tarval *a) /* negation */ return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); case float_number: +printf("FP NEG\n"); fc_neg(a->value); return get_tarval(fc_get_buffer(), fc_get_buffer_length(), a->mode); diff --git a/ir/tv/tv.h b/ir/tv/tv.h index 0fbb52311..7f1f4f283 100644 --- a/ir/tv/tv.h +++ b/ir/tv/tv.h @@ -510,8 +510,8 @@ char *tarval_sub_bitpattern(tarval *tv, int from, int to); * Because this is the bit representation of the target machine, only the following * operations are legal on the result: * - * - concatenation (be aware of the endieness) - * - bitwise logical operations to selct/mask bits + * - concatenation (endian dependance MUST be handled by the CALLER) + * - bitwise logical operations to select/mask bits * * @param tv the tarval * @param byte_ofs the byte offset