69
Electrónica Digital Computadoras de la Arena al Lenguaje C Ing. Jose Luis Hamkalo

Electrónica Digital

  • Upload
    ciro

  • View
    51

  • Download
    1

Embed Size (px)

DESCRIPTION

Electrónica Digital. Computadoras de la Arena al Lenguaje C. Ing. Jose Luis Hamkalo. Construyendo una Computadora Paso 1: La CPU. EL camino de datos Registros Register file ALU Bus Señales disponibles El ciclo de instrucción Búsqueda (Fetch) Decodificación Ejecución - PowerPoint PPT Presentation

Citation preview

Electrónica Digital

Computadorasde la Arena al Lenguaje C

Ing. Jose Luis Hamkalo

Construyendo una Computadora

Paso 1: La CPU• EL camino de datos

RegistrosRegister fileALUBus

• Señales disponibles• El ciclo de instrucción

Búsqueda (Fetch)DecodificaciónEjecución

• Secuenciamiento de instruccionesMicrooperacionesEjemplos

Registro con Salida de Alta Impedancia

D Q D Q D

R_inR_out

D_in_31 D_in_30 D_in_0

D_out_31 D_out_30 D_out_0

Ck Ck CkQ

Transferencias entre Registros por un BUS

A

B

Din

Din

Dout

Dout

BUS

Ain

BinBout

Aout

Para Copiar el contenido de A en B: Poner Aout y Bin en 1 (las otras en 0)

Transferencias entre Registros por un BUS (continuación)

A

C

Din

Din

Dout

Dout

BUS

Ain

CinCout

Aout

Para Copiar el contenido de A en B y C al mismo tiempo!!!: Poner Aout , Bin y Cin en 1 (las otras en 0)

B

Din

Dout

BinBout

Pone en 1 la salida correspondiente al número binario que se pone en las entradas .

El resto de las salidas en 0.Se usa en todas la memorias (RAM)

Decodificador Binario

Solo hace cálculos (ni más ni menos!): aritméticos, lógicos, comparaciones, etc.

Un ejemplo simple: opera sobre 2 bits (a y b) solo hace OR y AND:

Ahora hacela de 32 bits y que además sume, reste, multiplique, divida, etc.!!!

La Unidad Aritmético Lógica (ALU)

Solo hace cálculos (ni más ni menos!)

Pueder haber especializadas y más de una!

La Unidad Aritmético Lógica (ALU)

SumarRestar

Dividir...

ALU1

A B

A+B

Es un circuito secuencial (Máquina de estado Finito).

Recibe un código de operación como entrada y genera una secuencia de señales de control en tiempo en forma.

La Unidad de Control

Lógica Combinacional

Estado

Entrada(código de

Operación, i.e sumar, copiar,

etc)

Salida(Señales de

Control, i.e. Aout, Bin, SUMAR,

etc.)

Unidad de Control

Celdas con información.Se pueden leer o escribir.Se acceden por su dirección (posición en

un arreglo).Tipos

RAMROM (solo lectura)FLASH

Memoria

Ejemplo RAM de 4 x 2 bits (que chiquita!, quiero una de 4Gbytes!)

Memoria

Poniéndolo todo junto

El Camino de Datos (Data Path)

Qué es cada cosa?

Tenemos estas SeñalesREGISTER control signal EffectALUadd Configures the ALU to add its inputs

ALUand Configures the ALU to bitwise AND its inputs

ALUxor Configures the ALU to bitwise eXclusive OR its inputs

ALUor Configures the ALU to bitwise OR its inputs

ALUsll Configures the ALU to shift left logical; the result is (bus << Y)

ALUslt Configures the ALU to compare its inputs; the result is (Y < bus)

ALUsrl Configures the ALU to shift right logical; the result is (bus >> Y)

ALUsub Configures the ALU to subtract the buss input from Y

CONST(value) Places the constant value onto the bus

Y estas otras (quiero más!)IRaddrout

Tri-state enables the portion of the Instruction Register that contains the (26 bit, MIPS "J" format) address, along with the top 6 bits of the Program Counter, to be driven onto the bus

IRimmedoutTri-state enables the portion of the Instruction Register that contains the (16 bit, MIPS "I" format) 2's complement immediate value to be sign-extended to 32 bits and driven onto the bus

IRin Latches the bus data into the Instruction Register at the trailing edge of the clock cycle

IRoffsetout Tri-state enables the Instruction Register's shifted and sign extended value from the offset field to be driven onto the bus (used for branches)

JUMP(label) Microcode jump to label

JUMPonop Microcode jump to label named like the opcode; e.g., if an "Addi" is in the IR, jumps to the microcode label Addi

MARin Latches the bus data into the Memory Address Register at the trailing edge of the clock cycle

