Integer Arithmetic. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Similar documents
Arithmetic for Computers. Hwansoo Han

Thomas Polzer Institut für Technische Informatik

Chapter 3. Arithmetic Text: P&H rev

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

TDT4255 Computer Design. Lecture 4. Magnus Jahre

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

Chapter 3. Arithmetic for Computers

Chapter 3. Arithmetic for Computers

COMPUTER ORGANIZATION AND DESIGN

Tailoring the 32-Bit ALU to MIPS

EEC 483 Computer Organization

Lecture 8: Addition, Multiplication & Division

Chapter 3. Arithmetic for Computers

Boolean Algebra. Chapter 3. Boolean Algebra. Chapter 3 Arithmetic for Computers 1. Fundamental Boolean Operations. Arithmetic for Computers

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

Fast Arithmetic. Philipp Koehn. 19 October 2016

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

ECE260: Fundamentals of Computer Engineering

Chapter 3 Arithmetic for Computers (Part 2)

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Integer Multiplication and Division

MIPS Integer ALU Requirements

Arithmetic for Computers

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

Signed Multiplication Multiply the positives Negate result if signs of operand are different

ECE331: Hardware Organization and Design

ECE331: Hardware Organization and Design

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: The MIPS ISA (P&H ) Consulting hours. Milestone #1 (due 1/26)

Number Systems and Their Representations

Review: MIPS Organization

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Chapter Two MIPS Arithmetic

Floating Point Arithmetic

Computer Architecture. Chapter 3: Arithmetic for Computers

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

CPS 104 Computer Organization and Programming

COMP 303 Computer Architecture Lecture 6

ECE331: Hardware Organization and Design

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

ECE 30 Introduction to Computer Engineering

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

The Processor (1) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 3. Arithmetic for Computers

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

EECS150 - Digital Design Lecture 13 - Combinational Logic & Arithmetic Circuits Part 3

Integer Multiplication and Division

Review of Last lecture. Review ALU Design. Designing a Multiplier Shifter Design Review. Booth s algorithm. Today s Outline

Chapter 3 Arithmetic for Computers

Chapter 3: Arithmetic for Computers

Arithmetic for Computers. Integer Addition. Chapter 3

Number Systems and Computer Arithmetic

Divide: Paper & Pencil

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner. Topic 3: Arithmetic

Integer Subtraction. Chapter 3. Overflow conditions. Arithmetic for Computers. Signed Addition. Integer Addition. Arithmetic for Computers

xx.yyyy Lecture #11 Floating Point II Summary (single precision): Precision and Accuracy Fractional Powers of 2 Representation of Fractions

IEEE Standard 754 for Binary Floating-Point Arithmetic.

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Chapter 3 Arithmetic for Computers

COMPUTER ORGANIZATION AND. Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

CENG3420 L05: Arithmetic and Logic Unit

CS61C : Machine Structures

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

Computer Architecture Set Four. Arithmetic

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

Midterm I March 12, 2003 CS152 Computer Architecture and Engineering

MIPS Instruction Set Architecture (1)

Module 2: Computer Arithmetic

MIPS Instruction Set

M2 Instruction Set Architecture

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

Chapter 5: Computer Arithmetic

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b;

CENG 3420 Lecture 05: Arithmetic and Logic Unit

Assembly Programming

MIPS Instruction Format

Arithmetic. Chapter 3 Computer Organization and Design

Review from last time. CS152 Computer Architecture and Engineering Lecture 6. Verilog (finish) Multiply, Divide, Shift

Part III The Arithmetic/Logic Unit. Oct Computer Architecture, The Arithmetic/Logic Unit Slide 1

Chapter 5 : Computer Arithmetic

COMPUTER ARITHMETIC (Part 1)

CSE 141 Computer Architecture Summer Session Lecture 3 ALU Part 2 Single Cycle CPU Part 1. Pramod V. Argade

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

