CS226 Practice Problem Set 3 (Spring 2016

CS226 Practice Problem Set 3 (Spring 2016) Solutions
1. F = ite(x5 , f50 , f5 ), where f5 = (x2 ⊕ x3 ).((x1 ⊕ x03 ) + x4 ).
In turn, f5 = ite(x4 , (x2 ⊕ x3 ), (x2 ⊕ x3 ).(x1 ⊕ x03 ))
Furthermore, x2 ⊕ x3 = ite(x2 , x03 , x3 ) and
(x2 ⊕ x3 ).(x1 ⊕ x03 ) = ite(x2 , x03 .(x1 ⊕ x03 ), x3 .(x1 ⊕ x03 )).
The latter can be re-written as: ite(x2 , ite(x3 , 0, x01 ), ite(x3 , x1 , 0)).
To get the ite expression for f50 , we simply use the recursive formulation used for complementing
an ROBDD. Thus, f50 = ite(x4 , (x2 ⊕ x3 )0 , ((x2 ⊕ x3 ).(x1 ⊕ x03 ))0 ). Applying this recursively, we get
(x2 ⊕ x3 )0 = ite(x2 , x3 , x03 ) and
((x2 ⊕ x3 ).(x1 ⊕ x03 ))0 = ite(x2 , ite(x3 , 1, x1 ), ite(x3 , x01 , 1)).
The ROBDD can now be constructed as shown in Fig. 1.
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
0
1
Figure 1: ROBDD for 1(a)
The following figures show how the variable ordering of x2 and x3 can be swapped in the ROBDD.
The red labels in Fig. 2 give the labels of the outgoing edges as values of x3 x2 . We need to make
sure that outgoing edges with these labels are also available after swapping the order of x2 and x3 .
The blue shaded regions must stay unchanged. The result is shown in Fig. 3.
1
x5
x4
x4
Label:
x3 x2
x2
x3
x3
01
11
x2
x2
10
x3
11
x2
x3
x3
01
00
00
10
x1
01
10
x3
00
11
x1
0
1
(a)
Figure 2: ROBDD from 1(a) with labels of outgoing edges (in red)
2
x5
x4
x4
Label:
x3 x2
x3
x2
x2
x2
01
10
x3
x3
x2
x2
10
11
x3
00
01
01
11
00
x2
00
10
x1
x1
0
1
Figure 3: ROBDD solution for 1(b).
3
11
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
1
Figure 4: Inserting bubbles on edges to 0-leaf
(b) This requires a sequence of transformations.
i. Insert bubbles on all edges leading to the 0-leaf. This is shown in Fig. 4.
ii. Now shift bubbles out from solid edges, going from lower levels of the BDD upwards. You
should continue this until no solid edges are left with bubbles. Note that, in general, this can
result in an edge above the root node with a bubble on it (in this example, this doesn’t happen
though). This is shown in Fig. 5, Fig. 6, and Fig. 7.
iii. Next, cancel even numbers of bubbles on all dotted edges. This is shown in Fig. 8.
The end-result of the sequence of transformations is shown in Fig. 9.
4
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
1
Figure 5: Moving bubbles out of solid edges (step 1).
5
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
1
Figure 6: Moving bubbles out of solid edges (step 2).
6
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
1
Figure 7: Moving bubbles out of solid edges (step 3).
7
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
1
Figure 8: Cancelling even numbers of bubbles.
8
x5
x4
x2
x3
x4
x2
x2
x3
x3
x2
x3
x3
x1
x1
1
Figure 9: The end result
9
x3
(c) Fig. 10 shows nodes with the same functionality coloured with the same colour. On merging these
nodes, we get the ROBDD with complement edges shown in Fig. 11.
x5
x4
x2
x3
x4
x2
x2
x3
x3
x3
x1
x2
x3
x3
x1
1
Figure 10: Identifying functionally equivalent nodes.
10
x5
x4
x2
x2
x3
x3
x3
x1
1
Figure 11: ROBDD with complement edges
11
2. Observe from the given ROBDD (shown in Fig. 12) that when a = 1, then regardless of the value of b,
if c = 0, the same node (coloured node labeled d) is reached in the ROBDD.
a
b
b
c
c
c
d
d
0
1
Figure 12: Original ROBDD
This suggests that when a = 1, if we split on c first, then the 0-edge from the node labeled c can directly
reach the coloured node labeled d without splitting on b. On the other hand, when a = 1, and c = 0,
then depending on whether b = 0 or b = 1, the appropriate co-factors have to be chosen. This suggests
that instead of having one node to split on b, and two nodes to split on c (as in Fig. 12), we can have
only one node to split on c and one node to split on b. The resulting BDD is shown in Fig. 13.
12
a
b
c
c
b
d
d
0
1
Figure 13: BDD with different orders on different paths
13
3. Recall that we discussed in class how the ordering of variables affects the size of the ROBDD. In
particular, if the variable order is such that you can’t determine whether the function will evaluate to
1 or 0 even after knowing the values of the first few variables in the order, then the ROBDD must split
into sufficiently many parts after reading these variables, effectively remembering something about the
values of the variables read so far. This is then used to determine the value of the function after the
remaining variables’s values are read.
The example we saw in class (and given on the slides on the course webpage) is one such function:
x1 .x2 + x3 .x4 + x5 .x6 + · · · x2n−1 .x2n , where the variable order x1 < x3 < · · · x2n−1 < x2 < x4 < · · · x2n
requires that you remember the 2n combinations of values of x1 , x3 , . . . x2n−1 , before you can decide the
value of the function on reading the values of x2 , x4 , . . ..
XOR functions are notoriously good (or bad, as you see it) in this respect: you cannot determine the
value of the function until you have read in all the variables. However, XORs are not the only functions
with such a property. In this problem, however, using an XOR function is sufficient. In particular,
(x1 ⊕ x4 ).(x2 ⊕ x3 ) requires 11 nodes (including the leaves) with the order x1 < x2 < x3 < x4 , while
each of (x1 ⊕ x4 ) and (x2 ⊕ x3 ) requires 5 nodes (including the leaves).
Draw the ROBDDs yourself to convince yourself of the above.
4. For algorithm 1, we can follow the sequence of steps given below. Here, we have chosen to store X in
register U , Z in register V and Y in register W .
CurrSt
S1
A lt B
-
NextSt
S2
Mu
01
Mv
0
Mw
01
Ma
-
Mb
-
Mq
-
Reset
1
doAdd
-
S2
-
S3
00
0
00
00
01
0
0
1
S3
1
S4
00
1
00
00
01
0
0
0
S3
0
S7
00
0
00
11
00
0
0
1
S4
-
S5
11
0
00
01
01
0
0
1
S5
-
S6
00
0
11
-
-
0
0
-
S6
-
S3
00
0
00
00
01
0
0
1
S7
-
S8
00
0
00
11
00
1
0
1
S8
-
S8
00
0
00
11
00
1
0
1
Comment
Reset regs (0 in all regs),
feed X,Y to regs U ,W
X in U ; Y in W ; 0 in V and P
feed U ,W to adder
U + W in P ; U, V, W unchanged
U < W : entering while loop
feed P to V ,
feed U ,W to subtractor
U + W in P ; U, V, W unchanged
U ≥ W : exiting while loop
feed V ,V to adder
U + W in V ; V, W unchanged; U − W in P
Inside while loop
feed P to U
feed W ,W to adder
2W in P ; Uprev − W in U ; V, W unchanged
Inside while loop
feed P to W
2W in W ; U, V unchanged; garbage in P P
Inside while loop
feed U , W to adder (like S2 )
2V in P ; U, V, W unchanged
Out of while loop:
feed P to Q, and V, V to adder
2V in P and in Q; U, V, W unchanged
Keep looping:
feed P to Q, and V, V to adder
Given that there are 8 states, three state bits should suffice. You could encode S1 as 000, S2 as 001
or use your favourite encoding. By replacing each state Si with its encoding in the above table, and
by removing the “Comment” column, we get the state transition table of the controller required to
implement algorithm 1 with the given datapath.
14
To implement algorithm 2, we can use the following sequence of steps. Once again, we have chosen to
store X in register U , Z in register V and Y in register W .
CurrSt
S1
A lt B
-
NextSt
S2
Mu
01
Mv
0
Mw
01
Ma
-
Mb
-
Mq
-
Reset
1
doAdd
-
S2
-
S3
00
0
00
00
11
0
0
1
S3
-
S4
11
0
00
-
-
0
0
-
S4
-
S5
00
0
00
00
01
0
0
0
S5
-
S6
00
1
00
-
-
0
0
-
S6
-
S7
00
0
00
11
00
0
0
1
S7
-
S8
00
0
11
11
11
0
0
-
S8
1
S3
00
0
00
00
11
0
0
1
S8
0
S9
00
0
00
11
00
0
0
1
S9
-
S10
00
0
00
11
00
1
0
1
S10
-
S10
00
0
00
11
00
1
0
1
Comment
Reset regs (0 in all regs),
feed X,Y to regs U ,W
X in U ; Y in W ; 0 in V and P
In do-while loop
feed U ,U to adder
2U in P ; U, V, W unchanged
In do-while loop
feed P to U
2Uprev in U ; V, W unchanged; garbage in P
In do-while loop
feed U ,W to subtractor
U − W in P ; U, V, W unchanged
Inside do-while loop
feed P to V
U − W in V ; U, W unchanged; garbage in P
Inside do-while loop
feed V, V to adder
2V in P ; U, V, W unchanged
Inside do-while loop
feed P to W , and V, U to adder/sub
2V in W ; U, V unchanged; garbage in P
Inside do-while loop:
feed U, U to adder (as in S2 )
2V in W ; U, V unchanged; garbage in P
Out of do-while loop:
feed V, V to adder
2V in P ; U, V, W unchanged
Out of do-while loop:
feed P to Q, and V, V to adder
2V (= W ) in P and Q; U, V, W unchanged
Keep looping:
feed P to Q, and V, V to adder
There are 10 states now and four state bits should suffice. You can choose your encoding of states to
complete the controller’s state transition table.
15