Unformatted text preview:

CS152 Computer Architecture and Engineering Lecture 6 Multiply Divide Shift February 12 2003 John Kubiatowicz www cs berkeley edu kubitron lecture slides http www inst eecs berkeley edu cs152 2 12 03 UCB Spring 2003 CS152 Kubiatowicz Review Elements of the Design Process Divide and Conquer e g ALU Formulate a solution in terms of simpler components Design each of the components subproblems Generate and Test e g ALU Given a collection of building blocks look for ways of putting them together that meets requirement Successive Refinement e g multiplier divider Solve most of the problem i e ignore some constraints or special cases examine and correct shortcomings Formulate High Level Alternatives e g shifter Articulate many strategies to keep in mind while pursuing any one approach Work on the Things you Know How to Do The unknown will become obvious as you make progress 2 12 03 UCB Spring 2003 CS152 Kubiatowicz Review ALU Design Bit slice plus extra on the two ends Overflow means number too large for the representation Carry look ahead and other adder tricks A 32 B 32 signed arith and cin xor co a31 a0 b31 ALU0 co cin s0 ALU31 co cin s31 Ovflw 2 12 03 b0 S 32 UCB Spring 2003 4 M C L to produce select comp c in CS152 Kubiatowicz Review Carry Look Ahead Design trick peek C0 Cin A0 B0 G P A 0 0 1 1 S C1 G0 C0 P0 A1 B1 G P S B 0 1 0 1 C out 0 C in C in 1 kill propagate propagate generate G A and B P A xor B C2 G1 G0 P1 C0 P0 P1 A2 B2 G P S C3 G2 G1 P2 G0 P1 P2 C0 P0 P1 P2 A3 B3 G P S G P C4 2 12 03 UCB Spring 2003 CS152 Kubiatowicz Review Design Trick Guess or Precompute CP 2n 2 CP n n bit adder n bit adder CP 2n CP n CP mux n bit adder 1 n bit adder n bit adder Carry select adder Cout 2 12 03 0 UCB Spring 2003 CS152 Kubiatowicz Review Carry Skip Adder reduce worst case delay B A4 B A0 4 bit Ripple Adder P3 P2 P1 P0 4 bit Ripple Adder S P3 P2 P1 P0 S Just speed up the slowest case for each block Exercise optimal design uses variable block sizes 2 12 03 UCB Spring 2003 CS152 Kubiatowicz MIPS arithmetic instructions Instruction Example add subtract add immediate add unsigned subtract unsigned add imm unsign multiply multiply unsigned divide Meaning add 1 2 3 1 2 3 sub 1 2 3 1 2 3 addi 1 2 100 1 2 100 addu 1 2 3 1 2 3 subu 1 2 3 1 2 3 addiu 1 2 100 1 2 100 mult 2 3 Hi Lo 2 x 3 multu 2 3 Hi Lo 2 x 3 div 2 3 Lo 2 3 divide unsigned divu 2 3 Lo 2 3 Move from Hi Move from Lo mfhi 1 mflo 1 1 Hi 1 Lo 2 12 03 UCB Spring 2003 Comments 3 operands exception possible 3 operands exception possible constant exception possible 3 operands no exceptions 3 operands no exceptions constant no exceptions 64 bit signed product 64 bit unsigned product Lo quotient Hi remainder Hi 2 mod 3 Unsigned quotient remainder Hi 2 mod 3 Used to get copy of Hi Used to get copy of Lo CS152 Kubiatowicz MULTIPLY unsigned Paper and pencil example unsigned Multiplicand Multiplier 1000 0000 0000 1000 Product 01001000 1000 1001 m bits x n bits m n bit product Binary makes it easy 0 place 0 0 x multiplicand 1 place a copy 1 x multiplicand 4 versions of multiply hardware algorithm successive refinement 2 12 03 UCB Spring 2003 CS152 Kubiatowicz Unsigned Combinational Multiplier 0 0 A3 A3 A3 A3 P7 P6 A2 A2 A1 P5 A2 A1 A2 A1 0 A1 0 A0 B0 A0 B1 A0 B2 A0 P4 B3 P3 P2 P1 P0 Stage i accumulates A 2 i if Bi 1 Q How much hardware for 32 bit multiplier Critical path 2 12 03 UCB Spring 2003 CS152 Kubiatowicz How does it work 0 0 0 A3 A3 A3 P7 P6 A2 P5 A2 A1 0 A3 A2 A1 0 0 A2 A1 A1 0 A0 A0 B1 A0 B2 A0 P4 P3 B0 B3 P2 P1 P0 At each stage shift A left x 2 Use next bit of B to determine whether to add in shifted multiplicand Accumulate 2n bit partial product at each stage 2 12 03 UCB Spring 2003 CS152 Kubiatowicz Carry Save addition of 4 integers A2A1A0 Adding B2B1B0 C2C1C0 D2D1D0 C2 B2 A2 C1 B1 A1 C0 B0 A0 I1 I1 I1 S1 S4S3S2S1S0 Add Columns first then rows S0 I3 S1 I2 I3 S0 S1 S1 I2 I3 S0 S1 0 I1 Carry Save Adder 3 2 S0 I3 D0 I1 Carry Save Adder 3 2 I2 Carry Save Adder 3 2 D1 I1 Can be used to reduce critical path of multiply I2 Carry Save Adder 3 2 D2 Full Adder 3 2 element 2 12 03 I3 Carry Save Adder 3 2 Example 53 bit multiply for floating point At least 53 levels with na ve technique Only 9 with Carry save addition I2 I2 I3 Carry Save Adder 3 2 S0 S1 S0 0 I1 I2 I3 Carry Save Adder 3 2 S1 I1 I2 I3 Carry Save Adder 3 2 S0 S4 S3 UCB Spring 2003 S1 S0 S2 I1 I2 I3 Carry Save Adder 3 2 S1 S0 S1 S0 CS152 Kubiatowicz Unisigned shift add multiplier version 1 64 bit Multiplicand reg 64 bit ALU 64 bit Product reg 32 bit multiplier reg Shift Left Multiplicand 64 bits Multiplier 64 bit ALU Product 32 bits Write 64 bits Multiplier datapath control 2 12 03 Shift Right UCB Spring 2003 Control CS152 Kubiatowicz Multiply Algorithm Version 1 Multiplier0 1 Start Multiplier0 0 1 Test Multiplier0 1a Add multiplicand to product place the result in Product register 1 2 3 1 2 3 Product Multiplier Multiplicand 0000 0000 0011 0000 0010 0000 0010 0011 0000 0010 0000 0010 0011 0000 0100 0000 0010 0001 0000 0100 0000 0110 0001 0000 0100 0000 0110 0001 0000 1000 0000 0110 0000 0000 1000 0000 0110 2 12 03 0000 2 Shift the Multiplicand register left 1 bit 3 Shift the Multiplier register right 1 bit 0000 1000 UCB Spring 2003 32nd repetition No 32 repetitions Yes 32 repetitions CS152 Kubiatowicz Done Observations on Multiply Version 1 1 clock per cycle 100 clocks per multiply Ratio of multiply to add 5 1 to 100 1 1 2 bits in multiplicand always 0 64 bit adder is wasted 0 s inserted in right of multiplicand as shifted least significant bits of product never changed once formed Instead of shifting multiplicand to left shift product to right 2 12 03 UCB Spring 2003 CS152 Kubiatowicz MULTIPLY HARDWARE Version 2 32 bit Multiplicand reg 32 bit ALU 64 bit Product reg 32 bit Multiplier reg Multiplicand 32 …


View Full Document

Berkeley COMPSCI 152 - Lecture 6 Multiply, Divide, Shift

Documents in this Course
Quiz 5

Quiz 5

9 pages

Memory

Memory

29 pages

Quiz 5

Quiz 5

15 pages

Memory

Memory

29 pages

Memory

Memory

35 pages

Memory

Memory

15 pages

Quiz

Quiz

6 pages

Midterm 1

Midterm 1

20 pages

Quiz

Quiz

12 pages

Memory

Memory

33 pages

Quiz

Quiz

6 pages

Homework

Homework

19 pages

Quiz

Quiz

5 pages

Memory

Memory

15 pages

Load more
Loading Unlocking...
Login

Join to view Lecture 6 Multiply, Divide, Shift and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 6 Multiply, Divide, Shift and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?