tclbdd

Check-in [3016cbe3d8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Broke off the easy cases from Apply (to be used in ApplyAndQuantify)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3016cbe3d8ba7618dbdad1200afdc41bf23b7413
User & Date: kbk 2013-12-10 12:25:38
Context
2013-12-10
12:33
Added operator to the key of 'applyCache' so that multiple applications can be in flight at once. check-in: 61ca0d0495 user: kbk tags: trunk
12:25
Broke off the easy cases from Apply (to be used in ApplyAndQuantify) check-in: 3016cbe3d8 user: kbk tags: trunk
04:30
Shorten parameter lists of internal routines by keeping state in the BDD_System object. Start drafting ApplyAndQuantify - but it's not right, so define it away. check-in: 75bd8ee9ed user: kbk tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/bdd.c.

1058
1059
1060
1061
1062
1063
1064



























































































1065
1066
1067
1068
1069
1070
1071
....
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173

1174
1175
1176
1177
1178
1179
1180
1181
1182
    Tcl_DeleteHashTable(&(sysPtr->negateCache));
    return result;
}
 
/*
 *-----------------------------------------------------------------------------
 *



























































































 * BDD_Apply --
 *
 *	Applies a Boolean operator between two BDD's.
 *
 * Results:
 *	Returns the resulting BDD.
 *
................................................................................
				 * right-hand bead*/

    BDD_BeadIndex l, h;	        /* Low and high transitions of the result */
    int newFlag;		/* Flag==1 if the output is a new bead */
    BDD_BeadIndex result;	/* Return value */
    Tcl_HashEntry* entry;	/* Pointer to the entry in the
				 * cache of beads for this operation */
    BDD_BinOp opmask;		/* Mask of relevant bits for this operation */

    /* Check if the result is already hashed */

    u[0] = u1;
    u[1] = u2;
    entry = Tcl_CreateHashEntry(&(sysPtr->applyCache), u, &newFlag);
    if (!newFlag) {
	result = (BDD_BeadIndex) Tcl_GetHashValue(entry);
	++sysPtr->beads[result].refCount;
    } else {

	/* 
	 * Check if the result is constant or a copy of one of the operands
	 */
	opmask = 0xF;
	if (u1 == 0) {
	    opmask &= 0x3;
	} else if (u1 == 1) {
	    opmask &= 0xC;
	}
	if (u2 == 0) {
	    opmask &= 0x5;
	} else if (u2 == 1) {
	    opmask &= 0xA;
	}
	if ((op & opmask) == 0) {
	    /* 
	     * Result is constant zero 
	     */
	    result = 0;

	    ++sysPtr->beads[result].refCount;
	} else if ((op & opmask) == opmask) {
	    /* 
	     * Result is constant one 
	     */
	    result = 1;
	    ++sysPtr->beads[result].refCount;
	} else if ((op & opmask) == (0xC & opmask)) {
	    /*
	     * Result is the left operand
	     */
	    result = u1;
	    ++sysPtr->beads[result].refCount;
	} else if ((op & opmask) == (0xA & opmask)) {
	    /*
	     * Result is the right operand
	     */
	    result = u2;
	    ++sysPtr->beads[result].refCount;

	    /*
	     * Special cases for 'x OP x':
	     */

	} else if ((op == BDD_BINOP_AND || op == BDD_BINOP_OR) && (u1 == u2)) {
	    result = u2;
	    ++sysPtr->beads[result].refCount;
	} else if ((op == BDD_BINOP_XOR 
		    || op == BDD_BINOP_LT
		    || op == BDD_BINOP_GT) && (u1 == u2)) {
	    result = 0;
	    ++sysPtr->beads[result].refCount;
	} else if ((op == BDD_BINOP_EQ
		    || op == BDD_BINOP_LE
		    || op == BDD_BINOP_GE) && (u1 == u2)) {
	    result = 1;
	    ++sysPtr->beads[result].refCount;
	} else {
	    
	    /*

	     * Result is not constant. Apply recursively to the subexpression
	     * with the earlier top variable.
	     */
	    if (u1Ptr->level == u2Ptr->level) {
		/*
		 * Both subexpressions have the same top variable
		 */
		level = u1Ptr->level;
		low1 = u1Ptr->low;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







<











|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
>

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<

>
|
|







1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
....
1187
1188
1189
1190
1191
1192
1193

1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205















1206
1207

1208
1209




































1210

1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
    Tcl_DeleteHashTable(&(sysPtr->negateCache));
    return result;
}
 
/*
 *-----------------------------------------------------------------------------
 *
 * ApplyEasyCases --
 *
 *	Tests for the easy cases in BDD_Apply, where one or the other
 *	operand is constant, or both operands are identical.
 *
 * Result:
 *	Returns 1 if an easy case was found, 0 otherwise.
 *
 * Side effects:
 *	Sets 'result' to the result of the easy case. The caller is
 *	responsible for incrementing the reference count.
 *
 *-----------------------------------------------------------------------------
 */

inline static int
ApplyEasyCases(
    BDD_BinOp op,		/* Operator to apply */
    BDD_BeadIndex u1,		/* Left operand */
    BDD_BeadIndex u2,		/* Right operand */
    BDD_BeadIndex* result)	/* OUTPUT: Result */
{
    BDD_BinOp opmask;		/* Mask of relevant bits for this operation */

    /* 
     * Check if the result is constant or a copy of one of the operands
     */
    opmask = 0xF;
    if (u1 == 0) {
	opmask &= 0x3;
    } else if (u1 == 1) {
	opmask &= 0xC;
    }
    if (u2 == 0) {
	opmask &= 0x5;
    } else if (u2 == 1) {
	opmask &= 0xA;
    }
    if ((op & opmask) == 0) {
	/* 
	 * Result is constant zero 
	 */
	*result = 0;
	return 1;
    }
    if ((op & opmask) == opmask) {
	/* 
	 * Result is constant one 
	 */
	*result = 1;
	return 1;
    } 
    if ((op & opmask) == (0xC & opmask)) {
	/*
	 * Result is the left operand
	 */
	*result = u1;
	return 1;
    } 
    if ((op & opmask) == (0xA & opmask)) {
	/*
	 * Result is the right operand
	 */
	*result = u2;
	return 1;
    }

    /*
     * Special cases for 'x OP x':
     */
    
    if ((op == BDD_BINOP_AND || op == BDD_BINOP_OR) && (u1 == u2)) {
	*result = u2;
	return 1;
    }
    if ((op == BDD_BINOP_XOR || op == BDD_BINOP_LT || op == BDD_BINOP_GT)
	&& (u1 == u2)) {
	*result = 0;
	return 1;
    } 
    if ((op == BDD_BINOP_EQ || op == BDD_BINOP_LE || op == BDD_BINOP_GE)
	&& (u1 == u2)) {
	*result = 1;
	return 1;
    }
    return 0;
}
 
/*
 *-----------------------------------------------------------------------------
 *
 * BDD_Apply --
 *
 *	Applies a Boolean operator between two BDD's.
 *
 * Results:
 *	Returns the resulting BDD.
 *
................................................................................
				 * right-hand bead*/

    BDD_BeadIndex l, h;	        /* Low and high transitions of the result */
    int newFlag;		/* Flag==1 if the output is a new bead */
    BDD_BeadIndex result;	/* Return value */
    Tcl_HashEntry* entry;	/* Pointer to the entry in the
				 * cache of beads for this operation */


    /* Check if the result is already hashed */

    u[0] = u1;
    u[1] = u2;
    entry = Tcl_CreateHashEntry(&(sysPtr->applyCache), u, &newFlag);
    if (!newFlag) {
	result = (BDD_BeadIndex) Tcl_GetHashValue(entry);
	++sysPtr->beads[result].refCount;
    } else {

	/*















	 * Test for 'result is constant', 'result is copy of operand'
	 */

	if (ApplyEasyCases(op, u1, u2, &result)) {
	    ++sysPtr->beads[result].refCount;




































	} else {

	    /*
	     * Result is neither constant nor a simple copy.  Apply
	     * the operator recursively to the subexpression with the
	     * earlier top variable.
	     */
	    if (u1Ptr->level == u2Ptr->level) {
		/*
		 * Both subexpressions have the same top variable
		 */
		level = u1Ptr->level;
		low1 = u1Ptr->low;