From 058a0a139446cec80b5d1d166c11835867b05c65 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Mon, 15 May 2006 10:53:24 +0000 Subject: [PATCH] Fixed really slow overflow handling ;-) [r7728] --- ir/tv/tv.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 5ae82fb20..90d24bb7a 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -191,13 +191,8 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) case TV_OVERFLOW_WRAP: { char *temp = alloca(sc_get_buffer_length()); - char *diff = alloca(sc_get_buffer_length()); - sc_sub(get_mode_max(mode)->value, get_mode_min(mode)->value, diff); - sc_val_from_ulong(1, temp); - sc_add(diff, temp, diff); - sc_sub(value, diff, temp); - while (sc_comp(temp, get_mode_max(mode)->value) == 1) - sc_sub(temp, diff, temp); + sc_val_from_ulong(-1, temp); + sc_and(temp, value, temp); return get_tarval(temp, length, mode); } case TV_OVERFLOW_BAD: @@ -213,13 +208,8 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) case TV_OVERFLOW_WRAP: { char *temp = alloca(sc_get_buffer_length()); - char *diff = alloca(sc_get_buffer_length()); - sc_sub(get_mode_max(mode)->value, get_mode_min(mode)->value, diff); - sc_val_from_ulong(1, temp); - sc_add(diff, temp, diff); - sc_add(value, diff, temp); - while (sc_comp(temp, get_mode_max(mode)->value) == 1) - sc_add(temp, diff, temp); + sc_val_from_ulong(-1, temp); + sc_and(temp, value, temp); return get_tarval(temp, length, mode); } case TV_OVERFLOW_BAD: @@ -1521,20 +1511,20 @@ int tarval_snprintf(char *buf, size_t len, tarval *tv) case irms_reference: if (tv == tv->mode->null) return snprintf(buf, len, "NULL"); - if (tv->value != NULL){ - if (len > tv->length) { - memcpy(buf, tv->value, tv->length); - buf[tv->length] = '\0'; - } - else { - /* truncated */ - memcpy(buf, tv->value, len-1); - buf[len-1] = '\0'; + if (tv->value != NULL) { + if (len > tv->length) { + memcpy(buf, tv->value, tv->length); + buf[tv->length] = '\0'; + } + else { + /* truncated */ + memcpy(buf, tv->value, len-1); + buf[len-1] = '\0'; + } + return tv->length; } - return tv->length; - } else - return snprintf(buf, len, "void"); + return snprintf(buf, len, "void"); case irms_internal_boolean: switch (mode_info->mode_output) { -- 2.20.1