The MIPS Instruction Set Architecture

Computer Architecture. The Language of the Machine

Chapter Three. Arithmetic

Chapter 3 Arithmetic for Computers

More complicated than addition. Let's look at 3 versions based on grade school algorithm (multiplicand) More time and more area

We are quite familiar with adding two numbers in decimal

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Today s Outline. CS152 Computer Architecture and Engineering Lecture 5. VHDL, Multiply, Shift

Transcription:

Integer Arithmetic Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Where Are We? Abstraction Layers in Modern Systems Scope of this course Application Algorithm Programming Language Operating System/Virtual Machine Instruction Set Architecture (ISA) Microarchitecture Gates/Register-Transfer Level (RTL) Circuits Devices Physics SW (HW/SW Interface) Ch. 2 Ch. 3, 4 and 5 HW * Sources: CS 252 lecture notes from Prof. Kubiatowicz (UC Berkeley). Coursera lecture notes for HW/SW Interface from Profs. Borriello and Ceze (Univ. of Washington). EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 2

Introduction Bits are just bits No inherent meaning: conventions define relationship between bits and numbers n-bit binary numbers: 0 ~ 2 n -1 decimal numbers Of course it gets more complicated Numbers are finite (overflow) Negative numbers Fractions and real numbers Precision and accuracy Error propagation,... EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 3

Arithmetic for Computers: An Overview Operations on integers Textbook: P&H 3.1-3.4 (for both 4 th and 5 th Editions) Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Textbook: P&H 3.5 Representation and operations EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 4

Integer Addition & Subtraction EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Integer Addition 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 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 6

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 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 7

Simple Adder (n-bit ripple-carry adder) n-bit ripple-carry adder EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 8

Dealing with Overflow 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 reg) instruction can retrieve EPC value, to return after corrective action EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 9

Arithmetic for Multimedia Graphics and media processing Operates on vectors of 8-bit and 16-bit data Use 64-bit adder, with partitioned carry chain Operate on 8 8-bit, 4 16-bit, or 2 32-bit vectors SIMD (single-instruction, multiple-data) Saturating operations On overflow, result is largest representable value c.f. 2s-complement modulo arithmetic E.g., clipping in audio, saturation in video EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 10

Integer Multiplication EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Multiplication Start with long-multiplication approach multiplicand multiplier product 1000 1001 1000 0000 0000 1000 1001000 Length of product is the sum of operand lengths EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 12

Multiplication Hardware Initially 0 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 13

Optimized Multiplier Perform steps in parallel: add/shift One cycle per partial-product addition That s ok, if frequency of multiplications is low EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 14

Faster Multiplier Uses multiple adders Cost/performance tradeoff Can be pipelined Several multiplication performed in parallel EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 15

MIPS Multiplication Two 32-bit registers for product HI: most-significant 32 bits LO: least-significant 32-bits Instructions mult rs, rt / multu rs, rt 64-bit product in HI/LO mfhi rd / mflo rd Move from HI/LO to rd Can test HI value to see if product overflows 32 bits mul rd, rs, rt Least-significant 32 bits of product > rd EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 16

Integer Division EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Division divisor quotient dividend remainder 1001 1000 1001010-1000 10 101 1010-1000 10 n-bit operands yield n-bit quotient and remainder 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 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 18

Division Hardware Initially divisor i n left half Initially dividend EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 19

Optimized Divider One cycle per partial-remainder subtraction Looks a lot like a multiplier! Same hardware can be used for both EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 20

Faster Division Can t use parallel hardware as in multiplier Subtraction is conditional on sign of remainder Faster dividers (e.g. SRT devision) generate multiple quotient bits per step Still require multiple steps EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 21

MIPS Division Use HI/LO registers for result HI: 32-bit remainder LO: 32-bit quotient Instructions div rs, rt / divu rs, rt No overflow or divide-by-0 checking Software must perform checks if required Use mfhi, mflo to access result EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 22