is_singlebit_tarval() added, needed for Cmp optimization
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 20 Mar 2006 00:43:27 +0000 (00:43 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 20 Mar 2006 00:43:27 +0000 (00:43 +0000)
[r7480]

ir/tv/tv.c
ir/tv/tv.h

index 5c6b09b..5ae82fb 100644 (file)
@@ -1664,7 +1664,33 @@ tarval_classification_t classify_tarval(tarval *tv)
   return TV_CLASSIFY_OTHER;
 }
 
-/**
+/*
+ * Returns non-zero if a given (integer) tarval has only one single bit
+ * set.
+ */
+int is_single_bit_tarval(tarval *tv) {
+  int i, l;
+  int bits;
+
+  if (!tv || tv == tarval_bad) return 0;
+  if (! mode_is_int(tv->mode)) return 0;
+
+  l = get_mode_size_bytes(tv->mode);
+  for (bits = 0, i = l - 1; i >= 0; --i) {
+    unsigned char v = get_tarval_sub_bits(tv, (unsigned)i);
+
+    /* check for more than one bit in these */
+    if (v) {
+      if (v & (v-1))
+        return 0;
+      if (++bits > 1)
+        return 0;
+    }
+  }
+  return bits;
+}
+
+/*
  * Sets the overflow mode for integer operations.
  */
 void tarval_set_integer_overflow_mode(tarval_int_overflow_mode_t ov_mode) {
index f26b5d4..e4224e9 100644 (file)
@@ -578,7 +578,9 @@ typedef enum _tarval_classification_t {
 
 /**
  * Identifying tarvals values for algebraic simplifications.
- * @param tv
+ *
+ * @param tv        the tarval
+ *
  * @return
  *   - TV_CLASSIFY_NULL    for additive neutral or the NULL tarval for reference modes,
  *   - TV_CLASSIFY_ONE     for multiplicative neutral,
@@ -587,6 +589,12 @@ typedef enum _tarval_classification_t {
  */
 tarval_classification_t classify_tarval(tarval *tv);
 
+/**
+ * Returns non-zero if a given (integer) tarval has only one single bit
+ * set.
+ */
+int is_single_bit_tarval(tarval *tv);
+
 /**
  * Output of tarvals to a buffer.
  */