MARout Tri-state enables the Memory Address Register's output to be driven onto the bus

y las últimasMDRin Latches the bus data into the Memory Data Register at the trailing edge of the clock cycleMDRout Tri-state enables the Memory Data Register's output to be driven onto the bus

MEMread Initiate a memory read from the address in the MAR; here, you may assume that the memory will take 2 clock cycles to respond

MEMwrite Initiate a memory write using the data in the MDR and the address in the MAR; in this simple design, you may assume that a memory write takes precisely 1 clock cycle

PCin Latches the bus data into the Program Counter at the trailing edge of the clock cycle

PCinif0 Only if the value in Z is zero, latch the bus data into the Program Counter at the trailing edge of the clock cycle

PCout Tri-state enables the Program Counter's output to be driven onto the bus

REGin Latches the bus data into whichever register is selected by SELrs, SELrt, or SELrd; the value is latched at the trailing edge of the clock cycle

REGout Tri-state enables the output of whichever register is selected by SELrs, SELrt, or SELrd; the selected value is driven onto the bus

SELrs Selects the rs field of the IR to be used to control the register file's decoderSELrt Selects the rt field of the IR to be used to control the register file's decoderSELrd Selects the rd field of the IR to be used to control the register file's decoder

UNTILmfc Repeat this state until the memory has issued a memory fetch complete signal, indicating that the fetched value will be valid to read from the MDR in the next clock cycle

YinLatches the bus data into the Y register at the trailing edge of the clock cycle; this register is needed because, with only one bus, one of the two operands for a binary operation (e.g., Add) must come from somewhere other than the bus

Yout Tri-state enables the Y register's output to be driven onto the bus

Zin The ALU is always producing a result, but we only make note of that result if we latch the ALU's output into the Z register at the trailing edge of the clock cycle

Zout Tri-state enables the Z Register's output to be driven onto the bus

Como hago una suma?: Paso a Paso (Secuenciamiento de Instrucciones)

Start: PCout, MARin, MEMread, Yin CONST(4), ALUadd, Zin

Zout, PCin, UNTILmfc MDRout, Irin, JUMPonop ...

Add: SELrs, REGout, Yin SELrt, REGout, ALUadd, Zin

Zout, SELrd, REGin, JUMP(Start)

-Cada renglón se hace en un ciclo-Las señales dentro de un renglón se hacen al mismo tiempo (en paralelo)-En 7 ciclos logro sumar 2 registros! (El resultado lo guardo en un tercero)

Que tipos de instrucciones hay?

Aritmético-LógicasAcceso a Memoria (Load y Store)Saltos

CondicionalesIncondicionales

Aritméticas de Punto Flotante (FP)Sistema

Una CPU que obtiene sus instrucciones y datos de la memoria.

Y es capaz de ejecutarlas!

Como vamos por ahora?

Que Clase de Computadora Queremos?

• Computadoras de escritorioPCs y workstationsPrecio-desempeño óptimo

• ServidoresWebDisponibiladEscalabilidad

• Procesadores embarcadosDesempeño a precio mínimoMínimo conumo de potencia

Un Mouse es un Sistema de Cómputo!

-Mouse ÓpticoLED ilumina el escritorioCámara de baja resol.Procesador básico deImágenes detecta mov.Botones y rueda.-Supera al mouse mecánico de bolita.

Conjunto de instrucciones simple, Load/Store o tipo RISC (pocas instrucciones).

Diseñada para eficiencia del pipeline (procesamiento en línea de montaje)

Eficiencia para el compilador

Quiero una computadora de alto desempeño: La Arquitectura

MIPS 32

La Arquitectura MIPS 32

• Registros 32 registros de 32 bits: $0, $1, $2, $31 (int) 32 registros de 32 bits: $f0, $f1, $f2, $f31 (fp)

• Tipos de datosBytes (8 bits), Half Word (16 bits), Words (32 bits)Double words (fp)

• Modos de direccionamiento (Qué?) InmediatoDesplazamiento

CPU y FPUde MIPS 32 Para el Sistema

(Windows, linux ...)

Convención de Uso de Registros

Registers

Name Number Use Callee must preserve?

$zero $0 constant 0 N/A

$at $1 assembler temporary No

$v0–$v1 $2–$3values for function returns and expression evaluation

No

$a0–$a3 $4–$7 function arguments No

$t0–$t7 $8–$15 temporaries No

$s0–$s7 $16–$23 saved temporaries Yes

$t8–$t9 $24–$25 temporaries No

$k0–$k1 $26–$27 reserved for OS kernel No

$gp $28 global pointer Yes

$sp $29 stack pointer Yes

$fp $30 frame pointer Yes

$ra $31 return address N/A

Formatos de Instrucciones MIPS

Instrucción del Tipo I addi

8 rs rt imm

