Sei sulla pagina 1di 77

Università degli Studi dell’Insubria

Dipartimento di Scienze Teoriche e Applicate

Architettura degli elaboratori

CPU a ciclo singolo


Reminder: livelli di astrazione

Livello 5 Linguaggi Applicativi


Traduzione
(compilatore)
Livello 4 Linguaggio Assembly
Traduzione
(assemblatore)
Livello 3 Sistema operativo
Interpretazione
parziale
(sistema operativo)
Livello 2 Instruction Set
Interpretazione
(microprogramma)
o esecuzione diretta
Livello 1 Microarchitettura (hardware)

Esecuzione diretta
(hardware)
Livello 0 Logica digitale
Architettura degli elaboratori
Livelli di astrazione

Ciascun livello consiste di:


Un’interfaccia
cos’è visibile dall’esterno
usata dal livello superiore
Un’implementazione
come lavora internamente
usa l’interfaccia del livello inferiore

Nel progettare un dato livello


scopo: dobbiamo porci il problema di implementare l’interfaccia,
cioè le funzionalità richieste dal livello superiore
mezzi: possiamo utilizzare le funzionalità messe a disposizione dal
livello inferiore
possiamo ignorare tutti gli altri livelli!
cioè possiamo ASTRARRE da essi
Architettura degli elaboratori -3- Il livello ISA
Livelli di astrazione:
Livelli intermedi
Nota: è arbitrario delimitare cosa chiamiamo “livello di astrazione”.
Possiamo adottare livelli intermedi fra quelli proposti, per es:

Livello 1 Microarchitettura

Livello 0.5 Blocchi Funzionali

Livello 0 Logica digitale

Architettura degli elaboratori -4- Il livello ISA


Progettazione di una macchina

Criterio di progettazione di una CPU: prestazioni


Le prestazioni di una macchina sono determinate da:
Numero di istruzioni da eseguire
Durata del ciclo di clock
Numero di Cicli Per Istruzione (CPI)
Le ultime due determinate dal processore
design del datapath e dell’unità di controllo
tecnologia usata!
Per prima cosa, progettiamo un processore a ciclo singolo
CPI = 1, cioè si esegue una istruzione in un (solo) ciclo di clock
Vantaggi: semplicità di progettazione
Svantaggi: tempo di ciclo lungo, limitato dall’istruzione più lenta da
gestire.

-5-
Procedura passo-passo per il progetto di
un processore
1. L’instruction set fornisce i requisiti per il datapath
2. Scegliere i componenti del datapath
e la metodologia di temporizzazione (clocking)
3. Progettare il datapath in modo da soddisfare i requisiti
4. Analizzare il datapath per identificare i controlli che determinano il
trasferimento tra registri.
5. Progettare la logica di controllo (Control Unit)

-6-
Procedura passo-passo per il progetto di
un processore
1. L’instruction set fornisce i requisiti per il datapath
Semantica delle istruzioni = cosa fanno.
Es. una data istruzione opera sui registri facendo:
R[a] <– R[b] + R[c];
Il datapath deve essere in grado di realizzare ciascuna istruzione
Prendiamo come esempio un Instruction Set reale: il MIPS
vediamo brevemente le sue caratteristiche

-7-
Il formato delle istruzioni MIPS
Tutte le istruzioni sono lunghe 32 bit. Tre formati:
31 26 25 21 20 16 15 11 10 6 5 0
R-type op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits

31 26 25 21 20 16 15 0
I-type op rs rt address / immediate
6 bits 5 bits 5 bits 16 bits

31 26 25 0
J-type op target address
6 bits 26 bits
op: codice operativo (quale operazione esegue l’istruzione)
rs, rt, rd: indicano registri degli operandi e del risultato
shamt: shift amount: di quanto shiftare (a dx o sx) il risultato
funct: indica varianti dell’operazione indicata da op
address / immediate: indirizzo (spiazzamento) o valore immediato
target address: indirizzo destinazione di un’istruzione di salto
-8-
Un sottoinsieme delle istruzioni MIPS

Per progettare il datapath ci basterà un sottoinsieme rappresentativo


delle istruzioni MIPS.
ADD e SUB
31 26 25 21 20 16 15 11 10 6 5 0
addu rd, rs, rt op rs rt rd shamt funct
subu rd, rs, rt 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
OR Immediate: 31 26 25 21 20 16 15 0
op rs rt immediate
ori rt, rs, imm16
6 bits 5 bits 5 bits 16 bits
LOAD e STORE
31 26 25 21 20 16 15 0
lw rt, rs, imm16
op rs rt immediate
sw rt, rs, imm16 6 bits 5 bits 5 bits 16 bits
BRANCH:
31 26 25 21 20 16 15 0
beq rs, rt, imm16 op rs rt immediate
6 bits 5 bits 5 bits 16 bits

oppure: address
-9-
Instruction fetch

Prima di eseguire una istruzione (di qualsiasi tipo) è necessario


eseguire il suo fetch (lettura dalla memoria dell’istruzione)

R-type

31 26 25 21 20 16 15 11 10 6 5 0
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
I-type
31 26 25 21 20 16 15 0
op rs rt address / immediate MEM[PC]
6 bits 5 bits 5 bits 16 bits

