O Processador: Via de Dados e Controle (Parte C: microprogramação) Ch5B 1
Possibilidades para o projeto de UCs Initial representation Finite state diagram M icroprogram Sequencing control Explicit next state function M icroprogram counte r + dispatch ROMS Logic representation Logic equations Truth table s Im plementation technique Pro gram mable logic array Read only memory Ler Historical perspective and further reading RISC x CISC Controle hardwired microprogramado (firmware) Ch5B 2
Implementando o controle Valores dos sinais de controle dependem de: Qual instrução está sendo executada Que passo está sendo processado Especificar a máquina de estados finitos graficamente, ou Usar microprogramação Implementação pode ser derivada da especificação Ch5B 3
Especificação gráfica da MEF 2 Memory address computation ALUSrcA = 1 ALUSrcB = 10 ALUOp = 00 Start Instruction fetch 0 MemRead ALUSrcA = 0 IorD = 0 IRWrite ALUSrcB = 01 ALUOp = 00 PCSource = 00 6 (Op = 'LW') or (Op = 'SW') Execution ALUSrcA =1 ALUSrcB = 00 ALUOp= 10 8 (Op = R type) Branch completion ALUSrcA = 1 ALUSrcB = 00 ALUOp = 01 Cond PCSource = 01 Instruction decode/ register fetch 1 (Op = 'BEQ') 9 ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00 (Op = 'J') Jump completion PCSource = 10 (Op = 'SW') 3 (Op = 'LW') Memory access 5 Memory access 7 R type completion MemRead IorD = 1 MemWrite IorD = 1 RegDst = 1 RegWrite MemtoReg = 0 4 Write back step RegDst=0 RegWrite MemtoReg=1 Quantos bits de estado serão necessários? Ch5B 4
MEF para controle Control logic Inputs Outputs Cond IorD MemRead MemWrite IRWrite MemtoReg PCSource ALUOp ALUSrcB ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0 Op5 Op4 Op3 Op2 Op1 Op0 S3 S2 S1 S0 Instruction register opcode field State register Ch5B 5
Implementação via PLA Op5 Op4 Op3 Op2 Op1 Op0 S3 S2 S1 S0 Cond IorD MemRead MemWrite IRWrite MemtoReg PCSource1 PCSource0 ALUOp1 ALUOp0 ALUSrcB1 ALUSrcB0 ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0 Ch5B 6
Implementação via ROM ROM = "Read Only Memory" Uma ROM pode ser usada para implementar uma tabela verdade Se o endereço possui m bits, pode se endereçar 2 m entradas na ROM. A saída são os bits de dados que o endereço aponta m n 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 m é a altura, e n é a largura Ch5B 7
Implementação via ROM Quantas entradas? 6 bits para opcode, 4 bits para estado = 10 bits de endereço (i.e., 2 10 = 1024 endereços diferentes) Quantas saídas? 16 saídas para controle da via de dados, 4 bits de estado= 20 bits de saída ROM é 2 10 x 20 = 1K x 20 bits Ocupa muita área! Ch5B 8
ROM vs PLA Divisão da tabela em duas partes 4 bits de estado indicam 16 saídas, 2 4 x 16 bits da ROM 10 bits tell you the 4 next state bits, 2 10 x 4 bits da ROM Total: 4.3K bits de ROM PLA é muito menor Pode compartilhar termos de produtos Necessita apenas de entradas que produzem uma saída ativa Pode levar em conta sinais do tipo don't care Tamanho é (#inputs #product terms) + (#outputs #product terms) Para o nosso exemplo = (10x17)+(20x17) = 460 células de PLA Ch5B 9
Outro estilo de implementação Instruções complexas: o próximo estado é o estado atual + 1 Control unit PLA or ROM Input Outputs Cond IorD MemRead MemWrite IRWrite BWrite MemtoReg PCSource ALUOp ALUSrcB ALUSrcA Reg Write RegDst AddrCtl 1 State Adder Address select logic Op[5 0] Instruction register opcode field Ch5B 10
Visão geral PLA or ROM 1 Unidade de controle µprogramado Adder State Mux 3 2 1 0 0 AddrCtl Memória de MicroControle End Dados µir seq Dispatch ROM 2 Op Instruction register opcode field Dispatch ROM 1 Address select logic µpc INCR CC (tabelas) IR OP Ch5B 11
controle Dispatch ROM 1 Dispatch ROM 2 Op Opcode name Value Op Opcode name Value 000000 R format 0110 100011 lw 0011 000010 jmp 1001 101011 sw 0101 000100 beq 1000 100011 lw 0010 1 101011 sw 0010 Adder PLA or ROM State Mux 3 2 1 0 AddrCtl 0 Dispatch ROM 2 Dispatch ROM 1 Address select logic Op Instruction register opcode field State number Address control action Value of AddrCtl 0 Use incremented state 3 1 Use dispatch ROM 1 1 2 Use dispatch ROM 2 2 3 Use incremented state 3 4 Replace state number by 0 0 5 Replace state number by 0 0 6 Use incremented state 3 7 Replace state number by 0 0 8 Replace state number by 0 0 9 Replace state number by 0 0 Ch5B 12
Microprogramação Control unit Microcode memory Input Outputs Cond IorD MemRead MemWrite IRWrite BWrite MemtoReg PCSource ALUOp ALUSrcB ALUSrcA RegWrite RegDst AddrCtl Datapath 1 Microprogram counter Adder Address select logic Op[5 0] Instruction register opcode field O que são as microinstruções? Ch5B 13
Diagrama de transição de estados Estado Address control action seq 0 Use incremented state 3 1 Use dispatch ROM 1 1 2 Use dispatch ROM 2 2 3 Use incremented state 3 4 Replace state number by 0 0 5 Replace state number by 0 0 6 Use incremented state 3 7 Replace state number by 0 0 8 Replace state number by 0 0 9 Replace state number by 0 0 2 Memory address computation ALUSrcA = 1 ALUSrcB = 10 ALUOp = 00 Start Instruction fetch 0 MemRead ALUSrcA = 0 IorD = 0 IRWrite ALUSrcB = 01 ALUOp = 00 PCSource = 00 6 (Op = 'LW') or (Op = 'SW') Execution ALUSrcA =1 ALUSrcB = 00 ALUOp= 10 8 (Op = R type) Branch completion ALUSrcA = 1 ALUSrcB = 00 ALUOp = 01 Cond PCSource = 01 Instruction decode/ register fetch 1 (Op = 'BEQ') 9 ALUSrcA = 0 ALUSrcB = 11 ALUOp = 00 (Op = 'J') Jump completion PCSource = 10 (Op = 'SW') 3 (Op = 'LW') Memory access 5 Memory access 7 R type completion MemRead IorD = 1 MemWrite IorD = 1 RegDst = 1 RegWrite MemtoReg = 0 4 Write back step RegDst=0 RegWrite MemtoReg=1 Ch5B 14
Um microprograma horizontal Estado Address control action seq 0 Use incremented state 3 1 Use dispatch ROM 1 1 2 Use dispatch ROM 2 2 3 Use incremented state 3 4 Replace state number by 0 0 5 Replace state number by 0 0 6 Use incremented state 3 7 Replace state number by 0 0 8 Replace state number by 0 0 9 Replace state number by 0 0 IorD IRWR MemRD MemWR PCWR PCWR cond Mem2Reg RegDst RegWR AluSrcA Desvio Obs Fetch 0 1 1 1 0 01 00 00 Seq Lê instrução; PC < PC+4 0 11 00 Dispatch1 ALUout< end de desvio LWSW1 1 10 00 Dispatch2 end efetivo LW2 1 1 Seq Lê memória 1 0 1 Fetch Write Back SW2 1 1 Fetch Escreve na Mem. RFormat1 1 00 10 Seq Executa ALU 0 1 1 Fetch Write Back Beq1 1 1 00 01 01 Fetch Desvio condicional Jump1 1 10 Fetch Desvio incondicional AluSrcB AluOP PCSrc Ch5B 15
Microprogramação Uma metodologia de especificação Apropriada se centenas de opcodes, modos, ciclos, etc. Sinais especificados simbolicamente usando microinstruções Label ALU control SRC1 SRC2 Register control Memory control Sequencing Fetch Add PC 4 Read PC ALU Seq Add PC Extshft Read (nada) Dispatch 1 Mem1 Add A Extend Dispatch 2 LW2 Read ALU Seq Write MDR Fetch SW2 Write ALU Fetch Rformat1 Func code A B Seq Write ALU Fetch BEQ1 Subt A B ALUOut cond Fetch JUMP1 Jump address Fetch Duas implementações da mesma arquitetura possuem o mesmo microcódigo? Ch5B 16
Formato das microinstruções Field name Value Signals active Comment Add ALUOp = 00 Cause the ALU to add. ALU control Subt ALUOp = 01 Cause the ALU to subtract; this implements the compare for branches. Func code ALUOp = 10 Use the instruction's function code to determine ALU control. SRC1 PC ALUSrcA = 0 Use the PC as the first ALU input. A ALUSrcA = 1 Register A is the first ALU input. B ALUSrcB = 00 Register B is the second ALU input. SRC2 4 ALUSrcB = 01 Use 4 as the second ALU input. Extend ALUSrcB = 10 Use output of the sign extension unit as the second ALU input. Extshft ALUSrcB = 11 Use the output of the shift by two unit as the second ALU input. Read Read two registers using the rs and rt fields of the IR as the register numbers and putting the data into registers A and B. Write ALU RegWrite, Write a register using the rd field of the IR as the register number and Register RegDst = 1, the contents of the ALUOut as the data. control MemtoReg = 0 Write MDR RegWrite, Write a register using the rt field of the IR as the register number and RegDst = 0, the contents of the MDR as the data. MemtoReg = 1 Read PC MemRead, Read memory using the PC as address; write result into IR (and lord = 0 the MDR). Memory Read ALU MemRead, Read memory using the ALUOut as address; write result into MDR. lord = 1 Write ALU MemWrite, Write memory using the ALUOut as address, contents of B as the lord = 1 data. ALU PCSource = 00 Write the output of the ALU into the PC. PC write control ALUOut cond PCSource = 01, If the Zero output of the ALU is active, write the PC with the contents Cond of the register ALUOut. jump address PCSource = 10, Write the PC with the jump address from the instruction. Seq AddrCtl = 11 Choose the next microinstruction sequentially. Sequencing Fetch AddrCtl = 00 Go to the first microinstruction to begin a new instruction. Dispatch 1 AddrCtl = 01 Dispatch using the ROM 1. Dispatch 2 AddrCtl = 10 Dispatch using the ROM 2.
Codificação x Não codificação Não codificado 1 bit para cada operação da via de dados Mais rápido, requer mais memória (lógica) Usado pelo Vax 780 incríveis 400K de memória! Codificado Enviar microinstruções e obter sinais de controle Usa menos memória mas é mais lento Contexto histórico de CISC: Muita lógica de controle para colocar em um único chip Utilizar uma ROM (ou mesmo uma RAM) para manter o microcódigo A adição de novas instruções é mais simples Ch5B 18
Microcódigo A distinção entre especificação e implementação é, algumas vezes, difícil de encontrar Vantagens da especificação: Fácil de projetar e escrever Projetar arquitetura e microcódigo em paralelo Vantagens da implementação (ROM) Fácil de modificar uma vez que os valores estão em uma memória Pode emular outras arquiteturas Pode fazer uso de registradores internos Desvantagens da implementação : Controle é implementado no mesmo chip como o processador ROM não é mais rápida que uma RAM Ch5B 19