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.
15 * 32 bit should be enough for now
17 #define STAT_CNT_NUM 1
19 typedef struct _counter_t {
20 unsigned cnt[STAT_CNT_NUM];
26 static INLINE void cnt_inc(counter_t *cnt)
30 for (i = 0; i < STAT_CNT_NUM; ++i) {
39 static INLINE void cnt_dec(counter_t *cnt)
43 for (i = 0; i < STAT_CNT_NUM; ++i) {
44 if (--cnt->cnt[i] != -1)
50 * set a counter to zero
52 static INLINE void cnt_clr(counter_t *cnt)
54 memset(cnt->cnt, 0, sizeof(cnt->cnt));
58 * add a counter to another
60 static INLINE void cnt_add(counter_t *dst, const counter_t *src)
64 for (i = 0; i < STAT_CNT_NUM; ++i) {
65 unsigned a = dst->cnt[i] + src->cnt[i] + carry;
68 carry = a <= dst->cnt[i];
70 carry = a < dst->cnt[i];
80 * add an integer to an counter
82 static INLINE void cnt_add_i(counter_t *dst, int src)
85 unsigned a = dst->cnt[0] + src;
86 unsigned carry = a < dst->cnt[0];
92 for (i = 1; i < STAT_CNT_NUM; ++i) {
93 unsigned a = dst->cnt[i] + carry;
95 carry = a < dst->cnt[i];
104 #endif /* _COUNTER_H_ */