XU, Qiang 徐強 [Adapted from UC Berkeley’s D. Patterson’s and

Slides:



Advertisements
Similar presentations
CSE431 Chapter 3.1Irwin, PSU, 2008 CSE 431 Computer Architecture Fall 2008 Chapter 3: Arithmetic for Computers Mary Jane Irwin ( )
Advertisements

Chapter Three.
Arithmetic for Computers
©UCB CPSC 161 Lecture 6 Prof. L.N. Bhuyan
1 CONSTRUCTING AN ARITHMETIC LOGIC UNIT CHAPTER 4: PART II.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
1  2004 Morgan Kaufmann Publishers Chapter Three.
CSE431 L03 MIPS Arithmetic Review.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 03: MIPS Arithmetic Review Mary Jane Irwin (
Computer Systems Organization: Lecture 3
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
Arithmetic for Computers
CSE331 W07&8.1Irwin Fall 2007 PSU CSE 331 Computer Organization and Design Fall 2007 Week 7&8 Section 1: Mary Jane Irwin (
Computer Organization and Architecture Computer Arithmetic Chapter 9.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Computer Arithmetic Nizamettin AYDIN
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
EGRE 426 Fall 09 Chapter Three
Computing Systems Basic arithmetic for computers.
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
1  1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
Computer Architecture Chapter 3 Instructions: Arithmetic for Computer Yu-Lun Kuo 郭育倫 Department of Computer Science and Information Engineering Tunghai.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
CPE 232 MIPS Arithmetic1 CPE 232 Computer Organization MIPS Arithmetic – Part I Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin (
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
EI 209 Chapter 3.1CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 3: Arithmetic for Computers Haojin Zhu ( )
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
Prof. Hsien-Hsin Sean Lee
Computer Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
CSE 340 Computer Architecture Spring 2016 MIPS Arithmetic Review.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 Chapter 3 Arithmetic for Computers Lecture Slides are from Prof. Jose Delgado-Frias, Mr. Paul Wettin, and Prof. Valeriu Beiu (Washington State University.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
William Stallings Computer Organization and Architecture 8th Edition
Computer System Design Lecture 3
Computer Arthmetic Chapter Four P&H.
CS 230: Computer Organization and Assembly Language
Integer Multiplication and Division
Arithmetic for Computers
CS 314 Computer Organization Fall Chapter 3: Arithmetic for Computers
Morgan Kaufmann Publishers
William Stallings Computer Organization and Architecture 7th Edition
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
Arithmetic Logical Unit
ECE232: Hardware Organization and Design
Computer Arithmetic Multiplication, Floating Point
ECEG-3202 Computer Architecture and Organization
CS/COE0447 Computer Organization & Assembly Language
Computer Architecture
CS/COE0447 Computer Organization & Assembly Language
Chapter 3 Arithmetic for Computers
Morgan Kaufmann Publishers Arithmetic for Computers
Winter 2017 S. Areibi School of Engineering University of Guelph
Chapter 3 Arithmetic for Computers
Number Representation
MIPS Arithmetic and Logic Instructions
Presentation transcript:

CENG/CSCI 3420 Computer Organization and Design Spring 2014 Lecture 03: Arithmetic for Computers XU, Qiang 徐強 [Adapted from UC Berkeley’s D. Patterson’s and from PSU’s Mary J. Irwin’s slides with additional credits to Y. Xie]

Review: VHDL Supports design, documentation, simulation & verification, and synthesis of hardware Allows integrated design at behavioral and structural levels Basic structure Design entity-architecture descriptions Time-based execution (discrete event simulation) model Entity == External Characteristics Design Entity-Architecture == Hardware Component Architecture (Body ) == Internal Behavior or Structure

Review: Entity-Architecture Features Entity defines externally visible characteristics Ports: channels of communication signal names for inputs, outputs, clocks, control Generic parameters: define class of components timing characteristics, size (fan-in), fan-out Architecture defines the internal behavior or structure of the circuit Declaration of internal signals Description of behavior collection of Concurrent Signal Assignment (CSA) statements (indicated by <=); can also model temporal behavior with the delay annotation one or more processes containing CSAs and (sequential) variable assignment statements (indicated by :=) Description of structure interconnections of components; underlying behavioral models of each component must be specified

Arithmetic Where we've been What's up ahead Abstractions Instruction Set Architecture (ISA) Assembly and machine language What's up ahead Implementing the architecture (in VHDL) zero ovf 1 1 A 32 ALU result 32 B 32 4 m (operation)

ALU VHDL Representation entity ALU is port(A, B: in std_logic_vector (31 downto 0); m: in std_logic_vector (3 downto 0); result: out std_logic_vector (31 downto 0); zero: out std_logic; ovf: out std_logic) end ALU; architecture process_behavior of ALU is . . . begin ALU: process(A, B, m) result := A + B; end process ALU; end process_behavior;

Machine Number Representation Bits are just bits (have no inherent meaning) conventions define the relationships between bits and numbers Binary numbers (base 2) - integers 0000 -> 0001 -> 0010 -> 0011 -> 0100 -> 0101 -> . . . in decimal from 0 to 2n-1 for n bits Of course, it gets more complicated storage locations (e.g., register file words) are finite, so have to worry about overflow (i.e., when the number is too big to fit into 32 bits) have to be able to represent negative numbers, e.g., how do we specify -8 in addi $sp, $sp, -8 #$sp = $sp - 8 in real systems have to provide for more than just integers, e.g., fractions and real numbers (and floating point) and alphanumeric (characters)

MIPS Representations 32-bit signed numbers (2’s complement): 0000 0000 0000 0000 0000 0000 0000 0000two = 0ten 0000 0000 0000 0000 0000 0000 0000 0001two = + 1ten 0000 0000 0000 0000 0000 0000 0000 0010two = + 2ten ... 0111 1111 1111 1111 1111 1111 1111 1110two = + 2,147,483,646ten 0111 1111 1111 1111 1111 1111 1111 1111two = + 2,147,483,647ten 1000 0000 0000 0000 0000 0000 0000 0000two = – 2,147,483,648ten 1000 0000 0000 0000 0000 0000 0000 0001two = – 2,147,483,647ten 1000 0000 0000 0000 0000 0000 0000 0010two = – 2,147,483,646ten ... 1111 1111 1111 1111 1111 1111 1111 1101two = – 3ten 1111 1111 1111 1111 1111 1111 1111 1110two = – 2ten 1111 1111 1111 1111 1111 1111 1111 1111two = – 1ten What if the bit string represented addresses? need operations that also deal with only positive (unsigned) integers maxint minint

Two's Complement Operations Negating a two's complement number – complement all the bits and then add a 1 remember: “negate” and “invert” are quite different! Converting n-bit numbers into numbers with more than n bits: MIPS 16-bit immediate gets converted to 32 bits for arithmetic sign extend - copy the most significant bit (the sign bit) into the other bits 0010 -> 0000 0010 1010 -> 1111 1010 sign extension versus zero extend (lb vs. lbu)

Design the MIPS Arithmetic Logic Unit (ALU) 32 m (operation) result A B ALU 4 zero ovf 1 Must support the Arithmetic/Logic operations of the ISA add, addi, addiu, addu sub, subu mult, multu, div, divu sqrt and, andi, nor, or, ori, xor, xori beq, bne, slt, slti, sltiu, sltu Tradeoffs of cost and speed based on frequency of occurrence, hardware budget Immediate can be negative in addiu and it is simply an addi counterpart that ignors overflow. With special handling for sign extend – addi, addiu, slti, sltiu zero extend – andi, ori, xori Overflow detected – add, addi, sub

MIPS Arithmetic and Logic Instructions 31 25 20 15 5 R-type: op Rs Rt Rd funct I-Type: op Rs Rt Immed 16 Type op funct ADDI 001000 xx ADDIU 001001 xx SLTI 001010 xx SLTIU 001011 xx ANDI 001100 xx ORI 001101 xx XORI 001110 xx LUI 001111 xx Type op funct ADD 000000 100000 ADDU 000000 100001 SUB 000000 100010 SUBU 000000 100011 AND 000000 100100 OR 000000 100101 XOR 000000 100110 NOR 000000 100111 Type op funct 000000 101000 000000 101001 SLT 000000 101010 SLTU 000000 101011 000000 101100 funct = m (b3, b2, b1, b0) where b0 tells whether its signed (0) or not (1) (i.e., is overflow activated), b1 tells whether its an add (0) or subtract (1) operation, b2 tells whether it’s a logic operation (1) or arithmetic operation (2), and b3 tells whether its an immediate operation (1) or not (0) (except for slt)

Design Trick: Divide & Conquer Break the problem into simpler problems, solve them and glue together the solution Example: assume the immediates have been taken care of before the ALU now down to 10 operations can encode in 4 bits 0 add 1 addu 2 sub 3 subu 4 and 5 or 6 xor 7 nor a slt b sltu

Addition & Subtraction Just like in grade school (carry/borrow 1s) 0111 0111 0110 + 0110 - 0110 - 0101 Two's complement operations are easy do subtraction by negating and then adding 0111 -> 0111 - 0110 -> + 1010 Overflow (result too large for finite computer word) e.g., adding two n-bit numbers does not yield an n-bit number 0111 + 0001 1101 0001 0001 0001 1 0001 for lecture 1000

Building a 1-bit Binary Adder carry_in A B carry_in carry_out S 1 A 1 bit Full Adder S B carry_out S = A xor B xor carry_in carry_out = A&B | A&carry_in | B&carry_in (majority function) How can we use it to build a 32-bit adder? How can we modify it easily to build an adder/subtractor?

Building 32-bit Adder 1-bit FA A0 B0 S0 c0=carry_in c1 Just connect the carry-out of the least significant bit FA to the carry-in of the next least significant bit and connect . . . 1-bit FA A1 B1 S1 c2 1-bit FA A2 B2 S2 c3 Ripple Carry Adder (RCA) advantage: simple logic, so small (low cost) disadvantage: slow and lots of glitching (so lots of energy consumption) c32=carry_out 1-bit FA A31 B31 S31 c31 . . .

A 32-bit Ripple Carry Adder/Subtractor add/sub 1-bit FA S0 c0=carry_in c1 S1 c2 S2 c3 c32=carry_out S31 c31 . . . A0 A1 A2 A31 Remember 2’s complement is just complement all the bits add a 1 in the least significant bit B0 control (0=add,1=sub) B0 if control = 0 !B0 if control = 1 A 0111 -> 0111 B - 0110 -> + For lecture 1001 1 0001 1 0001

Overflow Detection and Effects Overflow: the result is too large to represent in the number of bits allocated When adding operands with different signs, overflow cannot occur! Overflow occurs when adding two positives yields a negative or, adding two negatives gives a positive or, subtract a negative from a positive gives a negative or, subtract a positive from a negative gives a positive On overflow, an exception (interrupt) occurs Control jumps to predefined address for exception Interrupted address (address of instruction causing the overflow) is saved for possible resumption Don't always want to detect (interrupt on) overflow Recalled from some earlier slides that the biggest positive number you can represent using 4-bit is 7 and the smallest negative you can represent is negative 8. So any time your addition results in a number bigger than 7 or less than negative 8, you have an overflow. Keep in mind is that whenever you try to add two numbers together that have different signs, that is adding a negative number to a positive number, overflow can NOT occur. Overflow occurs when you to add two positive numbers together and the sum has a negative sign. Or, when you try to add negative numbers together and the sum has a positive sign. If you spend some time, you can convince yourself that If the Carry into the most significant bit is NOT the same as the Carry coming out of the MSB, you have a overflow.

New MIPS Instructions Sign extend – addi, addiu, slti, sltiu Category Instr Op Code Example Meaning Arithmetic (R & I format) add unsigned 0 and 21 addu $s1, $s2, $s3 $s1 = $s2 + $s3 sub unsigned 0 and 23 subu $s1, $s2, $s3 $s1 = $s2 - $s3 add imm.unsigned 9 addiu $s1, $s2, 6 $s1 = $s2 + 6 Data Transfer ld byte unsigned 24 lbu $s1, 20($s2) $s1 = Mem($s2+20) ld half unsigned 25 lhu $s1, 20($s2) Cond. Branch (I & R format) set on less than unsigned 0 and 2b sltu $s1, $s2, $s3 if ($s2<$s3) $s1=1 else $s1=0 set on less than imm unsigned b sltiu $s1, $s2, 6 if ($s2<6) $s1=1 else similarity of the binary representation of related instructions simplifies the hardware design Sign extend – addi, addiu, slti, sltiu Zero extend – andi, ori, xori Overflow detected – add, addi, sub

Minimal Implementation of a Full Adder Gate library: inverters, 2-input nands, or-and-inverters architecture concurrent_behavior of full_adder is signal t1, t2, t3, t4, t5: std_logic; begin t1 <= not A after 1 ns; t2 <= not cin after 1 ns; t4 <= not((A or cin) and B) after 2 ns; t3 <= not((t1 or t2) and (A or cin)) after 2 ns; t5 <= t3 nand B after 2 ns; S <= not((B or t3) and t5) after 2 ns; cout <= not(t1 or t2) and t4) after 2 ns; end concurrent_behavior; Can you create the equivalent schematic? Can you determine worst case delay (the worst case timing path through the circuit)?

Tailoring the ALU to the MIPS ISA Also need to support the logic operations (and,nor,or,xor) Bit wise operations (no carry operation involved) Need a logic gate for each function and a mux to choose the output Also need to support the set-on-less-than instruction (slt) Uses subtraction to determine if (a – b) < 0 (implies a < b) Also need to support test for equality (bne, beq) Again use subtraction: (a - b) = 0 implies a = b Also need to add overflow detection hardware overflow detection enabled only for add, addi, sub Immediates are sign extended outside the ALU with wiring (i.e., no logic needed)

A Simple ALU Cell with Logic Op Support B add/subt 1-bit FA carry_in carry_out result op Old book shows the B input to the logic gates as the output of the inverter mux (xor in our case) . This way you can also get A and !B, A or !B, A xor !B (which is A xnor B) and !(A or !B) (which is !A and B) in addition to A and B, A or B, A xor B, and A nor B by setting the add/subt control correctly. wouldn’t it be better to pull it directly from the B input? Yes, so I modified the design from that presented in the (old) book. Leads to simplier decoding of m bits (to ALUlogic) to the add_subt and op control lines. how many bits does op need to be?

Modifying the ALU Cell for slt add/subt carry_in op A 1 2 result 3 1-bit FA 6 B less 7 add/subt carry_out

Modifying the ALU for slt B1 A0 B0 A31 B31 + result1 less result0 result31 . . . First perform a subtraction Make the result 1 if the subtraction yields a negative result Make the result 0 if the subtraction yields a positive result set tie the most significant sum bit (sign bit) to the low order less input For lecture

Modifying the ALU for Zero op add/subt Modifying the ALU for Zero A0 First perform subtraction Insert additional logic to detect when all result bits are zero result0 zero . . . B0 + less A1 result1 B1 + less . . . For lecture A31 result31 Note zero is a 1 when result is all zeros B31 + less set

Overflow Detection Overflow occurs when the result is too large to represent in the number of bits allocated adding two positives yields a negative or, adding two negatives gives a positive or, subtract a negative from a positive gives a negative or, subtract a positive from a negative gives a positive On your own: Prove you can detect overflow by: Carry into MSB xor Carry out of MSB For lecture Recalled from some earlier slides that the biggest positive number you can represent using 4-bit is 7 and the smallest negative you can represent is negative 8. So any time your addition results in a number bigger than 7 or less than negative 8, you have an overflow. Keep in mind is that whenever you try to add two numbers together that have different signs, that is adding a negative number to a positive number, overflow can NOT occur. Overflow occurs when you to add two positive numbers together and the sum has a negative sign. Or, when you try to add negative numbers together and the sum has a positive sign. If you spend some time, you can convince yourself that If the Carry into the most significant bit is NOT the same as the Carry coming out of the MSB, you have a overflow. 1 1 1 1 1 1 1 + 7 3 1 + –4 – 5 – 6 1 1 7

Modifying the ALU for Overflow op add/subt Modifying the ALU for Overflow A0 Modify the most significant cell to determine overflow output setting Enable overflow bit setting for signed arithmetic (add, addi, sub) result0 B0 + less A1 result1 B1 + . . . zero less . . . For slt (and slti and sltiu and sltu) “No integer overflow exception occurs under any circumstances. The comparison is valid even if the subtraction used during the comparison overflows.” The way I read this is that if the result overflows during the subtraction, no attempt is made to correct the set line to reflect that! Otherwise, you would need to add additional logic in front of the set line to do the correction in case of overflow. Like exoring the overflow bit with the sign bit. A31 result31 overflow + B31 less set

But What about Performance? Critical path of n-bit ripple-carry adder is n*CP Design trick – throw hardware at it (Carry Lookahead) CarryIn0 A0 1-bit ALU Result0 B0 CarryOut0 CarryIn1 A1 1-bit ALU Result1 B1 CarryOut1 CarryIn2 A2 1-bit ALU Result2 B2 CarryOut2 CarryIn3 A3 1-bit ALU Result3 B3 CarryOut3

More complicated than addition Multiplication More complicated than addition Can be accomplished via shifting and adding 0010 (multiplicand) x_1011 (multiplier) 0010 0010 (partial product 0000 array) 0010 00010110 (product) Double precision product produced More time and more area to compute

Add and Right Shift Multiplier Hardware 0 1 1 0 = 6 multiplicand add 32-bit ALU shift right product multiplier Control 0 0 0 0 0 1 0 1 = 5 add 0 1 1 0 0 1 0 1 0 0 1 1 0 0 1 0 For lecture add 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 1 add 0 1 1 1 1 0 0 1 0 0 1 1 1 1 0 0 add 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 = 30

MIPS Multiply Instruction Multiply (mult and multu) produces a double precision product mult $s0, $s1 # hi||lo = $s0 * $s1 Low-order word of the product is left in processor register lo and the high-order word is left in register hi Instructions mfhi rd and mflo rd are provided to move the product to (user accessible) registers in the register file 0 16 17 0 0 0x18 multu – does multiply unsigned Both multiplies ignore overflow, so its up to the software to check to see if the product is too big to fit into 32 bits. There is no overflow if hi is 0 for multu or the replicated sign of lo for mult. Multiplies are usually done by fast, dedicated hardware and are much more complex (and slower) than adders

Division Division is just a bunch of quotient digit guesses and left shifts and subtracts n n quotient dividend divisor partial remainder array remainder n

MIPS Divide Instruction Divide generates the reminder in hi and the quotient in lo div $s0, $s1 # lo = $s0 / $s1 # hi = $s0 mod $s1 Instructions mflo rd and mfhi rd are provided to move the quotient and reminder to (user accessible) registers in the register file op rs rt rd shamt funct Seems odd to me that the machine doesn’t support a double precision dividend in hi || lo but it looks like it doesn’t As with multiply, divide ignores overflow so software must determine if the quotient is too large. Software must also check the divisor to avoid division by 0.

Shift Operations Shifts move all the bits in a word left or right sll $t2, $s0, 8 #$t2 = $s0 << 8 bits srl $t2, $s0, 8 #$t2 = $s0 >> 8 bits sra $t2, $s0, 8 #$t2 = $s0 >> 8 bits op rs rt rd shamt funct Notice that a 5-bit shamt field is enough to shift a 32-bit value 25 – 1 or 31 bit positions Logical shifts fill with zeros, arithmetic left shifts fill with the sign bit An arithmetic shift (sra) maintain the arithmetic correctness of the shifted value (i.e., a number shifted right one bit should be ½ of its original value; a number shifted left should be 2 times its original value) The shift operation is implemented by hardware separate from the ALU using a barrel shifter (which would takes lots of gates in discrete logic, but is pretty easy to implement in VLSI)

Parallel Programmable Shifters Shift amount (Sh4Sh3Sh2Sh1Sh0) Shift direction (left, right) Shift type (logical, arithmetic) = Control Data Out Data In Shifting a data word left or right over a constant amount is a trivial hardware operation and is implemented by the appropriate signal wiring

Logarithmic Shifter Structure shifts of 0 or 1 bits !Sh0 Sh0 0,1 shifts shifts of 0 or 16 bits !Sh4 Sh4 0,1,2…31 shifts shifts of 0 or 8 bits !Sh3 Sh3 0,1,2…15 shifts shifts of 0 or 4 bits !Sh2 Sh2 0,1,2,3,4,5,6,7 shifts shifts of 0 or 2 bits !Sh1 Sh1 0,1,2,3 shifts Sh1 & right dataini dataouti dataini-2 dataini+2 Sh1 & left !Sh0 Sh0 & right dataini dataouti dataini-1 dataini+1 Sh0 & left !Sh0 Data Out Data In For lecture

Representing Big (and Small) Numbers What if we want to encode the approx. age of the earth? 4,600,000,000 or 4.6 x 109 or the weight in kg of one a.m.u. (atomic mass unit) 0.0000000000000000000000000166 or 1.6 x 10-27 There is no way we can encode either of the above in a 32-bit integer. Floating point representation (-1)sign x F x 2E Still have to fit everything in 32 bits (single precision) Notice that in scientific notation the mantissa is represented in normalized form (no leading zeros) s E (exponent) F (fraction) 1 bit 8 bits 23 bits The base (2, not 10) is hardwired in the design of the FPALU More bits in the fraction (F) or the exponent (E) is a trade-off between precision (accuracy of the number) and range (size of the number)

Exception Events in Floating Point Overflow (floating point) happens when a positive exponent becomes too large to fit in the exponent field Underflow (floating point) happens when a negative exponent becomes too large to fit in the exponent field One way to reduce the chance of underflow or overflow is to offer another format that has a larger exponent field Double precision – takes two MIPS words s E (exponent) F (fraction) 1 bit 11 bits 20 bits F (fraction continued) 32 bits

IEEE 754 FP Standard Most (all?) computers these days conform to the IEEE 754 floating point standard (-1)sign x (1+F) x 2E-bias Formats for both single and double precision F is stored in normalized format where the msb in F is 1 (so there is no need to store it!) – called the hidden bit To simplify sorting FP numbers, E comes before F in the word and E is represented in excess (biased) notation where the bias is -127 (-1023 for double precision) so the most negative is 00000001 = 21-127 = 2-126 and the most positive is 11111110 = 2254-127 = 2+127 Examples (in normalized format) Smallest+: 0 00000001 1.00000000000000000000000 = 1 x 21-127 Zero: 0 00000000 00000000000000000000000 = true 0 Largest+: 0 11111110 1.11111111111111111111111 = 2-2-23 x 2254-127 1.02 x 2-1 = 0.7510 x 24 = Book distinguishes between the representation with the hidden bit there – significand (the 24 bit version) , and the one with the hidden bit removed – fraction (the 23 bit version) .75 = 0.11 base 2 = 1.1 and decrement the exponent base 2 Excess exponents (128 64 32 16 8 4 2 1) 0000 0000 reserved for true zero (with F=0) or denorms (with F != 0) 0000 0001 1-127 so -126 0000 0010 2-127 so -125 … 0111 1101 125-127 so -2 0111 1110 126-127 so -1 0111 1111 127-127 so 0 (e.g., so can represent 1 x 2^0 ) 1000 0000 128-127 so +1 1000 0001 129-127 so +2 1000 0010 130-127 so +3 1111 1110 254-127 so +127 1111 1111 255-127 so +128, but reserved for infinity with F = 0 and NAN with F != 0 0 01111110 1.00000000000000000000000 0 10000010 1.10000000000000000000000

Wrap-Up We can build an ALU to support the MIPS ISA we can efficiently perform subtraction using two’s complement we can replicate a 1-bit ALU to produce a 32-bit ALU Important points about hardware all of the gates are always working (concurrent) the speed of a gate is affected by the number of inputs to the gate (fan-in) and the number of gates that the output is connected to (fan-out) the speed of a circuit is affected by the speed of and number of gates in series (on the “critical path” or the “number of levels of logic”) and the length of wires interconnecting the gates Our primary focus is comprehension, however, clever changes to organization can improve performance (similar to using better algorithms in software)