abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cvrmisc.c
Go to the documentation of this file.
1 /*
2  * Revision Control Information
3  *
4  * $Source$
5  * $Author$
6  * $Revision$
7  * $Date$
8  *
9  */
10 #include "espresso.h"
11 
13 
14 
15 
16 /* cost -- compute the cost of a cover */
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 */
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 
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 */
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 */
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 */
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 */
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 */
140 void fatal(s)
141 char *s;
142 {
143  (void) fprintf(stderr, "espresso: %s\n", s);
144  exit(1);
145 }
147 
VOID_HACK exit()
ABC_NAMESPACE_IMPL_START void cover_cost(IN pcover F, INOUT pcost cost)
Definition: cvrmisc.c:17
void fatal(char *s)
Definition: cvrmisc.c:140
void copy_cost(pcost s, pcost d)
Definition: cvrmisc.c:86
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define pcover
Definition: espresso.h:264
int var(Lit p)
Definition: SolverTypes.h:62
long total_time[TIME_COUNT]
Definition: globals.c:22
void print_trace(pcover T, char *name, long time)
Definition: cvrmisc.c:109
bool trace
Definition: globals.c:36
#define PRIME
Definition: espresso.h:127
#define foreach_set(R, last, p)
Definition: espresso.h:135
#define INOUT
Definition: espresso.h:334
#define IN
Definition: espresso.h:332
char * total_name[TIME_COUNT]
Definition: globals.c:21
char * print_cost(IN pcover F)
Definition: cvrmisc.c:76
#define print_time(t)
Definition: espresso.h:22
int total_calls[TIME_COUNT]
Definition: globals.c:23
char * name
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * sprintf()
#define ptime()
Definition: util_old.h:283
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void size_stamp(IN pcover T, IN char *name)
Definition: cvrmisc.c:99
#define free_cubelist(T)
Definition: espresso.h:267
char * fmt_cost(IN pcost cost)
Definition: cvrmisc.c:59
#define TESTP(set, flag)
Definition: espresso.h:124
void totals(long time, int i, pcover T, pcost cost)
Definition: cvrmisc.c:121
#define pcube
Definition: espresso.h:261
void massive_count(IN pcube *T)
Definition: cofactor.c:131
pcube * cube1list(pcover A)
Definition: cofactor.c:289