• Non ci sono risultati.

Progetto di una ALU

N/A
N/A
Protected

Academic year: 2021

Condividi "Progetto di una ALU"

Copied!
25
0
0

Testo completo

(1)

Progetto di una ALU

(2)

Progettare una ALU veloce

Quali sono le specifiche?

n

Deve supportare le operazioni Aritmetico/Logiche

di una macchina moderna

n

Deve essere garantito un efficiente compromesso

tra costi e velocità basato sulla frequenza di

occorrenza delle operazioni e sul budget

(3)

Tecniche di progetto

o

Divide et Impera

o

Riuso di componenti

(4)

Specifiche ALU MIPS (semplificata)

o

Add, AddU, Sub, SubU, AddI, AddIU

n

=> add/sub in complemento a 2 con

rilevamento dell’overflow

o

And, Or, AndI, OrI, Xor, Xori, Nor

n

=> AND e OR logiche, XOR, NOR

o

SLTI, SLTIU (set less than)

n

=> comparazione usata come condizione per i

(5)

Formato istruzioni aritmetiche

o

L’aritmetica con

segno genera

overflow, non riporti

R-type:

I-Type:

31

25

20

15

5

0

op

Rs

Rt

Rd

funct

op

Rs

Rt

Immed 16

Type op funct ADDI 10 xx ADDIU 11 xx SLTI 12 xx SLTIU 13 xx ANDI 14 xx ORI 15 xx XORI 16 xx LUI 17 xx Type op funct ADD 00 40 ADDU 00 41 SUB 00 42 SUBU 00 43 AND 00 44 OR 00 45 XOR 00 46 NOR 00 47 Type op funct 00 50 00 51 SLT 00 52 SLTU 00 53

(6)

divide et impera

o

Suddividere il problema in problemi

più semplici, risolverli e mettere

assieme le soluzioni

o

Esempio: assumiamo che gli

immediati siano stati trattati prima

di arrivare alla ALU

00 add 01 addU 02 sub 03 subU 04 and 05 or 06 xor 07 nor 12 slt 13 sltU

ci siamo ridotti a 10

operazioni (4 bits)

(7)

Specifiche raffinate

(1) Specifiche Funzionali

inputs: 2 operandi da 32-bit

A

e

B

,

4-bit per

il controllo

outputs: risultato a 32-bit

S

,

1-bit riporto

,

1

bit overflow

operazioni: add, addu, sub, subu, and, or, xor,

nor, slt, sltU

ALU

A

B

m

ovf

S

32

32

32

4

c

(2)

Diagramma

a Blocchi

(8)

Decomponiamo in bit-slice

ALU0

a0 b0 cin cout s0

ALU31

a31 b31 cin cout s31

M

4

m m

A

32

B

32

S

32

(9)

Qual è il nostro elemento base?

o

Logica

Combinatoria

7-a-2

M

4

ALU0

a0

b0

m

cin

co

s0

Function

Inputs

Outputs

M0 M1 M2 M3 A B Cin S Cout

add 0 0 0 0 0 0 0 0 0

0

(10)

Semi Addizionatore (Half Adder)

Ai 0 0 1 1 Bi 0 1 0 1 Sum 0 1 1 0 Carry 0 0 0 1 Ai Bi 0 1 0 1 0 1 1 0 Sum = Ai Bi + Ai Bi = Ai + Bi Ai Bi 0 1 0 1 0 0 1 0 Carry = Ai Bi

Schema realizzativo

Carry Sum A i B i

(11)

Full Adder

+

A3 B3

S3

+

A2 B2

S2

+

A1 B1

S1

+

A0 B0

S0

C1

C2

C3

Cascaded Multi-bit

Adder

Come abbiamo visto, di solito siamo interessati ad addizionare

più di 2 bit

Ecco perché ci serve un full adder

(12)

Addizione Binaria

Full Adder

A

0

0

0

0

1

1

1

1

B

0

0

1

1

0

0

1

1

CI

0

1

0

1

0

1

0

1

S

0

1

1

0

1

0

0

1

CO

0

0

0

1

0

1

1

1

A B

CI

0

1

00 01 11 10

0

1

1

0

1

0

0

1

A B

CI

0

1

00 01 11 10

0

0

0

1

0

1

1

1

S

CO

S = CI xor A xor B

CO = B CI + A CI + A B = CI (A + B) + A B

(13)

Full Adder/Half Adder

Implementazione

Alternativa : 5 Gates

Half

Adder

A

B

Half

Adder

A + B

CI

A + B + CI

S S CO CO

A B

CI (A + B)

S

CO

A B + CI (A xor B) = A B + B CI + A CI

Approccio Standard : 6 Gates

+

A A A B B B CI CI S CO

(14)

Torniamo alla ALU

o

Trucco N. 2: prendiamo

pezzi noti e proviamo a

metterli assieme

o

Trucco N. 3: risolvere

parti del problema e

provare a estendere la

soluzione

A B CarryIn 1-bit Full Adder add

and

or

M u x Result

S-select

E se usassimo un MUX ?

Come estendiamo a

tutte le operazioni

richieste?

(15)

Estensione a ulteriori operazioni

o

A - B = A + (– B)

n 

formare il complemento a 2 invertendo e sommando 1

A B 1-bit Full Adder CarryOut M u x CarryIn Result add

and

or

S-select

invert

(16)

Operazioni addizionali: Schema modificato

o

LSB e MSB richiedono qualche piccolo

extra

A

B

M

S

32

32

32

4

Ovflw

ALU0

a0

b0

cin

co

s0

ALU31

a31 b31

cin

co

s31

Logica di

controllo

per

produrre

select,

comp,

?

(17)

Overflow

o