J-type
31 26 25 0
op target address
6 bits 26 bits
- 10 -
Semantica delle istruzioni
espressa con «RTL» (Register Transfer Logic)
Istruzione Effetto su registri e memoria Effetto su PC
addu R[rd] ← R[rs] + R[rt] PC ← PC + 4
subu R[rd] ← R[rs] – R[rt] PC ← PC + 4
ori R[rt]
← PC ← PC + 4
R[rs] OR zero_ext(imm16)
lw R[rt] Aggiungere 2
zeri nelle
← PC ← PC + 4 posizioni meno
MEM[R[rs] + sign_ext(imm16)] significative
=
sw MEM[R[rs] + sign_ext(imm16)] moltiplicare x 4.
← PC ← PC + 4 Serve per
indirizzare
R[rt] parole da 32 bit.
beq if(R[rs]==R[rt])
then PC ← PC + 4 +
sign_ext(imm16)||00
else PC ← PC + 4
- 11 -
Sign-extension Vs zero extension
(reminder)

In binario In complemento a 2
Su 4 bit: Su 4 bit,
1101 per i positivi: 0101
denota tredici; denota cinque;
allora su 8 bit allora su 8 bit: 00000101
00001101 denota ancora cinque
denota ancora tredici per i negativi: 1101
(banale) denota meno tre;
allora su 8 bit: 11111101
denota ancora meno tre

Basta aggiungere tanti 0 a sx Basta ripetere il MSB a sx

Architettura degli elaboratori - Luigi Lavazza - 12 -


Procedura passo-passo per il progetto di
un processore
1. L’instruction set fornisce i requisiti per il datapath
2. Scegliere i componenti del datapath e la metodologia di
temporizzazione (clocking)
3. Progettare il datapath in modo da soddisfare i requisiti
4. Analizzare il datapath per identificare i controlli che determinano il
trasferimento tra registri.
5. Progettare la logica di controllo

Ciò che abbiamo fatto


in quasi tutte le lezioni
precedenti!

- 13 -
Requisiti per l’esecuzione delle istruzioni
Quali blocchi funzionali useremo
Due banchi di memoria distinti
Istruzioni (sola lettura – un solo bus)
Dati (lettura e scrittura – un bus per direzione)
Un register Bank (32x32) per i 32 «user registers»
Due bus di lettura
Un bus di scrittura
Un Program Counter (PC): registro separato (su 30 bit, vedremo)
Blocchi funzionali combinatori:
sommatori, estensori (con scelta fra «in segno» e «con zeri»),
mutex, moltiplicatori di 1 bit …
ALU
due ingressi a 32 bit, e una uscita a 32 bit
in input, anche il codice di operazione
in output, anche i bit di esito (es: uguaglianza)

- 14 -
Requisiti per l’esecuzione delle istruzioni

Memorie
Istruzioni
Dati
Due separate, perché dobbiamo leggere l’istruzione da eseguire e,
nello stesso ciclo di clock, leggere o scrivere dati !
Nota: dalla memoria di istruzioni, non si scrive mai, si legge e basta
(e sempre all’indirizzo indicato dal PC)

Rd/Wr
32
Instruction
Address
Memory
32 32 Data Memory
Instruction
Instruction 32 32
Address
Data In Data Out

- 15 -
Requisiti per l’esecuzione delle istruzioni

Register File
• Register File: 32
32 registri da 32 bit WrEnable Write
5 Data Out A Bus A
Due bus di uscita RA
5
BusA e BusB RB
5
Un bus di input RW 32
BusW Data Out B Bus B
32
Bus W Data In

Ingressi: Clock
Indici RA e RB selezionano i registri da riversare su BusA e BusB
Indice RW seleziona il registro in cui verranno scritti i dati
provenienti da BusW quando Write è 1
Clock: significativo solo in scrittura. In lettura il circuito si comporta
in modo combinatorio: su BusA e BusB ci sono sempre i valori
contenuti nei registri indicati da RA e RB
- 16 -
Requisiti per l’esecuzione delle istruzioni

Program Counter:
un registro speciale in più, separato
E’ preposto ad un unico scopo:
PC
memorizzare l’indice dell’istruzione
corrente (in memoria istruzioni).
Il ciclo delle istruzioni comincia dal
fetch: cioè quando 32 32
il PC assume il valore della prossima Data Data
istruzione, e viene usato per leggerla In PC Out
(nota: la semantica di ogni istruzione
specifica cosa succede al PC
nella prossima istruzione –
di solito, aumenta di 4 unità) Clock

- 17 -
Requisiti per l’esecuzione delle istruzioni

Estensione con zero Estensione in segno Estensione a scelta

Extender
Ext Zero

Ext Sign
16 32 16 32 16 32

se 0: con zero
EXTENDER se 1: in segno

Tre circuiti combinatori MOLTO semplici


(Guardare lezione su blocchi funzionali!)

- 18 -
Requisiti per l’esecuzione delle istruzioni

Estensione con zero Estensione in segno Estensione a scelta


