cs:app3e cs:app chapter 4 computer architecture logic design cs:app chapter 4 computer architecture...

27
– 1 – CS:APP3e CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat Manguoglu Adapted from slides of the textbook: http://csapp.cs.cmu.edu/

Upload: austin-miles

Post on 19-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

CS:APP3e

CS:APP Chapter 4Computer Architecture

Logic Design

CS:APP Chapter 4Computer Architecture

Logic Design

CENG331 - Computer Organization

Murat Manguoglu

Adapted from slides of the textbook: http://csapp.cs.cmu.edu/

Page 2: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 2 – CS:APP3e

Overview of Logic DesignOverview of Logic Design

Fundamental Hardware Requirements Communication

How to get values from one place to another Computation Storage

Bits are Our Friends Everything expressed in terms of values 0 and 1 Communication

Low or high voltage on wire Computation

Compute Boolean functions Storage

Store bits of information

Page 3: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 3 – CS:APP3e

Digital SignalsDigital Signals

Use voltage thresholds to extract discrete values from continuous signal

Simplest version: 1-bit signalEither high range (1) or low range (0)With guard range between them

Not strongly affected by noise or low quality circuit elementsCan make circuits simple, small, and fast

Voltage

Time

0 1 0

Page 4: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 4 – CS:APP3e

Computing with Logic GatesComputing with Logic Gates

Outputs are Boolean functions of inputs Respond continuously to changes in inputs

With some, small delay

ab out

ab out a out

out = a && b out = a || b out = !a

And Or Not

Voltage

Time

a

ba && b

Rising Delay Falling Delay

Page 5: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 5 – CS:APP3e

Combinational CircuitsCombinational Circuits

Acyclic Network of Logic Gates Continously responds to changes on primary inputs Primary outputs become (after some delay) Boolean

functions of primary inputs

Acyclic Network

PrimaryInputs

PrimaryOutputs

Page 6: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 6 – CS:APP3e

Bit EqualityBit Equality

Generate 1 if a and b are equal

Hardware Control Language (HCL) Very simple hardware description language

Boolean operations have syntax similar to C logical operations We’ll use it to describe control logic for processors

Bit equala

b

eqbool eq = (a&&b)||(!a&&!b)

HCL Expression

Page 7: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 7 – CS:APP3e

Word EqualityWord Equality

64-bit word size HCL representation

Equality operationGenerates Boolean value

b63Bit equal

a63

eq63

b62Bit equal

a62

eq62

b1Bit equal

a1

eq1

b0Bit equal

a0

eq0

Eq

==B

A

Eq

Word-Level Representation

bool Eq = (A == B)

HCL Representation

Page 8: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 8 – CS:APP3e

Bit-Level MultiplexorBit-Level Multiplexor

Control signal s Data signals a and b Output a when s=1, b when s=0

Bit MUX

b

s

a

out

bool out = (s&&a)||(!s&&b)

HCL Expression

Page 9: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 9 – CS:APP3e

Word MultiplexorWord Multiplexor

Select input word A or B depending on control signal s

HCL representationCase expressionSeries of test : value pairsOutput value for first

successful test

Word-Level Representation

HCL Representation

b63

s

a63

out63

b62

a62

out62

b0

a0

out0

int Out = [ s : A; 1 : B;];

s

B

AOutMUX

Page 10: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 10 – CS:APP3e

HCL Word-Level ExamplesHCL Word-Level Examples

Find minimum of three input words

HCL case expression Final case guarantees

match

AMin3MIN3B

Cint Min3 = [ A < B && A < C : A; B < A && B < C : B; 1 : C;];

D0

D3

Out4

s0s1

MUX4D2D1

Select one of 4 inputs based on two control bits

HCL case expression Simplify tests by

assuming sequential matching

int Out4 = [ !s1&&!s0: D0; !s1 : D1; !s0 : D2; 1 : D3;];

Minimum of 3 Words

4-Way Multiplexor

Page 11: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 11 – CS:APP3e

OFZFCF

OFZFCF

OFZFCF

OFZFCF

Arithmetic Logic UnitArithmetic Logic Unit

Combinational logicContinuously responding to inputs

Control signal selects function computedCorresponding to 4 arithmetic/logical operations in Y86-64

Also computes values for condition codes

ALU

Y

X

X + Y

0

ALU

Y

X

X - Y

1

ALU

Y

X

X & Y

2

ALU

Y

X

X ^ Y

3

A

B

A

B

A

B

A

B

Page 12: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 12 – CS:APP3e

V1

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Vin

V1

Storing 1 BitStoring 1 BitBistable Element

Q+

Q–

q

!q

q = 0 or 1

Vin V1

V2

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Vin

V1

V2

Page 13: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 13 – CS:APP3e

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Vin

V1

V2

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Vin

Vin

V2

Storing 1 Bit (cont.)Storing 1 Bit (cont.)Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Vin V1

V2

Vin V1

V2

Vin = V2

Stable 0

Stable 1

Metastable

Page 14: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 14 – CS:APP3e

Physical AnalogyPhysical Analogy

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Vin

V1

V2

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Vin

Vin

V2

Stable 0

Stable 1

Metastable

.Stable left

. Stable right.

Metastable

Page 15: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 15 – CS:APP3e

Storing and Accessing 1 BitStoring and Accessing 1 Bit

Q+

Q–

R

S

R-S Latch (Flip-Flop)

Resetting

1

0

1 0

0 1

Setting

0

1

0 1

1 0

Storing

0

0

!q q

q !q

Bistable Element

Q+

Q–

q

!q

q = 0 or 1

Page 16: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 16 – CS:APP3e

