ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
congruence.c File Reference
#include "congruence.h"
#include "dense.h"
#include "fifo.h"
#include "inline.h"
#include "inlinevector.h"
#include "internal.h"
#include "logging.h"
#include "print.h"
#include "proprobe.h"
#include "rank.h"
#include "reference.h"
#include "report.h"
#include "sort.h"
#include "terminate.h"
#include "trail.h"
#include "utilities.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
Include dependency graph for congruence.c:

Go to the source code of this file.

Classes

struct  gate
 
struct  hash_ref
 
struct  closure
 
struct  offsetsize
 
struct  refsize
 

Macros

#define MERGE_CONDITIONAL_EQUIVALENCES
 
#define AND_GATE   0
 
#define XOR_GATE   1
 
#define ITE_GATE   2
 
#define LD_MAX_ARITY   26
 
#define MAX_ARITY   ((1 << LD_MAX_ARITY) - 1)
 
#define REMOVED   ((gate *) (~(uintptr_t) 0))
 
#define BEGIN_RHS(G)
 
#define END_RHS(G)
 
#define all_rhs_literals_in_gate(LIT, G)
 
#define SIZE_NONCES   16
 
#define CLOGANDGATE(G, ...)
 
#define CLOGXORGATE(G, ...)
 
#define CLOGITEGATE(G, ...)
 
#define CLOGREPR(L)
 
#define LOGATE(G, ...)
 
#define check_lits_sorted(...)
 
#define check_and_lits_normalized   check_lits_sorted
 
#define check_xor_lits_normalized   check_lits_sorted
 
#define check_ite_lits_normalized   check_lits_sorted
 
#define LESS_LIT(A, B)
 
#define MAX_HASH_TABLE_SIZE   ((size_t) 1 << 32)
 
#define check_and_gate_implied(...)
 
#define check_xor_gate_implied   check_and_gate_implied
 
#define check_ternary   check_and_gate_implied
 
#define check_ite_implied   check_and_gate_implied
 
#define check_ite_gate_implied   check_and_gate_implied
 
#define add_xor_matching_proof_chain(...)
 
#define delete_proof_chain(...)
 
#define add_ite_matching_proof_chain(...)
 
#define add_ite_turned_and_binary_clauses   add_ite_matching_proof_chain
 
#define add_xor_shrinking_proof_chain(...)
 
#define RANK_OTHER(A)
 
#define LESS_OTHER(A, B)
 
#define SMALLER_NEGATED_BIN_COUNT(A, B)
 
#define RADIDX_SORT_PAIR_LIMIT   32
 
#define RANKREFSIZE(REFSIZE)
 

Typedefs

typedef struct gate gate
 
typedef struct gate_hash_table gate_hash_table
 
typedef struct closure closure
 
typedef struct offsetsize offsetsize
 
typedef struct refsize refsize
 

Functions

typedef STACK (gate *)
 
void reset_gate_hash_table (closure *closure)
 
typedef STACK (refsize)
 
bool kissat_congruence (kissat *solver)
 

Macro Definition Documentation

◆ add_ite_matching_proof_chain

#define add_ite_matching_proof_chain ( ...)
Value:
do { \
} while (0)

Definition at line 1294 of file congruence.c.

1294#define add_ite_matching_proof_chain(...) \
1295 do { \
1296 } while (0)

◆ add_ite_turned_and_binary_clauses

#define add_ite_turned_and_binary_clauses   add_ite_matching_proof_chain

Definition at line 1298 of file congruence.c.

◆ add_xor_matching_proof_chain

#define add_xor_matching_proof_chain ( ...)
Value:
do { \
} while (0)

Definition at line 1163 of file congruence.c.

1163#define add_xor_matching_proof_chain(...) \
1164 do { \
1165 } while (0)

◆ add_xor_shrinking_proof_chain

#define add_xor_shrinking_proof_chain ( ...)
Value:
do { \
} while (0)

Definition at line 1682 of file congruence.c.

1682#define add_xor_shrinking_proof_chain(...) \
1683 do { \
1684 } while (0)

◆ all_rhs_literals_in_gate

#define all_rhs_literals_in_gate ( LIT,
G )
Value:
unsigned LIT, \
*LIT##_PTR = BEGIN_RHS (G), *const LIT##_END = END_RHS (G); \
LIT##_PTR != LIT##_END && ((LIT = *LIT##_PTR), true); \
++LIT##_PTR
#define END_RHS(G)
Definition congruence.c:64
#define BEGIN_RHS(G)
Definition congruence.c:63
#define LIT(IDX)
Definition literal.h:31