i0 o0 i0 o0 i0 o0

i15 i15 i15

0 : con zero
1: in segno

o31 o31 o31

- 19 -
Requisiti per l’esecuzione delle istruzioni

Operazioni come: somma, sottrazione, or bitwise


di registri o di immediato (una volta esteso a 32 bit)
Confronto di registri (richiesto da op. branch: beq)
Ipotizziamo di avere molte altre op e varianti nella ALU, fino a 27 = 128

Uguale?
32
A
32

ALU
ALU 32
Result
B
7

Codice
operaz.

- 20 -
Requisiti per l’esecuzione delle istruzioni

Incremento del PC (di 4 bytes)


oppure somma di un valore, nelle istruzioni di branch e jump
Deve essere fatta da un circuito separato dall’ALU!
Per lo stesso motivo per cui abbiamo due memorie separate:
durante lo stesso ciclo di clock la ALU è occupata con le operazioni
richieste dall’istruzione (somma, sottrazione, ecc.)

32
PC
32

Adder
PC+B + Carryin
32
B

CarryIn (0 o 1)

- 21 -
Requisiti per l’esecuzione delle istruzioni

in MIPS: 1 istruzione = 1 parola da 32 bit = 4 bytes  SEMPRE


e le istruzioni sono “allienate alla parola”
Possiamo usare quindi un PC a 30 bit
il PC è l’indice di parola, non di byte
Vantaggio: per incrementare un indice-di-byte di 4
basta incrementare l’indice-di-parola di 1
Il +1 si può fare usando il bit di riporto in ingresso (CarryIn)!
Alla memoria_istruzioni (che indicizza in bytes) passeremo come
address: PC<<2 (cioè l’indice del byte)
00
PC indirizzo
30 30
Adder
(in word) dell’istruzione
30 PC+1 (in bytes)
0…0
CarryIn = 1

- 22 -
Altri blocchi funzionali (combinatori)
del datapath
MUX:
necessari in tutti i casi in cui è necessario fare delle scelte
Tipicamente, pilotati da segnali di controllo provenienti
dalla Control Unit

Istruzione corrente
op … voglio A
oppure B?
(dato che devo
Control fare op)
Unit

n
possibilità A n
n MUX A oppure B
possibilità B

- 25 -
Altri blocchi funzionali (combinatori)
del datapath
MUX:
necessari in tutti i casi è in cui è necessario fare delle scelte
Nota:
è del tutto ininfluente cosa entra dai cavi della possibilità NON scelta
possiamo comodamente disinteressarcene
(nei disegni che seguono, verranno a volte mostrati in grigio chiaro)

scegli
A

n
possibilità A n
n MUX A
possibilità B
(inutilizzato)

- 26 -
Altri blocchi funzionali (combinatori)
del datapath

Istruzione
corrente

op rs rt rd shamt funct

Control Register file


Unit
WrEn WrEnable
5
RA 32
5 Bus A
RB

5 5
RW
MUX

32 32
5 Bus B
Bus W

Clock
- 28 -
Temporizzazione: scelte

Tutte le scritture in qualsiasi memoria sono sincronizzate


I 32 registri utente
Il registro PC
La memoria centrale
Usiamo lo stesso segnale di clock per tutti
Sincronizzazione sul fronte in salita:
quando il clock passa da basso a alto, il segnale in attesa nell’ingresso
viene memorizzato (se la scrittura è abilitata) – non prima
Importante: quando ciò avviene, il segnale deve essere pronto!
Ricordare: in lettura, tutti i circuiti di memoria si comportano invece in
maniera completamente combinatoria:
Si mette l’indirizzo in ingresso, e (dopo il tempo di commutazione)
l’uscita emette la parola letta (costante, finché l’indirizzo non muta)
Nota: in qualsiasi mem, quando non scrivo, il clock non ha effetto
Nota: la mem istruzioni non ha scritture e quindi non usa il clock
- 30 -
Procedura passo-passo per il progetto di
un processore
1. L’instruction set fornisce i requisiti per il datapath
2. Scegliere i componenti del datapath e la metodologia di
temporizzazione (clocking)
3. Progettare il datapath in modo da soddisfare i requisiti
4. Analizzare il datapath per identificare i controlli che determinano il
trasferimento tra registri.
5. Progettare la logica di controllo

- 32 -
Quadro Complessivo a più alto livello

32 Instruction 32
istruzione corrente Memory

Op
Funct
Control Unit
C O M A N D I

Immediate

indirizzi
registri
DataPath
PC

- 33 -
Passo 3

Requisiti su trasferimento registri → Datapath Design

Fetch Istruzione
Decodifica istruzioni e lettura operandi
Esecuzione dell’operazione
Scrittura del risultato

Progettiamo Datapath incrementalmente, partendo dai circuiti che


risolvono ciascun sottoproblema
Fetch
Addu
ORI
...
- 34 -
Instruction Fetch Unit

STEP 1. Instruction Fetch: lettura di mem[PC]


STEP 2. Aggiornamento del program counter:
Se si va in sequenza: PC ← PC + 4
In caso di salto: PC ← “indirizzo indicato nell’istruzione”

