CS 152 L02 Verilog & Multiply Review (1)Patterson Fall 2003 © UCB 2003-08-28 Dave Patterson (www.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs152/

Slides:



Advertisements
Similar presentations
Simulation executable (simv)
Advertisements

Verilog Overview. University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
ELEN 468 Lecture 21 ELEN 468 Advanced Logic Design Lecture 2 Hardware Modeling.
Chapter 11 Verilog HDL Application-Specific Integrated Circuits Michael John Sebastian Smith Addison Wesley, 1997.
Verilog Intro: Part 1.
Hardware Description Language (HDL)
Give qualifications of instructors: DAP
Datorteknik IntegerMulDiv bild 1 MIPS mul/div instructions Multiply: mult $2,$3Hi, Lo = $2 x $3;64-bit signed product Multiply unsigned: multu$2,$3Hi,
Computer Architecture ECE 361 Lecture 6: ALU Design
CS 151 Digital Systems Design Lecture 37 Register Transfer Level
361 div.1 Computer Architecture ECE 361 Lecture 7: ALU Design : Division.
CS 61C L25 Verilog I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
CS 61C L24 Verilog I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
Silicon Programming--Intro. to HDLs1 Hardware description languages: introduction intellectual property (IP) introduction to VHDL and Verilog entities.
CS 61C L30 Verilog I (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C : Machine.
ECE 232 L9.Mult.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 9 Computer Arithmetic.
Today’s Lecture Process model –initial & always statements Assignments –Continuous & procedural assignments Timing Control System tasks.
CS152 Lec6.1 CS152 Computer Architecture and Engineering Lecture 6 VHDL, Multiply, Shift.
Overview Logistics Last lecture Today HW5 due today
Ceg3420 l7 Multiply 1 Fall 1998 © U.C.B. CEG3420 Computer Design Lecture 7: VHDL, Multiply, Shift.
CS 152 Lec 5.1 CS 152: Computer Architecture and Engineering Lecture 5 Hardware Description Languages, Multiple and Divide Randy H. Katz, Instructor Satrajit.
Verilog Basics Nattha Jindapetch November Agenda Logic design review Verilog HDL basics LABs.
Introduction to FPGA AVI SINGH. Prerequisites Digital Circuit Design - Logic Gates, FlipFlops, Counters, Mux-Demux Familiarity with a procedural programming.
ECE 2372 Modern Digital System Design
Copyright 1995 by Coherence LTD., all rights reserved (Revised: Oct 97 by Rafi Lohev, Oct 99 by Yair Wiseman, Sep 04 Oren Kapah) IBM י ב מ 10-1 The ALU.
Digital Kommunikationselektronik TNE027 Lecture 2 1 FA x n –1 c n c n1- y n1– s n1– FA x 1 c 2 y 1 s 1 c 1 x 0 y 0 s 0 c 0 MSB positionLSB position Ripple-Carry.
Lecture 6: Multiply, Shift, and Divide
CS 3850 Lecture 3 The Verilog Language. 3.1 Lexical Conventions The lexical conventions are close to the programming language C++. Comments are designated.
CS 61C L4.2.2 Verilog II (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Verilog II Kurt Meinz inst.eecs.berkeley.edu/~cs61c.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Cs 152 l6 Multiply 1 DAP Fa 97 © U.C.B. ECE Computer Architecture Lecture Notes Multiply, Shift, Divide Shantanu Dutt Univ. of Illinois at.
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
CS61C Finishing the Datapath: Subtract, Multiple, Divide Lecture 21
Module 1.2 Introduction to Verilog
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Anurag Dwivedi. Basic Block - Gates Gates -> Flip Flops.
 Lecture 2 Processor Organization  Control needs to have the  Ability to fetch instructions from memory  Logic and means to control instruction sequencing.
Behavioral Modelling - 1. Verilog Behavioral Modelling Behavioral Models represent functionality of the digital hardware. It describes how the circuit.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Csci 136 Computer Architecture II – Multiplication and Division
Verilog A Hardware Description Language (HDL ) is a machine readable and human readable language for describing hardware. Verilog and VHDL are HDLs.
Logic Design / Processor and Control Units Tony Diep.
CS152 / Kubiatowicz Lec6.1 2/12/03©UCB Spring 2003 CS152 Computer Architecture and Engineering Lecture 6 Multiply, Divide, Shift February 12, 2003 John.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Introduction to ASIC flow and Verilog HDL
Verilog hdl – II.
Introduction to Verilog. Data Types A wire specifies a combinational signal. – Think of it as an actual wire. A reg (register) holds a value. – A reg.
COE 202 Introduction to Verilog Computer Engineering Department College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals.
Integer Multiplication and Division COE 301 Computer Organization Dr. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University.
Verilog Intro: Part 1. Hardware Description Languages A Hardware Description Language (HDL) is a language used to describe a digital system, for example,
1 University of Jordan Computer Engineering Department CPE 439: Computer Design Lab.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
Integer Multiplication and Division ICS 233 Computer Architecture & Assembly Language Prof. Muhamed Mudawar College of Computer Sciences and Engineering.
Exp#5 & 6 Introduction to Verilog COE203 Digital Logic Laboratory Dr. Ahmad Almulhem KFUPM Spring 2009.
Hardware Description Languages: Verilog
Computer System Design Lecture 3
An Introduction to Verilog: Transitioning from VHDL
Integer Multiplication and Division
MIPS mul/div instructions
Discussion 2: More to discuss
Verilog-HDL-3 by Dr. Amin Danial Asham.
Hardware Description Languages: Verilog
Introduction to DIGITAL CIRCUITS MODELING & VERIFICATION using VERILOG [Part-I]
Topic 3c Integer Multiply and Divide
332:437 Lecture 8 Verilog and Finite State Machines
Computer Architecture EECS 361 Lecture 6: ALU Design
332:437 Lecture 8 Verilog and Finite State Machines
COE 202 Introduction to Verilog
Presentation transcript:

CS 152 L02 Verilog & Multiply Review (1)Patterson Fall 2003 © UCB Dave Patterson ( www-inst.eecs.berkeley.edu/~cs152/ CS152 – Computer Architecture and Engineering Lecture 2 – Verilog & Multiply Review

CS 152 L02 Verilog & Multiply Review (2)Patterson Fall 2003 © UCB Review: CS 152 roadmap CS152 Fall ‘03 Arithmetic Single/multicycle Datapaths IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB IFetchDcdExecMemWB PipeliningMemory Systems I/O YOURCPUYOURCPU

CS 152 L02 Verilog & Multiply Review (3)Patterson Fall 2003 © UCB Review °Continued rapid improvement in Computing 2X every 1.5 years in processor speed; every 2.0 years in memory size; every 1.0 year in disk capacity; Moore’s Law enables processor, memory (2X transistors/chip/ ~1.5 yrs) °5 classic components of all computers Control Datapath Memory Input Output } Processor

CS 152 L02 Verilog & Multiply Review (4)Patterson Fall 2003 © UCB Verilog °1 of 2 popular Hardware Description Languages (other is VHDL) °A language for describing and testing logic circuits. text based way to talk about designs easier to simulate before silicon translate into silicon directly °No sequential execution, normally hardware just “runs” continuously. °Verilog: A strange version of C, with some changes to account for time

CS 152 L02 Verilog & Multiply Review (5)Patterson Fall 2003 © UCB Overview °Behavioral vs. Structural Verilog °Time in Verilog and wave forms °Testing and Test Benches in Verilog °Nice online tutorial: fall/verilog-manual.html

CS 152 L02 Verilog & Multiply Review (6)Patterson Fall 2003 © UCB Verilog ° Verilog description composed of modules: module Name ( port list ) ; Declarations and Statements; endmodule ; °Modules can have instantiations of other modules, or use primitives supplied by language °Note that Verilog varies from C syntax, borrowing from Ada programming language at times ( endmodule)

CS 152 L02 Verilog & Multiply Review (7)Patterson Fall 2003 © UCB Verilog °Verilog has 2 basic modes 1. Structural composition: describes that structure of the hardware components, including how ports of modules are connected together module contents are built-in gates ( and, or, xor, not, nand, nor, xnor, buf ) or other modules previously declared 2. Behavioral: describes what should be done in a module module contents are C-like assignment statements, loops

CS 152 L02 Verilog & Multiply Review (8)Patterson Fall 2003 © UCB Example: Structural XOR (xor built-in, but..) module xor(Z, X, Y); input X, Y; output Z; wire notX, notY, XnotY, YnotX; not (notX, X), (notY, Y); or (Z, YnotX, XnotY); and (YnotX, notX, Y), (XnotY, X, notY); endmodule X Y X Y Z XnotY YnotX notX notY Says which “ports” input, output “nets” to connect components Note: order of gates doesn’t matter, since structure determines relationship Default is 1 bit wide data

CS 152 L02 Verilog & Multiply Review (9)Patterson Fall 2003 © UCB Example: Behavioral XOR in Verilog module xorB(Z, X, Y); input X, Y; output Z; reg Z; (X or Y) Z = X ^ Y; // ^ is C operator for xor endmodule; °Unusual parts of above Verilog “ (X or Y) ” => whenever X or Y changes, do the following statement “ reg ” is only type of behavioral data that can be changed in assignment, so must redeclare Z as reg Default is single bit data types: X, Y, Z

CS 152 L02 Verilog & Multiply Review (10)Patterson Fall 2003 © UCB Verilog: replication, hierarchy °Often in hardware need many copies of an item, connected together in a regular way Need way to name each copy Need way to specify how many copies °Specify a module with 4 XORs using existing module example

CS 152 L02 Verilog & Multiply Review (11)Patterson Fall 2003 © UCB Example: Replicated XOR in Verilog module 4xor(C, A, B); input [3:0] A, B; output[3:0] C; xor foo4xor[3:0] (.X(A),.Y(B),.Z(C) ); endmodule; °Note 1: can associate ports explicitly by name, (.X (A),.Y(B),.Z(C)) °or implicitly by order (as in C) (C, A, B) °Note 2: must give a name to new instance of xors ( foo4xor ) C[0] A[0] B[0] A[0] B[0] C[1] A[1] B[1] A[1] B[1] C[2] A[2] B[2] A[2] B[2] C[3] A[3] B[3] A[3] B[3]

CS 152 L02 Verilog & Multiply Review (12)Patterson Fall 2003 © UCB Verilog big idea: Time in code ° Difference from normal prog. lang. is that time is part of the language part of what trying to describe is when things occur, or how long things will take ° In both structural and behavioral Verilog, determine time with #n : event will take place in n time units structural: not #2(notX, X) says notX does not change until time advances 2 ns behavioral: #2 Z = A ^ B; says Z does not change until time advances 2 ns Default unit is nanoseconds; can change

CS 152 L02 Verilog & Multiply Review (13)Patterson Fall 2003 © UCB Example: °“Initial” means do this code once °Note: Verilog uses begin … end vs. { … } as in C °#2 stream = 1 means wait 2 ns before changing stream to 1 ° Output called a “waveform” module test(stream); output stream; reg stream; initial begin stream = 0; #2 stream = 1; #5 stream = 0; #3 stream = 1; #4 stream = 0; end endmodule stream 0 1 time

CS 152 L02 Verilog & Multiply Review (14)Patterson Fall 2003 © UCB Time and updates °When do assignments take place with respect to $time? °At next update of clock

CS 152 L02 Verilog & Multiply Review (15)Patterson Fall 2003 © UCB Time, variable update, and monitor °The instant before the rising edge of the clock, all outputs and wires have thier OLD values. This includes inputs to flip flops. Therefore, if you change the inputs to a flip flop at a particular rising edge, that change will not be reflected at the output until the NEXT rising edge. This is because when the rising edge occurs, the flip flop still sees the old value. So when simulated time changes in Verilog, then ports, registers updated or #2(Z, X, Y); Z X Y

CS 152 L02 Verilog & Multiply Review (16)Patterson Fall 2003 © UCB Testing in Verilog °Code above just defined a new module °Need separate code to test the module (just like C/Java) °Since hardware is hard to build, major emphasis on testing in HDL °Testing modules called “test benches” in Verilog; like a bench in a lab dedicated to testing °Can use time to say how things change

CS 152 L02 Verilog & Multiply Review (17)Patterson Fall 2003 © UCB Administrivia °Prerequisite Quiz Friday AM - 1 PM 320 Soda (John) 2. 2 PM - 4 PM 4 Evans (Kurt) 3. 3 PM - 5 PM 81 Evans (Jack) °Lab 1 due next Wednesday (Mon. holiday) °Tuesday: buy $37 PRS Transmitor from behind ASUC textbook desk (Chem 1A, CS 61ABC, 160) Can sell back to bookstore

CS 152 L02 Verilog & Multiply Review (18)Patterson Fall 2003 © UCB Example Verilog Code //Test bench for 2-input multiplexor. // Tests all input combinations. module testmux2; reg [2:0] c; wire f; reg expected; mux2 myMux (.select(c[2]),.in0(c[0]),.in1(c[1]),.out(f)); initial begin c = 3'b000; expected=1'b0;... Verilog constants syntax N’Bxxx where N is size of constant in bits B is base: b for binary, h for hex, o for octal xxx are the digits of the constant

CS 152 L02 Verilog & Multiply Review (19)Patterson Fall 2003 © UCB Example Verilog Code … begin c = 3'b000; expected=1'b0; repeat(7) begin #10 c = c + 3'b001; if (c[2]) expected=c[1]; else expected=c[0]; end #10 $finish; end Verilog if statement, for and while loops like C repeat (n) loops for n times (restricted for ) forever is an infinite loop Can select a bit of variable ( c[0] ) $finish ends simulation

CS 152 L02 Verilog & Multiply Review (20)Patterson Fall 2003 © UCB Rising and Falling Edges and Verilog °Challenge of hardware is when do things change relative to clock? Rising clock edge? (“positive edge triggered”) Falling clock edge? (“negative edge triggered”) When reach a logical level? (“level sensitive”) °Verilog must support any “clocking methodology” °Includes events “posedge”, “negedge” to say when clock edge occur, and “wait” statements for level

CS 152 L02 Verilog & Multiply Review (21)Patterson Fall 2003 © UCB Verilog Odds and Ends ° Memory is register with second dimension reg [31:0] memArray [0:255]; ° Can assign to group on Left Hand Side {Cout, sum} = A + B + Cin; °Can connect logical value 0 or 1 to port via supply0 or supply1 °If you need some temporary variables (e.g., for loops), can declare them as integer °Since variables declared as number of bits, to place a string need to allocate 8 * number of characters reg [1 : 6*8] Msg; Msg = ”abcdef”;

CS 152 L02 Verilog & Multiply Review (22)Patterson Fall 2003 © UCB Blocking v. Nonblocking assignment °Blocking assignment statement (= operator) like in traditional programming languages The whole statement is done before control passes on to the next statement. °Non-blocking (<= operator) evaluates all right-hand sides for current time unit and assigns left-hand sides at the end of the time unit Use old values of variables at beginning of current time unit and to assign registers new values at end of current time unit. This reflects how register transfers occur in some hardware systems.

CS 152 L02 Verilog & Multiply Review (23)Patterson Fall 2003 © UCB Blocking v. Nonblocking Example // testing blocking and non-blocking assignment module blocking; reg [0:7] A, B; initial begin: init1 A = 3; #1 A = A + 1; // blocking procedural assignment B = A + 1; $display("Blocking: A= %b B= %b", A, B ); A = 3; #1 A <= A + 1; // non-blocking procedural assignment B <= A + 1; #1 $display("Non-blocking: A= %b B= %b", A, B ); end endmodule °Above module produces the following output: Blocking: A= B= Non-blocking: A= B=

CS 152 L02 Verilog & Multiply Review (24)Patterson Fall 2003 © UCB ° How many mistakes in this module? module test(X); output X; initial begin X = 0; X = 1; end; Peer Instruction A. None B. 1 C. 2 D. 3 E. 4 F. >=5

CS 152 L02 Verilog & Multiply Review (25)Patterson Fall 2003 © UCB Peer Instruction ° How many mistakes in this module? module test2(X); output X; reg X; // so can change initial begin X = 0; #2 X = 1; // no time delay end_ // no ; endmodule_ // Ada style end, and no ; A. None B. 1 C. 2 D. 3 E. 4 F. >=5

CS 152 L02 Verilog & Multiply Review (26)Patterson Fall 2003 © UCB Peer Instruction ° Suppose writing a MIPS interpreter in Verilog. Which sequence below is best organization for the interpreter? I. A repeat loop that fetches instructions II. A while loop that fetches instructions III. Increments PC by 4 IV. Decodes instructions using case statement V. Decodes instr. using chained if statements VI. Executes each instruction A. I, IV, VI B. II, III, IV, VI C. II, V, VI, III D. IV, VI, III, II E. V, VI, III, I F. VI, III, II

CS 152 L02 Verilog & Multiply Review (27)Patterson Fall 2003 © UCB Peer Instruction ° Suppose writing a MIPS interpreter in Verilog. Which sequence below is best organization for the interpreter? I. A repeat loop that fetches instructions II. A while loop that fetches instructions III. Increments PC by 4 IV. Decodes instructions using case statement V. Decodes instr. using chained if statements VI. Executes each instruction A. I, IV, VI B. II, III, IV, VI C. II, V, VI, III D. IV, VI, III, II E. V, VI, III, I F. VI, III, II

CS 152 L02 Verilog & Multiply Review (28)Patterson Fall 2003 © UCB Verilog conclusion °Verilog allows both structural and behavioral descriptions, helpful in testing °Syntax a mixture of C (operators, for, while, if, print) and Ada (begin… end, case…endcase, module …endmodule) °Some special features only in Hardware Description Languages # time delay, initial vs. always, forever loops °Verilog can describe everything from single gate to full computer system; you get to design a simple processor

CS 152 L02 Verilog & Multiply Review (29)Patterson Fall 2003 © UCB MIPS arithmetic instructions °InstructionExampleMeaningComments °add add $1,$2,$3$1 = $2 + $33 operands; exception possible °subtractsub $1,$2,$3$1 = $2 – $33 operands; exception possible °add immediateaddi $1,$2,100$1 = $ constant; exception possible °add unsignedaddu $1,$2,$3$1 = $2 + $33 operands; no exceptions °subtract unsignedsubu $1,$2,$3$1 = $2 – $33 operands; no exceptions °add imm. unsign.addiu $1,$2,100$1 = $ constant; no exceptions °multiply mult $2,$3Hi, Lo = $2 x $364-bit signed product °multiply unsignedmultu$2,$3Hi, Lo = $2 x $3 64-bit unsigned product °divide div $2,$3Lo = $2 ÷ $3,Lo = quotient, Hi = remainder ° Hi = $2 mod $3 °divide unsigned divu $2,$3Lo = $2 ÷ $3,Unsigned quotient & remainder ° Hi = $2 mod $3 °Move from Himfhi $1$1 = HiUsed to get copy of Hi °Move from Lomflo $1$1 = LoUsed to get copy of Lo

CS 152 L02 Verilog & Multiply Review (30)Patterson Fall 2003 © UCB MULTIPLY (unsigned) °Paper and pencil example (unsigned): Multiplicand 1000 Multiplier Product °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

CS 152 L02 Verilog & Multiply Review (31)Patterson Fall 2003 © UCB Unsigned Combinational Multiplier °Stage i accumulates A * 2 i if B i == 1 °Q: How much hardware for 32 bit multiplier? Critical path? B0B0 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 B1B1 B2B2 B3B3 P0P0 P1P1 P2P2 P3P3 P4P4 P5P5 P6P6 P7P7 0000

CS 152 L02 Verilog & Multiply Review (32)Patterson Fall 2003 © UCB How does it work? °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 B0B0 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 B1B1 B2B2 B3B3 P0P0 P1P1 P2P2 P3P3 P4P4 P5P5 P6P6 P7P

CS 152 L02 Verilog & Multiply Review (33)Patterson Fall 2003 © UCB Unisigned shift-add multiplier (version 1) °64-bit Multiplicand reg, 64-bit ALU, 64- bit Product reg, 32-bit multiplier reg Product Multiplier Multiplicand 64-bit ALU Shift Left Shift Right Write Control 32 bits 64 bits Multiplier = datapath + control

CS 152 L02 Verilog & Multiply Review (34)Patterson Fall 2003 © UCB Multiply Algorithm Version 1 ProductMultiplierMultiplicand : : : : : : Shift the Multiplier register right 1 bit. Done Yes: 32 repetitions 2. Shift the Multiplicand register left 1 bit. No: < 32 repetitions 1. Test Multiplier0 Multiplier0 = 0 Multiplier0 = 1 1a. Add multiplicand to product & place the result in Product register 32nd repetition? Start

CS 152 L02 Verilog & Multiply Review (35)Patterson Fall 2003 © UCB 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?

CS 152 L02 Verilog & Multiply Review (36)Patterson Fall 2003 © UCB MULTIPLY HARDWARE Version 2 °32-bit Multiplicand reg, 32 -bit ALU, 64-bit Product reg, 32-bit Multiplier reg Product Multiplier Multiplicand 32-bit ALU Shift Right Write Control 32 bits 64 bits Shift Right

CS 152 L02 Verilog & Multiply Review (37)Patterson Fall 2003 © UCB How to think of this? B0B0 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 B1B1 B2B2 B3B3 P0P0 P1P1 P2P2 P3P3 P4P4 P5P5 P6P6 P7P Remember original combinational multiplier:

CS 152 L02 Verilog & Multiply Review (38)Patterson Fall 2003 © UCB Simply warp to let product move right... °Multiplicand stay’s still and product moves right B0B0 B1B1 B2B2 B3B3 P0P0 P1P1 P2P2 P3P3 P4P4 P5P5 P6P6 P7P A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3 A0A0 A1A1 A2A2 A3A3

CS 152 L02 Verilog & Multiply Review (39)Patterson Fall 2003 © UCB Multiply Algorithm Version 2 3. Shift the Multiplier register right 1 bit. Done Yes: 32 repetitions 2. Shift the Product register right 1 bit. No: < 32 repetitions 1. Test Multiplier0 Multiplier0 = 0 Multiplier0 = 1 1a. Add multiplicand to the left half of product & place the result in the left half of Product register 32nd repetition? Start : : : : : : : : : : : : Product Multiplier Multiplicand

CS 152 L02 Verilog & Multiply Review (40)Patterson Fall 2003 © UCB Still more wasted space! 3. Shift the Multiplier register right 1 bit. Done Yes: 32 repetitions 2. Shift the Product register right 1 bit. No: < 32 repetitions 1. Test Multiplier0 Multiplier0 = 0 Multiplier0 = 1 1a. Add multiplicand to the left half of product & place the result in the left half of Product register 32nd repetition? Start : : : : : : : : : : : : Product Multiplier Multiplicand

CS 152 L02 Verilog & Multiply Review (41)Patterson Fall 2003 © UCB Observations on Multiply Version 2 °Product register wastes space that exactly matches size of multiplier => combine Multiplier register and Product register

CS 152 L02 Verilog & Multiply Review (42)Patterson Fall 2003 © UCB MULTIPLY HARDWARE Version 3 °32-bit Multiplicand reg, 32 -bit ALU, 64-bit Product reg, (0-bit Multiplier reg) Product (Multiplier) Multiplicand 32-bit ALU Write Control 32 bits 64 bits Shift Right

CS 152 L02 Verilog & Multiply Review (43)Patterson Fall 2003 © UCB Multiply Algorithm Version 3 Done Yes: 32 repetitions 2. Shift the Product register right 1 bit. No: < 32 repetitions 1. Test Product0 Product0 = 0 Product0 = 1 1a. Add multiplicand to the left half of product & place the result in the left half of Product register 32nd repetition? Start : : : : : : : : Product Multiplicand

CS 152 L02 Verilog & Multiply Review (44)Patterson Fall 2003 © UCB Observations on Multiply Version 3 °2 steps per bit because Multiplier & Product combined °MIPS registers Hi and Lo are left and right half of Product °Gives us MIPS instruction MultU

CS 152 L02 Verilog & Multiply Review (45)Patterson Fall 2003 © UCB In Conclusion... °Multiply: successive refinement to see final design 32-bit Adder, 64-bit shift register, 32-bit Multiplicand Register There are algorithms that calculate many bits of multiply per cycle (see exercises 4.36 to 4.39 in COD)