1 /*
2 * Revision Control Information
3 *
4 * $Source$
5 * $Author$
6 * $Revision$
7 * $Date$
8 *
9 */
10 #include "espresso.h"
11
12 ABC_NAMESPACE_IMPL_START
13
14
15
16 /* cost -- compute the cost of a cover */
cover_cost(F,cost)17 void cover_cost(F, cost)
18 IN pcover F;
19 INOUT pcost cost;
20 {
21 register pcube p, last;
22 pcube *T;
23 int var;
24
25 /* use the routine used by cofactor to decide splitting variables */
26 massive_count(T = cube1list(F));
27 free_cubelist(T);
28
29 cost->cubes = F->count;
30 cost->total = cost->in = cost->out = cost->mv = cost->primes = 0;
31
32 /* Count transistors (zeros) for each binary variable (inputs) */
33 for(var = 0; var < cube.num_binary_vars; var++)
34 cost->in += cdata.var_zeros[var];
35
36 /* Count transistors for each mv variable based on sparse/dense */
37 for(var = cube.num_binary_vars; var < cube.num_vars - 1; var++)
38 if (cube.sparse[var])
39 cost->mv += F->count * cube.part_size[var] - cdata.var_zeros[var];
40 else
41 cost->mv += cdata.var_zeros[var];
42
43 /* Count the transistors (ones) for the output variable */
44 if (cube.num_binary_vars != cube.num_vars) {
45 var = cube.num_vars - 1;
46 cost->out = F->count * cube.part_size[var] - cdata.var_zeros[var];
47 }
48
49 /* Count the number of nonprime cubes */
50 foreach_set(F, last, p)
51 cost->primes += TESTP(p, PRIME) != 0;
52
53 /* Count the total number of literals */
54 cost->total = cost->in + cost->out + cost->mv;
55 }
56
57
58 /* fmt_cost -- return a string which reports the "cost" of a cover */
fmt_cost(cost)59 char *fmt_cost(cost)
60 IN pcost cost;
61 {
62 static char s[200];
63
64 if (cube.num_binary_vars == cube.num_vars - 1)
65 (void) sprintf(s, "c=%d(%d) in=%d out=%d tot=%d",
66 cost->cubes, cost->cubes - cost->primes, cost->in,
67 cost->out, cost->total);
68 else
69 (void) sprintf(s, "c=%d(%d) in=%d mv=%d out=%d",
70 cost->cubes, cost->cubes - cost->primes, cost->in,
71 cost->mv, cost->out);
72 return s;
73 }
74
75
print_cost(F)76 char *print_cost(F)
77 IN pcover F;
78 {
79 cost_t cost;
80 cover_cost(F, &cost);
81 return fmt_cost(&cost);
82 }
83
84
85 /* copy_cost -- copy a cost function from s to d */
copy_cost(s,d)86 void copy_cost(s, d)
87 pcost s, d;
88 {
89 d->cubes = s->cubes;
90 d->in = s->in;
91 d->out = s->out;
92 d->mv = s->mv;
93 d->total = s->total;
94 d->primes = s->primes;
95 }
96
97
98 /* size_stamp -- print single line giving the size of a cover */
size_stamp(T,name)99 void size_stamp(T, name)
100 IN pcover T;
101 IN char *name;
102 {
103 (void) printf("# %s\tCost is %s\n", name, print_cost(T));
104 (void) fflush(stdout);
105 }
106
107
108 /* print_trace -- print a line reporting size and time after a function */
print_trace(T,name,time)109 void print_trace(T, name, time)
110 pcover T;
111 char *name;
112 long time;
113 {
114 (void) printf("# %s\tTime was %s, cost is %s\n",
115 name, print_time(time), print_cost(T));
116 (void) fflush(stdout);
117 }
118
119
120 /* totals -- add time spent in the function into the totals */
totals(time,i,T,cost)121 void totals(time, i, T, cost)
122 long time;
123 int i;
124 pcover T;
125 pcost cost;
126 {
127 time = ptime() - time;
128 total_time[i] += time;
129 total_calls[i]++;
130 cover_cost(T, cost);
131 if (trace) {
132 (void) printf("# %s\tTime was %s, cost is %s\n",
133 total_name[i], print_time(time), fmt_cost(cost));
134 (void) fflush(stdout);
135 }
136 }
137
138
139 /* fatal -- report fatal error message and take a dive */
fatal(s)140 void fatal(s)
141 char *s;
142 {
143 (void) fprintf(stderr, "espresso: %s\n", s);
144 exit(1);
145 }
146 ABC_NAMESPACE_IMPL_END
147
148