Control Unit
Next
address
32 Cod.op.: Zero o uno
logic (dice se è un (condizione
branch) di salto)

Imm Op
16 6
Code
PC Datapath
32 memory 32 instruction
Clock

- 35 -
Datapath: partenza!

Assembliamo tutti i blocchi funzionali


per ottenere un unico datapath
Agiremo in modo incrementale:
Prima costruiamo un datapath per gestire una istruzione
dell’istruction set
Consideriamo una alla volta le altre istruzioni del set,
e ogni volta modifichiamo il datapath in modo che gestisca quella
istruzione, continuando a gestire anche le precedenti
(ogni volta, aggiungiamo alcuni controlli che la
Control Unit dovrà computare)

Il primo datapath gestisce l’istruzioni R-Type del tipo:


addu rd, rs, rt (“add unsigned”)
(semantica: R[rd] ← R[rs] + R[rt] , considerando i due operatori
come interi senza segno)

- 36 -
Somma e sottrazione (ADDU, SUBU)
addu rd, rs, rt R[rd] ← R[rs] op R[rt]

31 26 21 16 11 6 0
op rs rt rd shamt funct
(6+6)
12
Abilita
scrittura Unità di
Controllo
Rd Rs Rt
RegWr 5 ALUctr
5 5
32 7
busA Specifica di
Rw Ra Rb eseguire add o
busW
Result

ALU
32x32-bit sub, a seconda di
32 Registers busB
32 32 funct
Clk

Rosso: da Istruz.
Blu: da U.C.
- 37 - Verde: da/per ALU
Operazioni logiche con operando immediato

ori rt, rs, imm16 R[rt] <- R[rs] or ZeroExt[imm16]

Prima la destinazione Estensione


era rd. Ora è rt! a 32 bit

31 26 21 16 0
op rs rt immediate
6 bits 5 bits 5 bits 16 bits

- 38 -
Prossima operazione da aggiungere:
OR logico con operando immediato
R[rt] = R[rs] OR ZeroExt[imm16]
Datapath fin’ora:
Rd Rs Rt
RegWr 5 5 ALUctr
5 7
busA
Rw Ra Rb
busW 32 Result
32 32-bit

ALU
32 Registers 32
Clk busB
32

Rosso: da Istruz.
Blu: da U.C.
- 39 -
Operazioni logiche con operando immediato

Specifica di Rd Rt
Specifica di
selezionare rt
RegDst eseguire OR
Mux
Rs Rt
RegWr 5 ALUctr
Specifica di 5 5 7
scrivere in Rw busA
Rw Ra Rb
busW 32 Result
32 32-bit

ALU
32 Registers 32
Clk busB
32

Mux
imm16
16 ZeroExt 32

ALUSrc
Specifica di
Rosso: da Istruz. Verde: usato selezionare ingresso
Blu: da U.C. Grigio: non usato immediato esteso
- 40 -
Load (caricamento da memoria)

lw rt, rs, imm16


lw sta per load word (32 bit)

R[rt] ← Mem[R[rs] + SignExt[imm16]]


Viene letta la cella di memoria avente l’indirizzo dato dal contenuto
del registro rs, incrementato del valore immediato
Ad es. se rs contiene 1000 e imm16 = -67, viene letta la cella di
indirizzo 933
Il valore immediato a 16 bit è esteso in segno (può essere negativo)

31 26 21 16 0
op rs rt immediate
6 bits 5 bits 5 bits 16 bits

- 41 -
Prossimo comando da aggiungere: LOAD
R[rt] ← Mem[R[rs] + SignExt[imm16]]

Datapath fin’ora: Rosso: da Istruz.


Blu: da U.C.
Rd Rt
RegDst
Mux
Rs
RegWr 5 ALUctr
5 5
32 7
busA
Rw Ra Rb
busW
32

ALU
32x32
32
Registers busB 32
Clk

Mux
WrEn Address
Zero Ext

32
16
imm16 Data
Clk Memory
ALUSrc

- 42 -
Load Word Rosso: da Istruz.
Blu: da U.C.
(caricamento da memoria)
Verde: usato
selezionare Grigio: non usato
0:
Rt «non scrivere»
Rd Rt Carico il dato
MemWr Immette su
RegDst da mem a RT
Mux BusW il valore
Rs
SUM letto da mem
1: scrivere RegWr 5 ALUctr
5 5
7
in Rw busA 32
MemToReg
Rw Ra Rb
busW 32

ALU
32x32
32
Registers busB 32
Clk

Mux
Mux
Extender

32 WrEn Address
16 32
imm16 Data
Clk Memory
ALUSrc

Estensione ExtOp Seleziona


in segno l’immediato
- 43 -
Store (scrittura in memoria)

sw rt, rs, imm16


sw sta per store word (32 bit)
Mem[ R[rs] + SignExt[imm16] ] <- R[rt]
Il valore contenuto nel registro rt viene scritto nella cella di memoria
avente l’indirizzo dato dal contenuto del registro rs, incrementato
del valore immediato
Ad es. se rt contiene 49, rs contiene 1000 e imm16 = -67, nella cella di
indirizzo 933 viene scritto il valore 49
Il valore immediato a 16 bit è esteso in segno perché potrebbe essere
negativo.

