Docsity

Programmability - Computation Structures - Lecture Slides, Slides of Computer Fundamentals

Toggle sidebar
bg1
L12 - Models of Computation 1
6.004 – Spring 2009 3/17/09
Programmability
from silicon to bits 0110100110
1110010010
0011100011
the Big Ideas
of
Computer Science
modified 3/16/09 16:15 L12 - Models of Computation 2
6.004 – Spring 2009 3/17/09
6.004 Roadmap
Sequential logic:
FSMs
<PC>+4+C*4
ASEL 01
Data Memory
RD
WD
Adr
R/W
WDSEL
012
WA
Rc <25:21> 0
1
XP
PCSEL
PC
JT
+4
Instruction
Memory
A
D
Rb: <15:11>Ra <20:16>
RA2SEL
Rc <25:21>
+
Register
File
RA1 RA2
RD1 RD2
BSEL
01
C: <15:0>
C: <15:0>
sign-extended
Z
ALU
AB
JT
WA WD
WE
C: <15:0> << 2
sign-extended
ALUFN
Control Logic
Z
ASEL
BSEL
PCSEL
RA2SEL
WDSEL
ALUFN
Wr
<PC>+4
01
Wr
01234
XAdr
ILL
OP
WASEL
WASEL
IRQ
WERF
WERF
00
CPU Architecture:
interpreter for coded
programs
Programmability: Models
ā€¢ī˜‚Interpretation; Programs; Languages;
Translation
ā€¢ī˜‚Beta implementation
ā€¢ī˜‚Pipelined Beta
ā€¢ī˜‚Software conventions
ā€¢ī˜‚Memory architectures
Fets & voltages
Logic gates
Combinational
logic circuits
L12 - Models of Computation 3
6.004 – Spring 2009 3/17/09
FSMs as Programmable Machines
ROM-based FSM sketch:
Given i, s, and o, we need a ROM
organized as:
2i+s words x (o+s) bits
i
s
0...01
0...00 0...00 10110 011
o
2i+s
sN+1 osN
i
inputs outputs
2(o+s)2i+s
(some may be
equivalent)
An FSM’s behavior is completely
determined by its ROM contents.
So how many possible
i-input,
o-output,
FSMs with
s-state bits
exist?
L12 - Models of Computation 4
6.004 – Spring 2009 3/17/09
Big Idea #1:
FSM Enumeration
GOAL: List all possible FSMs in some
canonical order.
• INFINITE list, but
• Every FSM has an entry
and an associated index.
0...01
0...00 0...00 10110 011
sN+1
osN
i
inputs outputs
28
FSMs
264
Every possible FSM can be
associated with a number.
We can discuss the ith FSM
What if
s=2,
i=o=1??
pf3
pf4
pf5

Partial preview of the text

Download Programmability - Computation Structures - Lecture Slides and more Slides Computer Fundamentals in PDF only on Docsity!

L12 - Models of Computation 1

3/17/

Programmability

from silicon to bits

011010011011100100100011100011

the Big Ideas

of

Computer Science

modified 3/16/09 16:

L12 - Models of Computation 2

6.004 – Spring 2009

3/17/

6.004 Roadmap

Sequential logic:

FSMs

+4+C*

ASEL

0

1

Data Memory

WDRD

Adr

R/W

W

D S E

L

0

1

2

WA

Rc <25:21>

10

XP

PCSEL

JT PC +

Instruction

Memory

A

D

Rb: <15:11>

Ra <20:16>

RA2SEL

Rc <25:21>

Register

File

RA

RA

RD

RD

BSEL

0

1

C: <15:0>

C: <15:0> sign-extended

Z

ALU

A

B

JT

WA

WDWE

C: <15:0> << 2sign-extended

ALUFN

Control Logic

Z PCSELRA2SELASELBSELWDSELALUFNWr

+

0

1

Wr

0 1

2

3 4 XAdr

ILLOP

WASEL

WASEL

IRQ

W E R F

WERF

00

CPU Architecture:

interpreter

for coded

programs

Programmability: Models

Interpretation; Programs; Languages;

Translation

Beta implementation

Pipelined Beta

Software conventions

Memory architectures

Fets & voltages

Logic gates

Combinational

logic circuits

L12 - Models of Computation 3

3/17/

FSMs as Programmable Machines

ROM-based FSM sketch:Given i, s, and o, we need a ROMorganized as:

i+s

