73
Computer Architecture Sebastian Altmeyer ([email protected])

Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Computer Architecture

Sebastian Altmeyer([email protected])

Page 2: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

What is computer architecture?

Page 3: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

What is computer architecture?

(a) How to build a processorcommon understanding by computer architects

(b) How to build a computercommon understanding by many others …

(c) How a computer system worksIncluding all system layers

Page 4: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Aim of this lecture

● How a processor works● How instructions are processed● What the following items mean:

➢ Register and Gates➢ ALU➢ Program Counter➢ Instructions, Machine Code, Assembler➢ Pipelining➢ Caches

Page 5: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Aim of the next lecture

● How the peripherals of a processor work● What the following items mean:

➢ Interrupts?➢ Memory Management?➢ Virtual Memory?➢ Runtime systems?

(Actual content not yet fixed ...)

Page 6: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Unfortunately ...

that is way too much

Hence:– rough overview and basic concepts

– highly simplified explanation

– focus on the necessary abstractions

– and at some points you simply have to believe me ;)

– Feedback!

Page 7: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Intel Core i7

Quadcore with 731,000,000 transistors

Page 8: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

… and it's natural habitat

Page 9: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Highly complex, but simple components

● registers (to store information)● gates (to process information● buses (to connect registers and gates)● a clock

A processor can only flip 0 to 1 and vice versa

… but that is all we need

Page 10: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Gottfried LeibnizBinary Numbers

George Boole Boolean Algebra

John von NeumannFirst Processor

Claude ShannonExpressivness of Relays

Page 11: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Leibniz: Binary Numbers Or, how to represent any natural number just

using bits

n denotes register/bus width, i.e.32-bit architecture means n = 32

Example (8 bits): 00101010 = 42

Range: [0;2n-1-1]

bn−1 bn−2 bn−3…b2 b1 b0≡∑i=0

n−1

bi2i

Page 12: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Two's Complement how to represent a negative number

Example (8 bits):11010110 = -42

00101010 = 42

Range: [-2n-2;2n-2-1]

bn−1 bn−2 bn−3…b2 b1 b0≡−bn−1 2n−1+∑

i=0

n−2

b i2i

Page 13: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Floating Point(IEEE 754 single-precision 32-bit)

b31b30b29...b23b22b21...b0

Sign Exponent Fraction

−1Sign(Fraction)2 2(Exponent )2−127

Page 14: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Boole: Boolean Algebra

z , v ,w∈{0,1 }

z=¬v

z=v∧w

z=v∨w

Variables:

Operators:

Page 15: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Claude Shannon

Has shown in his Master's Thesis: „A Symbolic Analysis of

Relay and Switching Circuits“how to implement boolean logic using electronic

circuits

Page 16: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Boole and Shannon: Gates

z=¬v

z=v∧w

z=v∨w

Page 17: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Half Adder/Full Adder

xor or and

Page 18: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Adder

Page 19: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

How to substract?

Page 20: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

How to substract?

a−b=a+b+1

Page 21: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Add/Substract

a−b=a+b+1

Page 22: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Arithmetic Logic Unit (ALU)

Page 23: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

ALU and Register

Page 24: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

How to control ALU/Registers?Machine Code

s2s

1s

0rs

3rs

2rs

1rs

0rt

3rt

2rt

1rt

0rd

3rd

2rd

1rd

0

OP regS regT regD

regD = regS [OP] regT

Page 25: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

PC + Instruction Memory

s2s

1s

0rs

3rs

2rs

1rs

0rt

3rt

2rt

1rt

0rd

3rd

2rd

1rd

0

OP regS regT regD

regD = regS [OP] regT

Page 26: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Calculator Instructions

Page 27: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Calculator

Page 28: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Clock

Increase PC write result in register

one cycle

Page 29: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Here comes the example (SIM-PL)

Page 30: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Calculator with Immediates

Page 31: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Instructions

Page 32: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Machine Code

Instructions with 2 registerst0s

2s

1s

0rs

3rs

2rs

1rs

0rt

3rt

2rt

1rt

0rd

3rd

2rd

1rd

0

Type OP regS regT regD

regD = regS [OP] regT if Type = 1

Type with immediatest0s

2s

1s

0rs

3rs

2rs

1rs

0xxxxrd

3rd

2rd

1rd

0i15

i14

...i0

Type OP regS regD regT

regD = regS [OP] IMM if Type = 0

Page 33: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Loop Instructions

Page 34: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Calculator with Loops

condition

Page 35: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Registers are very limited ...

Page 36: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Little Endian/Big Endian

describes order in which bytes are written to memory ...

Page 37: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Harvard Machine

Load Store machine

Page 38: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Complete Instruction Set

Page 39: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Turing Complete

Page 40: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

We can now compute whatever we want …

Further improvements target - increasing usability- speed

Page 41: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Usability

Page 42: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

von Neumann Architecture

Just like Harvard Architecture, with one little difference

Instruction Memory and Data Memory are the same

(predates Harvard Architecture)

Page 43: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Procedure Call

PC PC + Offset

$ra PC + 1; Store PC+1 in register

Page 44: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Harvard Machine: ReturnLoad PC from register $ra

more details (recursive functions, stack, heap) in next lecture

Page 45: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Interrupts

ways to interrupt current execution for other stuff

Examples: ● pressing a key on the keyboard● network data available● shutting down processes● moving mouse

more details in the next lecture

Page 46: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Speed

Page 47: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

currently:● multiple cycles for one instruction● large parts of the pipeline are idle

with pipelining● one cycle for one instruction ● nearly all parts are nearly always busy

(similar to conveyor belt)

Page 48: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

Page 49: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

Page 50: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

Page 51: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

Page 52: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

Page 53: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipelining

Page 54: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Harvard Pipelining

Page 55: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Pipeline Hazards/Multicycle Instructions

One instruction per cycle is the best case … but that's not always possible:

● Memory accesses● Branches● Dependencies

ADD $r1, $r2, $r3ADD $r4, $r1, $r2

Page 56: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Forwarding

Data dependency

Data dependency

Page 57: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Harvard Machine with Forwarding

Page 58: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Branch Prediction

Page 59: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Clock rate scaling

easiest way to improve performance … but mostly for processor speed

Page 60: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Load $r2, _aLoad $r1, _b

Add $r3, $r2, $r1

MPC 5xx

Page 61: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Load $r2, _aLoad $r1, _b

Add $r3, $r2, $r1

MPC 755

Page 62: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Memory Hierarchy

emulates a fast and large memory

● on top: small and fast ● on bottom: large and

slow

each level contains a subset of the data below

rough idea:

books on your desk, books in your shelf, books in the library

Page 63: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Principle of Locality

● Spatial Locality neighboring memory blocks are likely to be accessed contemporary

● Temporal Locality recently accessed memory blocks are likely to be accessed in the near future again

Page 64: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Harvard Architecture with cache

Page 65: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

direct-mapped cache

Page 66: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Internal cache organization

Page 67: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

2 way set-associative cache

Concept can be extended to fully-associative caches

Page 68: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Different types of cache misses

● Compulsory (cold) misses: caches are initially empty, first access is always a miss.

● Capacity misses due to the limited cache capacity (i.e. cache is full)

● Conflict misses due to an unbalanced cache usage (eviction in one cache set, while other lines are still empty)

Page 69: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

See you in the lab session!

Page 70: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Exercise 1 (Boolean Algebra)

a) What is the minimal subset of the set of basic operations {and, or, not} sufficient to derive all logical operations? Justify your answer.

b) What is the minimal subset if we add the nand operation (i.e. not and) to the set {and, or, not}? Justify your answer.

Page 71: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Exercise 2 (Digital Circuit)

a) Draw a digital circuit of an 4-bit incrementer, i.e., a circuit that satisfies the equation

b = a + 1 mod 24

You can use the the operations from the set {and,or,nand,nor, not}.

b) Try to find an incrementer with the minimal number of operations needed.

c) Try to minimize the depth of the circuit, i.e. the maximal length of any path from input to output.

Page 72: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Exercise 3 (Assembler)

Write an assembler program (for the harvard machine) that converts memory data from little endian to big endian. Assume that the address of the memory data that should be converted is stored in register 1.

Test your assembly code using the SIM-PL.

Page 73: Computer Architecture - OS3 · What is computer architecture? (a) How to build a processor common understanding by computer architects (b) How to build a computer common understanding

Exercise 4 (Loops)

Extend you assembly code from Exercise 4 so that a complete block of data is converted.

Assume that the initial memory address is stored in register 1 and the number of blocks that should be converted in register 2. Your code shall convert each memory block from

[r1;r1 + r2]