X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Ftv.c;h=8552fc8c282660778cd8be68c362ccfbed4bcc6d;hb=9af128bc5ad9480ecc5c78fdeebe3a2776126d2a;hp=47ef2d4b6a53c94332b147bea1b3e05282ff91ce;hpb=e3b765fcef0e337f4fe2e17d57d2fbaf1912ec79;p=libfirm diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 47ef2d4b6..8552fc8c2 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -23,7 +23,6 @@ * values. * @date 2003 * @author Mathias Heil - * @version $Id$ * @brief * * Values are stored in a format depending upon chosen arithmetic @@ -78,11 +77,11 @@ static float_to_int_mode current_float_to_int_mode = TRUNCATE; # define TARVAL_VERIFY(a) ((void)0) #endif -#define INSERT_TARVAL(tv) ((ir_tarval*)set_insert(tarvals, (tv), sizeof(ir_tarval), hash_tv((tv)))) -#define FIND_TARVAL(tv) ((ir_tarval*)set_find(tarvals, (tv), sizeof(ir_tarval), hash_tv((tv)))) +#define INSERT_TARVAL(tv) (set_insert(ir_tarval, tarvals, (tv), sizeof(ir_tarval), hash_tv((tv)))) +#define FIND_TARVAL(tv) (set_find(ir_tarval, tarvals, (tv), sizeof(ir_tarval), hash_tv((tv)))) -#define INSERT_VALUE(val, size) (set_insert(values, (val), size, hash_val((val), size))) -#define FIND_VALUE(val, size) (set_find(values, (val), size, hash_val((val), size))) +#define INSERT_VALUE(val, size) (set_insert(char, values, (val), size, hash_val((val), size))) +#define FIND_VALUE(val, size) (set_find(char, values, (val), size, hash_val((val), size))) #define fail_verify(a) _fail_verify((a), __FILE__, __LINE__) @@ -200,7 +199,7 @@ static ir_tarval *get_tarval(const void *value, size_t length, ir_mode *mode) } /* if there is such a tarval, it is returned, else tv is copied * into the set */ - return (ir_tarval *)INSERT_TARVAL(&tv); + return INSERT_TARVAL(&tv); } /** @@ -345,6 +344,10 @@ static ir_tarval *new_tarval_from_str_int(const char *str, size_t len, str += 2; len -= 2; base = 16; + } else if (str[1] == 'b' || str[1] == 'B') { + str += 2; + len -= 2; + base = 2; } else { ++str; --len; @@ -637,7 +640,7 @@ ir_tarval *get_tarval_all_one(ir_mode *mode) int tarval_is_constant(ir_tarval *tv) { - int num_res = sizeof(reserved_tv) / sizeof(reserved_tv[0]); + size_t const num_res = ARRAY_SIZE(reserved_tv); /* reserved tarvals are NOT constants. Note that although tarval_b_true and tarval_b_false are reserved, they are constants of course. */ @@ -1186,6 +1189,7 @@ ir_tarval *tarval_and(ir_tarval *a, ir_tarval *b) case irms_internal_boolean: return (a == tarval_b_false) ? a : b; + case irms_reference: case irms_int_number: sc_and(a->value, b->value, NULL); return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); @@ -1206,6 +1210,7 @@ ir_tarval *tarval_andnot(ir_tarval *a, ir_tarval *b) case irms_internal_boolean: return a == tarval_b_true && b == tarval_b_false ? tarval_b_true : tarval_b_false; + case irms_reference: case irms_int_number: sc_andnot(a->value, b->value, NULL); return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); @@ -1229,6 +1234,7 @@ ir_tarval *tarval_or(ir_tarval *a, ir_tarval *b) case irms_internal_boolean: return (a == tarval_b_true) ? a : b; + case irms_reference: case irms_int_number: sc_or(a->value, b->value, NULL); return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); @@ -1252,6 +1258,7 @@ ir_tarval *tarval_eor(ir_tarval *a, ir_tarval *b) case irms_internal_boolean: return (a == b)? tarval_b_false : tarval_b_true; + case irms_reference: case irms_int_number: sc_xor(a->value, b->value, NULL); return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); @@ -1284,6 +1291,17 @@ ir_tarval *tarval_shl(ir_tarval *a, ir_tarval *b) return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); } +ir_tarval *tarval_shl_unsigned(ir_tarval *a, unsigned b) +{ + ir_mode *mode = a->mode; + unsigned modulo = get_mode_modulo_shift(mode); + if (modulo != 0) + b %= modulo; + assert((unsigned)(long)b==b); + sc_shlI(a->value, (long)b, get_mode_size_bits(mode), mode_is_signed(mode), NULL); + return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode); +} + /* * bitwise unsigned right shift */ @@ -1307,6 +1325,17 @@ ir_tarval *tarval_shr(ir_tarval *a, ir_tarval *b) return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); } +ir_tarval *tarval_shr_unsigned(ir_tarval *a, unsigned b) +{ + ir_mode *mode = a->mode; + unsigned modulo = get_mode_modulo_shift(mode); + if (modulo != 0) + b %= modulo; + assert((unsigned)(long)b==b); + sc_shrI(a->value, (long)b, get_mode_size_bits(mode), mode_is_signed(mode), NULL); + return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode); +} + /* * bitwise signed right shift */ @@ -1330,6 +1359,17 @@ ir_tarval *tarval_shrs(ir_tarval *a, ir_tarval *b) return get_tarval(sc_get_buffer(), sc_get_buffer_length(), a->mode); } +ir_tarval *tarval_shrs_unsigned(ir_tarval *a, unsigned b) +{ + ir_mode *mode = a->mode; + unsigned modulo = get_mode_modulo_shift(mode); + if (modulo != 0) + b %= modulo; + assert((unsigned)(long)b==b); + sc_shrsI(a->value, (long)b, get_mode_size_bits(mode), mode_is_signed(mode), NULL); + return get_tarval(sc_get_buffer(), sc_get_buffer_length(), mode); +} + /* * bitwise rotation to left */ @@ -1434,7 +1474,16 @@ int tarval_snprintf(char *buf, size_t len, ir_tarval *tv) } default: - return snprintf(buf, len, ""); + if (tv == tarval_bad) + return snprintf(buf, len, ""); + else if (tv == tarval_undefined) + return snprintf(buf, len, ""); + else if (tv == tarval_reachable) + return snprintf(buf, len, ""); + else if (tv == tarval_unreachable) + return snprintf(buf, len, ""); + else + return snprintf(buf, len, ""); } } @@ -1481,9 +1530,10 @@ unsigned char get_tarval_sub_bits(ir_tarval *tv, unsigned byte_ofs) case irma_twos_complement: return sc_sub_bits(tv->value, get_mode_size_bits(tv->mode), byte_ofs); case irma_ieee754: + case irma_x86_extended_float: return fc_sub_bits((const fp_value*) tv->value, get_mode_size_bits(tv->mode), byte_ofs); default: - panic("get_tarval_sub_bits(): arithmetic mode not supported"); + panic("arithmetic mode not supported"); } }