Fun with optimizations

advertisement
EECS 270, Fall 2014, Lecture 17
Page 1 of 7
Fun with optimizations
Today we’ll look at two different optimizations.
 Finding the minimal number of states for a state machine. (Section 6.3)
 Doing a faster addition (Section 6.4 up to page 374)
These examples are from our text!
I.
State minimization
Motivational Example
Consider the following two machines. Are they equivalent?
Say x were 0, 1, 1, 0, 0. What would be the output of the larger one? The smaller one? Are they always
the same? How can you be sure?
What makes states equivalent?
Two states are equivalent if
1. They assign the same values to outputs,
e.g. S0 and S2 both assign y to 0,S1 and S3 both assign y to 1
2. AND, for all possible sequences of inputs, the FSM outputs will be the same starting from either
state
Let’s look at this example. Are any states equivalent?
EECS 270, Fall 2014, Lecture 17
Let’s use an implication table.
Which states can’t be equivalent? Any with differing outputs! Cross those out.
Now we’ll follow the following algorithm. Do steps 2&3.
What does this look like after step 4?
Page 2 of 7
EECS 270, Fall 2014, Lecture 17
Another Example
Now let’s do a final, less trivial, example:
Page 3 of 7
EECS 270, Fall 2014, Lecture 17
Page 4 of 7
Bus-based data path
Design a machine which finds the maximum value of the first 16 memory elements and puts the result in
the 17th one.
address
i
max
element
data
address
data
memory
greater
equal16
greater_out
equal16_out
plus1
EECS 270, Fall 2014, Lecture 17
Page 5 of 7
And now a processor…
Instruction name Opcode
Effect
halt
0
PC = PC+4
stop executing instructions
add
1
PC = PC+4
memory[addr0] = memory[addr1] + memory[addr2]
sub
2
PC = PC+4
memory[addr0] = memory[addr1] - memory[addr2]
mult
3
PC = PC+4
memory[addr0] = memory[addr1] * memory[addr2]
div
4
PC = PC+4
memory[addr0] = memory[addr1] / memory[addr2]
cp
5
PC = PC+4
memory[addr0] = memory[addr1]
and
6
PC = PC+4
memory[addr0] = memory[addr1] & memory[addr2]
or
7
PC = PC+4
memory[addr0] = memory[addr1] | memory[addr2]
not
8
PC = PC+4
memory[addr0] = ~memory[addr1]
9
if (memory[addr1] == memory[addr2]) {
PC = addr0
} else {
PC = PC+4
}
10
if (memory[addr1] != memory[addr2]) {
PC = addr0
} else {
PC = PC+4
}
be
bne
blt
11
if (memory[addr1] < memory[addr2]) {
PC = addr0
} else {
PC = PC+4
}
Comparisons take into account the sign of the
number. E.g., 16'hffff (-1) is less than 16'h0000 (0).
All instructions are encoded over 4 memory locations. First is the opcode. Next three are addr0, addr1,
addr2, addr3.
EECS 270, Fall 2014, Lecture 17
Page 6 of 7
Maddr data
EECS 270, Fall 2014, Lecture 17
Page 7 of 7
Download