31 26 21 16 0
op rs rt immediate
6 bits 5 bits 5 bits 16 bits

- 44 -
Prossimo comando: STORE
Mem[ R[rs] + SignExt[imm16] ] <- R[rt]
Situazione precedente… Rosso: da Istruz.
Blu: da U.C.
Rd Rt
MemWr
RegDst Mux
Rs Rt ALUctr
RegWr 5 5 5 3
busA 32 MemToReg
Rw Ra Rb
busW 32 32

ALU
32x32
Registers busB 32
Clk

Mux
Mux
Extender

32 WrEn Address
16 32
imm16 In Data Out
Clk Memory

ExtOp ALUSrc

- 45 -
Datapath per istruzione Store

1 Rosso: da Istruz.
“scrivo” Blu: da U.C.
Rd Rt

SUM MemWr
RegDst Mux
Rs Rt ALUctr
RegWr 5 5 5 3
0
busA 32 MemToReg
Rw Ra Rb
busW 32 32

ALU
32x32
Registers busB 32
Clk

Mux
Mux
Extender

32 WrEn Address
16 32
imm16 In Data Out
Clk Memory

ExtOp ALUSrc
sign imm
- 46 -
Istruzione di salto condizionato (branch)

beq rs, rt, imm16


Sequenza logica di esecuzione
Instruction ← mem[PC] // Fetch dell’istruzione da mem.
COND ← R[rs] == R[rt] // Calcolo della condizione di salto
if (COND == 1)
PC ← PC + 4 + ( SignExt(imm16) x 4 )

Spiazzamento in parole,
indirizzo in byte

31 26 21 16 0
op rs rt immediate
6 bits 5 bits 5 bits 16 bits

- 48 -
Gestione del PC

Instruction Out Istruzione


Fetch 32 corrente
Instruction
Memory
PC corrente Addr
(in bytes)
32
PC corrente
(in words)
00

30
Clk
Prossimo PC PC
(in words): 30
quello precedente
+1 + X. 30
(se non c’è salto,
X = 0) 1 CIn SUM

30
X
Architettura degli elaboratori - Luigi Lavazza - 49 - Porte logiche
Prossima op: BEQ
if (R[rs] == R[rt]) then PC = PC+4+SignExt(imm16)x4
Out instruction
32 Rosso: da Istruz.
Instruction
Memory Blu: da CU
Rd Rt ALUctr
Adr
MemWr
32 7
RegDst Mux
00 RegWr Rs
30
5 5 5
Clk busA MemToReg
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 Extender WrEn Adr
16 32
0…0 32 Data Out
imm16 In

Clk Memory

ExtOp ALUSrc

- 50 -
Prossima op: BEQ
if (R[rs] == R[rt]) then PC = PC+4+SignExt(imm16)x4
Out Instruction [31:0]
32 alla CU
Instruction
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30
5 5 5
Clk busA MemToReg
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 32 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk
Memory

nPC_sel ExtOp ALUSrc

- 51 -
Il DATAPATH: quadro complessivo

Out Instruction [31:0]


32 alla CU
Instruction
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30 5 5 5
Clk busA MemToReg
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 32 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

nPC_sel ExtOp ALUSrc

- 52 -
Procedura passo-passo per il progetto di
un processore
1. L’instruction set fornisce i requisiti per il datapath
2. Scegliere i componenti del datapath e la metodologia di
temporizzazione (clocking)
3. Progettare il datapath in modo da soddisfare i requisiti
4. Analizzare il datapath
per identificare tutti i controlli che determinano il datapath.
5. Progettare la logica di controllo

- 54 -
Dal Datapath all’Unità di Controllo
Instruction[31:0]
Instruction

[21:25]

[16:20]

[11:15]

[0:15]
[26:31]

[0:5]
Memory

Op Fun Rs Rt Rd Imm16

Op

Funct
Control Unit
nPC_sel RegWr RegDst ExtOp ALUSrc ALUctr MemWr MemToReg

7
Rs Equal
Rt
Rd DataPath
Imm

- 55 -
Quadro Complessivo a più alto livello

32 Instruction 32
Memory

Op
Funct Control Unit
nPC_sel RegWr RegDst ExtOp ALUSrc ALUctr MemWr MemToReg

Rs Equal
Rt
Rd DataPath
Imm
PC

- 56 -
Quadro Complessivo a più alto livello
organizzazione in chip di un micropocessore

32 Instruction 32
Memory

CPU
Op Control Unit MemWr
Funct
RegWr ExtOp ALUctr
nPC_sel RegDst ALUSrc MemToReg

7
32
Rs Equal PC In WrEn
32
Rt
Rd
DataPath Out
32
Imm Adr
ALU Data
Memory

