Commit 5408f2f6 authored by nmedfort's avatar nmedfort
Browse files

Some performance improvements to BuDDy for functions called by the multiplexing pass.

git-svn-id: http://parabix.costar.sfu.ca/svn/icGREP/icgrep-devel@4938 a82c6ad6-7e1c-4be0-8e68-26c050b43eaf
parent fc0b1b19
......@@ -47,8 +47,8 @@
/*=== Defined operators for apply calls ================================*/
#define bddop_and 0
#define bddop_xor 1
#define bddop_or 2
#define bddop_or 1
#define bddop_xor 2
#define bddop_nand 3
#define bddop_nor 4
#define bddop_imp 5
......@@ -75,118 +75,6 @@ typedef struct s_bddPair
struct s_bddPair *next;
} bddPair;
/*=== Status information ===============================================*/
/*
NAME {* bddStat *}
SECTION {* kernel *}
SHORT {* Status information about the bdd package *}
PROTO {* typedef struct s_bddStat
{
long int produced;
int nodenum;
int maxnodenum;
int freenodes;
int minfreenodes;
int varnum;
int cachesize;
int gbcnum;
} bddStat; *}
DESCR {* The fields are \\[\baselineskip] \begin{tabular}{lp{10cm}}
{\tt produced} & total number of new nodes ever produced \\
{\tt nodenum} & currently allocated number of bdd nodes \\
{\tt maxnodenum} & user defined maximum number of bdd nodes \\
{\tt freenodes} & number of currently free nodes \\
{\tt minfreenodes} & minimum number of nodes that should be left after a
garbage collection. \\
{\tt varnum} & number of defined bdd variables \\
{\tt cachesize} & number of entries in the internal caches \\
{\tt gbcnum} & number of garbage collections done until now
\end{tabular} *}
ALSO {* bdd\_stats *}
*/
typedef struct s_bddStat
{
long int produced;
int nodenum;
int maxnodenum;
int freenodes;
int minfreenodes;
int varnum;
int cachesize;
int gbcnum;
} bddStat;
/*
NAME {* bddGbcStat *}
SECTION {* kernel *}
SHORT {* Status information about garbage collections *}
PROTO {* typedef struct s_bddGbcStat
{
int nodes;
int freenodes;
long time;
long sumtime;
int num;
} bddGbcStat; *}
DESCR {* The fields are \\[\baselineskip] \begin{tabular}{ll}
{\tt nodes} & Total number of allocated nodes in the nodetable \\
{\tt freenodes} & Number of free nodes in the nodetable \\
{\tt time} & Time used for garbage collection this time \\
{\tt sumtime} & Total time used for garbage collection \\
{\tt num} & number of garbage collections done until now
\end{tabular} *}
ALSO {* bdd\_gbc\_hook *}
*/
typedef struct s_bddGbcStat
{
int nodes;
int freenodes;
long time;
long sumtime;
int num;
} bddGbcStat;
/*
NAME {* bddCacheStat *}
SECTION {* kernel *}
SHORT {* Status information about cache usage *}
PROTO {* typedef struct s_bddCacheStat
{
long unsigned int uniqueAccess;
long unsigned int uniqueChain;
long unsigned int uniqueHit;
long unsigned int uniqueMiss;
long unsigned int opHit;
long unsigned int opMiss;
long unsigned int swapCount;
} bddCacheStat; *}
DESCR {* The fields are \\[\baselineskip] \begin{tabular}{ll}
{\bf Name} & {\bf Number of } \\
uniqueAccess & accesses to the unique node table \\
uniqueChain & iterations through the cache chains in the unique node table\\
uniqueHit & entries actually found in the the unique node table \\
uniqueMiss & entries not found in the the unique node table \\
opHit & entries found in the operator caches \\
opMiss & entries not found in the operator caches \\
swapCount & number of variable swaps in reordering \\
\end{tabular} *}
ALSO {* bdd\_cachestats *}
*/
typedef struct s_bddCacheStat
{
long unsigned int uniqueAccess;
long unsigned int uniqueChain;
long unsigned int uniqueHit;
long unsigned int uniqueMiss;
long unsigned int opHit;
long unsigned int opMiss;
long unsigned int swapCount;
} bddCacheStat;
/*=== BDD interface prototypes =========================================*/
/*
......@@ -210,14 +98,11 @@ extern "C" {
#endif
typedef void (*bddinthandler)(int);
typedef void (*bddgbchandler)(int,bddGbcStat*);
typedef void (*bdd2inthandler)(int,int);
typedef int (*bddsizehandler)(void);
typedef void (*bddfilehandler)(FILE *, int);
typedef void (*bddallsathandler)(char*, int);
extern bddinthandler bdd_error_hook(bddinthandler);
extern bddgbchandler bdd_gbc_hook(bddgbchandler);
extern bdd2inthandler bdd_resize_hook(bdd2inthandler);
extern bddinthandler bdd_reorder_hook(bddinthandler);
extern bddfilehandler bdd_file_hook(bddfilehandler);
......@@ -232,14 +117,6 @@ extern int bdd_setmaxincrease(int);
extern int bdd_setminfreenodes(int);
extern int bdd_getnodenum(void);
extern int bdd_getallocnum(void);
extern void bdd_stats(bddStat *);
extern void bdd_cachestats(bddCacheStat *);
extern void bdd_fprintstat(FILE *);
extern void bdd_printstat(void);
extern void bdd_default_gbchandler(int, bddGbcStat *);
extern void bdd_default_errhandler(int);
extern std::string bdd_errstring(const int);
extern void bdd_clear_error(void);
extern int bdd_varnum(void);
extern BDD bdd_ithvar(int);
extern BDD bdd_nithvar(int);
......@@ -267,12 +144,12 @@ extern void bdd_freepair(bddPair*);
extern int bdd_setcacheratio(int);
extern BDD bdd_buildcube(int, int, BDD *);
extern BDD bdd_ibuildcube(int, int, int *);
extern BDD bdd_not(BDD);
extern BDD bdd_apply(BDD, BDD, int);
extern BDD bdd_ite(BDD, BDD, BDD);
extern BDD bdd_restrict(BDD, BDD);
extern BDD bdd_constrain(BDD, BDD);
extern BDD bdd_replace(BDD, bddPair*);
extern BDD bdd_not(const BDD);
extern BDD bdd_apply(const BDD, const BDD, const int);
extern BDD bdd_ite(const BDD, const BDD, const BDD);
extern BDD bdd_restrict(const BDD, const BDD);
extern BDD bdd_constrain(const BDD, const BDD);
extern BDD bdd_replace(const BDD, const bddPair * const);
extern BDD bdd_compose(BDD, BDD, BDD);
extern BDD bdd_veccompose(BDD, bddPair*);
extern BDD bdd_simplify(BDD, BDD);
......@@ -345,11 +222,11 @@ extern void bdd_fprintorder(FILE *);
/*=== BDD constants ====================================================*/
static inline BDD bdd_one(void) {
static inline BDD bdd_one() {
return 1;
}
static inline BDD bdd_zero(void) {
static inline BDD bdd_zero() {
return 0;
}
......@@ -359,27 +236,27 @@ static inline BDD bdd_constant(const BDD var) {
/*=== BDD helpers ====================================================*/
static inline BDD bdd_and(BDD l, BDD r) {
static inline BDD bdd_and(const BDD l, const BDD r) {
return bdd_apply(l, r, bddop_and);
}
static inline BDD bdd_or(BDD l, BDD r) {
static inline BDD bdd_or(const BDD l, const BDD r) {
return bdd_apply(l, r, bddop_or);
}
static inline BDD bdd_xor(BDD l, BDD r) {
static inline BDD bdd_xor(const BDD l, const BDD r) {
return bdd_apply(l, r, bddop_xor);
}
static inline BDD bdd_nor(BDD l, BDD r) {
static inline BDD bdd_nor(const BDD l, const BDD r) {
return bdd_apply(l, r, bddop_nor);
}
static inline BDD bdd_imp(BDD l, BDD r) {
static inline BDD bdd_imp(const BDD l, const BDD r) {
return bdd_apply(l, r, bddop_imp);
}
static inline BDD bdd_biimp(BDD l, BDD r) {
static inline BDD bdd_biimp(const BDD l, const BDD r) {
return bdd_apply(l, r, bddop_biimp);
}
......@@ -400,32 +277,32 @@ static inline BDD bdd_biimp(BDD l, BDD r) {
/*=== Error codes ======================================================*/
#define BDD_MEMORY (-1) /* Out of memory */
#define BDD_VAR (-2) /* Unknown variable */
#define BDD_RANGE (-3) /* Variable value out of range (not in domain) */
#define BDD_DEREF (-4) /* Removing external reference to unknown node */
#define BDD_RUNNING (-5) /* Called bdd_init() twice whithout bdd_done() */
#define BDD_FILE (-6) /* Some file operation failed */
#define BDD_FORMAT (-7) /* Incorrect file format */
#define BDD_ORDER (-8) /* Vars. not in order for vector based functions */
#define BDD_BREAK (-9) /* User called break */
#define BDD_VARNUM (-10) /* Different number of vars. for vector pair */
#define BDD_NODES (-11) /* Tried to set max. number of nodes to be fewer */
#define BDD_MEMORY (0) /* Out of memory */
#define BDD_VAR (1) /* Unknown variable */
#define BDD_RANGE (2) /* Variable value out of range (not in domain) */
#define BDD_DEREF (3) /* Removing external reference to unknown node */
#define BDD_RUNNING (4) /* Called bdd_init() twice whithout bdd_done() */
#define BDD_FILE (5) /* Some file operation failed */
#define BDD_FORMAT (6) /* Incorrect file format */
#define BDD_ORDER (7) /* Vars. not in order for vector based functions */
#define BDD_BREAK (8) /* User called break */
#define BDD_VARNUM (9) /* Different number of vars. for vector pair */
#define BDD_NODES (10) /* Tried to set max. number of nodes to be fewer */
/* than there already has been allocated */
#define BDD_OP (-12) /* Unknown operator */
#define BDD_VARSET (-13) /* Illegal variable set */
#define BDD_VARBLK (-14) /* Bad variable block operation */
#define BDD_DECVNUM (-15) /* Trying to decrease the number of variables */
#define BDD_REPLACE (-16) /* Replacing to already existing variables */
#define BDD_NODENUM (-17) /* Number of nodes reached user defined maximum */
#define BDD_ILLBDD (-18) /* Illegal bdd argument */
#define BDD_SIZE (-19) /* Illegal size argument */
#define BVEC_SIZE (-20) /* Mismatch in bitvector size */
#define BVEC_SHIFT (-21) /* Illegal shift-left/right parameter */
#define BVEC_DIVZERO (-22) /* Division by zero */
#define BDD_ERRNUM 24
#define BDD_OP (11) /* Unknown operator */
#define BDD_VARSET (12) /* Illegal variable set */
#define BDD_VARBLK (13) /* Bad variable block operation */
#define BDD_DECVNUM (14) /* Trying to decrease the number of variables */
#define BDD_REPLACE (15) /* Replacing to already existing variables */
#define BDD_NODENUM (16) /* Number of nodes reached user defined maximum */
#define BDD_ILLBDD (17) /* Illegal bdd argument */
#define BDD_SIZE (18) /* Illegal size argument */
#define BVEC_SIZE (19) /* Mismatch in bitvector size */
#define BVEC_SHIFT (20) /* Illegal shift-left/right parameter */
#define BVEC_DIVZERO (21) /* Division by zero */
#define BDD_ERRNUM 22
#ifdef CPLUSPLUS
#include <iostream>
......
This diff is collapsed.
......@@ -48,8 +48,8 @@ int BddCache_init(BddCache *cache, int size)
size = bdd_prime_gte(size);
if ((cache->table=NEW(BddCacheData,size)) == NULL)
return bdd_error(BDD_MEMORY);
if ((cache->table=NEW(BddCacheData,size)) == nullptr)
bdd_error(BDD_MEMORY);
for (n=0 ; n<size ; n++)
cache->table[n].a = -1;
......@@ -62,7 +62,7 @@ int BddCache_init(BddCache *cache, int size)
void BddCache_done(BddCache *cache)
{
free(cache->table);
cache->table = NULL;
cache->table = nullptr;
cache->tablesize = 0;
}
......@@ -75,8 +75,8 @@ int BddCache_resize(BddCache *cache, int newsize)
newsize = bdd_prime_gte(newsize);
if ((cache->table=NEW(BddCacheData,newsize)) == NULL)
return bdd_error(BDD_MEMORY);
if ((cache->table=NEW(BddCacheData,newsize)) == nullptr)
bdd_error(BDD_MEMORY);
for (n=0 ; n<newsize ; n++)
cache->table[n].a = -1;
......
......@@ -48,22 +48,22 @@ imatrix* imatrixNew(int size)
int n,m;
if (!mtx)
return NULL;
return nullptr;
if ((mtx->rows=NEW(char*,size)) == NULL)
if ((mtx->rows=NEW(char*,size)) == nullptr)
{
free(mtx);
return NULL;
return nullptr;
}
for (n=0 ; n<size ; n++)
{
if ((mtx->rows[n]=NEW(char,size/8+1)) == NULL)
if ((mtx->rows[n]=NEW(char,size/8+1)) == nullptr)
{
for (m=0 ; m<n ; m++)
free(mtx->rows[m]);
free(mtx);
return NULL;
return nullptr;
}
memset(mtx->rows[n], 0, size/8+1);
......
This diff is collapsed.
......@@ -41,47 +41,58 @@
/*=== Includes =========================================================*/
#include <limits.h>
#include <stdexcept>
#include "bdd.h"
/*=== SANITY CHECKS ====================================================*/
/*=== BUILT-INS ==========================================================*/
/* Make sure we use at least 32 bit integers */
#if (INT_MAX < 0x7FFFFFFF)
#error The compiler does not support 4 byte integers!
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __GNUC_PREREQ
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
#define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
#else
#define __GNUC_PREREQ(maj, min) 0
#endif
#endif
/* Sanity check argument and return eventual error code */
#define CHECK(r)\
if (!bddrunning) return bdd_error(BDD_RUNNING);\
else if ((r) < 0 || (r) >= bddnodesize) return bdd_error(BDD_ILLBDD);\
else if (r >= 2 && LOW(r) == -1) return bdd_error(BDD_ILLBDD)\
#if __has_builtin(__builtin_expect) || __GNUC_PREREQ(4, 0)
#define LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
#define UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
#else
#define LIKELY(EXPR) (EXPR)
#define UNLIKELY(EXPR) (EXPR)
#endif
/* Sanity check argument and return eventually the argument 'a' */
#define CHECKa(r,a)\
if (!bddrunning) { bdd_error(BDD_RUNNING); return (a); }\
else if ((r) < 0 || (r) >= bddnodesize)\
{ bdd_error(BDD_ILLBDD); return (a); }\
else if (r >= 2 && LOW(r) == -1)\
{ bdd_error(BDD_ILLBDD); return (a); }
#ifndef NDEBUG
#define ALWAYS_INLINE
#elif defined _MSC_VER
#define ALWAYS_INLINE __forceinline
#elif defined __GNUC__
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#else
#define ALWAYS_INLINE inline
#endif
#define CHECKn(r)\
if (!bddrunning) { bdd_error(BDD_RUNNING); return; }\
else if ((r) < 0 || (r) >= bddnodesize)\
{ bdd_error(BDD_ILLBDD); return; }\
else if (r >= 2 && LOW(r) == -1)\
{ bdd_error(BDD_ILLBDD); return; }
/*=== SANITY CHECKS ====================================================*/
/* Make sure we use at least 32 bit integers */
#if (INT_MAX < 0x7FFFFFFF)
#error The compiler does not support 4 byte integers!
#endif
/*=== SEMI-INTERNAL TYPES ==============================================*/
typedef struct s_BddNode /* Node table entry */
{
unsigned int refcou : 10;
unsigned int level : 22;
unsigned int refcount : 10;
unsigned int level : 22;
int low;
int high;
int hash;
int next;
unsigned hash;
unsigned next;
} BddNode;
......@@ -92,7 +103,6 @@ extern "C" {
#endif
extern int bddrunning; /* Flag - package initialized */
extern int bdderrorcond; /* Some error condition was met */
extern int bddnodesize; /* Number of allocated nodes */
extern int bddmaxnodesize; /* Maximum allowed number of nodes */
extern int bddmaxnodeincrease; /* Max. # of nodes used to inc. table */
......@@ -104,35 +114,74 @@ extern int* bddvar2level;
extern int* bddlevel2var;
extern int bddreorderdisabled;
extern int bddresized;
extern bddCacheStat bddcachestats;
#ifdef CPLUSPLUS
}
#endif
/*=== KERNEL DEFINITIONS ===============================================*/
class reordering_required : public std::exception {
public:
reordering_required() = default;
virtual char const * what() const _GLIBCXX_USE_NOEXCEPT { return nullptr; }
};
/*=== KERNEL DEFINITIONS ===============================================*/
#define MAXVAR 0x1FFFFF
#define MAXREF 0x3FF
static ALWAYS_INLINE void DECREF(const BDD i) {
BddNode & n = bddnodes[i];
if (LIKELY(n.refcount != 0 && n.refcount != MAXREF)) {
n.refcount--;
}
}
static ALWAYS_INLINE void INCREF(const BDD i) {
BddNode & n = bddnodes[i];
if (LIKELY(n.refcount != MAXREF)) {
n.refcount++;
}
}
/* Reference counting */
#define DECREF(n) if (bddnodes[n].refcou!=MAXREF && bddnodes[n].refcou>0) bddnodes[n].refcou--
#define INCREF(n) if (bddnodes[n].refcou<MAXREF) bddnodes[n].refcou++
#define DECREFp(n) if (n->refcou!=MAXREF && n->refcou>0) n->refcou--
#define INCREFp(n) if (n->refcou<MAXREF) n->refcou++
#define HASREF(n) (bddnodes[n].refcou > 0)
static ALWAYS_INLINE bool HASREF(const BDD i) {
return (bddnodes[i].refcount != 0);
}
/* Marking BDD nodes */
#define MARKON 0x200000 /* Bit used to mark a node (1) */
#define MARKOFF 0x1FFFFF /* - unmark */
#define MARKHIDE 0x1FFFFF
#define SETMARK(n) (bddnodes[n].level |= MARKON)
#define UNMARK(n) (bddnodes[n].level &= MARKOFF)
#define MARKED(n) (bddnodes[n].level & MARKON)
#define SETMARKp(p) (node->level |= MARKON)
#define UNMARKp(p) (node->level &= MARKOFF)
#define MARKEDp(p) (node->level & MARKON)
static ALWAYS_INLINE void SETMARK(BddNode * const p) {
p->level |= MARKON;
}
static ALWAYS_INLINE void SETMARK(const BDD i) {
SETMARK(bddnodes + i);
}
static ALWAYS_INLINE void UNMARK(BddNode * const p) {
p->level &= MARKOFF;
}
static ALWAYS_INLINE void UNMARK(const BDD i) {
UNMARK(bddnodes + i);
}
static ALWAYS_INLINE bool MARKED(const BddNode * const p) {
return (p->level & MARKON) != 0;
}
static ALWAYS_INLINE bool MARKED(const BDD i) {
return MARKED(bddnodes + i);
}
/* Hashfunctions */
......@@ -145,18 +194,46 @@ extern bddCacheStat bddcachestats;
#define ISNONCONST(a) ((a) >= 2)
#define ISONE(a) ((a) == 1)
#define ISZERO(a) ((a) == 0)
#define LEVEL(a) (bddnodes[a].level)
#define LOW(a) (bddnodes[a].low)
#define HIGH(a) (bddnodes[a].high)
#define LEVELp(p) ((p)->level)
#define LOWp(p) ((p)->low)
#define HIGHp(p) ((p)->high)
static ALWAYS_INLINE unsigned LEVEL(const BddNode * const p) {
return p->level;
}
static ALWAYS_INLINE unsigned LEVEL(const BDD i) {
return LEVEL(bddnodes + i);
}
static ALWAYS_INLINE int LOW(const BddNode * const p) {
return p->low;
}
static ALWAYS_INLINE int LOW(const BDD i) {
return LOW(bddnodes + i);
}
static ALWAYS_INLINE int HIGH(const BddNode * const p) {
return p->high;
}
static ALWAYS_INLINE int HIGH(const BDD i) {
return HIGH(bddnodes + i);
}
/* Stacking for garbage collector */
#define INITREF bddrefstacktop = bddrefstack
#define PUSHREF(a) *(bddrefstacktop++) = (a)
#define READREF(a) *(bddrefstacktop-(a))
#define POPREF(a) bddrefstacktop -= (a)
#define INITREF bddrefstacktop = bddrefstack
static ALWAYS_INLINE BDD PUSHREF(const BDD n) {
*bddrefstacktop++ = n;
return n;
}
static ALWAYS_INLINE BDD READREF(const int i) {
return bddrefstacktop[-i];
}
static ALWAYS_INLINE void POPREF(const int i) {
bddrefstacktop -= i;
}
#define BDDONE 1
#define BDDZERO 0
......@@ -176,14 +253,13 @@ extern bddCacheStat bddcachestats;
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define NEW(t,n) ( (t*)malloc(sizeof(t)*(n)) )
/*=== KERNEL PROTOTYPES ================================================*/
#ifdef CPLUSPLUS
extern "C" {
#endif
extern int bdd_error(int);
extern void bdd_error(const unsigned code);
extern int bdd_makenode(unsigned int, int, int);
extern int bdd_noderesize(int);
extern void bdd_checkreorder(void);
......@@ -218,6 +294,19 @@ extern void bdd_cpp_init(void);
}
#endif
/*=== INPUT VALIDATION ==================================================*/
inline void CHECK(const BDD r) {
if (UNLIKELY(!bddrunning)) {
bdd_error(BDD_RUNNING);
} else if (UNLIKELY(r < 0 || r >= bddnodesize)) {
bdd_error(BDD_ILLBDD);
} else if (UNLIKELY(r >= 2 && LOW(r) == -1)) {
bdd_error(BDD_ILLBDD);
}
}
#endif /* _KERNEL_H */
......
......@@ -50,7 +50,7 @@ static bddPair* pairs; /* List of all replacement pairs in use */
void bdd_pairs_init(void)
{
pairsid = 0;
pairs = NULL;
pairs = nullptr;
}
......@@ -59,7 +59,7 @@ void bdd_pairs_done(void)
bddPair *p = pairs;
int n;
while (p != NULL)
while (p != nullptr)
{
bddPair *next = p->next;
for (n=0 ; n<bddvarnum ; n++)
......@@ -79,7 +79,7 @@ static int update_pairsid(void)
{
bddPair *p;
pairsid = 0;
for (p=pairs ; p!=NULL ; p=p->next)
for (p=pairs ; p!=nullptr ; p=p->next)
p->id = pairsid++;
bdd_operator_reset();
}
......@@ -99,7 +99,7 @@ void bdd_pairs_vardown(int level)
{
bddPair *p;
for (p=pairs ; p!=NULL ; p=p->next)
for (p=pairs ; p!=nullptr ; p=p->next)
{
int tmp;
......@@ -118,10 +118,10 @@ int bdd_pairs_resize(int oldsize, int newsize)
bddPair *p;
int n;
for (p=pairs ; p!=NULL ; p=p->next)
for (p=pairs ; p!=nullptr ; p=p->next)
{
if ((p->result=(BDD*)realloc(p->result,sizeof(BDD)*newsize)) == NULL)
return bdd_error(BDD_MEMORY);
if ((p->result=(BDD*)realloc(p->result,sizeof(BDD)*newsize)) == nullptr)
bdd_error(BDD_MEMORY);
for (n=oldsize ; n<newsize ; n++)
p->result[n] = bdd_ithvar(bddlevel2var[n]);
......@@ -148,17 +148,15 @@ bddPair *bdd_newpair(void)
int n;
bddPair *p;
if ((p=(bddPair*)malloc(sizeof(bddPair))) == NULL)
if ((p=(bddPair*)malloc(sizeof(bddPair))) == nullptr)
{
bdd_error(BDD_MEMORY);
return NULL;
}
if ((p->result=(BDD*)malloc(sizeof(BDD)*bddvarnum)) == NULL)
if ((p->result=(BDD*)malloc(sizeof(BDD)*bddvarnum)) == nullptr)
{
free(p);
bdd_error(BDD_MEMORY);
return NULL;
}
for (n=0 ; n<bddvarnum ; n++)
......@@ -195,13 +193,13 @@ ALSO {* bdd\_newpair, bdd\_setpairs, bdd\_resetpair, bdd\_replace, bdd\_compo
*/
int bdd_setpair(bddPair *pair, int oldvar, int newvar)
{
if (pair == NULL)
if (pair == nullptr)
return 0;
if (oldvar < 0 || oldvar > bddvarnum-1)
return bdd_error(BDD_VAR);
bdd_error(BDD_VAR);
if (newvar < 0 || newvar > bddvarnum-1)
return bdd_error(BDD_VAR);
bdd_error(BDD_VAR);
bdd_delref( pair->result[bddvar2level[oldvar]] );
pair->result[bddvar2level[oldvar]] = bdd_ithvar(newvar);
......@@ -218,12 +216,12 @@ int bdd_setbddpair(bddPair *pair, int oldvar, BDD newvar)
{
int oldlevel;
if (pair == NULL)
if (pair == nullptr)
return 0;
CHECK(newvar);
if (oldvar < 0 || oldvar >= bddvarnum)
return bdd_error(BDD_VAR);
bdd_error(BDD_VAR);
oldlevel = bddvar2level[oldvar];
bdd_delref( pair->result[oldlevel] );
......@@ -252,7 +250,7 @@ ALSO {* bdd\_newpair, bdd\_setpair, bdd\_replace, bdd\_compose *}
int bdd_setpairs(bddPair *pair, int *oldvar, int *newvar, int size)
{
int n,e;
if (pair == NULL)
if (pair == nullptr)
return 0;
for (n=0 ; n<size ; n++)
......@@ -266,7 +264,7 @@ int bdd_setpairs(bddPair *pair, int *oldvar, int *newvar, int size)
int bdd_setbddpairs(bddPair *pair, int *oldvar, BDD *newvar, int size)
{
int n,e;
if (pair == NULL)
if (pair == nullptr)
return 0;
for (n=0 ; n<size ; n++)
......@@ -290,16 +288,16 @@ void bdd_freepair(bddPair *p)
{
int n;
if (p == NULL)
if (p == nullptr)
return;
if (pairs != p)
{
bddPair *bp = pairs;
while (bp != NULL && bp->next != p)
while (bp != nullptr && bp->next != p)
bp = bp->next;
if (bp != NULL)
if (bp != nullptr)
bp->next = p->next;
}
else
......
This diff is collapsed.
......@@ -64,13 +64,13 @@ static void update_seq(BddTree *t)
BddTree * bddtree_new(int id)
{
BddTree *t = NEW(BddTree,1);
if (t == NULL)
return NULL;
if (t == nullptr)
return nullptr;
t->first = t->last = -1;
t->fixed = 1;
t->next = t->prev = t->nextlevel = NULL;
t->seq = NULL;
t->next = t->prev = t->nextlevel = nullptr;
t->seq = nullptr;
t->id = id;
return t;
}
......@@ -78,12 +78,12 @@ BddTree * bddtree_new(int id)
void bddtree_del(BddTree *t)
{
if (t == NULL)
if (t == nullptr)
return;
bddtree_del(t->nextlevel);
bddtree_del(t->next);
if (t->seq != NULL)
if (t->seq != nullptr)
free(t->seq);
free(t);
}
......@@ -93,13 +93,13 @@ BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
int first, int last, int fixed, int id)
{
if (first < 0 || last < 0 || last < first)
return NULL;
return nullptr;
/* Empty tree -> build one */
if (t == NULL)
if (t == nullptr)
{
if ((t=bddtree_new(id)) == NULL)
return NULL;
if ((t=bddtree_new(id)) == nullptr)
return nullptr;
t->first = first;
t->fixed = fixed;
t->seq = NEW(int,last-first+1);
......@@ -117,8 +117,8 @@ BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
if (last < t->first)
{
BddTree *tnew = bddtree_new(id);
if (tnew == NULL)
return NULL;
if (tnew == nullptr)
return nullptr;
tnew->first = first;
tnew->last = last;
tnew->fixed = fixed;
......@@ -141,7 +141,7 @@ BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
if (first >= t->first && last <= t->last)
{
t->nextlevel =
bddtree_addrange_rec(t->nextlevel,NULL,first,last,fixed,id);
bddtree_addrange_rec(t->nextlevel,nullptr,first,last,fixed,id);
return t;
}
......@@ -155,13 +155,13 @@ BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
{
/* Partial cover ->error */
if (last >= current->first && last < current->last)
return NULL;
return nullptr;
if (current->next == NULL || last < current->next->first)
if (current->next == nullptr || last < current->next->first)
{
tnew = bddtree_new(id);
if (tnew == NULL)
return NULL;
if (tnew == nullptr)
return nullptr;
tnew->first = first;
tnew->last = last;
tnew->fixed = fixed;
......@@ -170,10 +170,10 @@ BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
tnew->nextlevel = t;
tnew->next = current->next;
tnew->prev = t->prev;
if (current->next != NULL)
if (current->next != nullptr)
current->next->prev = tnew;
current->next = NULL;
t->prev = NULL;
current->next = nullptr;
t->prev = nullptr;
return tnew;
}
......@@ -182,20 +182,20 @@ BddTree *bddtree_addrange_rec(BddTree *t, BddTree *prev,
}
return NULL;
return nullptr;
}
BddTree *bddtree_addrange(BddTree *t, int first, int last, int fixed,int id)
{
return bddtree_addrange_rec(t,NULL,first,last,fixed,id);
return bddtree_addrange_rec(t,nullptr,first,last,fixed,id);
}
#if 0
int main(void)
{
BddTree *t = NULL;
BddTree *t = nullptr;
t = bddtree_addrange(t, 8,10,1);
printf("A\n"); bddtree_print(stdout, t, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment