ALU Architecture and ISA Extensions

Slides:



Advertisements
Similar presentations
Morgan Kaufmann Publishers Arithmetic for Computers
Advertisements

Spring 2013 Advising Starts this week! CS2710 Computer Organization1.
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
Computer Organization CS224 Fall 2012 Lesson 19. Floating-Point Example  What number is represented by the single-precision float …00 
Chapter 3 Arithmetic for Computers. Exam 1 CSCE
Lecture 15: Computer Arithmetic Today’s topic –Division 1.
Lecture Objectives: 1)Perform binary division of two numbers. 2)Define dividend, divisor, quotient, and remainder. 3)Explain how division is accomplished.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Lecture 9 Sept 28 Chapter 3 Arithmetic for Computers.
1  2004 Morgan Kaufmann Publishers Chapter Three.
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
1 ECE369 Chapter 3. 2 ECE369 Multiplication More complicated than addition –Accomplished via shifting and addition More time and more area.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
ALU Architecture and ISA Extensions Lecture notes from MKP, H. H. Lee and S. Yalamanchili.
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computing Systems Basic arithmetic for computers.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
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.
CSF 2009 Arithmetic for Computers Chapter 3. Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing.
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
Chapter 3 Arithmetic for Computers (Integers). Florida A & M University - Department of Computer and Information Sciences Arithmetic for Computers Operations.
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Chapter 3 Arithmetic for Computers. Chapter 3 — Arithmetic for Computers — 2 Arithmetic for Computers Operations on integers Addition and subtraction.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers.
Division Check for 0 divisor Long division approach – If divisor ≤ dividend bits 1 bit in quotient, subtract – Otherwise 0 bit in quotient, bring down.
CDA 3101 Spring 2016 Introduction to Computer Organization
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
Arithmetic for Computers Chapter 3 1. Arithmetic for Computers  Operations on integers  Addition and subtraction  Multiplication and division  Dealing.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
/ Computer Architecture and Design
Computer System Design Lecture 3
More Binary Arithmetic - Multiplication
Computer Architecture & Operations I
Computer Arthmetic Chapter Four P&H.
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
Morgan Kaufmann Publishers Arithmetic for Computers
/ Computer Architecture and Design
Morgan Kaufmann Publishers Arithmetic for Computers
Morgan Kaufmann Publishers
/ Computer Architecture and Design
Morgan Kaufmann Publishers
Ch 3: Computer Arithmetic
CDA 3101 Summer 2007 Introduction to Computer Organization
William Stallings Computer Organization and Architecture 7th Edition
Arithmetic for Computers
CS352H: Computer Systems Architecture
CSCE 350 Computer Architecture
Computer Architecture Computer Science & Engineering
Arithmetic Logical Unit
Computer Arithmetic Multiplication, Floating Point
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
Morgan Kaufmann Publishers Arithmetic for Computers
Presentation transcript:

ALU Architecture and ISA Extensions Lecture notes from MKP, H. H. Lee and S. Yalamanchili

Reading Sections 3.2-3.5 (only those elements covered in class) Appendix B.5 Practice Problems: 26, 27 Goal: Understand the ISA view of the core microarchitecture Time, space, energy Organization of functional units and register files into basic data path blocks

Overview Instruction Set Architectures have a purpose Applications dictate what we need We only have a fixed number of bits Impact on accuracy More is not better We cannot afford everything we want Basic Arithmetic Logic Unit (ALU) Design Addition/subtraction, multiplication, division

Reminder: ISA Who sees what? 0x00 0x01 0x02 0x03 0x1F 0xFFFFFFFF byte addressed memory Register File (Programmer Visible State) Memory Interface stack 0x00 0x01 0x02 0x03 Processor Internal Buses 0x1F Dynamic Data Data segment (static) Text Segment Programmer Invisible State Reserved 0xFFFFFFFF Program Counter Instruction register Arithmetic Logic Unit (ALU) Memory Map Kernel registers Who sees what?

