//ITE FUNCTION int circuit::ITE(int i, int t, int e){ int terminalResult = 0; //Check if ITE is a terminal node if(terminal(i, t, e, terminalResult)){ return terminalResult; } //Check computed Table to see if ITE is already computed if(iteExists(i,t,e, terminalResult)) return terminalResult; //Get top variable give i t e int top = topVariable(i, t, e); //Recurse ITE through true and false edge int TE = ITE(function(i, top, true), function(t, top, true), function(e, top, true)); int FE = ITE(function(i, top, false), function(t, top, false), function(e, top, false)); //Check if TE and FE are the same. if(TE == FE) return TE; //Add node into table if unique int label = insertUT(top, TE, FE); //Add node to CT; int keys[] = {i, t, e}; std::vector<int> key (keys, keys+sizeof(keys)/sizeof(int)); hashCT[key] = label; return label; }
static //Formula buildBDD(const Linear& c, int size, int lower_limit, int upper_limit, int material_left, Map<Pair<int,Int>,Formula>& memo, int max_cost) Formula buildBDD(const Linear& c, int size, Int sum, Int material_left, Map<Pair<int,Int>,Formula>& memo, int max_cost) { Int lower_limit = (c.lo == Int_MIN) ? Int_MIN : c.lo - sum; Int upper_limit = (c.hi == Int_MAX) ? Int_MAX : c.hi - sum; if (lower_limit <= 0 && upper_limit >= material_left) return _1_; else if (lower_limit > material_left || upper_limit < 0) return _0_; else if (FEnv::topSize() > max_cost) return _undef_; // (mycket elegant!) Pair<int,Int> key = Pair_new(size, lower_limit); Formula ret; if (!memo.peek(key, ret)){ assert(size != 0); size--; material_left -= c(size); Int hi_sum = sign(c[size]) ? sum : sum + c(size); Int lo_sum = sign(c[size]) ? sum + c(size) : sum; Formula hi = buildBDD(c, size, hi_sum, material_left, memo, max_cost); if (hi == _undef_) return _undef_; Formula lo = buildBDD(c, size, lo_sum, material_left, memo, max_cost); if (lo == _undef_) return _undef_; ret = ITE(var(var(c[size])), hi, lo); memo.set(key, ret); } return ret; }
//Extracts BDD From circuit file void circuit::getBDD(){ //Cycle through every gate (Gate is ordered in level fashion) for(int i = numInputs+1; i < numgates; i++){ int gate = gtype[i]; // Get the gate type int index = 0; int f,g,h; int *in = faninlist[i]; // Get the fanin list for the gate //Check which gate we are dealing with and call ITE switch(gate){ case 3: //XOR index = ITE(gateNode[in[0]], -1 * gateNode[in[1]], gateNode[in[1]]); break; case 4: //XNOR index = ITE(gateNode[in[0]], gateNode[in[1]], -1 * gateNode[in[1]]); break; case 6: //AND index = ITE(gateNode[in[0]], gateNode[in[1]], 1); //Check for multi input for(int j = 2; j < (fanin[i]); j++) index = ITE(gateNode[in[j]], index, 1); break; case 7: //NAND //Check for multi input. If more and 2 input, gates are and gates with the last one being a nand gate if(fanin[i] < 3) index = ITE(gateNode[in[0]], -1 * (gateNode[in[1]]), 2); else{ index = ITE(gateNode[in[0]], gateNode[in[1]], 1); for(int j = 2; j < (fanin[i] - 1); j++) index = ITE(index, gateNode[in[j]], 1); index = ITE(index, -1 * gateNode[in[fanin[i]-1]], 2); } break; case 8: //OR index = ITE(gateNode[in[0]], 2, gateNode[in[1]]); for(int j = 2; j < (fanin[i]); j++) index = ITE(gateNode[in[j]], 2, index); break; case 9: //NOR //Check for multi input. If more and 2 input, gates are and gates with the last one being a nor gate if(fanin[i] < 3) index = ITE(gateNode[in[0]], 1, -1 * (gateNode[in[1]])); else{ index = ITE(gateNode[in[0]], 2, gateNode[in[1]]); for(int j = 2; j < (fanin[i] - 1); j++) index = ITE(gateNode[in[j]], 2, index); index = ITE(index, 1, -1 * gateNode[in[fanin[i]-1]]); } break; case 10: //NOT index = ITE(gateNode[in[0]], 1, 2); break; }; //Add BDD node for that gate number gateNode.push_back(index); } }
* * * Copyright 1988 Regents of the University of California * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without * fee is hereby granted, provided that the above copyright * notice appear in all copies. The University of California * makes no representations about the suitability of this * software for any purpose. It is provided "as is" without * express or implied warranty. * */ #ifndef lint static char rcsid[] = "$Header$ SPR ITE (Berkeley)"; #endif not lint #define GOOD_SYSLOG #include "sprite.h" #include "mach.h" #include "proc.h" #include "vmMachInt.h" #include "vm.h" #include "vmInt.h" #include "machMon.h" #include "net.h" #include "netEther.h" #include "netInet.h" #include "dev.h"