typos fixed
[libfirm] / ir / stat / counter.h
index 055ea95..c327b46 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef _COUNTER_H_
 #define _COUNTER_H_
 
+#include <string.h>
+
 /*
  * 32 bit should be enough for now
  */
@@ -109,7 +111,6 @@ static INLINE int cnt_cmp(const counter_t *a, const counter_t *b)
   int i;
   unsigned va, vb;
 
-
   for (i = STAT_CNT_NUM - 1 ; i >= 0; --i) {
     va = a->cnt[i];
     vb = b->cnt[i];
@@ -123,4 +124,52 @@ static INLINE int cnt_cmp(const counter_t *a, const counter_t *b)
   return 0;
 }
 
+/**
+ * convert a counter into a double
+ */
+static INLINE double cnt_to_dbl(const counter_t *a)
+{
+  int i;
+  double res = 0.0, scale = 1.0, tmp;
+
+  i = (1 << (sizeof(a->cnt[i]) * 4));
+  tmp = ((double)i) * ((double)i);
+
+  for (i = 0; i < STAT_CNT_NUM; ++i) {
+    res += scale * (double)a->cnt[i];
+
+    scale *= tmp;
+  }
+  return res;
+}
+
+/**
+ * check, if a counter is equal to an unsigned
+ */
+static INLINE int cnt_eq(const counter_t *a, unsigned value)
+{
+  int i;
+
+  for (i = 1; i < STAT_CNT_NUM; ++i)
+    if (a->cnt[i])
+      return 0;
+
+  return a->cnt[0] == value;
+}
+
+/**
+ * check, if a counter as greater than an unsigned
+ */
+static INLINE int cnt_gt(const counter_t *a, unsigned value)
+{
+  int i;
+
+  for (i = 1; i < STAT_CNT_NUM; ++i)
+    if (a->cnt[i])
+      return 1;
+
+  return a->cnt[0] > value;
+}
+
+
 #endif /* _COUNTER_H_ */