42
Infra-estrutura de Hardware

Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Embed Size (px)

Citation preview

Page 1: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Page 2: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

CPU: Estrutura e Funcionalidade

Page 3: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Roteiro da Aula• Ciclo de Instrução • Projeto de uma CPU simples: conceitos• Componentes básicos

– Leitura da instrução– Operação entre registradores– Acesso à memória

• Implementação Mono-ciclo– Leitura da Instrução– Operações Aritméticas– Leitura + Operação entre registradores– Acesso à Memória– Desvio Condicional

• Visualizando a execução da instrução• Análise de Desempenho

Page 4: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Como um documento é processado?

1- Busca documento

2 - Identifica tipo de transação

3 - Verifica se saldo é positivo

4 - Efetiva transação e atualiza saldo

Page 5: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes de um computador

Vídeo

Teclado

CPU

Execução dasinstruções de um

programa

CPU

Execução dasinstruções de um

programa

Memória

Programas+

Dados

E/S

Buffers

Page 6: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Unidade Central de Processamento

PCReg.IRMARMAR

MBRMBR

Unidade de processamento

Unidade de controle

ALU

Gerais

Reg.FLAGS

Dados

Endereço

Controle

Page 7: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Ciclo de Instrução

Busca instruçãoBusca instrução

Executa instruçãoExecuta instrução

Busca operandoBusca operando

Decodifica instruçãoDecodifica instrução

Armazena resultadoArmazena resultado

Incrementa PCIncrementa PC

Page 8: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Projeto de uma Arquitetura

• Conjunto de registradores

• Tipos de Dados • Formato e Repertório

de instruções

• Conjunto de registradores

• Tipos de Dados • Formato e Repertório

de instruções

Page 9: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções

• Tipos de instruções– Processamento:

• aritméticas e lógicas

– Armazenamento– E/S– Controle:

• teste e desvio

5

Opcode

6

rs rt rd

5 5

F1 shamt

16

EndereçoOpcode rs

56

F2 rt

5

funct

65

Page 10: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Projeto: uma CPU simples...

Instrução Descrição LW rt, desl(rs) Carrega palavra de mem em rs SW rt, desl(rs) Armaz. Reg. na memória ADD rd, rs, rt rd <- rs + rt SUB rd, rs, rt rd <- rs – rt AND rd, rs, rt rd <- rs and rt BEQ rs, rt, end Desvio se rs = rt

Opcode rs rt rd shamt

EndereçoOpcode rs rt

funct

EndereçoOpcode rs rt

Aritm

lw/sw

beq

Page 11: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

MIPS - Visão Abstrata

Registers

Register #

Data

Register #

Datamemory

Address

Data

Register #

PC Instruction ALU

Instructionmemory

Address

Page 12: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Relógio - Clock

Clock cycle

S tate

e lem ent

1

Com binational logic

State

elem ent

2

Page 13: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Mono-ciclo

Clock cycle

Busca a próximainstrução

Busca a próximainstrução

Executa a instrução

Executa a instrução

Início

Término

Busca - Executa

Page 14: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Busca de Instrução

PC

Instructionmemory

Instructionaddress

Instruction Add Sum

8000

0000

0248

0020 00

0000

0480

0000

00

8000

0004

Memória (Instrução)

Contador Programa

Adicionador

Page 15: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Busca de Instrução

PC

Instructionmemory

Readaddress

Instruction

4

Add

8000

0000 80

0000

00

8000

0004

0248

0020

Page 16: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Operações Aritméticas

RegWrite

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

WritedataData

Data

Registernumbers

Banco de registradoresLeitura

5

5

500010

0001100000004

00000002

0000000400000002

Page 17: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Operações Aritméticas

RegWrite

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

WritedataData

Data

Registernumbers

Banco de registradoresEscrita

5

5

5

00001

00000006

0000000400000002

00000006

1

Page 18: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Operações Aritméticas

ALU control

ALUresult

ALU