- 57 -
Quadro Complessivo a più alto livello:
note
La Control Unit (CU) è un circuito puramente combinatorio
Rs, Rt, Rd e Imm16 sono passati a datapath con un collegamento fisso
Op e Funct sono passati alla Control Unit con un collegamento fisso
La CU produce i controlli che guidano il datapath
La maggior parte di questi dipende solo da Op , ma:
In alcune Op, ALUctr dipende anche da Fun (in altre, Fun non ha effetto)
nPC_sel dipende anche da Equal (che torna dal DataPath)
A causa del formato variabile delle istruzioni MIPS, alcuni bit
dell’istruzione sono replicati in campi diversi contemporaneamente;
per es:
I bit di Rd sono anche la prima parte di Imm16,
I bit di Fun sono anche l’ultima parte di Imm16, etc
…ma i controlli mandati dalla CU fanno sempre in modo che i campi
senza senso (per es Rd in una istruzione di tipo I) non abbiano alcun
effetto (per es siano nella parte ignorata di un Mutex)
- 58 -
Il Microprocessore

L’intera CPU sta tutta su un solo circuito integrato:


il «microprocessore»
(gli Istruction Set di tipo RISC, come il MIPS che abbiamo visto,
nascono proprio per permettere questo!)
Comprende:
La Control Unit
Il DataPath, che include
La ALU (spesso, la componente più grande!)
I banco dei registri e altri (compreso il PC)
Il circuito della gestione del PC
etc
La Memoria Cache (almeno quella L1)
Ma non comprende la RAM, che sta tipicamente su chip separati
(collegati al microprocessore attraverso un bus)

- 59 -
Procedura passo-passo per il progetto di
un processore
1. L’instruction set fornisce i requisiti per il datapath
2. Scegliere i componenti del datapath e la metodologia di
temporizzazione (clocking)
3. Progettare il datapath in modo da soddisfare i requisiti
4. Analizzare il datapath per identificare i controlli che determinano il
trasferimento tra registri.
5. Progettare la logica di controllo

- 60 -
Segnali di controllo: ricapitolando

Istruzione Register Transfer


ADD R[rd] ← R[rs] + R[rt]; PC ← PC + 1
ALUsrc = RegB, ALUctr = “add”, RegDst = rd, RegWr, nPC_sel = “+4”
SUB R[rd] ← R[rs] – R[rt]; PC ← PC + 1
ALUsrc = RegB, ALUctr = “sub”, RegDst = rd, RegWr, nPC_sel = “+4”
ORi R[rt] ← R[rs] + zero_ext(Imm16); PC ← PC + 1
ALUsrc = Im, Extop = “Z”, ALUctr = “or”, RegDst = rt, RegWr, nPC_sel = “+4”
LOAD R[rt] ← MEM[ R[rs] + sign_ext(Imm16)]; PC ← PC + 1
ALUsrc = Im, Extop = “Sn”, ALUctr = “add”,
MemtoReg, RegDst = rt, RegWr, nPC_sel = “+4”
STORE MEM[ R[rs] + sign_ext(Imm16)] ← R[rs]; PC ← PC + 1
ALUsrc = Im, Extop = “Sn”, ALUctr = “add”, MemWr, nPC_sel = “+4”
BEQ if ( R[rs] == R[rt] ) then PC ← PC + 1 + sign_ext(Imm16) else PC ← PC + 1
nPC_sel = EQUAL, ALUctr = “sub”

- 61 -
Definizione dei segnali di controllo

nPC_sel  if (OP == BEQ) then EQUAL else 0


ALUsrc  if (OP == “000000”) || (OP == BEQ)
then “regB” else “immed”
ALUctr  if (OP == “000000”) then funct
elseif (OP == ORi) then “or”
elseif (OP == BEQ) then “sub”
else “add”
ExtOp  if (OP == ORi) then “zero” else “sign”
MemWr  (OP == Store)
MemtoReg  (OP == Load)
RegWr:  if ((OP == Store) || (OP == BEQ)) then 0 else 1
RegDst:  if ((OP == Load) || (OP == ORi)) then 0 else 1

rt rd

- 62 -
I segnali di controllo
func 100000 100010 Don’t Care
op 000000 000000 001101 100011 101011 000100 000010
add sub ori lw sw beq jump
RegDst 1 1 0 0 x x x
ALUSrc 0 0 1 1 1 0 x
MemtoReg 0 0 0 1 x x x
RegWrite 1 1 1 1 0 0 0
MemWrite 0 0 0 0 1 0 0
nPCsel 0 0 0 0 0 1 0
Jump 0 0 0 0 0 0 1
ExtOp x x 0 1 1 x x
ALUctr[2:0] Add Sub Or Add Add Sub xxx

31 26 21 16 11 6 0
R-type op rs rt rd shamt funct add, sub

I-type op rs rt immediate ori, lw, sw, beq

J-type op target address jump

- 63 -
Un sottoinsieme delle istruzioni MIPS

Al sottoinsieme delle istruzioni MIPS implementate


manca il salto incondizionato
(utile perché: no condizione, ma salta più lontano)
JUMP:
j addr
Semantica: PC ← PC[31..28] || addr || 00

Addr in parole,
indirizzo in byte

31 26 25 0
op addr
6 bits 26 bits

- 64 -
Specifica delle istruzioni in RTL

Istruzione Effetto su registri e memoria Effetto su PC


