AMulet 2.0
AIG Multiplier Verification Tool
gate.h
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*/
9 /*------------------------------------------------------------------------*/
10 #ifndef _gate_H
11 #define _gate_H
12 /*------------------------------------------------------------------------*/
13 #include <map>
14 #include <queue>
15 
16 #include "aig.h"
17 #include "polynomial.h"
18 /*------------------------------------------------------------------------*/
20 extern bool xor_chain;
21 
23 extern bool booth;
24 
26 extern bool signed_mult;
27 /*------------------------------------------------------------------------*/
28 
32 class Gate {
33 
35  const Var * v;
36 
38  bool input;
39 
41  bool output;
42 
44  bool aig_output = 0;
45 
47  bool partial_product = 0;
48 
50  int level = 0;
51 
53  bool xor_chain = 0;
54 
56  int xor_gate = 0;
57 
59  int carry_gate = 0;
60 
62  int slice = -1;
63 
65  bool prop_gen_gate = 0;
66 
68  bool fsa = 0;
69 
71  int fsa_inp = 0;
72 
74  bool neg = 0;
75 
77  bool moved = 0;
78 
80  bool bo = 0;
81 
83  bool elim = 0;
84 
87 
90 
92  std::map<Gate*, Polynomial*> ancestors;
93 
95  std::list<Gate*> parents;
96 
98  std::list<Gate*> children;
99 
100 public:
101 
110  Gate (int n_, std::string name_, int level_, bool input_ = 0, bool output_ = 0);
111 
117  const Var * get_var() const {return v;};
118 
124  int get_var_num() const {return v->get_num();};
125 
131  const char * get_var_name()const {return v->get_name();};
132 
138  bool get_input() const {return input;};
139 
145  bool get_output() const {return output;};
146 
152  bool get_pp() const {return partial_product;};
153 
157  void mark_pp() {partial_product = 1;};
158 
164  bool get_aig_output() const {return aig_output;};
165 
169  void mark_aig_output() {aig_output = 1;};
170 
176  int get_level() const {return level;};
177 
183  void set_level(int l) {level = l;};
184 
190  bool get_xor_chain() const {return xor_chain;};
191 
195  void mark_xor_chain() {xor_chain = 1;};
196 
202  int get_xor_gate() const {return xor_gate;};
203 
209  void set_xor_gate(int val) {xor_gate = val;};
210 
216  int get_carry_gate() const {return carry_gate;};
217 
223  void set_carry_gate(int val) {carry_gate = val;};
224 
228  void inc_carry_gate() {carry_gate++;};
229 
233  void dec_carry_gate() {carry_gate--;};
234 
240  int get_slice() const {return slice;};
241 
247  void set_slice(int val) {slice = val;};
248 
252  void inc_slice() {slice++;};
253 
257  void dec_slice() {slice--;};
258 
264  bool get_prop_gen_gate() const {return prop_gen_gate;};
265 
269  void mark_prop_gen_gate() {prop_gen_gate = 1;};
270 
274  void unmark_prop_gen_gate() {prop_gen_gate = 0;};
275 
281  bool get_fsa() const {return fsa;};
282 
286  void mark_fsa() {fsa = 1;};
287 
293  int get_fsa_inp() const {return fsa_inp;};
294 
298  void inc_fsa_inp() {fsa_inp++;};
299 
303  void reset_fsa_inp() {fsa_inp = 0;};
304 
310  bool get_neg() const {return neg;};
311 
317  void set_neg(bool val) {neg = val;};
318 
324  bool get_moved() const {return moved;};
325 
329  void mark_moved() {moved = 1;};
330 
336  bool get_bo() const {return bo;};
337 
341  void mark_bo() {bo = 1;};
342 
348  bool get_elim() const {return elim;};
349 
353  void mark_elim(){elim = 1;};
354 
361 
367  void set_gate_constraint(Polynomial * p) {gate_constraint = p;};
368 
374  void print_gate_constraint(FILE * file) const { gate_constraint->print(file);};
375 
381  Polynomial * get_cofactor() const {return co_factor;};
382 
388  void set_cofactor(Polynomial * p) {co_factor = p;};
389 
395  std::map<Gate*, Polynomial*>::const_iterator anc_begin() const {
396  return ancestors.begin();
397  };
398 
404  std::map<Gate*, Polynomial*>::const_iterator anc_end() const {
405  return ancestors.end();
406  };
407 
414  std::map<Gate*, Polynomial*>::iterator search_in_anc(Gate *n) {
415  return ancestors.find(n);
416  };
417 
424  void set_ancestor (Gate *n, Polynomial * p) {ancestors[n] = p;};
425 
431  std::list<Gate*>::const_iterator parents_begin() const {
432  return parents.begin();
433  };
434 
440  std::list<Gate*>::const_iterator parents_end() const {
441  return parents.end();
442  };
443 
449  size_t parents_size() const {return parents.size();};
450 
456  Gate * parents_front() const {return parents.front();};
457 
463  void parents_push_back(Gate * n) {parents.push_back(n);};
464 
470  void parents_remove(Gate * n) {parents.remove(n);};
471 
477  std::list<Gate*>::const_iterator children_begin() const {
478  return children.begin();
479  };
480 
486  std::list<Gate*>::const_iterator children_end() const {
487  return children.end();
488  };
489 
495  size_t children_size() const {return children.size();};
496 
502  Gate * children_front() const {return children.front();};
503 
509  Gate * children_back() const {return children.back();};
510 
516  void set_children_front(Gate * n) {children.front() = n;};
517 
523  void set_children_back (Gate * n) {children.back() = n;};
524 
530  void children_push_back(Gate * n) {children.push_back(n);};
531 
537  void children_remove (Gate * n) {children.remove(n);};
538 
539 
546  bool orig() const;
547 
548 
552  ~Gate();
553 
561  bool is_in_parents(const Gate *n) const;
562 
570  bool is_child(const Gate *n) const;
571 
572 };
573 
574 /*------------------------------------------------------------------------*/
576 extern Gate ** gates;
577 
579 extern unsigned num_gates;
580 /*------------------------------------------------------------------------*/
581 
589 Gate * gate (unsigned lit);
590 
594 void allocate_gates(bool assert = 1);
595 
599 void mark_aig_outputs();
600 
609 Gate * derive_ha_and_gate(const Gate * n);
610 
614 void set_xor ();
615 
622 bool upper_half_xor_output();
623 
631 Gate * xor_left_child (const Gate * n);
632 
640 Gate * xor_right_child (const Gate * n);
641 
646 
652 void set_parents_and_children (bool set_children);
653 
654 
662 Polynomial * negative_poly (const Var * v);
663 
671 Polynomial * positive_poly (const Var * v);
672 
676 void init_gate_constraints ();
677 
681 void delete_gates();
682 
683 #endif
void reset_fsa_inp()
Definition: gate.h:303
const Var * v
Variable of the gate, as used in the polynomials.
Definition: gate.h:35
bool get_output() const
Definition: gate.h:145
void set_gate_constraint(Polynomial *p)
Definition: gate.h:367
~Gate()
Definition: gate.cpp:29
bool get_pp() const
Definition: gate.h:152
Polynomial * co_factor
Polynomial generated as co-factor for nss proofs (-certify)
Definition: gate.h:89
int carry_gate
Counts how often gate is used in bigger slice.
Definition: gate.h:59
bool get_input() const
Definition: gate.h:138
void set_slice(int val)
Definition: gate.h:247
bool get_prop_gen_gate() const
Definition: gate.h:264
void unmark_prop_gen_gate()
Definition: gate.h:274
void set_xor_gate(int val)
Definition: gate.h:209
Definition: variable.h:20
const char * get_var_name() const
Definition: gate.h:131
bool get_bo() const
Definition: gate.h:336
bool get_moved() const
Definition: gate.h:324
Polynomial * positive_poly(const Var *v)
Definition: gate.cpp:342
void set_children_back(Gate *n)
Definition: gate.h:523
bool signed_mult
set to true when a signed or unsigned multiplier is verified
Definition: gate.cpp:15
bool is_child(const Gate *n) const
Definition: gate.cpp:54
void mark_fsa()
Definition: gate.h:286
std::list< Gate * >::const_iterator parents_begin() const
Definition: gate.h:431
bool input
True if gate is an input.
Definition: gate.h:38
void set_carry_gate(int val)
Definition: gate.h:223
bool get_fsa() const
Definition: gate.h:281
int get_xor_gate() const
Definition: gate.h:202
void inc_fsa_inp()
Definition: gate.h:298
int fsa_inp
True if gate is input of complex fsa (-substitute)
Definition: gate.h:71
bool get_xor_chain() const
Definition: gate.h:190
void children_push_back(Gate *n)
Definition: gate.h:530
void set_cofactor(Polynomial *p)
Definition: gate.h:388
bool bo
True if gate is identified to belong to booth pattern.
Definition: gate.h:80
std::list< Gate * > children
list of gates that are children
Definition: gate.h:98
bool get_neg() const
Definition: gate.h:310
void inc_slice()
Definition: gate.h:252
int get_slice() const
Definition: gate.h:240
Gate * parents_front() const
Definition: gate.h:456
const char * get_name() const
Definition: variable.h:51
contains arithmetic operations for polynomials
void inc_carry_gate()
Definition: gate.h:228
Definition: gate.h:32
bool fsa
True if gate is identified to belong to complex fsa (-substitute)
Definition: gate.h:68
void mark_xor_chain()
Definition: gate.h:195
std::map< Gate *, Polynomial * >::iterator search_in_anc(Gate *n)
Definition: gate.h:414
contains functions to parse and manipulate the input AIG
Polynomial * get_gate_constraint() const
Definition: gate.h:360
bool get_elim() const
Definition: gate.h:348
std::list< Gate * > parents
list of gates that are parents
Definition: gate.h:95
std::list< Gate * >::const_iterator children_begin() const
Definition: gate.h:477
Gate * gate(unsigned lit)
Definition: gate.cpp:71
bool booth
set to true when the multiplier contains a booth pattern
Definition: gate.cpp:14
Gate ** gates
Gate ** where all gates are stored.
Definition: gate.cpp:66
std::map< Gate *, Polynomial * > ancestors
Used to store all dependencies in nss proofs (-certify)
Definition: gate.h:92
std::map< Gate *, Polynomial * >::const_iterator anc_begin() const
Definition: gate.h:395
bool orig() const
Definition: gate.cpp:23
void print(FILE *file, bool end=1) const
Definition: polynomial.cpp:30
void mark_moved()
Definition: gate.h:329
bool output
True if the gate is an output s_i.
Definition: gate.h:41
void allocate_gates(bool assert=1)
Definition: gate.cpp:78
Polynomial * get_cofactor() const
Definition: gate.h:381
std::map< Gate *, Polynomial * >::const_iterator anc_end() const
Definition: gate.h:404
void children_remove(Gate *n)
Definition: gate.h:537
const Var * get_var() const
Definition: gate.h:117
void dec_slice()
Definition: gate.h:257
bool upper_half_xor_output()
Definition: gate.cpp:194
Polynomial * negative_poly(const Var *v)
Definition: gate.cpp:327
void set_neg(bool val)
Definition: gate.h:317
Gate * xor_left_child(const Gate *n)
Definition: gate.cpp:204
bool moved
True if gate has been moved during fix_xors.
Definition: gate.h:77
void dec_carry_gate()
Definition: gate.h:233
Polynomial * gate_constraint
Polynomial implied by the aig gate.
Definition: gate.h:86
int level
Distance to inputs.
Definition: gate.h:50
bool elim
True if gate is eliminated during preprocessing.
Definition: gate.h:83
void set_xor()
Definition: gate.cpp:158
bool xor_chain
set to true when the last slice contains an xor_chain
Definition: gate.cpp:13
bool is_in_parents(const Gate *n) const
Definition: gate.cpp:42
int slice
slice a gate is attached to
Definition: gate.h:62
void mark_aig_outputs()
Definition: gate.cpp:127
std::list< Gate * >::const_iterator parents_end() const
Definition: gate.h:440
Gate(int n_, std::string name_, int level_, bool input_=0, bool output_=0)
Definition: gate.cpp:18
int get_carry_gate() const
Definition: gate.h:216
void print_gate_constraint(FILE *file) const
Definition: gate.h:374
void delete_gates()
Definition: gate.cpp:420
unsigned num_gates
Counts the number of gates.
Definition: gate.cpp:67
void mark_elim()
Definition: gate.h:353
Gate * children_front() const
Definition: gate.h:502
void init_gate_constraints()
Definition: gate.cpp:354
int get_fsa_inp() const
Definition: gate.h:293
int xor_gate
is set to 1 for root node, 2 for internal nodes of XORs
Definition: gate.h:56
void set_children_front(Gate *n)
Definition: gate.h:516
Gate * children_back() const
Definition: gate.h:509
bool aig_output
True if the gate is an output in the aig.
Definition: gate.h:44
void parents_remove(Gate *n)
Definition: gate.h:470
void mark_pp()
Definition: gate.h:157
void set_level(int l)
Definition: gate.h:183
void mark_prop_gen_gate()
Definition: gate.h:269
bool partial_product
True if gate is identified as a partial product.
Definition: gate.h:47
void set_parents_and_children(bool set_children)
Definition: gate.cpp:275
int get_level() const
Definition: gate.h:176
void mark_aig_output()
Definition: gate.h:169
size_t parents_size() const
Definition: gate.h:449
void mark_xor_chain_in_last_slice()
Definition: gate.cpp:240
Gate * derive_ha_and_gate(const Gate *n)
Definition: gate.cpp:137
std::list< Gate * >::const_iterator children_end() const
Definition: gate.h:486
bool prop_gen_gate
True if circuit is a prop_gen_gate (-substitute)
Definition: gate.h:65
void set_ancestor(Gate *n, Polynomial *p)
Definition: gate.h:424
Definition: polynomial.h:23
bool xor_chain
True if gate belongs to xor_chain in last slice.
Definition: gate.h:53
bool neg
True if gate occurs negative (-substitute)
Definition: gate.h:74
int get_var_num() const
Definition: gate.h:124
Gate * xor_right_child(const Gate *n)
Definition: gate.cpp:222
void parents_push_back(Gate *n)
Definition: gate.h:463
size_t children_size() const
Definition: gate.h:495
void mark_bo()
Definition: gate.h:341
bool get_aig_output() const
Definition: gate.h:164
int get_num() const
Definition: variable.h:69