From e3a791f11dde5d2613a7384285a12fc3bbd6c883 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 19 Oct 2004 10:58:44 +0000 Subject: [PATCH] Added overflow mode for interger operations (was already implemented, but had no IF) added tarval_carry() to access the carry flag of the last tarval Operation (was already implemented by no IF) BEWARE: tarval implementation is buggy because it uses always 68bit arithmentic, even for Div/Shr ... [r4153] --- ir/tv/tv.c | 59 ++++++++++++++++++++++++++++++++++++------------------ ir/tv/tv.h | 37 +++++++++++++++++----------------- 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/ir/tv/tv.c b/ir/tv/tv.c index e7c189291..92ab9a2cb 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -54,11 +54,8 @@ target values */ #define N_CONSTANTS 2048 -/* XXX hack until theres's a proper interface */ -#define BAD 1 -#define SATURATE 2 -#define WRAP 3 -#define GET_OVERFLOW_MODE() BAD +/* get the integer overflow mode */ +#define GET_OVERFLOW_MODE() int_overflow_mode /* unused, float to int doesn't work yet */ #define TRUNCATE 1 @@ -95,6 +92,7 @@ static long long count = 0; ****************************************************************************/ static struct set *tarvals; /* container for tarval structs */ static struct set *values; /* container for values */ +static tarval_int_overflow_mode_t int_overflow_mode = TV_OVERFLOW_WRAP; /**************************************************************************** * private functions @@ -170,6 +168,9 @@ static tarval *get_tarval(const void *value, int length, ir_mode *mode) return (tarval *)INSERT_TARVAL(&tv); } +/** + * handle overflow + */ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) { switch (get_mode_sort(mode)) @@ -177,9 +178,9 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) case irms_int_number: if (sc_comp(value, get_mode_max(mode)->value) == 1) { switch (GET_OVERFLOW_MODE()) { - case SATURATE: + case TV_OVERFLOW_SATURATE: return get_mode_max(mode); - case WRAP: + case TV_OVERFLOW_WRAP: { char *temp = alloca(sc_get_buffer_length()); char *diff = alloca(sc_get_buffer_length()); @@ -191,7 +192,7 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) sc_sub(temp, diff, temp); return get_tarval(temp, length, mode); } - case BAD: + case TV_OVERFLOW_BAD: return tarval_bad; default: return get_tarval(value, length, mode); @@ -199,9 +200,9 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) } if (sc_comp(value, get_mode_min(mode)->value) == -1) { switch (GET_OVERFLOW_MODE()) { - case SATURATE: + case TV_OVERFLOW_SATURATE: return get_mode_min(mode); - case WRAP: + case TV_OVERFLOW_WRAP: { char *temp = alloca(sc_get_buffer_length()); char *diff = alloca(sc_get_buffer_length()); @@ -213,7 +214,7 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) sc_add(temp, diff, temp); return get_tarval(temp, length, mode); } - case BAD: + case TV_OVERFLOW_BAD: return tarval_bad; default: return get_tarval(value, length, mode); @@ -792,7 +793,7 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) /* cast float to something */ case irms_float_number: switch (get_mode_sort(m)) { - case irms_float_number: + case irms_float_number: switch (get_mode_size_bits(m)) { case 32: @@ -808,7 +809,6 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) break; } return get_tarval(fc_get_buffer(), fc_get_buffer_length(), m); - break; case irms_int_number: switch (GET_FLOAT_TO_INT_MODE()) @@ -827,7 +827,6 @@ tarval *tarval_convert_to(tarval *src, ir_mode *m) * an intermediate representation is needed here first. */ /* return get_tarval(); */ return tarval_bad; - break; default: /* the rest can't be converted */ @@ -931,7 +930,8 @@ tarval *tarval_neg(tarval *a) ANNOUNCE(); assert(a); 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 */ + + /* note: negation is allowed even for unsigned modes. */ if (get_mode_n_vector_elems(a->mode) > 1) { /* vector arithmetic not implemented yet */ @@ -964,7 +964,7 @@ tarval *tarval_add(tarval *a, tarval *b) ANNOUNCE(); assert(a); assert(b); - assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode))); + assert(a->mode == b->mode); if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) { /* vector arithmetic not implemented yet */ @@ -999,7 +999,7 @@ tarval *tarval_sub(tarval *a, tarval *b) ANNOUNCE(); assert(a); assert(b); - assert((a->mode == b->mode) || (get_mode_sort(a->mode) == irms_character && mode_is_int(b->mode))); + assert(a->mode == b->mode); if (get_mode_n_vector_elems(a->mode) > 1 || get_mode_n_vector_elems(b->mode) > 1) { /* vector arithmetic not implemented yet */ @@ -1033,7 +1033,7 @@ tarval *tarval_mul(tarval *a, tarval *b) ANNOUNCE(); assert(a); assert(b); - assert((a->mode == b->mode) && mode_is_num(a->mode)); + assert(a->mode == b->mode); if (get_mode_n_vector_elems(a->mode) > 1) { /* vector arithmetic not implemented yet */ @@ -1364,6 +1364,13 @@ tarval *tarval_rot(tarval *a, tarval *b) return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); } +/* + * carry flag of the last operation + */ +int tarval_carry(void) +{ + return sc_had_carry(); +} /* * Output of tarvals @@ -1456,7 +1463,7 @@ int tarval_snprintf(char *buf, size_t len, tarval *tv) case irms_control_flow: case irms_memory: case irms_auxiliary: - return snprintf(buf, len, ""); + return snprintf(buf, len, ""); } return 0; @@ -1567,6 +1574,20 @@ tarval_classification_t classify_tarval(tarval *tv) return TV_CLASSIFY_OTHER; } +/** + * Sets the overflow mode for integer operations. + */ +void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode) { + int_overflow_mode = ov_mode; +} + +/** + * Get the overflow mode for integer operations. + */ +tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void) { + return int_overflow_mode; +} + /** * default mode_info for output as HEX */ diff --git a/ir/tv/tv.h b/ir/tv/tv.h index 0818fcff0..8ed8a5490 100644 --- a/ir/tv/tv.h +++ b/ir/tv/tv.h @@ -215,24 +215,6 @@ long double get_tarval_double(tarval *tv); */ int tarval_is_double(tarval *tv); -/** - * Construct a tarval that represents the address of the entity. - * - * The address must be constant, the entity must have as owner the global type. - * We no more support this function: Use the new SymConst instead. -tarval *new_tarval_from_entity (entity *ent, ir_mode *mode); - */ - -/** - * Returns the associated entity of a tarval. Asserts if tarval does not - * contain an entity. -entity *get_tarval_entity(tarval *tv); - */ - -/** - * Returns non-zero if a the given tarval represents an entity. -int tarval_is_entity(tarval *tv); - */ /** ********** Access routines for tarval fields ********** **/ @@ -336,6 +318,22 @@ tarval *get_tarval_inf(ir_mode *mode); /* ******************** Arithmethic operations on tarvals ******************** */ +typedef enum _tarval_int_overflow_mode_t { + TV_OVERFLOW_BAD, /**< tarval module will return tarval_bad if a overflow occurs */ + TV_OVERFLOW_WRAP, /**< tarval module will overflow will be ignored, wrap around occurs */ + TV_OVERFLOW_SATURATE /**< tarval module will saturate the overflow */ +} tarval_int_overflow_mode_t; + +/** + * Sets the overflow mode for integer operations. + */ +void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode); + +/** + * Get the overflow mode for integer operations. + */ +tarval_int_overflow_mode_t tarval_get_integer_overflow_mode(void); + /** * Compares two tarvals * @@ -454,6 +452,9 @@ tarval *tarval_shrs(tarval *a, tarval *b); /** Rotation. */ tarval *tarval_rot(tarval *a, tarval *b); +/** Carry flag of the last operation */ +int tarval_carry(void); + /* *********** Output of tarvals *********** */ /** -- 2.20.1