b. ALU

Zero

300000004

00000002

00000006

+: 001

ALU

Page 19: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções Aritméticas/Lógicas

InstructionRegisters

Writeregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Writedata

ALUresult

ALU

Zero

RegWrite

ALU operation3

0000

0000

0100

0011

0000

1000

0100

000

00010

000110000000400000002

00000004

000000002

001 (+)

00000006

00001

1

00000006

Page 20: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Busca e Execução de Instruções Aritméticas/Lógicas

InstructionRegisters

Writeregister

Readdata 1

Readdata 2

Readregister 1Readregister 2

Writedata

ALUresult

ALUZero

RegWrite

ALU operation3PC

Instructionmemory

Readaddress

Instruction

4

Add

8000

0000

0248

0020

8000

0004

00010

0001100000004

000000002

0000000600001

0000000400000002

00000006

+

1

add $1, $2, $3

Page 21: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Acesso à memória

MemRead

MemWrite

Datamemory

Writedata

Readdata

Address

8000

000C 00000005

1

Memória de Dados - Leitura

00000005

0

Page 22: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Acesso à memória

MemRead

MemWrite

Datamemory

Writedata

Readdata

Address

8000

0010

0000000700000005

00000007

1

0

Memória de Dados - Escrita

Page 23: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Componentes Básicos: Acesso à memória

16 32Sign

extend

Extensão de Sinal

FFFD FFFFFFFD

0002 00000002

Page 24: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções Load/Store

Instruction

16 32

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Datamemory

Writedata

Readdata

Writedata

Signextend

ALUresult

ZeroALU

Address

MemRead

MemWrite

RegWrite

ALU operation3

lw $8, desl($9)

8D28

04

B0

01001

01000

04B0

80000008

000004B0

800004B8

00000002

00000002

1

+

1

0

80000008

00000002

Page 25: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções Load/Store

Instruction

16 32

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Datamemory

Writedata

Readdata

Writedata

Signextend

ALUresult

ZeroALU

Address

MemRead

MemWrite

RegWrite

ALU operation3

sw $t0, desl($t1)

AB

28

04B

0

01001

01000

04B0

80000008

000004B0

800004B8

00000005

00000005

+

1

0

80000008

00000005

Page 26: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções Aritméticas e de Load/Store

Instruction

16 32

Registers

Write

register

Read

data 1

Read

data 2

Read

register 1

Read

register 2

Data

mem oryWrite

data

Read

dataM

u

x

M

u

xWrite

data

Sign

extend

ALU

result

Zero

ALU

Address

RegWrite

ALU operation3

MemRead

MemWrite

ALUSrcMemtoReg

0248

0020

00010

0001100000004

000000002 000000060000000400000002

00000006

00000006

000011

0

+

00000006

1

add $1, $2, $3

Page 27: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções Aritméticas e de Load/Store

Instruction

16 32

Registers

Write

register

Read

data 1

Read

data 2

Read

register 1

Read

register 2

Data

mem oryWrite

data

Read

dataM

u

x

M

u

xWrite

data

Sign

extend

ALU

result

Zero

ALU

Address

RegWrite

ALU operation3

MemRead

MemWrite

ALUSrcMemtoReg

0000000400000006

8D28

04

B0

01001

01000

04B0

80000008

80000008

000004B0

800004B8

00000005

00000005

00000005

1 0

lw $8, desl($9)

1

0

00000005

1

Page 28: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instruções Aritméticas e de Load/Store

Instruction

16 32

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Data

memoryWritedata

Readdata

Mux

MuxWrite

data

Sign

extend

ALUresult

Zero

ALU

Address

RegWrite

ALU operation3

MemRead

MemWrite

ALUSrcMemtoReg

Instrução Função da alu Controle da ALULoad word – lw Add 010Store word – sw Add 010Add Add 010Sub Sub 010And and 000Slt Set on less than 010Beq sub 111

Page 29: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instrução de Branch on equal