Esempi: 7 + 3 = 10 ma ...

o

- 4 - 5 = - 9 ma ...

Complemento a 2 Binario Decimale 0 0000 1 0001 2 0010 3 0011 0000 1111 1110 1101 Decimale 0 -1 -2 -3 4 0100 5 0101 6 0110 7 0111 1100 1011 1010 1001 -4 -5 -6 -7 1000 -8 0 1 1 1 0 0 1 1 + 1 0 1 0 1 1 1 0 0 1 0 1 1 + 0 1 1 1 1 1 0 7 3 1 – 6 – 4 – 5 7

(18)

Rilevazione dell’Overflow

o

Overflow: il

risultato

è troppo grande (o troppo piccolo) per essere

rappresentato opportunamente

n

Esempio: - 8 < = numero binario a 4-bit <= 7

o

Se stiamo sommando operandi con segni differenti, l’overflow non

può accadere!

o

L’Overflow accade quando sommiamo:

n

2 positivi e la somma è negativa

n

2 numeri negativi e la somma è positiva

o

  Esercizio

: Dimostrate che è possibile rilevare l’overflow quando

n

C’è riporto entrante nel MSB ° C’è riporto uscente dal MSB

0 1 1 1 0 0 1 1 + 1 1 0 7 3 1 1 1 0 0 1 0 1 1 + 1 –4 – 5 0

(19)

Logica Combinatoria per l

Overflow

o

Carry in MSB ° Carry out of MSB

n 

Per una ALU a N-bit : Overflow = CarryIn[N - 1] XOR CarryOut[N - 1]

CarryOut3 A0 B0 1-bit ALU Result0 CarryIn0 CarryOut0 A1 B1 1-bit ALU Result1 CarryIn1 CarryOut1 A2 B2 1-bit ALU Result2 CarryIn2 A3 B3 1-bit ALU Result3 CarryIn3 Overflow X Y X XOR Y 0 0 0 0 1 1 1 0 1 1 1 0

(20)

Ancora sullo Schema Modificato

o

I bit LSB e MSB necessitano di qualche

Extra

A

B

M

S

32

32

32

4

Ovflw

ALU0

a0

b0

cin

co

s0

ALU0

a31 b31

cin

co

s31

Logica di

controllo per

produrre

select,

comp,

c-in

Aritm. con segno

and cin xor co

(21)

La nostra ALU

o

Dobbiamo fornire l’istruzione slt:

set-on-less-than

n

Attenzione: slt è una istruzione aritmetica

n

produce un 1 se rs < rt e uno 0 in caso contrario

n

usiamo la sottrazione: (a-b) < 0 implica a < b

o

Dobbiamo fornire l’istruzione un test di

eguaglianza (beq $t5, $t6, $t7)

(22)

Set a31 ALU0 Result0 CarryIn a0 Result1 a1 0 Result2 a2 0 Operation b31 b0 b1 b2 Result31 Binvert CarryIn Less CarryIn CarryOut ALU1 Less CarryIn CarryOut ALU2 Less CarryIn CarryOut ALU31 CarryIn

Istruzione slt: come affrontare il problema?

Osservazione:

Tutti i bit vanno a 0

tranne il LSB che

dipende dal test

(23)

Istruzione slt: ALU MSB

0 3 Result Operation a 1 CarryIn 0 1 Binvert b 2 Less Set Overflow detection Overflow .

Nota:

Osservate

questa diversa

soluzione

per l

invert!

Segnale di Set

che va

riportato

nell’ingresso

Less della ALU

LSB

MA NON

DIMENTICHIAMO

Esercizio: Modificare questo schema in

modo che funzioni in presenza di overflow

(24)

Test di eguaglianza

o

Attenzione

alle linee di

controllo

o

000 = and

001 = or

010 = add

110 =

subtract

111 = slt

Nota: il segnale di

uscita zero vale 1

quando il risultato

è 0!

Set a31 0 Result0 a0 Result1 a1 0 Result2 a2 0 Operation b31 b0 b1 b2 Result31 Overflow Binvert Zero ALU0 Less CarryIn CarryOut ALU1 Less CarryIn CarryOut ALU2 Less CarryIn CarryOut ALU31 Less CarryIn

(25)

Prime Conclusioni

Abbiamo costruito una ALU

idea fondamentale: usare un multiplexer per selezionare

l’output

la sottrazione viene realizzata con il complemento a 2

approccio bit-slice: possiamo replicare la ALU da 1-bit per

produrre quella a 32-bit

Questioni hardware Importanti

Tutte i gate sono sempre in funzione

La velocità di un gate dipende dal numero di input

La velocità di una macchina dipende dal numero di gates in

serie (il “critical path”)

Riferimenti

Documenti correlati

Le prime 8 righe della tabella riguardano il caso in cui l’ esito del confronto si puo’ stabilire solo dai due gruppi di 4 bit di entrata ( i quattro bit di A sono maggiori dei

difference, being more relevant at the bottom of the wage distribution, thus showing a greater effect of JI for low wages. Bootstrap standard errors for semi-parametric estimates

[r]

Moreover, to implement the “decreasing distance” rout- ing mechanism described above, each message m carries a destination list: the (estimated) list of brokers interested

Results: Findings suggest the process of existential suffering begins with an experience of groundlessness that results in an overarching process of Longing for Ground in a

Specifically, the chapter presents evaluation of recommendation systems according to recommendation accuracy, technical constraints, and business values in the context of

A further investigation into the patient’s case history confirmed that 20 days earlier, during a holiday on Lake Bolsena, Central Italy, he had eaten raw fish marinated in fresh

We conclude with suggestive evidence that the underlying links between past slavery and current inequality run through the political exclusion of former slaves and the