Arithmetic for Computers Morgan Kaufmann Publishers 17 February, 2018 Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Operation on floating-point real numbers Representation and operations Let us first look at integers Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 Integer Addition(3.2) Example: 7 + 6 Overflow if result out of range Adding +ve and –ve operands, no overflow Adding two +ve operands Overflow if result sign is 1 Adding two –ve operands Overflow if result sign is 0 Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 Integer Subtraction Add negation of second operand Example: 7 – 6 = 7 + (–6) +7: 0000 0000 … 0000 0111 –6: 1111 1111 … 1111 1010 +1: 0000 0000 … 0000 0001 Overflow if result out of range Subtracting two +ve or two –ve operands, no overflow Subtracting +ve from –ve operand Overflow if result sign is 0 Subtracting –ve from +ve operand Overflow if result sign is 1 2’s complement representation Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 ISA Impact Some languages (e.g., C) ignore overflow Use MIPS addu, addui, subu instructions Other languages (e.g., Ada, Fortran) require raising an exception Use MIPS add, addi, sub instructions On overflow, invoke exception handler Save PC in exception program counter (EPC) register Jump to predefined handler address mfc0 (move from coprocessor register) instruction can retrieve EPC value, to return after corrective action (more later) ALU Design leads to many solutions. We look at one simple example Chapter 3 — Arithmetic for Computers

ISA View Register-to-Register data path CPU/Core $0 $1 $31 ALU Register-to-Register data path We want this to be as fast as possible

Multiplication (3.3) Long multiplication 1000 × 1001 0000 1001000 multiplicand 1000 × 1001 0000 1001000 multiplier product Length of product is the sum of operand lengths

Morgan Kaufmann Publishers 17 February, 2018 A Multiplier Uses multiple adders Cost/performance tradeoff Can be pipelined Several multiplication performed in parallel Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 Division(3.4) Check for 0 divisor Long division approach If divisor ≤ dividend bits 1 bit in quotient, subtract Otherwise 0 bit in quotient, bring down next dividend bit Restoring division Do the subtract, and if remainder goes < 0, add divisor back Signed division Divide using absolute values Adjust sign of quotient and remainder as required quotient dividend 1001 1000 1001010 -1000 10 101 1010 divisor remainder n-bit operands yield n-bit quotient and remainder Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 Faster Division Can’t use parallel hardware as in multiplier Subtraction is conditional on sign of remainder Faster dividers (e.g. SRT division) generate multiple quotient bits per step Still require multiple steps Customized implementations for high performance, e.g., supercomputers Chapter 3 — Arithmetic for Computers

ISA View Additional function units and registers (Hi/Lo) CPU/Core $0 $1 $31 ALU Multiply Divide Hi Lo Additional function units and registers (Hi/Lo) Additional instructions to move data to/from these registers mfhi, mflo What other instructions would you add? Cost?

Morgan Kaufmann Publishers 17 February, 2018 Floating Point(3.5) Representation for non-integral numbers Including very small and very large numbers Like scientific notation –2.34 × 1056 +0.002 × 10–4 +987.02 × 109 In binary ±1.xxxxxxx2 × 2yyyy Types float and double in C normalized not normalized Chapter 3 — Arithmetic for Computers

IEEE 754 Floating-point Representation Single Precision (32-bit) 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 S exponent significand 1bit 8 bits 23 bits (–1)sign x (1+fraction) x 2exponent-127 Double Precision (64-bit) 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 S exponent significand 1bit 11 bits 20 bits significand (continued) 32 bits (–1)sign x (1+fraction) x 2exponent-1023

Floating Point Standard Morgan Kaufmann Publishers 17 February, 2018 Floating Point Standard Defined by IEEE Std 754-1985 Developed in response to divergence of representations Portability issues for scientific code Now almost universally adopted Two representations Single precision (32-bit) Double precision (64-bit) Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 FP Adder Hardware Much more complex than integer adder Doing it in one clock cycle would take too long Much longer than integer operations Slower clock would penalize all instructions FP adder usually takes several cycles Can be pipelined Example: FP Addition Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 FP Adder Hardware Step 1 Step 2 Step 3 Step 4 Chapter 3 — Arithmetic for Computers

