bvec.h

Go to the documentation of this file.
00001 /*========================================================================
00002                Copyright (C) 1996-2002 by Jorn Lind-Nielsen
00003                             All rights reserved
00004 
00005     Permission is hereby granted, without written agreement and without
00006     license or royalty fees, to use, reproduce, prepare derivative
00007     works, distribute, and display this software and its documentation
00008     for any purpose, provided that (1) the above copyright notice and
00009     the following two paragraphs appear in all copies of the source code
00010     and (2) redistributions, including without limitation binaries,
00011     reproduce these notices in the supporting documentation. Substantial
00012     modifications to this software may be copyrighted by their authors
00013     and need not follow the licensing terms described here, provided
00014     that the new terms are clearly indicated in all files where they apply.
00015 
00016     IN NO EVENT SHALL JORN LIND-NIELSEN, OR DISTRIBUTORS OF THIS
00017     SOFTWARE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
00018     INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
00019     SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE
00020     ABOVE PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00021 
00022     JORN LIND-NIELSEN SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
00023     BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00024     FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
00025     ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
00026     OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
00027     MODIFICATIONS.
00028 ========================================================================*/
00029 
00030 /*************************************************************************
00031   $Header: /cvsroot/buddy/buddy/src/bvec.h,v 1.3 2007/07/16 13:51:56 nikos-g Exp $
00032   FILE:  bvec.h
00033   DESCR: Boolean (BDD) vector handling
00034   AUTH:  Jorn Lind
00035   DATE:  (C) may 1999
00036 *************************************************************************/
00040 #ifndef _BVEC_H
00041 #define _BVEC_H
00042 
00043 #include "fdd.h"
00044 
00045    /* Boolean (BDD) vector */
00055 typedef struct s_bvec
00056 {
00057    int bitnum;
00058    BDD *bitvec;
00059 } BVEC;
00060 
00061 #ifndef CPLUSPLUS
00062 typedef BVEC bvec;
00063 #endif
00064 
00065 
00066 #ifdef CPLUSPLUS
00067 extern "C" {
00068 #endif
00069    
00070    /* Prototypes for bvec.c */
00071 
00080 extern BVEC bvec_copy(BVEC v);
00081 
00082 
00092 extern BVEC bvec_true(int bitnum);
00093 
00094 
00104 extern BVEC bvec_false(int bitnum);
00105 
00106 
00117 extern BVEC bvec_con(int bitnum, int val);
00118 
00119 
00131 extern BVEC bvec_var(int bitnum, int offset, int step);
00132 
00133 
00144 extern BVEC bvec_varfdd(int var);
00145 
00146 
00157 extern BVEC bvec_varvec(int bitnum, int *var);
00158 
00159 
00170 extern BVEC bvec_coerce(int bitnum, BVEC v);
00171 
00172 
00182 extern int  bvec_isconst(BVEC e);   
00183 
00184 
00195 extern int  bvec_val(BVEC e);   
00196 
00197 
00206 extern void bvec_free(BVEC v);
00207 
00208 
00219 extern BVEC bvec_addref(BVEC v);
00220 
00221 
00231 extern BVEC bvec_delref(BVEC v);
00232 
00233 
00249 extern BVEC bvec_map1(BVEC a, BDD (*fun)(BDD));
00250 
00251 
00267 extern BVEC bvec_map2(BVEC a, BVEC b, BDD (*fun)(BDD,BDD));
00268 
00269 
00285 extern BVEC bvec_map3(BVEC a, BVEC b, BVEC c, BDD (*fun)(BDD,BDD,BDD));
00286 
00287 
00303 extern BVEC bvec_add(BVEC left, BVEC right);
00304 
00305 
00321 extern BVEC bvec_sub(BVEC left, BVEC right);
00322 
00323 
00333 extern BVEC bvec_mulfixed(BVEC e, int c);
00334 
00335 
00345 extern BVEC bvec_mul(BVEC left, BVEC right);
00346 
00347 
00360 extern int  bvec_divfixed(BVEC e, int c, BVEC *res, BVEC *rem);
00361 
00362 
00375 extern int  bvec_div(BVEC left, BVEC right, BVEC *res, BVEC *rem);
00376 extern BVEC bvec_ite(BDD a, BVEC b, BVEC c);
00377 
00378 
00389 extern BVEC bvec_shlfixed(BVEC e, int pos, BDD c);
00390 
00391 
00403 extern BVEC bvec_shl(BVEC l, BVEC r, BDD c);
00404 
00405 
00416 extern BVEC bvec_shrfixed(BVEC e, int pos, BDD c);
00417 
00418 
00430 extern BVEC bvec_shr(BVEC l, BVEC r, BDD c);
00431 
00432 
00442 extern BDD  bvec_lth(BVEC left, BVEC right);
00443 
00444 
00454 extern BDD  bvec_lte(BVEC left, BVEC right);
00455 
00456 
00466 extern BDD  bvec_gth(BVEC left, BVEC right);
00467 
00468 
00478 extern BDD  bvec_gte(BVEC left, BVEC right);
00479 
00480 
00490 extern BDD  bvec_equ(BVEC left, BVEC right);
00491 
00492 
00502 extern BDD  bvec_neq(BVEC left, BVEC right);
00503 
00504 #ifdef CPLUSPLUS
00505 }
00506 #endif
00507 
00508 
00509 /*************************************************************************
00510    If this file is included from a C++ compiler then the following
00511    classes, wrappers and hacks are supplied.
00512 *************************************************************************/
00513 #ifdef CPLUSPLUS
00514 
00515 /*=== User BVEC class ==================================================*/
00516 
00517 class bvec
00518 {
00519  public:
00520 
00521    bvec(void)                { roots.bitvec=NULL; roots.bitnum=0; }
00522    bvec(int bitnum)          { roots=bvec_false(bitnum); }
00523    bvec(int bitnum, int val) { roots=bvec_con(bitnum,val); }
00524    bvec(const bvec &v)       { roots=bvec_copy(v.roots); }
00525    ~bvec(void)               { bvec_free(roots); }
00526 
00527    void set(int i, const bdd &b);
00528    bdd operator[](int i)  const { return roots.bitvec[i]; }
00529    int bitnum(void) const       { return roots.bitnum; }
00530    int empty(void) const        { return roots.bitnum==0; }
00531    bvec operator=(const bvec &src);
00532    
00533 private:
00534    BVEC roots;
00535 
00536    bvec(const BVEC &v) { roots=v; } /* NOTE: Must be a shallow copy! */
00537 
00538    friend bvec bvec_truepp(int bitnum);
00539    friend bvec bvec_falsepp(int bitnum);
00540    friend bvec bvec_conpp(int bitnum, int val);
00541    friend bvec bvec_varpp(int bitnum, int offset, int step);
00542    friend bvec bvec_varfddpp(int var);
00543    friend bvec bvec_varvecpp(int bitnum, int *var);
00544    friend bvec bvec_coerce(int bitnum, const bvec &v);
00545    friend int  bvec_isconst(const bvec &e);   
00546    friend int  bvec_val(const bvec &e);   
00547    friend bvec bvec_copy(const bvec &v);
00548    friend bvec bvec_map1(const bvec &a,
00549                          bdd (*fun)(const bdd &));
00550    friend bvec bvec_map2(const bvec &a, const bvec &b,
00551                          bdd (*fun)(const bdd &, const bdd &));
00552    friend bvec bvec_map3(const bvec &a, const bvec &b, const bvec &c,
00553                          bdd (*fun)(const bdd &, const bdd &, const bdd &));
00554    friend bvec bvec_add(const bvec &left, const bvec &right);
00555    friend bvec bvec_sub(const bvec &left, const bvec &right);
00556    friend bvec bvec_mulfixed(const bvec &e, int c);
00557    friend bvec bvec_mul(const bvec &left, const bvec &right);
00558    friend int  bvec_divfixed(const bvec &e, int c, bvec &res, bvec &rem);
00559    friend int  bvec_div(const bvec &l, const bvec &r, bvec &res, bvec &rem);
00560    friend bvec bvec_ite(const bdd& a, const bvec& b, const bvec& c);
00561    friend bvec bvec_shlfixed(const bvec &e, int pos, const bdd &c);
00562    friend bvec bvec_shl(const bvec &left, const bvec &right, const bdd &c);
00563    friend bvec bvec_shrfixed(const bvec &e, int pos, const bdd &c);
00564    friend bvec bvec_shr(const bvec &left, const bvec &right, const bdd &c);
00565    friend bdd  bvec_lth(const bvec &left, const bvec &right);
00566    friend bdd  bvec_lte(const bvec &left, const bvec &right);
00567    friend bdd  bvec_gth(const bvec &left, const bvec &right);
00568    friend bdd  bvec_gte(const bvec &left, const bvec &right);
00569    friend bdd  bvec_equ(const bvec &left, const bvec &right);
00570    friend bdd  bvec_neq(const bvec &left, const bvec &right);
00571 
00572 public:
00573    bvec operator&(const bvec &a) const { return bvec_map2(*this, a, bdd_and); }
00574    bvec operator^(const bvec &a) const { return bvec_map2(*this, a, bdd_xor); }
00575    bvec operator|(const bvec &a) const { return bvec_map2(*this, a, bdd_or); }
00576    bvec operator!(void) const          { return bvec_map1(*this, bdd_not); }
00577    bvec operator<<(int a)   const   { return bvec_shlfixed(*this,a,bddfalse); }
00578    bvec operator<<(const bvec &a) const  { return bvec_shl(*this,a,bddfalse); }
00579    bvec operator>>(int a)   const   { return bvec_shrfixed(*this,a,bddfalse); }
00580    bvec operator>>(const bvec &a) const  { return bvec_shr(*this,a,bddfalse); }
00581    bvec operator+(const bvec &a) const { return bvec_add(*this, a); }
00582    bvec operator-(const bvec &a) const { return bvec_sub(*this, a); }
00583    bvec operator*(int a) const         { return bvec_mulfixed(*this, a); }
00584    bvec operator*(const bvec a) const  { return bvec_mul(*this, a); }
00585    bdd operator<(const bvec &a) const  { return bvec_lth(*this, a); }
00586    bdd operator<=(const bvec &a) const { return bvec_lte(*this, a); }
00587    bdd operator>(const bvec &a) const  { return bvec_gth(*this, a); }
00588    bdd operator>=(const bvec &a) const { return bvec_gte(*this, a); }
00589    bdd operator==(const bvec &a) const { return bvec_equ(*this, a); }
00590    bdd operator!=(const bvec &a) const { return bvec_neq(*this, a); }
00591 };
00592 
00593 std::ostream &operator<<(std::ostream &, const bvec &);
00594 
00595 inline bvec bvec_truepp(int bitnum)
00596 { return bvec_true(bitnum); }
00597 
00598 inline bvec bvec_falsepp(int bitnum)
00599 { return bvec_false(bitnum); }
00600 
00601 inline bvec bvec_conpp(int bitnum, int val)
00602 { return bvec_con(bitnum, val); }
00603 
00604 inline bvec bvec_varpp(int bitnum, int offset, int step)
00605 { return bvec_var(bitnum, offset, step); }
00606 
00607 inline bvec bvec_varfddpp(int var)
00608 { return bvec_varfdd(var); }
00609 
00610 inline bvec bvec_varvecpp(int bitnum, int *var)
00611 { return bvec_varvec(bitnum, var); }
00612 
00613 inline bvec bvec_coerce(int bitnum, const bvec &v)
00614 { return bvec_coerce(bitnum, v.roots); }
00615 
00616 inline int  bvec_isconst(const bvec &e)
00617 { return bvec_isconst(e.roots); }
00618 
00619 inline int  bvec_val(const bvec &e)
00620 { return bvec_val(e.roots); }
00621 
00622 inline bvec bvec_copy(const bvec &v)
00623 { return bvec_copy(v.roots); }
00624 
00625 inline bvec bvec_add(const bvec &left, const bvec &right)
00626 { return bvec_add(left.roots, right.roots); }
00627 
00628 inline bvec bvec_sub(const bvec &left, const bvec &right)
00629 { return bvec_sub(left.roots, right.roots); }
00630 
00631 inline bvec bvec_mulfixed(const bvec &e, int c)
00632 { return bvec_mulfixed(e.roots, c); }
00633 
00634 inline bvec bvec_mul(const bvec &left, const bvec &right)
00635 { return bvec_mul(left.roots, right.roots); }
00636 
00637 inline int bvec_divfixed(const bvec &e, int c, bvec &res, bvec &rem)
00638 { return bvec_divfixed(e.roots, c, &res.roots, &rem.roots); }
00639 
00640 inline int bvec_div(const bvec &l, const bvec &r, bvec &res, bvec &rem)
00641 { return bvec_div(l.roots, r.roots, &res.roots, &rem.roots); }
00642 
00643 inline bvec bvec_ite(const bdd& a, const bvec& b, const bvec& c)
00644 { return bvec_ite(a.root, b.roots, c.roots); }
00645 
00646 inline bvec bvec_shlfixed(const bvec &e, int pos, const bdd &c)
00647 { return bvec_shlfixed(e.roots, pos, c.root); }
00648 
00649 inline bvec bvec_shl(const bvec &left, const bvec &right, const bdd &c)
00650 { return bvec_shl(left.roots, right.roots, c.root); }
00651 
00652 inline bvec bvec_shrfixed(const bvec &e, int pos, const bdd &c)
00653 { return bvec_shrfixed(e.roots, pos, c.root); }
00654 
00655 inline bvec bvec_shr(const bvec &left, const bvec &right, const bdd &c)
00656 { return bvec_shr(left.roots, right.roots, c.root); }
00657 
00658 inline bdd  bvec_lth(const bvec &left, const bvec &right)
00659 { return bvec_lth(left.roots, right.roots); }
00660 
00661 inline bdd  bvec_lte(const bvec &left, const bvec &right)
00662 { return bvec_lte(left.roots, right.roots); }
00663 
00664 inline bdd  bvec_gth(const bvec &left, const bvec &right)
00665 { return bvec_gth(left.roots, right.roots); }
00666 
00667 inline bdd  bvec_gte(const bvec &left, const bvec &right)
00668 { return bvec_gte(left.roots, right.roots); }
00669 
00670 inline bdd  bvec_equ(const bvec &left, const bvec &right)
00671 { return bvec_equ(left.roots, right.roots); }
00672 
00673 inline bdd  bvec_neq(const bvec &left, const bvec &right)
00674 { return bvec_neq(left.roots, right.roots); }
00675 
00676 
00677    /* Hack to allow for overloading */
00678 #define bvec_var(a,b,c)  bvec_varpp(a,b,c)
00679 #define bvec_varfdd(a)   bvec_varfddpp(a)
00680 #define bvec_varvec(a,b) bvec_varvecpp(a,b)
00681 #define bvec_true(a)     bvec_truepp(a)
00682 #define bvec_false(a)    bvec_falsepp(a)
00683 #define bvec_con(a,b)    bvec_conpp((a),(b))
00684 
00685    
00686 #endif /* CPLUSPLUS */
00687 
00688 #endif /* _BVEC_H */
00689 
00690 /* EOF */

Generated on Mon Jul 23 13:25:13 2007 for BuDDy by  doxygen 1.5.1