Sequential Architecture Implementation CSCI 370 Computer Architecture Y

  • Slides: 51
Download presentation
Sequential Architecture Implementation CSCI 370: Computer Architecture

Sequential Architecture Implementation CSCI 370: Computer Architecture

Y 86 -64 Instruction Set #1 Byte 0 halt 0 0 nop 1 0

Y 86 -64 Instruction Set #1 Byte 0 halt 0 0 nop 1 0 cmov. XX r. A, r. B 2 fn r. A r. B irmovq V, r. B 3 0 F rmmovq r. A, D(r. B) 4 0 r. A r. B D mrmovq D(r. B), r. A 5 0 r. A r. B D OPq r. A, r. B 6 fn r. A r. B j. XX Dest 7 fn Dest call Dest 8 0 ret 9 0 pushq r. A A 0 r. A F popq r. A B 0 r. A F 1 2 r. B V Dest 3 4 5 6 7 8 9

Y 86 -64 Instruction Set #2 Byte 0 halt 0 0 nop 1 0

Y 86 -64 Instruction Set #2 Byte 0 halt 0 0 nop 1 0 cmov. XX r. A, r. B 2 fn r. A r. B irmovq V, r. B 3 0 rmmovq r. A, D(r. B) 4 0 mrmovq D(r. B), r. A 5 0 OPq r. A, r. B 6 fn r. A r. B j. XX Dest 7 fn Dest call Dest 8 0 ret 9 0 pushq r. A A 0 r. A F popq r. A B 0 r. A F 1 F 2 r. B V r. A r. B D Dest 3 4 5 6 7 rrmovq 8 cmovle 7 9 7 0 cmovl 7 2 cmove 7 3 cmovne 7 4 cmovge 7 5 cmovg 7 6 1

Byte Y 86 -64 Instruction Set #3 0 1 2 halt 0 0 nop

Byte Y 86 -64 Instruction Set #3 0 1 2 halt 0 0 nop 1 0 cmov. XX r. A, r. B 2 fn r. A r. B irmovq V, r. B 3 0 F rmmovq r. A, D(r. B) 4 0 r. A r. B D mrmovq D(r. B), r. A OPq r. A, r. B j. XX Dest 5 6 7 0 3 4 5 6 7 8 9 r. B V addq 6 0 subq 6 1 andq 6 2 xorq 6 3 r. A r. B D fn r. A r. B fn Dest call Dest 8 0 ret 9 0 pushq r. A A 0 r. A F popq r. A B 0 r. A F Dest

Y 86 -64 Instruction Set #4 Byte 0 halt 0 nop 8 jmp 97

Y 86 -64 Instruction Set #4 Byte 0 halt 0 nop 8 jmp 97 0 0 jle 7 1 1 0 jl 7 2 cmov. XX r. A, r. B 2 fn r. A r. B je 7 3 irmovq V, r. B 3 0 F r. B V jne 7 4 rmmovq r. A, D(r. B) 4 0 r. A r. B D jge 7 5 mrmovq D(r. B), r. A 5 0 r. A r. B D jg 7 6 OPq r. A, r. B 6 fn r. A r. B j. XX Dest 7 fn Dest call Dest 8 0 ret 9 0 pushq r. A A 0 r. A F popq r. A B 0 r. A F 1 2 Dest 3 4 5 6 7

Building Blocks fun A • Combinational Logic • Compute Boolean functions of inputs •

Building Blocks fun A • Combinational Logic • Compute Boolean functions of inputs • Continuously respond to input changes • Operate on data and implement control B 0 MUX 1 • Storage Elements • • Store bits Addressable memories Non-addressable registers Loaded only as clock rises = A L U val. A src. A val. B src. B A Register file B val. W W dst. W Clock

Hardware Control Language • Very simple hardware description language • Can only express limited

Hardware Control Language • Very simple hardware description language • Can only express limited aspects of hardware operation • Parts we want to explore and modify • Data Types • bool: Boolean • a, b, c, … • int: words • A, B, C, … • Does not specify word size---bytes, 32 -bit words, … • Statements • bool a = bool-expr ; • int A = int-expr ;

