Iterative Division

download Iterative Division

of 15

Transcript of Iterative Division

  • 7/27/2019 Iterative Division

    1/15

    1

    ECE366

    ComputerArchitecture

    Instructor:ShantanuDutt

    Departmento

    fElectricalandCo

    mputerEn

    gineering

    UniversityofIllinoisatChicago

    LectureNotes#

    13

    CO

    MPUTERARITH

    METIC:

    Ite

    rativeDivisionTechniques

    cShantanuDutt,UIC

    1

  • 7/27/2019 Iterative Division

    2/15

    2

    DivisionBas

    ics

    Rad

    ix

    divisionisess

    entiallyatrial-and-errorprocess,inw

    hichthenext

    quo

    tientbitischosenfrom

    Exa

    mple:

    Binarydivisionismuchsim

    pler,sincethenextquotientbitiseithera0

    or1

    dependin

    gonwh

    etherthepartialremainderislessthanor

    greater

    than

    /equaltothedivisor,respectively

    Inte

    gerdivision:Give

    n2integers

    the

    dividendand

    thedivisor,we

    wan

    ttoobtainanintegerquotient

    and

    anintegerremaind

    er

    ,s.t.

    Inte

    gerFPdivision:G

    iven2integers

    thedividendand

    thedivisor,

  • 7/27/2019 Iterative Division

    3/15

    3

    wewanttoobtainafloating-point(FP)o

    rrealquotient

    s.t.

    We

    willtalkaboutdivisionofunsignedn

    umbersfirst

    cShantanuDutt,UIC

    3

  • 7/27/2019 Iterative Division

    4/15

    4

    Div

    isionSHR-DivisorMethod

    Startsubtractionof

    fromleftmostp

    ositionof

    ;SHR

    fornext

    subtractioneveryitera

    tion

    Pen

    cil-paperdivisionexam

    ple:

    cShantanuDutt,UIC

    4

  • 7/27/2019 Iterative Division

    5/15

    5

    Division

    SHL-Partial-Rem

    ainderMethod

    Inst

    eadofshiftingthe

    divisorrightby1

    bit,thepartialrem

    aindercanbe

    shif

    tedleftbyonebit

    Exa

    mple:

    cShantanuDutt,UIC

    5

  • 7/27/2019 Iterative Division

    6/15

    6

    DivisionHandling

    with0s

    inHigh-OrderBits

    Ano

    therExam

    ple:Somehigherorderbitsofthe

    -bitdivis

    or

    are0s:

    Not

    ethat

    isstoredasa4-bit#(0010)in

    thecom

    puter.Thetypeofman-

    ualadjustmentdonein

    theaboveexampleofconverting4-bitsubtractions

    into

    2-bitones(ingeneral,

    -bitsubtractionsto

    -bitones,

    where

    )

    isnotpossibleinacom

    puter

    cShantanuDutt,UIC

    6

  • 7/27/2019 Iterative Division

    7/15

    7

    DivisionHandl

    ing

    with0sinH

    igh-OrderBits(contd.)

    Problemwith

    havinghi

    gherorderbitsas

    0s:

    Twowaystotacklethepr

    oblem:

    Method1:Shift

    totheleftby

    bits(untilitsMSBisa1),dothe

    divisionfor

    stepsfo

    raninteger

    (mo

    restepsforaFP

    )

    Examp

    le:

    cShantanuDutt,UIC

    7

  • 7/27/2019 Iterative Division

    8/15

    8

    DivisionHandl

    ing

    with0sinH

    igh-OrderBits(contd.)

    Problemwith

    havinghi

    gherorderbitsas

    0s:

    Method2:Augment

    totheleftby

    bitsthatareall0s.Perform

    divisionfor

    stepsforan

    integer

    andmorestepsforaFP

    Examp

    le:

    Thisis

    thetypeofdivisionalgorithmusedinacomputer

    cShantanuDutt,UIC

    8

  • 7/27/2019 Iterative Division

    9/15

    9

    DivisionACa

    veat

    Examp

    leforneedin

    gane

    xtrabittotheleftofthedividendtocatcha1ona

    shiftleft(requiredwheno

    riginally

    hasmorebitsthan

    (e.g.,dividingan

    8-bitnumberbya6-bitone):

    ThusneedanextrabitinACistocatcha1outofACwhentheMSBsofthe

    partial

    remainder

    and

    areboth1sbut

    !

  • 7/27/2019 Iterative Division

    10/15

    10

    Thead

    der/subtracterthusalsoneedstobe

    bits;seeb

    lockdiagram

    ofdividergivennext.

    NOTE:

    Theextrabitisneverrequiredwhenboth

    and

    havethesame

    number

    ofbitstostart

    with(thisdoesno

    tcountthe

    bitsthatare

    addedlaterto

    ).

    cShantanuDutt,UIC

    10

  • 7/27/2019 Iterative Division

    11/15

    11

    Divis

    ionCompleteAl

    gorithm#1

    Sim

    ple

    restoringdivision

    algorithm:

    Accum

    ulator

    Q

    M

    Cout

    1

    1

    1

    17

    17bitAdd/Sub

    DividendD

    DivisorV

    XOR

    1

    7

    17

    17

    Serial

    divisionfor16bitunsignednumbers

    T

    FromControlUnit

    FromCo

    ntrolUnit

    1.Tocompute

    "

    ,store

    inthe

    register,

    inthe

    #

    registerand

    0in

    AC(Accumulator

    ),and0in

    $

    (holdsthequotientbitbeforetheshift

    left).Notethat

    isa

    n

    -bitregister,w

    hile#

    and%

    &

    are

    '

    ( -bit

    ones,with0sinitially

    intheir'

    ( th

    bits.

    Rep

    eatthefollowings

    teps

    times:

    2.ShiftAC-Q-Tregister

    combinationleft1bit(initially,this

    hastheeffect

    ofa

    ddingon

    0s

    totheleftofthedividend)

    3.Perform

    %

    &

    %

    &

    (subtractdivisorfrom

    '

    ( -bitpartialremainder

    )

  • 7/27/2019 Iterative Division

    12/15

    12

    4.Ifth

    eresultisnegative,set

    $

    ,otherw

    iseset

    $

    5.Iftheresultofstep2

    isnegative,restor

    etheoldvalueof

    ACbydoin

    g

    %

    &

    %

    &

    NOTE:

    Noticesimilaritybetweenhardware

    forA&Smultiplic

    ationanddi-

    vision.

    Thesamehardwarewithadditiona

    lcontrolcanbeu

    sedforboth

    purposes.

    cShantanuDutt,UIC

    12

  • 7/27/2019 Iterative Division

    13/15

    13

    Divis

    ionCompleteAl

    gorithm#2

    Non-re

    storingdivisionalgorithm:Anextraadditionstepisneededinthe

    previou

    salgorithmtorestoretheoldvalueof%

    &

    whenthere

    sultofasub-

    tractionisnegative.Thisstepiseliminatedinnon-restoringdivision:

    1.Sam

    einitializationasbefore.

    Rep

    eatthefollowings

    teps

    times:

    2.ShiftAC-Q-Tregister

    combinationleft1

    bit

    3.IfcurrentQ[0]is0andthisisnotthe1st

    iteration

    then

    perform%

    &

    %

    &

    else

    perform%

    &

    %

    &

    4.Ifth

    eresultisnegative,set

    $

    ,otherw

    iseset

    $

    Thisworksbecause:Let

    bethecontentso

    fregisterAC-Qat

    thebeginning

    ofthe

    )

    thiteration.AfteraSHLandsubtrac

    tion,0

    isco

    mputed.

    Inrestoringdivision:Ifth

    isresult(

    0

    )is-ve,restorationandthenan-

    othersubtractioninthenextiteration

    givesus1

    .

  • 7/27/2019 Iterative Division

    14/15

    14

    Innon-restoringdivision:Iftheresultofthepreviousiteration

    (0

    )is

    -ve,we

    donotrestorebutinthe

    '

    )

    (thiterationweperform

    aSHLtoget

    1

    0

    andthenaddto

    get1

    .This

    givesusthesameresultinAC-Q

    asinre

    storingdivision,andbasedonthissa

    meresultwedeter

    minethenext

    bitoft

    hequotient.Thus

    non-restoringdivisionwill

    giveusthesamequo-

    tientas

    restorin

    gdivision

    ,thoughfaster.Th

    usnon-restoringd

    ivisionworks

    correctlysincerestoringd

    ivisioniscorrect.

    cShantanuDutt,UIC

    14

  • 7/27/2019 Iterative Division

    15/15

    15

    Twos

    ComplementDivision(contd.)

    The

    rearenosimpledivisionalgorithmsfor2scomplement#sunlikethe

    caseformultiplication

    Thisisprimarilyduetothedifficultyins

    electingthequotientbitsinsuch

    awaythatithastthec

    orrect+veor-ve2

    scom

    plementrep

    resentation

    Thu

    stheapproach

    gen

    erallyfollowedis

    tonegatea-ve

    or

    ,perform

    divisionandthennega

    tethequotientifo

    nlyoneof

    or

    was-ve

    Am

    oreefficientdivisionalgorithmfor

    2scom

    plement#sistheSRT

    met

    hod(forSweeney,

    RobertsonandTocher,itsinventors);seeRef.text

    #1

    (HenneseyandPatterson)forthisalg

    orithmifinterested

    cShantanuDutt,UIC

    15