Definition at line 66 of file congruence.c.

66#define all_rhs_literals_in_gate(LIT, G) \
67 unsigned LIT, \
68 *LIT##_PTR = BEGIN_RHS (G), *const LIT##_END = END_RHS (G); \
69 LIT##_PTR != LIT##_END && ((LIT = *LIT##_PTR), true); \
70 ++LIT##_PTR

◆ AND_GATE

#define AND_GATE   0

Definition at line 28 of file congruence.c.

◆ BEGIN_RHS

#define BEGIN_RHS ( G)
Value:
((G)->rhs)

Definition at line 63 of file congruence.c.

◆ check_and_gate_implied

#define check_and_gate_implied ( ...)
Value:
do { \
} while (0)

Definition at line 723 of file congruence.c.

723#define check_and_gate_implied(...) \
724 do { \
725 } while (0)

◆ check_and_lits_normalized

#define check_and_lits_normalized   check_lits_sorted

Definition at line 337 of file congruence.c.

◆ check_ite_gate_implied

#define check_ite_gate_implied   check_and_gate_implied

Definition at line 730 of file congruence.c.

◆ check_ite_implied

#define check_ite_implied   check_and_gate_implied

Definition at line 729 of file congruence.c.

◆ check_ite_lits_normalized

#define check_ite_lits_normalized   check_lits_sorted

Definition at line 339 of file congruence.c.

◆ check_lits_sorted

#define check_lits_sorted ( ...)
Value:
do { \
} while (0)

Definition at line 333 of file congruence.c.

333#define check_lits_sorted(...) \
334 do { \
335 } while (0)

◆ check_ternary

#define check_ternary   check_and_gate_implied

Definition at line 728 of file congruence.c.

◆ check_xor_gate_implied

#define check_xor_gate_implied   check_and_gate_implied

Definition at line 727 of file congruence.c.

◆ check_xor_lits_normalized

#define check_xor_lits_normalized   check_lits_sorted

Definition at line 338 of file congruence.c.

◆ CLOGANDGATE

#define CLOGANDGATE ( G,
... )
Value:
do { \
KISSAT_assert ((G)->tag == AND_GATE); \
LOGANDGATE ((G)->id, closure->repr, (G)->lhs, (G)->arity, (G)->rhs, \
__VA_ARGS__); \
} while (0)
#define AND_GATE
Definition congruence.c:28
unsigned * repr
Definition congruence.c:119

Definition at line 193 of file congruence.c.

193#define CLOGANDGATE(G, ...) \
194 do { \
195 KISSAT_assert ((G)->tag == AND_GATE); \
196 LOGANDGATE ((G)->id, closure->repr, (G)->lhs, (G)->arity, (G)->rhs, \
197 __VA_ARGS__); \
198 } while (0)

◆ CLOGITEGATE

#define CLOGITEGATE ( G,
... )
Value:
do { \
KISSAT_assert ((G)->tag == ITE_GATE); \
LOGITEGATE ((G)->id, closure->repr, (G)->lhs, (G)->rhs[0], \
(G)->rhs[1], (G)->rhs[2], __VA_ARGS__); \
} while (0)
#define ITE_GATE
Definition congruence.c:30

Definition at line 207 of file congruence.c.

207#define CLOGITEGATE(G, ...) \
208 do { \
209 KISSAT_assert ((G)->tag == ITE_GATE); \
210 LOGITEGATE ((G)->id, closure->repr, (G)->lhs, (G)->rhs[0], \
211 (G)->rhs[1], (G)->rhs[2], __VA_ARGS__); \
212 } while (0)

◆ CLOGREPR

#define CLOGREPR ( L)
Value:
LOGREPR ((L), closure->repr)

Definition at line 214 of file congruence.c.

◆ CLOGXORGATE

#define CLOGXORGATE ( G,
... )
Value:
do { \
KISSAT_assert ((G)->tag == XOR_GATE); \
LOGXORGATE ((G)->id, closure->repr, (G)->lhs, (G)->arity, (G)->rhs, \
__VA_ARGS__); \
} while (0)
#define XOR_GATE
Definition congruence.c:29

Definition at line 200 of file congruence.c.

