projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed some typos.
[libfirm]
/
ir
/
stat
/
distrib.c
diff --git
a/ir/stat/distrib.c
b/ir/stat/distrib.c
index
1002faa
..
bd4299e
100644
(file)
--- a/
ir/stat/distrib.c
+++ b/
ir/stat/distrib.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 1995-20
08
University of Karlsruhe. All right reserved.
+ * Copyright (C) 1995-20
11
University of Karlsruhe. All right reserved.
*
* This file is part of libFirm.
*
*
* This file is part of libFirm.
*
@@
-21,12
+21,11
@@
* @file
* @brief Statistics for Firm. Distribution tables.
* @author Michael Beck
* @file
* @brief Statistics for Firm. Distribution tables.
* @author Michael Beck
- * @version $Id$
*/
#include "config.h"
#include "hashptr.h"
*/
#include "config.h"
#include "hashptr.h"
-#include "
irtools
.h"
+#include "
util
.h"
#include "xmalloc.h"
#include "firmstat_t.h"
#include "xmalloc.h"
#include "firmstat_t.h"
@@
-35,7
+34,7
@@
*/
static unsigned addr_hash(const void *object)
{
*/
static unsigned addr_hash(const void *object)
{
- return
HASH_PTR
(object);
+ return
hash_ptr
(object);
}
/**
}
/**
@@
-51,10
+50,12
@@
static unsigned int_hash(const void *object)
*/
static int int_cmp_fun(const void *elt, const void *key)
{
*/
static int int_cmp_fun(const void *elt, const void *key)
{
- const distrib_entry_t *p1 = elt;
- const distrib_entry_t *p2 = key;
+ const distrib_entry_t *p1 =
(const distrib_entry_t*)
elt;
+ const distrib_entry_t *p2 =
(const distrib_entry_t*)
key;
- return (char *)p1->object - (char *)p2->object;
+ if (p1->object == p2->object)
+ return 0;
+ return p1->object < p2->object ? -1 : 1;
}
/*
}
/*
@@
-111,7
+112,7
@@
static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object
key.object = object;
key.object = object;
- elem = pset_find(tbl->hash_map, &key, tbl->hash_func(object));
+ elem =
(distrib_entry_t*)
pset_find(tbl->hash_map, &key, tbl->hash_func(object));
if (elem)
return elem;
if (elem)
return elem;
@@
-122,7
+123,7
@@
static distrib_entry_t *distrib_get_entry(distrib_tbl_t *tbl, const void *object
elem->object = object;
elem->object = object;
- return pset_insert(tbl->hash_map, elem, tbl->hash_func(object));
+ return
(distrib_entry_t*)
pset_insert(tbl->hash_map, elem, tbl->hash_func(object));
}
/*
}
/*
@@
-185,10
+186,9
@@
void stat_insert_int_distrib_tbl(distrib_tbl_t *tbl, int key)
*/
int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
{
*/
int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
{
- distrib_entry_t *entry;
counter_t cnt = ZERO_CNT;
counter_t cnt = ZERO_CNT;
- foreach_pset(tbl->hash_map, entry)
+ foreach_pset(tbl->hash_map,
distrib_entry_t,
entry)
cnt_add(&cnt, &entry->cnt);
return cnt_to_uint(&cnt);
}
cnt_add(&cnt, &entry->cnt);
return cnt_to_uint(&cnt);
}
@@
-198,25
+198,19
@@
int stat_get_count_distrib_tbl(distrib_tbl_t *tbl)
*/
double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
{
*/
double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
{
- distrib_entry_t *entry;
- unsigned count;
+ size_t count;
double sum;
if (tbl->int_dist) {
/* integer distribution, need min, max */
double sum;
if (tbl->int_dist) {
/* integer distribution, need min, max */
- int min, max;
-
- entry = pset_first(tbl->hash_map);
-
- if (! entry)
+ if (pset_count(tbl->hash_map) == 0)
return 0.0;
return 0.0;
- min =
- max = PTR_TO_INT(entry->object);
- sum = cnt_to_dbl(&entry->cnt);
-
+ int min = INT_MAX;
+ int max = INT_MIN;
+ sum = 0.0;
- for
(entry = pset_next(tbl->hash_map); entry; entry = pset_next(tbl->hash_map)
) {
+ for
each_pset(tbl->hash_map, distrib_entry_t, entry
) {
int value = PTR_TO_INT(entry->object);
if (value < min)
int value = PTR_TO_INT(entry->object);
if (value < min)
@@
-230,7
+224,7
@@
double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
} else {
sum = 0.0;
count = 0;
} else {
sum = 0.0;
count = 0;
- foreach_pset(tbl->hash_map, entry) {
+ foreach_pset(tbl->hash_map,
distrib_entry_t,
entry) {
sum += cnt_to_dbl(&entry->cnt);
++count;
}
sum += cnt_to_dbl(&entry->cnt);
++count;
}
@@
-244,20
+238,19
@@
double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl)
*/
double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
{
*/
double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
{
- distrib_entry_t *entry;
- unsigned count = 0;
- double sum = 0.0;
+ size_t count = 0;
+ double sum = 0.0;
if (tbl->int_dist) {
if (pset_count(tbl->hash_map) <= 0)
return 0.0;
if (tbl->int_dist) {
if (pset_count(tbl->hash_map) <= 0)
return 0.0;
- foreach_pset(tbl->hash_map, entry) {
+ foreach_pset(tbl->hash_map,
distrib_entry_t,
entry) {
sum += cnt_to_dbl(&entry->cnt) * PTR_TO_INT(entry->object);
count += cnt_to_uint(&entry->cnt);
}
} else {
sum += cnt_to_dbl(&entry->cnt) * PTR_TO_INT(entry->object);
count += cnt_to_uint(&entry->cnt);
}
} else {
- foreach_pset(tbl->hash_map, entry) {
+ foreach_pset(tbl->hash_map,
distrib_entry_t,
entry) {
sum += cnt_to_dbl(&entry->cnt);
++count;
}
sum += cnt_to_dbl(&entry->cnt);
++count;
}
@@
-271,8
+264,6
@@
double stat_calc_avg_distrib_tbl(distrib_tbl_t *tbl)
*/
void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env)
{
*/
void stat_iterate_distrib_tbl(const distrib_tbl_t *tbl, eval_distrib_entry_fun eval, void *env)
{
- distrib_entry_t *entry;
-
- foreach_pset(tbl->hash_map, entry)
+ foreach_pset(tbl->hash_map, distrib_entry_t, entry)
eval(entry, env);
}
eval(entry, env);
}