16 32Sign

extend

ZeroALU

Sum

Shiftleft 2

To branchcontrol logic

Branch target

PC + 4 from instruction datapath

Instruction

Add

RegistersWriteregister

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Writedata

RegWrite

ALU operation3

Endereçamento relativo

Beq $1,$2, end.

0000000600000006

00000005

00001

0001000000006

00000006

04b0000004b0

000012C0

80000004 800012C4

comp

Page 30: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Unidade de Processamento

MemtoReg

MemRead

MemWrite

ALUOp

ALUSrc

RegDst

PC

Instructionmemory

Readaddress

Instruction[31– 0]

Instruction [20– 16]

Instruction [25– 21]

Add

Instruction [5– 0]

RegWrite

4

16 32Instruction [15– 0]

0Registers

WriteregisterWritedata

Writedata

Readdata 1

Readdata 2

Readregister 1Readregister 2

Signextend

ALUresult

Zero

Datamemory

Address Readdata M

ux

1

0

Mux

1

0

Mux

1

0

Mux

1

Instruction [15– 11]

ALUcontrol

Shiftleft 2

PCSrc

ALU

Add ALUresult

Page 31: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Unidade de Processamento

MemtoReg

MemRead

MemWrite

ALUOp

ALUSrc

RegDst

PC

Instructionmemory

Readaddress

Instruction[31– 0]

Instruction [20– 16]

Instruction [25– 21]

Add

Instruction [5– 0]

RegWrite

4

16 32Instruction [15– 0]

0Registers

WriteregisterWritedata

Writedata

Readdata 1

Readdata 2

Readregister 1Readregister 2

Signextend

ALUresult

Zero

Datamemory

Address Readdata M

ux

1

0

Mux

1

0

Mux

1

0

Mux

1

Instruction [15– 11]

ALUcontrol

Shiftleft 2

PCSrc

ALU

Add ALUresult

Opcode rs rt rd shamt

EndereçoOpcode rs rt

funct

EndereçoOpcode rs rt

Aritm

lw/sw

beq

31-26 25-21 20-16 15-11 10-6 5-0

31-26 25-21 20-16 15-0

31-26 25-21 20-16 15-0

Page 32: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Unidade de Controle

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 33: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Busca de instrução

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 34: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Leitura de registradores

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 35: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instr. Aritmética: Operação com ALU

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 36: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Instr. Aritmética: Escrita Reg.

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 37: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Lw/Sw: Operação com ALU (cálculo do endereço)

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 38: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Lw: Leitura de Memória

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 39: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Lw: Escrita em Registrador

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 40: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Sw: Escrita de Memória

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 41: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Beq: Operação com ALU (comparação) e cálculo de endereço de desvio

PC

Instructionmemory

Readaddress

Instruction[31–0]

Instruction [20 16]

Instruction [25 21]

Add

Instruction [5 0]

MemtoRegALUOpMemWrite

RegWrite

MemReadBranchRegDst

ALUSrc

Instruction [31 26]

4

16 32Instruction [15 0]

0

0Mux

0

1

Control

Add ALUresult

Mux

0

1

RegistersWriteregister

Writedata

Readdata 1

Readdata 2

Readregister 1

Readregister 2

Signextend

Mux1

ALUresult

Zero

PCSrc

Datamemory

Writedata

Readdata

Mux

1

Instruction [15 11]

ALUcontrol

Shiftleft 2

ALUAddress

Page 42: Infra-estrutura de Hardware. CPU: Estrutura e Funcionalidade

Infra-estrutura de Hardware

Análise de Desempenho

• Mono-ciclo:– Período do relógio definido em função da

duração da instrução mais lenta• 8ns (5ns)• Implementação pouco eficiente

• Como melhorar o desempenho na execução de várias instruções?– Multi-ciclo: cada estágio é executado em um

ciclo do relógio.– Começar uma instrução ANTES da última

instrução iniciada terminar.