addi rt, rs, imm regs[rt] ← regs[rs] + imm

Op Code fuente destino inmediato(6 bits) (5 bits) (5 bits) (16 bits)

031

Ejemplo Instrucción del Tipo I addi

001000 00010 00001 0000000000001111

regs[1] ← regs[2] + 15

(Hardware)

Op Code fuente destino inmediato

Suma el contenido del registro fuente (rs) a una constante y lo guardaen el registro destino (rd)

Programando a Nivel de la Máquina

Programa en MIPS 32 que calcula la suma de los cuadrados de los numeros de 0 a 100.

Programando en Lenguaje Ensamblador

Da una sintaxis con mnemónicospara las instrucciones, registros y modos de direccionamiento.

Instrucción del Tipo I addi

8 rs rt imm

addi rt, rs, imm regs[rt] ← regs[rs] + imm(Texto)

(Hardware)

Op Code fuente destino inmediato(6 bits) (5 bits) (5 bits) (16 bits)

Ensam

blado

031

Ejemplo de addi

001000 00010 00001 0000000000001111

addi $1, $2, 15 regs[1] ← regs[2] + 15(Texto)

(Hardware)

Op Code fuente destino inmediato

Ensam

blado

Instrucción del Tipo I: lw

0x23 rs rt Offset

lw rt, offset(rs) Regs[rt] ← Mem[Regs[rs] + imm](Texto)

(Hardware)

Op Code fuente destino inmediato(6 bits) (5 bits) (5 bits) (16 bits)

Ensam

blado

031

Ejemplo de lw

010111 00100 00011 0000000000100001

lw $3, 33($4) Regs[3] ← Mem[Regs[4] + 33](Texto)

(Hardware)

Op Code fuente destino inmediato(6 bits) (5 bits) (5 bits) (16 bits)

Ensam

blado

031

Instrucción del Tipo I: bne

5 rs rt Offset

bne rs, rt, label if (Regs[rs] ≠ Regs[rt]) then PC ← PC+4+(Offsetx4)(Texto)

(Hardware)

Op Code fuente destino inmediato(6 bits) (5 bits) (5 bits) (16 bits)

Ensam

blado

031

else PC ← PC+4

Ejemplo de bne

000101 000101 000110 1111111111111011

bne $5, $6, loop if (Regs[5] ≠ Regs[6]) then PC ← PC+4+(-5x4)

Op Code fuente destino inmediato(6 bits) (5 bits) (5 bits) (16 bits)

031

else PC ← PC+4Loop:

bne $5, $6,-16

Instrucción del Tipo R: add

add rd, rs, rt Regs[rd] ← Regs[rs] + Regs[rt](Texto)

(Hardware)

Op Code fuente 1 fuente 2 destino función (6 bits) (5 bits) (5 bits) (5 bits) (6 bits)

Ensam

blado

031

0 rs rt rd 0 0x20

Ejemplo de add:

add $7, $8, $9 Regs[rd] ← Regs[rs] + Regs[rt](Texto)

(Hardware)

Op Code fuente 1 fuente 2 destino función (6 bits) (5 bits) (5 bits) (5 bits) (6 bits)

Ensam

blado

031

0 01000 01001 00111 0 0x20

Instrucción del Tipo R: sll

sll rd, rt, shamt Regs[rd] ← Regs[rt] << shamt(Texto)

(Hardware)

Op Code fuente destino despl. función (6 bits) (5 bits) (5 bits) (5 bits) (6 bits)

Ensam

blado

031

0 rt rd shamt 0

Instrucción del Tipo J: j

j target pc ← target*(Texto)

(Hardware)

Op Code destino(6 bits) (26 bits)

Ensam

blado

031

2 target

Instrucción del Tipo J: jal

jal target Regs[31] ← pcpc ← target*

(Texto)

(Hardware)

Op Code destino(6 bits) (26 bits)

Ensam

blado

031

3 target

Instrucciones Aritmético Lógicasen MIPS 32

• add, addu, addi, addiu, sub• and, andi, xor, xori, nor, or, ori • clo, clz• div (cociente en lo, resto en hi), divu• mult, multu (resultado en hi lo)• mul (especifica rdest)• madd, maddu, msub, msubu (resultado en hi lo)• sll, sllv, sra, srav, srl, srlv

Instrucciones que Manipulan Constantes y de Comparación

• lui • slt, sltu, slti, sltiu,

Instrucciones de Branch

• beq• bgez, bgezal• bgtz• blez• bltz, bltzal• bne

Instrucciones de Jump

• j, jal• jr, jalr

Instrucciones de carga-almacenamiento

• lb, lbu, lh, lhu, lw• sb, sh, sw

Instrucciones de Movimiento de Datos

• mfhi, mflo• mthi, mtlo• movn• movz