words x (o+s) bits

i

s

0...00 0...

0...

10110

011

o

i+s

s

N+

o

s

N

i

inputs

outputs

(o+s)

i+s

(some may be

equivalent)

An FSM’s behavior is completely

determined by its ROM contents.

So how many possible

i-input,o-output,FSMs withs-state bitsexist?

L12 - Models of Computation 4

6.004 – Spring 2009

3/17/

Big Idea #1:

FSM Enumeration

GOAL: List all possible FSMs in some

canonical order. • INFINITE list, but• Every FSM has an entryand an associated index.

0...00 0...

0...

10110

011

s

N+

o

s

N

i

inputs

outputs

8

FSMs

64

Every possible FSM can be

associated with a number.

We can discuss the i

th

FSM

What if

s=2,

i=o=1??

L12 - Models of Computation 5

3/17/

Some Perennial Favorites...

FSM

837

modulo 3 counter

FSM

1077

4-bit counter

FSM

1537

lock for 6.004 Lab

FSM

89143

Steve’s digital watch

FSM

22698469884

Intel Pentium CPU – rev 1

FSM

784362783

Intel Pentium CPU – rev 2

FSM

72698436563783

Intel Pentium II CPU

Reality: The integer indexes of actual FSMs are

much

bigger

than the examples above. They must include

enough information to constitute a

complete

description

of each device’s unique structure.

L12 - Models of Computation 6

6.004 – Spring 2009

3/17/

Models of Computation

The roots of computer science stem from thestudy of many alternative mathematical ā€œmodelsā€of computation, and study of the classes ofcomputations they could represent.An elusive goal was to find an ā€œultimateā€ model,capable of representing all practicalcomputations...

We’ve got FSMs ...

what else do we need?

switches

gates

combinational logic

memories

FSMs

Are FSMs the

ultimate digital

computing device?

L12 - Models of Computation 7

3/17/

FSM Limitations

Despite their usefulness and flexibility, there exist common problems thatcannot be computed by FSMs. For instance:

Paren

Checker

OK

Paren

Checker

Nix

Well-formed Parentheses Checker:

Given any string of coded left & rightparens, outputs 1 if it is balanced, else 0.

Simple, easy to describe.Is this device equivalent to one of our

enumerated FSMs???

PROBLEM: Requires ARBITRARILY many states,

depending on input. Must "COUNT" unmatchedLEFT parens. An FSM can only keep track of afinite number of unmatched parens: for everyFSM, we can find a string it can’t check.

NO!

L12 - Models of Computation 8

6.004 – Spring 2009

3/17/

Big Idea #2:

Turing Machines

Alan Turing was one of a group of

researchers studying alternativemodels of computation.

He proposed a conceptual model

consisting of an FSM combinedwith an infinite digital tape thatcould be read and written at eachstep.

Turing’s model (like others of the time)

solves the "FINITE" problem ofFSMs.

S

1

1 1 1 0

0 0 0 1

0 0 0 0

0 0 0 0

S

2

0,(1,R)

0,(1,L)

1,Halt

1,(1,L)

L12 - Models of Computation 13

3/17/

The 1

st

Computer Industry Shakeout

Here’s a TM that

computes SQUARE ROOT!

FSM

how am I going

to beat

that

?

L12 - Models of Computation 14

6.004 – Spring 2009

3/17/

And the battles raged

Here’s a Lambda Expression

that does the same thing...

... and here’s one that computes

the n

th

root for ANY n!

(x)

(x

n)

maybe if I gave

away a

microwave oven

with every

Turing Machine...

RESULT:

an N-way TIE!

CONTEST:

Which model computes more functions?

L12 - Models of Computation 15

3/17/

Big Idea #3:

Computability

FACT: Each model studied is capable of computing exactly the same

set of integer functions!

Proof Technique:

Constructions that translate between models

BIG IDEA:

Computability, independent of computation scheme chosen

Church's Thesis:

Every discrete function computable

by ANY realizable machine is

computable by some Turing machine.

unproved, but

universallyaccepted...

L12 - Models of Computation 16

6.004 – Spring 2009

3/17/

Computable Functions

Representation Tricks:

Multi-argument functions? to compute f

k

(x,y), use

<x,y> =



nteger whose

even

bits come from x, and whose

odd

bits come from y;

whence

f

K

(x, y) = T

K

[<x, y>]

Data types: Can encode characters, strings, floats, ...as integers.

