Docsity

Integer Processing Unit: Shifting, Multiplication, Division and Barrel Shifter - Prof. Lou, Study notes of Computer Architecture and Organization

Toggle sidebar
bg1
ECEN 4243 Computer Architecture
Integer Processing Unit March 11, 2008 page 1 of 8
Integer Processing Unit
The integer processing unit usually contains more complex hardware than the basic ALU.
There is special purpose hardware for shifting, multiplication and division. Although
shifting, multiplication and division are not frequently used instructions, they are usually
implemented in hardware because software versions would be very slow.
Shifting
We have already seen that the ALU delay is critical in determining the speed of the CPU.
In order to avoid lengthening this delay, the shifter is usually put in parallel with the ALU.
This avoids increasing the clock period since
td(shift) < T and td(ALU) < T
is easier to satisfy than
td(shift) + td(ALU) < T.
The MIPS might implement shifting as follows. The operand to be shifted comes from the
register file and the shift amount comes from the shamt field in the instruction.
The shift operation does not require a shift-register to be used. Shifting is a purely combi-
national logic function. The following circuit, which contains only 4 to 1 multiplexers,
accomplishes no shift (S=1), a shift to the left(S=0) or a shift to the right(S=2). The S=3
input can be used for a larger shift.
Register File
ALU shifter
abus
bbus
shamt
shift amount
ID/EX
MUX
b1 b2 b3
d1 d2 d3
S
3 2 1 0
MUX
3 2 1 0
MUX
3 2 1 0
pf3
pf4
pf5
pf8

Partial preview of the text

Download Integer Processing Unit: Shifting, Multiplication, Division and Barrel Shifter - Prof. Lou and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Integer Processing Unit

The integer processing unit usually contains more complex hardware than the basic ALU. There is special purpose hardware for shifting, multiplication and division. Although shifting, multiplication and division are not frequently used instructions, they are usually implemented in hardware because software versions would be very slow.

Shifting

We have already seen that the ALU delay is critical in determining the speed of the CPU. In order to avoid lengthening this delay, the shifter is usually put in parallel with the ALU. This avoids increasing the clock period since td (shift) < T and td (ALU) < T

is easier to satisfy than td (shift) + td (ALU) < T.

The MIPS might implement shifting as follows. The operand to be shifted comes from the register file and the shift amount comes from the shamt field in the instruction.

The shift operation does not require a shift-register to be used. Shifting is a purely combi- national logic function. The following circuit, which contains only 4 to 1 multiplexers, accomplishes no shift (S=1), a shift to the left(S=0) or a shift to the right(S=2). The S= input can be used for a larger shift.

Register File

ALU shifter

bbus abus

shamt

shift amount

ID/EX

MUX

b1 b2 b

d1 d2 d

3 2 1 0 S

MUX

MUX

The above switching circuit can be generalized to allow shifts by any number of bit posi- tions. This type of circuit is called a “barrel shifter” and a typical transmission gate imple- mentation is shown below

where each circle is a multiplexer.

and the above example is for an 8-bit output bus. Note that the signal travels through only 3=log 2 8 gates. In general, this shifter has a delay ~log 2 N, where N= no. of bits. We can

extend the 8-bit shifter to 32-bits by adding two more columns of multiplexers.

The 8-bit barrel shifter can be viewed as connecting any 8 consecutive bits on the x-bus to the d-bus.

S d-bus 000 x14 ... x8 | x7 ... x0 | | d7 ... d0 | 001 x14 ... x9 | x8 ... x1 | x | d7 ... d0 | : :

d

d

d

d

d

d

d

d

x

x

x

x

x

x

x

x

x

x

x

x

x

x

x

S

S

S

<=>

S

S

multiplication is achieved with a single adder by shifting the partial product (partial sum) and adding the next partial product. A naive implementation is in fig. 3.5, p.177, and the controller algorithm is in fig. 3.6, p. 178.

A more efficient implementation that uses less hardware is shown in fig. 3.7, p. 179.

- Product: initially, most significant half zero, least significant half multiplier; finally, product - Multiplicand: does not change

This clever strategy uses the least significant half of the Product register for the multiplier. As the least significant bits of the multiplier in the Product register are used to create each partial product, these bits are shifted out of the Product register making room for extra bits from the partial sum in the Product register.

Fast Multipliers. The simple shift and add algorithm takes N clock cycles for an N bit operands. In the MIPS, it would take 32 clock cycles for a multiply (or 32 pipeline stages if we try to pipeline it). Given the miniscule instruction frequency of integer multiplies, adequate system performance could be achieved with this simple design. However, this would be complicated to integrate into the MIPS pipeline.

Faster multiplication is possible by adding additional hardware. It is difficult to justify additional hardware purely on the basis of performance for a general purpose processor. Perhaps psychological or marketing factors are more important. Anyway, most modern commercial processors have additional hardware to speed up multiplication.