Instrucciones de Llamada al Sistema

• eret• syscall• break

Instrucción que no Hace Nada

• nop

Pseudoinstrucciones (Facilidades del Assembler)

Name instruction syntax Real instruction translation meaning

Move move $rt,$rs addi $rt,$rs,0 R[rt]=R[rs]

Clear clear $rt add $rt,$zero,$zero R[rt]=0

Load Address la $at, LabelAddrlui $at, LabelAddr[31:16]; ori $at,$at, LabelAddr[15:0]

$at = Label Address

Load Immediate li $at, IMMED[31:0] lui $at, IMMED[31:16]; ori $at,$at, IMMED[15:0]

$at = 32 bit Immediate value

Branch if greater than bgt $rs,$rt,Label slt $at,$rt,$rs; bne $at,$zero,Label if(R[rs]>R[rt]) PC=Label

Branch if less than blt $rs,$rt,Label slt $at,$rs,$rt; bne $at,$zero,Label if(R[rs]<R[rt]) PC=Label

Branch if greater than or equal bge $rs,$rt,Label slt $at,$rs,$rt; beq $at,

$zero,Labelif(R[rs]>=R[rt]) PC=Label

Branch if less than or equal ble $rs,$rt,Label slt $at,$rt,$rs; beq $at,

$zero,Labelif(R[rs]<=R[rt]) PC=Label

Branch if greater than unsigned bgtu $rs,$rt,Label if(R[rs]=>R[rt])

PC=Label

Branch if greater than zero bgtz $rs,$rt,Label if(R[rs]>0) PC=Label

Multiplies and returns only first 32 bits mul $1, $2, $3 mult $2, $3; mflo $1 $1 = $2 * $3

Programando en Lenguaje Ensamblador (con

abstracciones)Agrega: directivas, labels, pseudoinstrucciones, modos de direccionamiento no soportadospor el procesador.

Proceso de producir un ejecutable

Ensamblador

• Programa que traduce el código assembly a binario.

• Genera como salida un archivo objeto.

Archivo objeto generado por un assembler en Unix

Modelo de memoria

Llamados a Funciones

Necesidad de Mayores Abstracciones: Lenguajes de Alto Nivel

#include <stdio.h>int main(){ int i, sum = 0; for(i=0;i<=100;i++) sum = sum + i*i; printf("La suma de 0 ... 100 es \n%10d",sum); return 0;}

El Compilador

Generación de un Ejecutable

Linker• Enlaza los archivos objeto y genera el ejecutable.• Resuelve las referencias a bibliotecas externas.• Asigna las posiciones finales en memoria.

Construyendo una ComputadoraPaso 2: Los Dispositivos de Entrada

Salida

Sistemas basados en MIPS• Routers• Cablemodem• ADSL• Smart Cards• Impresoras laser• Decodificadores• PlaySation 2• Robots• Celulares

Arquitectura MIPS presente en los siguientes procesadores

• IDT RC32438; ATI Xilleon; Alchemy Au1000, 1100, 1200; Broadcom Sentry5; RMI XLR7xx, Cavium Octeon CN30xx, CN31xx, CN36xx, CN38xx and CN5xxx; Infineon Technologies EasyPort, Amazon, Danube, ADM5120, WildPass, INCA-IP, INCA-IP2; Microchip Technology PIC32; NEC EMMA and EMMA2, NEC VR4181A, VR4121, VR4122, VR4181A, VR5432, VR5500; Oak Technologies Generation; PMC-Sierra RM11200; QuickLogic QuickMIPS ESP; Toshiba Donau, Toshiba TMPR492x, TX4925, TX9956, TX7901.

Supercomputadoras basadas en MIPS.

Evolución SGI

Estaciónesde Trabajo

gráficasServidores Supercomputadoras

1990 1996 2005

Supercomputadoras basadas en MIPS.

SGI Origin 2000

Supercomputadoras basadas en MIPS. Sircortex startup

(2007)

Sircortex SC5832 CHIP (nodo): multinucleo 6 MIPS 64Topologia Kautz graphControlador de memoria crossbarinterconnect DMA engine, Gigabit Ethernet y PCI Expressen un chip que consume 10 wattsDesempeño pico de 6 Gigaflops.Configuración tope (un solo gabinete):972 nodos, total de 5832 nucleos MIPS64 y 8.2 teraFLOPS de desempeñopico.

Todos se basan en los principios del que acabamos de estudiar

Que Micros estamos Usando?

Múltiples NúcleosCada Núcleo ejecuta varias instrucciones

en un cicloMemorias CacheY a una altísima velocidad!!! (3.000

millones de ciclos por segundo)

Que Micros estamos Usando?

Plataforma Intel 975

Ejemplo chipset intel 975

FIN• El intel 4004, primer microprocesador

(1971)