HCL Operations • Classify by type of value returned • Boolean Expressions • Logic

HCL Operations • Classify by type of value returned • Boolean Expressions • Logic Operations • a && b, a || b, !a • Word Comparisons • A == B, A != B, A <= B, A > B • Set Membership • A in { B, C, D } • Same as A == B || A == C || A == D • Word Expressions • Case expressions • [ a : A; b : B; c : C ] • Evaluate test expressions a, b, c, … in sequence • Return word expression A, B, C, … for first successful test

SEQ Hardware Structure • State • • Program counter register (PC) Condition code register

SEQ Hardware Structure • State • • Program counter register (PC) Condition code register (CC) Register File Memories • Access same memory space • Data: for reading/writing program data • Instruction: for reading instructions • Instruction Flow • Read instruction at address specified by PC • Process through stages • Update program counter

SEQ Stages • Fetch • Read instruction from instruction memory • Decode • Read

SEQ Stages • Fetch • Read instruction from instruction memory • Decode • Read program registers • Execute • Compute value or address • Memory • Read or write data • Write Back • Write program registers • PC • Update program counter

Instruction Decoding Optional 5 0 Optional r. A r. B D icode ifun r.

Instruction Decoding Optional 5 0 Optional r. A r. B D icode ifun r. A r. B val. C • Instruction Format • Instruction byte • Optional register byte • Optional constant word icode: ifun r. A: r. B val. C

Executing Arith. /Logical Operation OPq r. A, r. B • Fetch • Read 2

Executing Arith. /Logical Operation OPq r. A, r. B • Fetch • Read 2 bytes • Decode • Read operand registers • Execute • Perform operation • Set condition codes 6 fn r. A r. B • Memory • Do nothing • Write back • Update register • PC Update • Increment PC by 2

Stage Computation: Arith/Log. Ops OPq r. A, r. B icode: ifun M 1[PC] r.

Stage Computation: Arith/Log. Ops OPq r. A, r. B icode: ifun M 1[PC] r. A: r. B M 1[PC+1] Read instruction byte Read register byte val. P PC+2 val. A R[r. A] Compute next PC Read operand A val. B R[r. B] val. E val. B OP val. A Set CC Read operand B Perform ALU operation Set condition code register Memory Write R[r. B] val. E Write back result back PC update PC val. P Update PC Fetch Decode Execute • Formulate instruction execution as sequence of simple steps • Use same general form for all instructions

Executing rmmovq r. A, D(r. B) 4 0 r. A r. B D •

Executing rmmovq r. A, D(r. B) 4 0 r. A r. B D • Fetch • Read 10 bytes • Decode • Read operand registers • Execute • Compute effective address • Memory • Write to memory • Write back • Do nothing • PC Update • Increment PC by 10

Stage Computation: rmmovq r. A, D(r. B) Fetch Decode Execute Memory Write back PC

Stage Computation: rmmovq r. A, D(r. B) Fetch Decode Execute Memory Write back PC update icode: ifun M 1[PC] r. A: r. B M 1[PC+1] val. C M 8[PC+2] val. P PC+10 val. A R[r. A] Read instruction byte Read register byte Read displacement D Compute next PC Read operand A val. B R[r. B] val. E val. B + val. C Read operand B Compute effective address M 8[val. E] val. A Write value to memory PC val. P Update PC • Use ALU for address computation

Executing popq r. A • Fetch • Read 2 bytes • Decode • Read

Executing popq r. A • Fetch • Read 2 bytes • Decode • Read stack pointer • Execute • Increment stack pointer by 8 b 0 r. A 8 • Memory • Read from old stack pointer • Write back • Update stack pointer • Write result to register • PC Update • Increment PC by 2

Stage Computation: popq r. A icode: ifun M 1[PC] r. A: r. B M