Alphabet size: use groups of N bits for 2

N

symbols

f(x)

computable

<=> for some k, all x:

f(x) = T

K

[x]

f

K

(x)

Equivalently: f(x) computable on Cray, Pentium, in C, Scheme, Java, ...

L12 - Models of Computation 17

3/17/

Enumeration of Computable functions

f

m

(n)

f

i

f

i

(0) f

i

f

i

(n)

f

i

f

0

f

1

f

2

f

m

Conceptual table of ALL Turing Machine behaviors...

VERTICAL AXIS: Enumeration of TM’s (computable functions)HORIZONTAL AXIS: Enumeration of input tapes.ENTRY AT (n, m): Result of applying m

th

TM to argument n

INTEGER k: TM halts, leaving k on tape.

: TM never halts.

aren’t

all

well-defined

integer functions

computable?

NO!

there are simply too many integer functions to fit in

our enumeration!

L12 - Models of Computation 18

6.004 – Spring 2009

3/17/

THEOREM: f

H

is different from every function in our

enumeration of computable functions; hence it cannot becomputed by any Turing Machine.

Uncomputable Functions

Unfortunately, not every well-defined integer function is computable. The most famous

such function is the so-called Halting function, f

H

(k, j), defined by:

f

H

(k, j) = 1 if T

k

[ j] halts;

0 otherwise.

f

H

(k, j) determines whether the k

th

TM halts when given a tape containing j.

PROOF TECHNIQUE: ā€œDiagonalizationā€ (after Cantor, Gƶdel)

If f

H

is computable, it is equivalent to some TM (say, T

H

Using T

H

as a component, we can construct another TM whose behavior

differs from every entry in our enumeration and hence must not becomputable.

Hence f

H

cannot be computable.

L12 - Models of Computation 19

3/17/

Why f

H

is uncomputable

If f

H

is computable, it is equivalent to some TM (say, T

H

T

H

k

j

1 iff T

k

[ j] halts,

else 0

Then T

N

(N for ā€œNastyā€), which must be computable if T

H

is:

T

N

T

H

LOOPHALT

T

N

[x]:

LOOPS if T

x

[x] halts;

HALTS if T

x

[x] loops

Finally, consider giving N as an argument to T

N

T

N

[N]:

LOOPS if T

N

[N] halts;

HALTS if T

N

[N] loops

T

N

can’t be

computable, hence

T

H

can’t either!

x

L12 - Models of Computation 20

6.004 – Spring 2009

3/17/

Footnote: Diagonalization

(clever proof technique used by Cantor, Gƶdel, Turing)

f

m

(n)

f

i

f

i

(0) f

i

f

i

(n)

f

i

f

0

f

1

f

2

f

m

If T

H

exists, we can use it to construct T

N

. Hence T

N

is computable if T

H

is.

(informally we argue by Church’s Thesis; but we can show the actual T

N

construction, if pressed)

Why T

N

can’t be computable:

T

N

differs from every

computable functionfor at least oneargument – along thediagonal of our table.Hence T

N

can’t be

among the entries inour table!

Hence no such T

H

can be constructed, even in theory.

Computable Functions:

A TINY SUBSET of all

Integer functions!

L12 - Models of Computation 25

6.004 – Spring 2009

3/17/

Coded Algorithms: Key to CS

data vs hardware

Algorithms as data:

enables

COMPILERS: analyze, optimize, transform behavior

SOFTWARE ENGINEERING:

Composition, iteration,abstraction of coded behavior

F(x) = g(h(x), p((q(x)))

T

COMPILER-X-to-Y

[P

X

] = P

Y

, such that

T

X

[P

X

, z] = T

Y

[P

Y

, z]

LANGUAGE DESIGN: Separate specification

from implementation

C, Java, JSIM, Linux, ... all run on X86,PPC, Sun, ...

Parallel development paths:

Language/Software design

Interpreter/Hardware design

L12 - Models of Computation 26

6.004 – Spring 2009

3/17/

Summary

Formal models (computability, Turing Machines, Universality)

provide the basis for modern computer science:

Fundamental limits (what can’t be done, even given plenty of memoryand time)

Fundamental equivalence of computation models

Representation of algorithms as data, rather than machinery

Programs, Software, Interpreters, Compilers, ...

They leave many practical dimensions to deal with:

Costs: Memory size, Time Performance

Programmability

Next step: Design of a practical interpreter!