Commit 6f76121b authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

[buddy] get rid of many recursive algorithms

This patch addresses the BuDDy part of #396,
reported by Florian Renkin and Reed Oei.

* src/kernel.c, src/kernel.h: Declare a bddrecstack and
associated macros.  Resize it when new variable are declared.
* src/cache.h: Add a BddCache_index macro.
* src/bddop.c (not_rec, apply_rec, quant_rec, appquant_rec,
support_rec, ite_rec, compose_rec, restrict_rec, satone_rec,
satoneset_rec): Rewrite using this stack to get rid of the recursion.
parent d7b3d05e
Pipeline #20999 passed with stages
in 229 minutes and 26 seconds
This diff is collapsed.
/*========================================================================
Copyright (C) 1996-2002 by Jorn Lind-Nielsen
Copyright (C) 1996-2002, 2020 by Jorn Lind-Nielsen
All rights reserved
Permission is hereby granted, without written agreement and without
......@@ -67,7 +67,7 @@ extern int BddCache_resize(BddCache *, int);
extern void BddCache_reset(BddCache *);
#define BddCache_lookup(cache, hash) (&(cache)->table[hash & ((cache)->tablesize - 1)])
#define BddCache_index(cache, hash, index) (&(cache)->table[index = (hash & ((cache)->tablesize - 1))])
#endif /* _CACHE_H */
......
......@@ -45,7 +45,6 @@
#include <assert.h>
#include "kernel.h"
#include "cache.h"
#include "prime.h"
/*************************************************************************
......@@ -103,6 +102,8 @@ jmp_buf bddexception; /* Long-jump point for interrupting calc. */
int bddresized; /* Flag indicating a resize of the nodetable */
int bddcachesize; /* Size of the operator caches */
int bddhashsize; /* Size of the BDD node hash */
int* bddrecstack; /* Internal recursion stack */
int* bddrecstacktop; /* Internal recursion stack top */
bddCacheStat bddcachestats;
......@@ -273,6 +274,7 @@ void bdd_done(void)
free(bddnodes);
free(bddrefstack);
free(bddrecstack);
free(bddvarset);
free(bddvar2level);
free(bddlevel2var);
......@@ -280,6 +282,7 @@ void bdd_done(void)
bddnodes = NULL;
bddrefstack = NULL;
bddrecstack = NULL;
bddvarset = NULL;
bdd_operator_done();
......@@ -374,7 +377,11 @@ int bdd_setvarnum(int num)
if (__likely(bddrefstack != NULL))
free(bddrefstack);
bddrefstack = bddrefstacktop = (int*)malloc(sizeof(int)*(num*2+4));
bddrefstack = bddrefstacktop = (int*)malloc(sizeof(int)*((num+2)*2));
if (__likely(bddrecstack != NULL))
free(bddrecstack);
bddrecstack = bddrecstacktop = (int*)malloc(sizeof(int)*((num+1)*9));
for(bdv=bddvarnum ; bddvarnum < num; bddvarnum++)
{
......
......@@ -43,6 +43,7 @@
#include <limits.h>
#include <setjmp.h>
#include "bddx.h"
#include "cache.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
......@@ -133,6 +134,8 @@ extern int bddreorderdisabled;
extern int bddresized;
extern int bddcachesize;
extern bddCacheStat bddcachestats;
extern int* bddrecstack;
extern int* bddrecstacktop;
/* from reorder.c */
extern int bddreordermethod;
......@@ -214,6 +217,28 @@ static inline int PUSHREF(int a)
#define READREF(a) *(bddrefstacktop-(a))
#define POPREF(a) bddrefstacktop -= (a)
#define PUSHREF_(a) *(localbddrefstacktop++) = (a)
#define READREF_(a) *(localbddrefstacktop-(a))
#define POPREF_(a) localbddrefstacktop -= (a)
#define PUSHINT_(a) *(localbddrecstacktop++) = (a)
#define PUSH2INT_(a, b) {PUSHINT_(a); PUSHINT_(b);}
#define PUSH3INT_(a, b, c) {PUSHINT_(a); PUSHINT_(b); PUSHINT_(c);}
#define PUSH4INT_(a, b, c, d) {PUSHINT_(a); PUSHINT_(b); PUSHINT_(c); PUSHINT_(d);}
#define POPINT_() *(--localbddrecstacktop)
#define LOCAL_REC_STACKS \
int* restrict localbddrefstacktop = bddrefstacktop; \
int* restrict localbddrecstacktop = bddrecstacktop; \
int* localbddrecstackbot = bddrecstacktop;
#define NONEMPTY_REC_STACK (localbddrecstacktop > localbddrecstackbot)
#define SYNC_REC_STACKS \
bddrefstacktop = localbddrefstacktop; \
bddrecstacktop = localbddrecstacktop;
#define BDDONE 1
#define BDDZERO 0
......
Supports Markdown
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