Stage Computation: popq r. A icode: ifun M 1[PC] r. A: r. B M 1[PC+1] Read instruction byte Read register byte val. P PC+2 val. A R[%rsp] val. B R[%rsp] val. E val. B + 8 Compute next PC Read stack pointer Increment stack pointer Memory Write val. M M 8[val. A] R[%rsp] val. E Read from stack Update stack pointer back PC update R[r. A] val. M PC val. P Write back result Update PC Fetch Decode Execute • Use ALU to increment stack pointer • Must update two registers • Popped value • New stack pointer

Executing Conditional Moves cmov. XX r. A, r. B • Fetch • Read 2

Executing Conditional Moves cmov. XX r. A, r. B • Fetch • Read 2 bytes • Decode • Read operand registers • Execute • If !cnd, then set destination register to 0 x. F 2 fn r. A r. B • Memory • Do nothing • Write back • Update register (or not) • PC Update • Increment PC by 2

Stage Computation: Cond. Move cmov. XX r. A, r. B icode: ifun M 1[PC]

Stage Computation: Cond. Move cmov. XX r. A, r. B icode: ifun M 1[PC] r. A: r. B M 1[PC+1] Read instruction byte Read register byte val. P PC+2 val. A R[r. A] val. B 0 val. E val. B + val. A If ! Cond(CC, ifun) r. B 0 x. F Compute next PC Read operand A Memory Write R[r. B] val. E Write back result back PC update PC val. P Update PC Fetch Decode Execute Pass val. A through ALU (Disable register update) • Read register r. A and pass through ALU • Cancel move by setting destination register to 0 x. F • If condition codes & move condition indicate no move

Executing Jumps j. XX Dest 7 fn Dest fall thru: XX XX Not taken

Executing Jumps j. XX Dest 7 fn Dest fall thru: XX XX Not taken target: XX XX Taken • Fetch • Read 9 bytes • Increment PC by 9 • Decode • Do nothing • Execute • Determine whether to take branch based on jump condition and condition codes • Memory • Do nothing • Write back • Do nothing • PC Update • Set PC to Dest if branch taken or to incremented PC if not branch

Stage Computation: Jumps j. XX Dest Fetch icode: ifun M 1[PC] Read instruction byte

Stage Computation: Jumps j. XX Dest Fetch icode: ifun M 1[PC] Read instruction byte val. C M 8[PC+1] val. P PC+9 Read destination address Fall through address Cnd Cond(CC, ifun) Take branch? PC Cnd ? val. C : val. P Update PC Decode Execute Memory Write back PC update • Compute both addresses • Choose based on setting of condition codes and branch condition

Executing call Dest 8 0 Dest return: XX XX target: XX XX • Fetch

Executing call Dest 8 0 Dest return: XX XX target: XX XX • Fetch • Read 9 bytes • Increment PC by 9 • Decode • Read stack pointer • Execute • Decrement stack pointer by 8 • Memory • Write incremented PC to new value of stack pointer • Write back • Update stack pointer • PC Update • Set PC to Dest

Stage Computation: call Dest icode: ifun M 1[PC] Read instruction byte val. C M

Stage Computation: call Dest icode: ifun M 1[PC] Read instruction byte val. C M 8[PC+1] val. P PC+9 Read destination address Compute return point val. B R[%rsp] val. E val. B + – 8 Read stack pointer Decrement stack pointer Memory Write M 8[val. E] val. P R[%rsp] val. E Write return value on stack Update stack pointer back PC update PC val. C Set PC to destination Fetch Decode Execute • Use ALU to decrement stack pointer • Store incremented PC

Executing ret 9 0 return: • Fetch • Read 1 byte • Decode •

Executing ret 9 0 return: • Fetch • Read 1 byte • Decode • Read stack pointer • Execute • Increment stack pointer by 8 XX XX • Memory • Read return address from old stack pointer • Write back • Update stack pointer • PC Update • Set PC to return address

Stage Computation: ret icode: ifun M 1[PC] Read instruction byte val. A R[%rsp] Read

Stage Computation: ret icode: ifun M 1[PC] Read instruction byte val. A R[%rsp] Read operand stack pointer val. B R[%rsp] val. E val. B + 8 Read operand stack pointer Increment stack pointer Memory Write val. M M 8[val. A] R[%rsp] val. E Read return address Update stack pointer back PC update PC val. M Set PC to return address Fetch Decode Execute • Use ALU to increment stack pointer • Read return address from memory