200#define CLOGXORGATE(G, ...) \
201 do { \
202 KISSAT_assert ((G)->tag == XOR_GATE); \
203 LOGXORGATE ((G)->id, closure->repr, (G)->lhs, (G)->arity, (G)->rhs, \
204 __VA_ARGS__); \
205 } while (0)

◆ delete_proof_chain

#define delete_proof_chain ( ...)
Value:
do { \
} while (0)

Definition at line 1167 of file congruence.c.

1167#define delete_proof_chain(...) \
1168 do { \
1169 } while (0)

◆ END_RHS

#define END_RHS ( G)
Value:
(BEGIN_RHS (G) + (G)->arity)

Definition at line 64 of file congruence.c.

◆ ITE_GATE

#define ITE_GATE   2

Definition at line 30 of file congruence.c.

◆ LD_MAX_ARITY

#define LD_MAX_ARITY   26

Definition at line 32 of file congruence.c.

◆ LESS_LIT

#define LESS_LIT ( A,
B )
Value:
((A) < (B))

Definition at line 343 of file congruence.c.

◆ LESS_OTHER

#define LESS_OTHER ( A,
B )
Value:
#define RANK_OTHER(A)

Definition at line 2190 of file congruence.c.

◆ LOGATE

#define LOGATE ( G,
... )
Value:
do { \
if ((G)->tag == AND_GATE) \
CLOGANDGATE (G, __VA_ARGS__); \
else if ((G)->tag == XOR_GATE) \
CLOGXORGATE (G, __VA_ARGS__); \
else { \
KISSAT_assert ((G)->tag == ITE_GATE); \
CLOGITEGATE (G, __VA_ARGS__); \
} \
} while (0)

Definition at line 216 of file congruence.c.

216#define LOGATE(G, ...) \
217 do { \
218 if ((G)->tag == AND_GATE) \
219 CLOGANDGATE (G, __VA_ARGS__); \
220 else if ((G)->tag == XOR_GATE) \
221 CLOGXORGATE (G, __VA_ARGS__); \
222 else { \
223 KISSAT_assert ((G)->tag == ITE_GATE); \
224 CLOGITEGATE (G, __VA_ARGS__); \
225 } \
226 } while (0)

◆ MAX_ARITY

#define MAX_ARITY   ((1 << LD_MAX_ARITY) - 1)

Definition at line 33 of file congruence.c.

◆ MAX_HASH_TABLE_SIZE

#define MAX_HASH_TABLE_SIZE   ((size_t) 1 << 32)

Definition at line 395 of file congruence.c.

◆ MERGE_CONDITIONAL_EQUIVALENCES

#define MERGE_CONDITIONAL_EQUIVALENCES

Definition at line 26 of file congruence.c.

◆ RADIDX_SORT_PAIR_LIMIT

#define RADIDX_SORT_PAIR_LIMIT   32

Definition at line 3440 of file congruence.c.

◆ RANK_OTHER

#define RANK_OTHER ( A)
Value:
((A).lits[1])

Definition at line 2189 of file congruence.c.

◆ RANKREFSIZE

#define RANKREFSIZE ( REFSIZE)
Value:
((REFSIZE).size)

◆ REMOVED

#define REMOVED   ((gate *) (~(uintptr_t) 0))

Definition at line 61 of file congruence.c.

◆ SIZE_NONCES

#define SIZE_NONCES   16

Definition at line 107 of file congruence.c.

◆ SMALLER_NEGATED_BIN_COUNT

#define SMALLER_NEGATED_BIN_COUNT ( A,
B )
Value:
smaller_negated_bin_count (negbincount, A, B)

Definition at line 2472 of file congruence.c.

2472#define SMALLER_NEGATED_BIN_COUNT(A, B) \
2473 smaller_negated_bin_count (negbincount, A, B)

◆ XOR_GATE

#define XOR_GATE   1

Definition at line 29 of file congruence.c.

Typedef Documentation

◆ closure

typedef struct closure closure

Definition at line 145 of file congruence.c.

◆ gate

typedef struct gate gate

Definition at line 50 of file congruence.c.

◆ gate_hash_table

Definition at line 59 of file congruence.c.

◆ offsetsize

typedef struct offsetsize offsetsize

Definition at line 2187 of file congruence.c.

◆ refsize

typedef struct refsize refsize

Definition at line 4449 of file congruence.c.

Function Documentation

◆ kissat_congruence()

bool kissat_congruence ( kissat * solver)

Definition at line 4591 of file congruence.c.

4591 {
4592 if (solver->inconsistent)
4593 return false;
4595 KISSAT_assert (!solver->level);
4596 KISSAT_assert (solver->probing);
4597 KISSAT_assert (solver->watching);
4598 if (!GET_OPTION (congruence))
4599 return false;
4600 if (!GET_OPTION (congruenceands) && !GET_OPTION (congruenceites) &&
4601 !GET_OPTION (congruencexors))
4602 return false;
4603 if (GET_OPTION (congruenceonce) && solver->statistics_.closures)
4604 return false;
4606 return false;
4607 if (DELAYING (congruence))
4608 return false;
4609 START (congruence);
4610 INC (closures);
4612 init_closure (solver, &closure);
4613 extract_gates (&closure);
4614 bool reset = false;
4615 if (!solver->inconsistent && !TERMINATED (congruence_terminated_9)) {
4616 find_units (&closure);
4617 if (!solver->inconsistent && !TERMINATED (congruence_terminated_10)) {
4618 find_equivalences (&closure);
4619 if (!solver->inconsistent && !TERMINATED (congruence_terminated_11)) {
4620 size_t propagated = propagate_units_and_equivalences (&closure);
4621 if (!solver->inconsistent && propagated &&
4623 forward_subsume_matching_clauses (&closure);
4624 reset = true;
4625 }
4626 }
4627 }
4628 }
4629 if (!reset)
4630 reset_closure (&closure);
4631 unsigned equivalent = reset_repr (&closure);
4632 kissat_phase (solver, "congruence", GET (closures),
4633 "merged %u equivalent variables %.2f%%", equivalent,
4634 kissat_percent (equivalent, solver->active));
4635 KISSAT_assert (solver->active >= equivalent);
4636#ifndef KISSAT_QUIET
4637 solver->active -= equivalent;
4638 REPORT (!equivalent, 'c');
4639 if (!solver->inconsistent)
4640 solver->active += equivalent;
4641#endif
4642 if (kissat_average (equivalent, solver->active) < 0.001)
4643 BUMP_DELAY (congruence);
4644 else
4645 REDUCE_DELAY (congruence);
4646 STOP (congruence);
4648 return equivalent;
4649}
#define INC(NAME)
#define BUMP_DELAY(NAME)
Definition kimits.h:183
#define REDUCE_DELAY(NAME)
Definition kimits.h:185
#define DELAYING(NAME)
Definition kimits.h:181
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define GET_OPTION(N)
Definition options.h:295
#define kissat_phase(...)
Definition print.h:48
#define STOP(P)
Definition profile.hpp:158
#define START(P)
Definition profile.hpp:150
#define REPORT(...)
Definition report.h:10
#define kissat_check_statistics(...)
Definition statistics.h:464
#define GET(NAME)
Definition statistics.h:416
#define congruence_terminated_10
Definition terminate.h:57
#define TERMINATED(BIT)
Definition terminate.h:42
#define congruence_terminated_12
Definition terminate.h:59
#define congruence_terminated_8
Definition terminate.h:55
#define congruence_terminated_9
Definition terminate.h:56
#define congruence_terminated_11
Definition terminate.h:58

◆ reset_gate_hash_table()

void reset_gate_hash_table ( closure * closure)

Definition at line 236 of file congruence.c.

236 {
237 kissat *const solver = closure->solver;
238 gate **table = closure->hash.table;
239 for (size_t pos = 0; pos != closure->hash.size; pos++) {
240 gate *g = table[pos];
241 if (g && g != REMOVED && !g->garbage)
242 delete_gate (closure, g);
243 }
244 DEALLOC (table, closure->hash.size);
245}
#define DEALLOC(P, N)
#define REMOVED
Definition congruence.c:61
bool pos
Definition globals.c:30
kissat * solver
Definition congruence.c:110
gate_hash_table hash
Definition congruence.c:120
bool garbage
Definition congruence.c:42

◆ STACK() [1/2]

typedef STACK ( gate * )

Definition at line 51 of file congruence.c.

53 {
54 gate **table;
55 size_t size;
56 size_t entries;
57};
unsigned long long size
Definition giaNewBdd.h:39

◆ STACK() [2/2]

typedef STACK ( refsize )

Definition at line 4450 of file congruence.c.

4455 {
4456 RADIX_STACK (refsize, unsigned, *candidates, RANKREFSIZE);
4457}
#define RANKREFSIZE(REFSIZE)
#define RADIX_STACK(VTYPE, RTYPE, S, RANK)
Definition rank.h:136