1-Bit Latch (Flip-Flop)1-Bit Latch (Flip-Flop)D Latch

Q+

Q–

R

S

D

C

Data

Clock

Latching

1

d !d !d !d d

d d !d0

Storing

d !d q

!q

!q

q0

0

Page 17: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 17 – CS:APP3e

Transparent 1-Bit LatchTransparent 1-Bit Latch

When in latching mode, combinational propogation from D to Q+ and Q–

Value latched depends on value of D as C falls

C

D

Q+

Time

Changing DLatching

1

d !d !d !d d

d d !d

Page 18: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 18 – CS:APP3e

Edge-Triggered LatchEdge-Triggered Latch

Only in latching mode for brief period

Rising clock edge Value latched depends

on data as clock rises Output remains stable at

all other times

Q+

Q–

R

S

D

C

Data

ClockTTrigger

C

D

Q+

Time

T

Page 19: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 19 – CS:APP3e

RegistersRegisters

Stores word of dataDifferent from program registers seen in assembly code

Collection of edge-triggered latches Loads input on rising edge of clock

I O

Clock

DC

Q+

DC

Q+

DC

Q+

DC

Q+

DC

Q+

DC

Q+

DC

Q+

DC

Q+

i7

i6

i5

i4

i3

i2

i1

i0

o7

o6

o5

o4

o3

o2

o1

o0

Clock

Structure

Page 20: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 20 – CS:APP3e

Register OperationRegister Operation

Stores data bits For most of time acts as barrier between input and output As clock rises, loads input

State = x

Risingclock

Output = xInput = y

x

State = y

Output = y

y

Page 21: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 21 – CS:APP3e

State Machine ExampleState Machine Example

Accumulator circuit

Load or accumulate on each cycle

Comb. Logic

ALU

0

OutMUX

0

1

Clock

In

Load

x0 x1 x2 x3 x4 x5

x0 x0+x1 x0+x1+x2 x3 x3+x4 x3+x4+x5

Clock

Load

In

Out

Page 22: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 22 – CS:APP3e

Random-Access MemoryRandom-Access Memory

Stores multiple words of memoryAddress input specifies which word to read or write

Register fileHolds values of program registers %rax, %rsp, etc.Register identifier serves as address

» ID 15 (0xF) implies no read or write performed Multiple Ports

Can read and/or write multiple words in one cycle» Each has separate address and data input/output

Registerfile

Registerfile

A

B

W dstW

srcA

valA

srcB

valB

valW

Read ports Write port

Clock

Page 23: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 23 – CS:APP3e

Register File TimingRegister File Timing

Reading Like combinational logic Output data generated based on

input address After some delay

Writing Like register Update only as clock rises

Registerfile

Registerfile

A

B

srcA

valA

srcB

valB

y2

Registerfile

Registerfile

W dstW

valW

Clock

x2

Risingclock Register

fileRegister

fileW dstW

valW

Clock

y2

x2

x

2

Page 24: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 24 – CS:APP3e

Architecture GPRs/data+address registersFPregisters

z/Architecture 16 16Xilinx Spartan 1 3Xeon Phi[7] 16 32x86-64[6][5] 16 16

W65C816S 1 0

SPARC 31 32SH 16-bit 1 6Power Architecture 32 32PIC microcontroller 1 0

Motorola 68k[9] 8 data (d0-d7), 8 address (a0-a7) 8 (if FP present)

Motorola 6800[8] 2 data, 1 index 0MIPS 31 32Itanium 128 128

IBM/360 16 4 (if FP present)

IBM POWER 32 32IBM Cell SPE 0 1

IA-32[5] 8stack of 8 (if FP present), 8 (if SSE/MMX present)

Epiphany 64 (per core)

Emotion Engine 4 1 + 32

CUDA 1 8/16/32/64/128

AVR microcontroller 32 0ARM 64/32-bit[12] 31 32

ARM 32-bit 14 Varies (up to 32)

Alpha 31 31

8080[3] 1 accumulator, 6 others 0

8008[2] 1 accumulator, 6 others 0

6502 1 0

65002 1 0

4004[1] 1 accumulator, 16 others 0

16-bit x86[4] 8 stack of 8 (if FP present)

Source: https://en.wikipedia.org/wiki/Processor_register

Page 25: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 25 – CS:APP3e

Hardware Control LanguageHardware Control Language

Very simple hardware description language Can only express limited aspects of hardware operation

Parts we want to explore and modify

Data Types bool: Boolean

a, b, c, … int: words

A, B, C, …Does not specify word size---bytes, 64-bit words, …

Statements bool a = bool-expr ; int A = int-expr ;

Page 26: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 26 – CS:APP3e

HCL OperationsHCL Operations

Classify by type of value returned

Boolean Expressions Logic Operations

a && b, a || b, !a Word Comparisons

A == B, A != B, A < B, A <= B, A >= B, A > B Set Membership

A in { B, C, D }» Same as A == B || A == C || A == D

Word Expressions Case expressions

[ a : A; b : B; c : C ]Evaluate test expressions a, b, c, … in sequenceReturn word expression A, B, C, … for first successful test

Page 27: CS:APP3e CS:APP Chapter 4 Computer Architecture Logic Design CS:APP Chapter 4 Computer Architecture Logic Design CENG331 - Computer Organization Murat

– 27 – CS:APP3e

SummarySummary

Computation Performed by combinational logic Computes Boolean functions Continuously reacts to input changes

Storage Registers

Hold single wordsLoaded as clock rises

Random-access memoriesHold multiple wordsPossible multiple read or write portsRead word when address input changesWrite word as clock rises