3 * File name: ir/ir/counter.h
4 * Purpose: Statistics for Firm. Counter implementation.
8 * Copyright: (c) 2004 Universität Karlsruhe
9 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 * 32 bit should be enough for now
19 #define STAT_CNT_NUM 1
21 typedef struct _counter_t {
22 unsigned cnt[STAT_CNT_NUM];
28 static INLINE void cnt_inc(counter_t *cnt)
32 for (i = 0; i < STAT_CNT_NUM; ++i) {
41 static INLINE void cnt_dec(counter_t *cnt)
45 for (i = 0; i < STAT_CNT_NUM; ++i) {
46 if (--cnt->cnt[i] != -1)
52 * set a counter to zero
54 static INLINE void cnt_clr(counter_t *cnt)
56 memset(cnt->cnt, 0, sizeof(cnt->cnt));
60 * add a counter to another
62 static INLINE void cnt_add(counter_t *dst, const counter_t *src)
66 for (i = 0; i < STAT_CNT_NUM; ++i) {
67 unsigned a = dst->cnt[i] + src->cnt[i] + carry;
70 carry = a <= dst->cnt[i];
72 carry = a < dst->cnt[i];
82 * add an integer to an counter
84 static INLINE void cnt_add_i(counter_t *dst, int src)
87 unsigned a = dst->cnt[0] + src;
88 unsigned carry = a < dst->cnt[0];
94 for (i = 1; i < STAT_CNT_NUM; ++i) {
95 unsigned a = dst->cnt[i] + carry;
97 carry = a < dst->cnt[i];
107 * compare two counter
109 static INLINE int cnt_cmp(const counter_t *a, const counter_t *b)
115 for (i = STAT_CNT_NUM - 1 ; i >= 0; --i) {
124 return va < vb ? -1 : 1;
128 #endif /* _COUNTER_H_ */