ia32: Merge Test and Test8Bit.
[libfirm] / ir / tv / tv.c
index 47ef2d4..8552fc8 100644 (file)
@@ -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, "<TV_??""?>");
+               if (tv == tarval_bad)
+                       return snprintf(buf, len, "<TV_BAD>");
+               else if (tv == tarval_undefined)
+                       return snprintf(buf, len, "<TV_UNDEFINED>");
+               else if (tv == tarval_reachable)
+                       return snprintf(buf, len, "<TV_REACHABLE>");
+               else if (tv == tarval_unreachable)
+                       return snprintf(buf, len, "<TV_UNREACHABLE>");
+               else
+                       return snprintf(buf, len, "<TV_??""?>");
        }
 }
 
@@ -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");
        }
 }