Computation Steps OPq r. A, r. B Fetch Decode Execute Memory Write back PC

Computation Steps OPq r. A, r. B Fetch Decode Execute Memory Write back PC update icode, ifun r. A, r. B val. C val. P val. A, src. A val. B, src. B val. E Cond code val. M dst. E dst. M PC icode: ifun M 1[PC] r. A: r. B M 1[PC+1] val. P PC+2 val. A R[r. A] val. B R[r. B] val. E val. B OP val. A Set CC R[r. B] val. E PC val. P • All instructions follow same general pattern • Differ in what gets computed on each step Read instruction byte Read register byte [Read constant word] Compute next PC Read operand A Read operand B Perform ALU operation Set/use cond. code reg [Memory read/write] Write back ALU result [Write back memory result] Update PC

Computation Steps call Dest Fetch Decode Execute Memory Write back PC update icode, ifun

Computation Steps call Dest Fetch Decode Execute Memory Write back PC update icode, ifun r. A, r. B val. C val. P val. A, src. A icode: ifun M 1[PC] val. B, src. B val. E Cond code val. M dst. E dst. M PC val. B R[%rsp] val. C M 8[PC+1] val. P PC+9 val. E val. B + – 8 M 8[val. E] val. P R[%rsp] val. E PC val. C • All instructions follow same general pattern • Differ in what gets computed on each step Read instruction byte [Read register byte] Read constant word Compute next PC [Read operand A] Read operand B Perform ALU operation [Set /use cond. code reg] Memory read/write Write back ALU result [Write back memory result] Update PC

Computed Values • Fetch icode ifun r. A r. B val. C val. P

Computed Values • Fetch icode ifun r. A r. B val. C val. P • Execute Instruction code Instruction function Instr. Register A Instr. Register B Instruction constant Incremented PC • Decode src. A src. B dst. E dst. M val. A val. B Register ID A Register ID B Destination Register E Destination Register M Register value A Register value B • val. E • Cnd ALU result Branch/move flag • Memory • val. M Value from memory

SEQ Hardware • Blue boxes • predesigned hardware blocks • E. g. , memories,

SEQ Hardware • Blue boxes • predesigned hardware blocks • E. g. , memories, ALU • Gray boxes • control logic • Describe in HCL • White ovals • labels for signals • Thick lines • 64 -bit word values • Thin lines • 4 -8 bit values • Dotted lines • 1 -bit values

Fetch Logic • Predefined Blocks • PC: Register containing PC • Instruction memory: Read

Fetch Logic • Predefined Blocks • PC: Register containing PC • Instruction memory: Read 10 bytes (PC to PC+9) • Signal invalid address • Split: Divide instruction byte into icode and ifun • Align: Get fields for r. A, r. B, and val. C

Fetch Logic Control Logic • Instr. Valid: Is this instruction valid? • icode, ifun:

Fetch Logic Control Logic • Instr. Valid: Is this instruction valid? • icode, ifun: Generate no-op if invalid address • Need regids: Does this instruction have a register byte? • Need val. C: Does this instruction have a constant word?

Fetch Control Logic in HCL icode ifun Split Byte 0 # Determine instruction code

Fetch Control Logic in HCL icode ifun Split Byte 0 # Determine instruction code int icode = [ imem_error: INOP; 1: imem_icode; ]; # Determine instruction function int ifun = [ imem_error: FNONE; 1: imem_ifun; ]; imem_error Instruction memory PC

Fetch Control Logic in HCL halt 0 0 nop 1 0 cmov. XX r.