addu R[rd] ← R[rs] + R[rt]; PC ← PC + 4
subu R[rd] ← R[rs] – R[rt]; PC ← PC + 4
ori R[rt] ← R[rs] or zero_ext(imm16); PC ← PC + 4
ldw R[rt] ← PC ← PC + 4
MEM[R[rs] + sign_ext(imm16)];
stw MEM[R[rs] + sign_ext(imm16)] ← PC ← PC + 4
R[rt];
beq if(R[rs]==R[rt]) then PC ←
PC+4+sign_ext(imm16)||00
else PC ← PC + 4
j PC[0..27] ← addr || 00

PC[31..28]
resta immutato

- 65 -
Cammino critico per l’istruzione load
R[rt] ← MEM[R[rs] + sign_ext(imm16)];
Out instruction
32
Instruction alla CU
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30 5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

nPC_sel ExtOp ALUSrc

- 66 -
Cammino critico per l’istruzione load
R[rt] ← MEM[R[rs] + sign_ext(imm16)]
Out instruction
32
Instruction alla CU
Memory
Rt SUM
ALUctr
Adr Rd
MemWr
32
0
1
RegDst Mux 7

Rs
30 00 1
RegWr
5 5 5
Clk busA 1
WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

0
nPC_sel sign
ExtOp 1
ALUSrc

- 67 -
Cammino critico per l’istruzione load
R[rt] ← MEM[R[rs] + sign_ext(imm16)];
Out instruction
32
Instruction alla CU
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30 5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

nPC_sel ExtOp ALUSrc

- 68 -
Cammino critico per l’istruzione load
R[rt] ← MEM[R[rs] + sign_ext(imm16)]
Out instruction
32
Instrucntion alla CU
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30 5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

nPC_sel ExtOp ALUSrc

- 69 -
Cammino critico per l’istruzione load
R[rt] ← MEM[R[rs] + sign_ext(imm16)]
Out instruction
32
Instrucntion alla CU
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30 5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
*CONTROL Clk Memory
UNIT

nPC_sel ExtOp ALUSrc

- 70 -
Cammino critico per l’istruzione load
R[rt] ← MEM[R[rs] + sign_ext(imm16)]
Out instruction
32
Instrucntion alla CU
Memory ALUctr
Rt
Adr Rd
MemWr
32 7
RegDst Mux
00 RegWr Rs
30 5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
start 30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 end Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

nPC_sel ExtOp ALUSrc

- 71 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
PC Old Value New Value
Instruction Memory Access Time
Rs, Rt, Rd,
Old Value New Value
Op, Func
Delay through Control Logic
ALUctr Old Value New Value

ExtOp Old Value New Value

ALUSrc Old Value New Value

MemtoReg Old Value New Value Register


Write Occurs
RegWr Old Value New Value
Register File Access Time
busA Old Value New Value
Delay through Extender & Mux
busB Old Value New Value
ALU Delay
Address Old Value New Value
Data Memory Access Time
busW Old Value New

- 72 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
1. Il fronte di discesa
PC Old Value New Value del clock ordina
l’aggiornamento dei
Instruction Memory Access Time
Rs, Rt, Rd,
Old Value New Value registri
Op, Func
Delay through Control Logic
ALUctr Old Value New Value

ExtOp Old Value New Value


2. Il nuovo valore del
ALUSrc Old Value New Value
PC diventa disponibile.
Inizia il fetch
MemtoReg Old Value New Value Register
dell’istruzione Write Occurs
RegWr Old Value New Value
Register File Access Time
busA Old Value New Value
Delay through Extender & Mux
busB Old Value New Value
ALU Delay
Address Old Value New Value
Data Memory Access Time
busW Old Value New

- 73 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
PC Old Value New Value
Instruction Memory Access Time
Rs, Rt, Rd,
Old Value New Value
Op, Func
Delay through Control Logic
ALUctr Old Value New Value

ExtOp Old Value New Value


3. La nuova istruzione
ALUSrc diventa disponibile.
Old Value New Value

MemtoReg
Inizia la decodifica
Old Value New Value Register
dell’istruzione Write Occurs
RegWr Old Value New Value
Register File Access Time
busA Old Value New Value
Delay through Extender & Mux
busB Old Value New Value
4. La UC genera i
ALU Delay
Address
segnali di controllo
Old Value New Value
Data Memory Access Time
busW Old Value New

- 74 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
PC Old Value New Value
Instruction Memory Access Time
Rs, Rt, Rd,
Old Value New Value
Op, Func
Delay through Control Logic
ALUctr Old Value New Value

ExtOp Old Value New Value

ALUSrc Old Value New Value

MemtoReg Old Value New Value Register


Write Occurs
RegWr Old Value New Value
Register File Access Time
busA Old Value New Value
Delay through Extender & Mux
busB Old Value New Value
5. I dati sono stati letti dai ALU Delay
Address registri, si sono propagati
Old Value New Value
attraverso bus, muliplexer Data Memory Access Time
busW e ALU. Old Value New
Inizia la lettura da mem. - 75 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
PC Old Value New Value
Instruction Memory Access Time
Rs, Rt, Rd,
Old Value New Value
Op, Func
Delay through Control Logic
ALUctr Old Value New Value

