Word-Level Combinational Circuits and HCL Integer Expressions

Một phần của tài liệu Computer systems a programmers perspective randal e bryant, david r ohallaron (Trang 411 - 416)

4.2 Logic Design and the Hardware Control Language HCL

4.2.3 Word-Level Combinational Circuits and HCL Integer Expressions

Combinational circuits that perform word-level computations are constructed using logic gates to compute the individual bits of the output word, based on the individual bits of the input words. For example, Figure 4.12 shows a combinational circuit that tests whether two 64-bit words A andã B are equal. niat'is, the output will equal 1 if and only if each bit of A equals the corresponding bit of B. This circuit is implemented using 64 of the single-bit equality circuits shown in Figure 4.10. The outputs of these single-bit circuits are combined with an AND gate to form the circuit output..

In HCL, we will declare any word-level signal as an int, without specifying the word size. This is done for simplicity. In a full-featured hardware description language, every word can be declared to have a specific number of bits. HCL allows words to be compared for equality, and so the functionality of the circuit shown in Figure 4.12 can be expressed at the word level as

bool Eq =(A== B);

where arguments A and B are of type int. Note that we use the same syntax conventions as in C, where '=' denotes assignment and '==' denotes the equality operator.

'

I

'•

I I I

Section 4.2 Logic Design and the Hardware Control Language HCL 377 As is shown on the right side of Figure 4.121.we will draw word-level circuits

using medium-thickness lines to represent the set of wires carrying the individual bits of the word, and we .will show a single-bit signal as a dashed line.

~iq§Jifil>:filQilio1Pfm~i;f~~tZ!1!l~'!~~?l

Suppose you want to implement a word-level equality circuit using the EXCLUSJVE- OR circuits from Problem 4.9 rather than from bit-level equality circuits. Design such a circuit for a 64-bit word consisting of 64 bit-level EXCLUSIVE-OR circuits and two additional logic gates.

Figure 4.13 shows the circuit for a word-level multiplexor. This circuit gener- ates a 64-bit word Out equal to one of the two input words, A or B, depending on the control input bit s. The circuit consists of 64 identical subcircuits, each hav- ing a structure similar to the bit-level multiplexor from Figure 4.11. Rather than replicating the bit-level multiplexor 64 times, the word-level version reduces the number of Inverters by generating ! s once and tensing it at each bit position.

OU!a3

s ... ããã;

B A

.. , ... ~ ~~,:..,'

.•. /N:l\)•ã

;-MUX.,

" """.:~~ã ,l').

ã~'ã"_'I.'.,,;,.

int Out =

s A;

l : B;

l ;

Out

I bo -r--;-,---1Il-'-'

Outo

I

lã-t:::==::::!~!::_~_:___J

I o

fa) Bit-level implementation (b) Word-level abstraction Oigure 4.13 Word-level multiplexor circuit. The output will equal input word A when lhe control signal s is 1, and it will equal B otherwise. Multiplexors are described in HCL

11sing case expressions.

I I I

"

,I

I I

I

l

I

378 Chapter 4 Processor Architecture

We will use many forms of multiplexors in our processor designs. They allow us to select a word from a number of sources depending on some control condi- tion. Multiplexing functions are described in HCL using case expressions. A case expression has the following general form:

select1 expr1 ; select2 expr2j

selectk exprk;

]

The expression contains a series of cases, where each case i consists of a Boolean expression select;, indicating when this case should be selected, and an integer expression expr;, indicating tJ;ie.resulting value.

lJnlike the switch statement of C, we do not require the different selection expressions to be mutually exclu~ive. Logically, the selection expressions are eval- uated in sequence, and the case for the first one yielding 1 is selected. For example, the word-level multiplexor of Figure 4.13 can be described in HCL as

word Out = [ s: A;

1: B;

] ;

In this code, the second selection expression is simply 1, indicating that this case should be selected if no prior one has been. This is the way to specify a default case in HCL. Nearly all case expressions end in this manner.

Allowing nonexclusive selection expressions makes the HCL code more read- able. An actual hardware multiplexor must have mutually exclusive signals con- trolling which input word should be passed to the output, such as the signals s and

! sin Figure 4.13. To translate an HCL case expression into hardware, a logic syn- thesis program would need to analyze the set of selection expressions and resolve any possible conflicts by making sure that only the first matching case would be selected.

The selection expressions can be arbitrary Boolean expressions, and there can be an arbitrary number of cases. This allows case expressions to describe blocks where there are many choices of input signals with complex selection criteria. For example, consider the diagram of a 4-way multiplexor shown in Figure 4.14. This circuit selects from among the four input words A, B, C, and D based on the control signals sl and sO, treating the controls as a 2-bit binary number. We can express this in HCL using Boolean expressions to describe the different combinations of control bit patterns:

word Out4 = [

!sl k& !sO Ai # 00

Section 4.2 Logic Design and the Hardware Control Language HCL 379

Figure 4.14

Four-way multiplexor.

The different combinations of control signals sl and sO determine which data input is transmitted to the output.

s1 ... !

so ... ! ~

D c

B A

!s1

!sO 1

B; # 01 C; # 10 D'f # 11 ];

Out4

The comments on the right (any text starting with# and rnnning for the rest of the line is a comment) show which combination of sl and sO will cause the case to be selected. Observe that the selection expressions can sometimes be simplified, since only the first matching case is selected. For example, the second expression can be' written ! sl, rather than the more complete ! sl && sO, since the only other possibility having sl equal to 0 was given as the first selection expression. Similarly, the' third expression can be written as ! sO, while the fourth can simply be written as 1.

As a fihal example, suppose we want to design a logic circuit that finds the minimum 'value among a set of words A, B, and C, diagrammed as follows:

~<Ii ~fr~;:

c 'iliti~~~

B Min3

A ~""; . z.~

"""

We can expr~ss this using an HCL case expression as word Min3 = [

A<=B&&A<=C B<=A&&B<=C 1

l ;

Aã ' Bã ' Cã '

!Praa~;:6Pi!mfttilãt'iÊ91idf!a5!6~ã~fil;;J:&.,";Ơ~~f:.:..;;~~T~

The HCL code given for computing the minimum of three words contains four comparison expressions of the form X <= Y. Rewrite the code to compute the same result, but using only three comparisons.

l

' I

380 Chapter 4 Processor Architecture

0 2 3

yjj}_.ã.

;. X +Y

. uã

X B •

Y--.~ . t.. u• X&Y

X-+B";,

X-Y x-v

Figure 4.15 Arithmetic/logic unit (ALU). Depending on the setting of the function input, the circuit will perform one of four different arithmetic and logical operations.

'''~i'l'!:"'"-'>";'11'"l""""-ã~ ... _ .. ~--~~ã-ã-,..,w,,.,....,.,...-~,.,, """"""'''t:: <

~fssJ>e .. Prom~m~~.12~cs!!l!!l•qi'J'J>'!'!teã41!4> oivw,,, -~ ""'"'*"" ": :,.:>.~ '$

Write HCL code describing a circuit that for word inputs A, B, and C selects the median of the three values. That is, the output equals the word lying between the minimum and maximum of the three inputs.

Combinational logic circuits can be designed to perform many different types of operations on word-level data. The detailed design of these is beyond the scope of our presentation. One important comb4'-ational circuit, kno"'.n as an arithmetidlogic unit (ALU), is diagrammed at an abstract level in Figure 4.15.

In our version, the circuit has three inputs: two data inputs labeled A and B ~nd a control input. Depending on the setting of the control input, the circuit will perform different arithn)etic or logical operations op the data inputs. Observe that the four operations diagrammed ,for this ALU correspond to the four different integer operations supported by the Y86-64 instruction set, and the control values match the function codes for these instructions (Figure 4.3). Note also the ordering of operands for subtraction, where the A input is subtracted from the B input.

This ordering is chosen in anticipation of the ordering of arguments in the subq instruction.

4.2.4 Set Membership

In our processor designs, we will find many examples where we want to compare one signal against a number of possible matching signals, such as to test whether the code for some instruction being processed matches some category of instruc- tion codes. As aã simple example, suppose we want to generate the signals sl and sO for the 4-way multiplexor of Figure 4.14 by selecting the high- and'low-order bits from a 2-bit signal code, as follows:

-B.,,,,,,-... ? s1

code ... 1 l so j D

c

B

. ~"' 1:

... rl'Ơ:,ã

MUX4-'

• • Out4

Section 4.2 Logic Design and the Hardware Control Language HCL 381 In this circuit, the 2-bit signal code would then control the selection among the

four data words A, B, C, and D. We can express the generation of signals sl and sO using equality tests based on the possible values of code:

bool s1 code bool sO code

2 11 code 1 11 code

3ã ,

3;

A more concise expression can be written that expresses the property that sl is 1 when code is in the set {2, 3), ani:l sO is 1 when code is in the set {l, 3):

bool s1 bool sO

code in { 2, 3 };

code in { 1, 3 };

The general form of a set membership test is iexpr in {iexpr1, iexprz, ... , iexprk}

where the v~lue being tested (iexpr) and the candidate matches (iexpr1 through iexprk) are all integer expressions.

Một phần của tài liệu Computer systems a programmers perspective randal e bryant, david r ohallaron (Trang 411 - 416)

Tải bản đầy đủ (PDF)

(1.120 trang)