Fetch Control Logic in HCL halt 0 0 nop 1 0 cmov. XX r. A, r. B 2 fn r. A r. B irmovq V, r. B 3 0 8 rmmovq r. A, D(r. B) 4 0 r. A r. B D mrmovq D(r. B), r. A 5 0 r. A r. B D OPq r. A, r. B 6 fn r. A r. B j. XX Dest 7 fn Dest call Dest 8 0 ret 9 0 popq r. A A 0 r. A F popq r. A B 0 r. A F r. B V Dest bool need_regids = icode in { IRRMOVQ, IOPQ, IPUSHQ, IPOPQ, IIRMOVQ, IRMMOVQ, IMRMOVQ }; bool instr_valid = icode in { INOP, IHALT, IRRMOVQ, IIRMOVQ, IRMMOVQ, IMRMOVQ, IOPQ, IJXX, ICALL, IRET, IPUSHQ, IPOPQ };

Decode Logic Register File • Read ports A, B • Write ports E, M

Decode Logic Register File • Read ports A, B • Write ports E, M • Addresses are register IDs or 15 (0 x. F) (no access) Control Logic • src. A, src. B: read port addresses • dst. E, dst. M: write port addresses Signals • Cnd: Indicate whether or not to perform conditional move • Computed in Execute stage

A Src. Decode OPq r. A, r. B val. A R[r. A] Read operand