FP Arithmetic Hardware Morgan Kaufmann Publishers 17 February, 2018 FP Arithmetic Hardware FP multiplier is of similar complexity to FP adder But uses a multiplier for significands instead of an adder FP arithmetic hardware usually does Addition, subtraction, multiplication, division, reciprocal, square-root FP  integer conversion Operations usually takes several cycles Can be pipelined Chapter 3 — Arithmetic for Computers

Morgan Kaufmann Publishers 17 February, 2018 ISA Impact FP hardware is coprocessor 1 Adjunct processor that extends the ISA Separate FP registers 32 single-precision: $f0, $f1, … $f31 Paired for double-precision: $f0/$f1, $f2/$f3, … Release 2 of MIPs ISA supports 32 × 64-bit FP reg’s FP instructions operate only on FP registers Programs generally do not perform integer ops on FP data, or vice versa More registers with minimal code-size impact Chapter 3 — Arithmetic for Computers

ISA View: The Co-Processor ALU Hi Multiply Divide Lo $0 $1 $31 FP ALU BadVaddr Status Causes EPC CPU/Core Co-Processor 1 Co-Processor 0 later Floating point operations access a separate set of 32-bit registers Pairs of 32-bit registers are used for double precision

Morgan Kaufmann Publishers 17 February, 2018 Associativity Floating point arithmetic is not commutative Parallel programs may interleave operations in unexpected orders Assumptions of associativity may fail Need to validate parallel programs under varying degrees of parallelism Chapter 3 — Arithmetic for Computers

Performance Issues Latency of instructions Integer instructions can take a single cycle Floating point instructions can take multiple cycles Some (FP Divide) can take hundreds of cycles What about energy (we will get to that shortly) What other instructions would you like in hardware? Would some applications change your mind? How do you decide whether to add new instructions?

Domain Impact on the ISA: Example Scientific Computing Embedded Systems Integers Lower precision Streaming data Security support Energy constrained Floats Double precision Massive data Power constrained

Summary ISAs support operations required of application domains Note the differences between embedded and supercomputers! Signed, unsigned, FP, etc. Bounded precision effects Software must be careful how hardware used e.g., associativity Need standards to promote portability Avoid “kitchen sink” designs There is no free lunch Impact on speed and energy  we will get to this later

Study Guide Perform 2’s complement addition and subtraction (review) Add a few more instructions to the simple ALU Add an XOR instruction Add an instruction that returns the max of its inputs Make sure all control signals are accounted for Convert real numbers to single precision floating point (review) and extract the value from an encoded single precision number (review) Execute the programs (class website) that use floating point numbers. Study the memory/register contents via single step execution

Study Guide (cont.) Write a few simple programs for Multiplication/division of signed and unsigned numbers Use numbers that produce >32-bit results Move to/from HI and LO registers ( find the instructions for doing so) Addition/subtraction of floating point numbers Try to write a simple program that demonstrates that floating point operations are not associative (this takes some thought and review of the range of floating point numbers)

Glossary Co-processor Instruction set extensions Overflow Precision Signed arithmetic support Unsigned arithmetic support

Backup

Integer ALU (arithmetic logic unit)(B.5) Build a 1 bit ALU, and use 32 of them (bit-slice) operation result op a b res a b

Single Bit ALU Implements only AND and OR operations Operation Result Result A 1 B

Adding Functionality We can add additional operators (to a point) How about addition? Review full adders from digital design cout = ab + acin + bcin sum = a  b  cin

Building a 32-bit ALU

Subtraction (a – b) ? Two's complement approach: just negate b and add 1. How do we negate? A clever solution: sub B i n v e r t b 3 1 2 R s u l a C y I O p o A L U

Tailoring the ALU to the MIPS Need to support the set-on-less-than instruction(slt) remember: slt is an arithmetic instruction produces a 1 if rs < rt and 0 otherwise use subtraction: (a-b) < 0 implies a < b Need to support test for equality (beq $t5, $t6, $t7) use subtraction: (a-b) = 0 implies a = b

What Result31 is when (a-b)<0? 3 R e s u l t O p r a i o n 1 C y I B v b 2 L Unsigned vs. signed support

Test for equality Notice control lines: 000 = and 001 = or 010 = add 110 = subtract 111 = slt Note: zero is a 1 when the result is zero! Note test for overflow!