Fast multipliers use a mixture of the following two techniques.

  1. Higher Radix Multiplier - In binary multipliers, a partial product is generated for each digit (binary bit) in the multiplier. If we represent the multiplier in a radix larger than two, then it will take less digits to represent the multiplier, and hence, less partial prod- ucts to add together. The problem with radices larger than two is that multiplication tables are increasingly difficult to implement. The multiplication table for binary digits, can be implemented with a single AND gate. Imagine all the hardware necessary to implement base 10 multiplication tables as we learned in grade school! The most popular radices other than two are: 4, 8, 16. Modified Booth recoding is often used to reduce the number of partial products (see the Advanced VLSI course for details).
  2. More Adders - With more adders, it is possible to compute more partial products at the same time in parallel (the adders in fig. 3.9, p. 182, compute partial products serially which is not significantly faster than the shift-add hardware). Using adders wired in parallel, it is possible to make N -bit multiply hardware that is only about twice as slow as an N -bit add (see the VLSI course for more details).

Adding Multiply to Pipeline. The multiply hardware is too slow to fit into the MIPS pipeline as designed to the ALU delay. One approach that has been taken is to add more pipeline stages. Let us suppose that we use the ultra fast adder that requires only one more execution stage. This maintains throughput, but increases latency just as we did for the load/store instructions. This 6-stage pipeline would need the following operand forward- ing paths.

Compared to the 5-stage pipeline, a new forwarding path from the EX1/EX2 pipeline reg- ister is needed. This forwarding path works for add, sub or logical instructions, but would not work for mult instructions since the mult result is not available until the end of EX2. Thus, a mult instruction followed by another instruction using the mult result register as a source would be a data hazard that can only be avoided with a stall.

The additional forwarding path and the additional stall control necessary for the 6-stage pipeline are typical of the cost of increasing pipeline latency. With the low instruction fre- quency for integer multiplies, it might be difficult to justify this cost.

In order to avoid the cost of increased latency, a separate pipeline can be used for multi- plies. This leaves the original pipeline unchanged for all instructions except multiplies. The MIPS instruction set allows designers do something like the following.

The multiply pipeline shares the IF, ID and the first part of the EX stage with the main pipeline. The second part of the multiply is executed in the MEM stage. At the end of the MEM stage, the multiplier output is written into two special register, Hi and Lo (the prod- uct of two 32-bit operands takes 64-bits). Special instructions, mfhi and mflo, are used to move data from Hi and Lo into the register file.

CC0 CC1 CC2 CC3 CC4 CC5 CC6 CC7 CC IF ID EX1 EX2 MEM WB IF ID EX1 EX2 MEM WB IF ID EX1 EX2 MEM WB IF ID EX1 EX2 MEM WB

ID/EX ALU

EX/MEM

DM Reg

MEM/WB

PC IM IF/ID Reg

mult1 mult

Hi

Lo

IF ID EX MEM WB

The non-restoring divide algorithm sets the first trial remainder, r^1 = 2a - b, and then repeats the following steps for i = 0, 1, 2, ...

  1. If ri+1^ is positive, qi = 1 and ri+2^ = 2ri+1^ - b.
  2. If ri+1^ is negative, qi = 0 and ri+2^ = 2ri+1^ + b.

If the final remainder is negative, the last restoring step must be done.

A naive implementation is in fig. 3.10, p. 184, and the controller algorithm is in fig. 3.11, p. 185.

A more efficient implementation that uses less hardware is shown in fig. 3.13, p. 187.

- Remainder: initially, dividend ; finally, remainder in most significant half, quotient in least significant half - Divisor: always has divisor

This clever strategy uses the same two registers for the dividend, quotient and remainders. As the remainder grows smaller it is left shifted, making room for the quotient bits to be left shifted into the Remainder register.

Fast Division. Fast division suffers from an inherent disadvantage. Division is fundamen- tally sequential in nature. Each successive quotient bit and remainder depends on the pre- vious quotient bit and remainder. (Compare with multiply where all of the partial products are independent of the others.) This prevents speeding up division by computing the quo- tient bits in parallel.

Fast dividers use one or the other of the following two techniques.

  1. Higher radix division - With higher radix division, more quotient bits are computed during each division iteration. The computation time is still proportional to the number of bits.
  2. Iterate with high speed multiply hardware - For example, find 1/b from b by using Newton’s method to find the root of f(x) = 1/x - b. Then multiply to get a/b. The key point is that Newton’s method has quadratic convergence. Each iteration gives twice as many bits accuracy as the previous iteration. This makes this method extremely attractive for division with large word sizes.

Adding Division to the Pipeline. The sequential nature of division algorithms makes it extremely costly to pipeline division. Fortunately, the low instruction frequency of integer division (even smaller than integer multiply) means that an efficient implentation of divi- sion is not required to get high average performance.

Let us suppose that we use Newton’s method for division with the fast two stage multiplier discussed previously. The first iteration gives us 1 quotient bit, the next 2 more bits, the next 4 more bits, etc. Six iterations are needed to get the 32 quotient bits. If we use the same multiplier hardware for all six iterations, then the divide is not pipelined (since no other instruction can start dividing until the previous divide finishes). This is the solution usually used.

If we insist on pipelining divide, it can be accomplished by unwrapping the six multiply iterations.

A total of 12 pipeline stages would be needed just for the divide execution. This would be excessively expensive given the low instruction frequency of divide.

mult1 mult2 mult1 mult

iteration 1 iteration 2