ExtOp Old Value New Value

ALUSrc Old Value New Value

MemtoReg Old Value New Value Register


Write Occurs
RegWr Old Value New Value
6. Lettura completata.
Register File Access Time
busA Old Value
Poco dopo il dato letto è
New Value
Delay through Extender & Mux
disponibile agli ingressi
busB Old Value
del banco di reg.New per la
Value
scrittura. ALU Delay
Address Old Value New Value
Data Memory Access Time
busW Old Value New

- 76 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
PC Old Value New Value
Instruction Memory Access Time
Rs, Rt, Rd,
Op, Func
Old Value New Value 7. Il fronte di discesa ordina
l’aggiornamento
Delay dei registri.
through Control Logic
ALUctr Old Value New Value
Il valore presente su busW
ExtOp Old Value
viene scritto nel registro di
New Value
destinazione.
ALUSrc Old Value New Value

MemtoReg Old Value New Value Register


Write Occurs
RegWr Old Value New Value
Register File Access Time
busA Old Value New Value
Delay through Extender & Mux
busB Old Value New Value
ALU Delay
Address Old Value New Value
Data Memory Access Time
busW Old Value New

- 77 -
Caso pessimo: tempo di esecuzione dell’istruzione Load
Clk
Clk-to-Q
PC Old Value New Value
Instruction Memory Access Time
Rs, Rt, Rd,
Old Value New Value
Op, Func
Delay through Control Logic
ALUctr Old Value New Value

ExtOp Old Value New Value

ALUSrc Old Value New Value

MemtoReg Old Value New Value Register


Write Occurs
RegWr Old Value New Value
Register File Access Time
busA Old Value New Value
Delay through Extender & Mux
busB Old Value New Value
ALU Delay
Address Old Value New Value
Data Memory Access Time
busW Old Value New

- 78 -
Cammino critico di Beq (Branch on Equal)
if (R[rs] == R[rt]) then PC = PC+4+SingExt(imm16)x4
Out instruction
32
Instrucntion alla CU
Memory COMPARE
Rt
Adr Rd
0
32 7
RegDst Mux
00 0 Rs
30
5 5 5
Clk busA MemToReg
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk
Memory

1o0 1 0
- 79 -
Cammino critico di Beq (Branch on Equal)
if (R[rs] == R[rt]) then PC = PC+4+SingExt(imm16)x4
Out instruction
32
Instrucntion alla CU
Memory CONTROL
ALUctr
Rt
Adr Rd UNIT
MemWr
32 7
RegDst Mux
start 00 RegWr Rs
30
5 5 5
Clk busA MemToReg
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
end Registers
CIn SUM Clk busB
1

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk
Memory

nPC_sel ExtOp ALUSrc

- 80 -
Cammino critico per l’istruzione StoreW
MEM[R[rs] + sign_ext(imm16)] ← R[rt]
Out instruction
32
Instrucntion alla CU
Memory
Rt SUM
ALUctr
Adr Rd
MemWr
32 7
1
RegDst Mux
Rs
30 00 0
RegWr
5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

0
nPC_sel sign
ExtOp 1
ALUSrc

- 81 -
Cammino critico per l’istruzione StoreW
MEM[R[rs] + sign_ext(imm16)] ← R[rt]
Out instruction
32
Instrucntion alla CU
Memory
Rt SUM
ALUctr
Adr Rd
MemWr
32 7
1
RegDst Mux
start 00 0
RegWr Rs
30 5 5 5
Clk busA WSrc
PC Rw Ra Rb =
busW 32 32 32

ALU
30 30 32x32
Registers busB
1 CIn SUM Clk

Mux
Mux
32
30 30 Extender WrEn Adr
16 32
imm16 32 In Data Out
* Clk Memory

end
0
nPC_sel sign
ExtOp 1
ALUSrc

- 82 -
Non si usano le implementazioni a ciclo singolo

È uno spreco che operazioni potenzialmente brevi debbano durare


tanto quanto quelle lunghe.
Anche per le operazioni lunghe (che accedono a memoria)
esiste la possibilità (molto concreta! quasi una sicurezza)
di usare la memoria cache, abbreviando i tempi …
(una piccola percentuale di accessi sfortunati è molto lenta –
la maggior parte risulta invece in cache hit)

- 83 -
Ricapitolando
5 passi di progetto del processore
Derivare i requisiti per il datapath dall’instruction set
Scegliere i componenti del datapath e la metodologia di
temporizzazione (clocking)
Progettare il datapath in modo da soddisfare i requisiti
Analizzare il datapath per identificare i controlli che determinano il
trasferimento tra registri
Progettare la logica di controllo
Il processore MIPS consente alcune semplificazioni
Tutte le istruzioni hanno la medesima dimensione (32 bit)
L’indicazione dei registri sorgenti ha sempre la stessa posizione
nell’istruzione
I valori immediati hanno la stessa dimensione e posizione
nell’istruzione
Le operazioni sono sempre su registri o valori immediati
Datapath a singolo ciclo => CPI=1, durata del clock lunga
- 84 -

Potrebbero piacerti anche