A Src. Decode OPq r. A, r. B val. A R[r. A] Read operand A Decode cmov. XX r. A, r. B val. A R[r. A] Read operand A rmmovq r. A, D(r. B) Decode val. A R[r. A] Read operand A Decode popq r. A val. A R[%rsp] Read stack pointer j. XX Dest Decode No operand call Dest Decode No operand ret val. A R[%rsp] int src. A = [ icode in { IRRMOVQ, IRMMOVQ, IOPQ, IPUSHQ icode in { IPOPQ, IRET } : RRSP; 1 : RNONE; # Don't need register ]; Read stack pointer } : r. A;

E Dest. Write-back OPq r. A, r. B R[r. B] val. E Write back

E Dest. Write-back OPq r. A, r. B R[r. B] val. E Write back result Write-back cmov. XX r. A, r. B R[r. B] val. E Conditionally write back result rmmovq r. A, D(r. B) Write-back None popq r. A R[%rsp] val. E Update stack pointer j. XX Dest Write-back None Write-back call Dest R[%rsp] val. E Update stack pointer Write-back ret R[%rsp] val. E Update stack pointer int dst. E = [ icode in { IRRMOVQ } && Cnd : r. B; icode in { IIRMOVQ, IOPQ} : r. B; icode in { IPUSHQ, IPOPQ, ICALL, IRET } : RRSP; 1 : RNONE; # Don't write any register ];

Execute Logic • Units • ALU • Implements 4 required functions • Generates condition

Execute Logic • Units • ALU • Implements 4 required functions • Generates condition code values • CC • Register with 3 condition code bits • cond • Computes conditional jump/move flag • Control Logic • Set CC: Should condition code register be loaded? • ALU A: Input A to ALU • ALU B: Input B to ALU • ALU fun: What function should ALU compute?

ALU A Input Execute OPq r. A, r. B val. E val. B OP

ALU A Input Execute OPq r. A, r. B val. E val. B OP val. A Perform ALU operation Execute cmov. XX r. A, r. B val. E 0 + val. A Pass val. A through ALU rmmovq r. A, D(r. B) Execute val. E val. B + val. C Compute effective address popq r. A Execute val. E val. B + 8 Increment stack pointer j. XX Dest Execute No operation call Dest Execute val. E val. B + – 8 Decrement stack pointer ret Execute val. E val. B + 8 Increment stack pointer int alu. A = [ icode in { IRRMOVQ, IOPQ } : val. A; icode in { IIRMOVQ, IRMMOVQ, IMRMOVQ } : val. C; icode in { ICALL, IPUSHQ } : -8; icode in { IRET, IPOPQ } : 8; # Other instructions don't need ALU ];

ALU Op. Execute OPl r. A, r. B val. E val. B OP val.

ALU Op. Execute OPl r. A, r. B val. E val. B OP val. A Perform ALU operation Execute cmov. XX r. A, r. B val. E 0 + val. A Pass val. A through ALU rmmovl r. A, D(r. B) Execute val. E val. B + val. C Compute effective address popq r. A Execute val. E val. B + 8 Increment stack pointer j. XX Dest Execute No operation call Dest Execute val. E val. B + – 8 Decrement stack pointer ret Execute val. E val. B + 8 int alufun = [ icode == IOPQ : ifun; 1 : ALUADD; ]; Increment stack pointer

Memory Logic • Memory • Reads or writes memory word • Control Logic •

Memory Logic • Memory • Reads or writes memory word • Control Logic • stat: What is instruction status? • Mem. read: should word be read? • Mem. write: should word be written? • Mem. addr. : Select address • Mem. data. : Select data

Instruction Status • Control Logic • stat: What is instruction status? ## Determine instruction

Instruction Status • Control Logic • stat: What is instruction status? ## Determine instruction status int Stat = [ imem_error || dmem_error : SADR; !instr_valid: SINS; icode == IHALT : SHLT; 1 : SAOK; ];

Memory Address OPq r. A, r. B Memory No operation rmmovq r. A, D(r.

Memory Address OPq r. A, r. B Memory No operation rmmovq r. A, D(r. B) Memory M 8[val. E] val. A Write value to memory popq r. A Memory val. M M 8[val. A] Read from stack j. XX Dest Memory No operation call Dest Memory M 8[val. E] val. P Write return value on stack ret Memory val. M M 8[val. A] Read return address int mem_addr = [ icode in { IRMMOVQ, IPUSHQ, ICALL, IMRMOVQ } : val. E; icode in { IPOPQ, IRET } : val. A; # Other instructions don't need address ];

Memory Read OPq r. A, r. B Memory No operation rmmovq r. A, D(r.

Memory Read OPq r. A, r. B Memory No operation rmmovq r. A, D(r. B) Memory M 8[val. E] val. A Write value to memory popq r. A Memory val. M M 8[val. A] Read from stack j. XX Dest Memory No operation call Dest Memory M 8[val. E] val. P Write return value on stack ret Memory val. M M 8[val. A] Read return address bool mem_read = icode in { IMRMOVQ, IPOPQ, IRET };

PC Update Logic • New PC • Select next value of PC

PC Update Logic • New PC • Select next value of PC

PC Update OPq r. A, r. B PC update PC val. P Update PC

PC Update OPq r. A, r. B PC update PC val. P Update PC rmmovq r. A, D(r. B) PC update PC val. P Update PC popq r. A PC update PC val. P Update PC PC update j. XX Dest PC Cnd ? val. C : val. P Update PC call Dest PC update PC val. C Set PC to destination ret PC update PC val. M Set PC to return address int new_pc = [ icode == ICALL : val. C; icode == IJXX && Cnd : val. C; icode == IRET : val. M; 1 : val. P; ];

SEQ Operation • State • PC register • Cond. Code register • Data memory

SEQ Operation • State • PC register • Cond. Code register • Data memory • Register file All updated as clock rises • Combinational Logic • ALU • Control logic • Memory reads • Instruction memory • Register file • Data memory

SEQ Op @1 • state set according to second irmovq instruction • combinational logic

SEQ Op @1 • state set according to second irmovq instruction • combinational logic starting to react to state changes

SEQ Op @2 • state set according to second irmovq instruction • combinational logic

SEQ Op @2 • state set according to second irmovq instruction • combinational logic generates results for addq instruction

SEQ Op @3 • state set according to addq instruction • combinational logic starting

SEQ Op @3 • state set according to addq instruction • combinational logic starting to react to state changes

SEQ Op @4 • state set according to addq instruction • combinational logic generates

SEQ Op @4 • state set according to addq instruction • combinational logic generates results for je instruction

SEQ Summary Implementation • Express every instruction as series of simple steps • Follow

SEQ Summary Implementation • Express every instruction as series of simple steps • Follow same general flow for each instruction type • Assemble registers, memories, predesigned combinational blocks • Connect with control logic Limitations • Too slow to be practical • In one cycle, must propagate through instruction memory, register file, ALU, and data memory • Would need to run clock very slowly • Hardware units only active for fraction of clock cycle