1 big versus little endian addressing...subset of bits from many, specify exactly which bits are...
TRANSCRIPT
Design of Digital Circuits (252-0028-00L), Spring 2018
Optional HW 3: Basic Microarchitectural Design
Instructor: Prof. Onur MutluTAs: Juan Gomez Luna, Hasan Hassan, Arash Tavakkol, Minesh Patel, Jeremie Kim, Giray Yaglikci
Assigned: Thursday, Apr 25, 2018
1 Big versus Little Endian Addressing
Consider the 32-bit hexadecimal number 0xcafe2b3a.
1. What is the binary representation of this number in little endian format? Please clearly mark the bytesand number them from low (0) to high (3).
2. What is the binary representation of this number in big endian format? Please clearly mark the bytesand number them from low (0) to high (3).
1/29
2 The MIPS ISA
2.1 Warmup: Computing a Fibonacci Number
The Fibonacci number Fn is recursively defined as
F (n) = F (n− 1) + F (n− 2),
where F (1) = 1 and F (2) = 1. So, F (3) = F (2) + F (1) = 1 + 1 = 2, and so on. Write the MIPS assemblyfor the fib(n) function, which computes the Fibonacci number F (n):
int fib(int n)
{
int a = 0;
int b = 1;
int c = a + b;
while (n > 1) {
c = a + b;
a = b;
b = c;
n--;
}
return c;
}
Remember to follow MIPS calling convention and its register usage (just for your reference, you may notneed to use all of these registers):
• The argument n is passed in register $4.
• The result (i.e., c) should be returned in $2.
• $8 to $15 are caller-saved temporary registers.
• $16 to $23 are callee-saved temporary registers.
• $29 is the stack pointer register.
• $31 stores the return address.
Note: A summary of the MIPS ISA is provided at the end of this handout.
2/29
2.2 MIPS Assembly for REP MOVSB
MIPS is a simple ISA. Complex ISAs—such as Intel’s x86—often use one instruction to perform the functionof many instructions in a simple ISA. Here you will implement the MIPS equivalent for a single Intel x86instruction, REP MOVSB, which is specified as follows.
The REP MOVSB instruction uses three fixed x86 registers: ECX (count), ESI (source), and EDI(destination). The “repeat” (REP) prefix on the instruction indicates that it will repeat ECX times. Eachiteration, it moves one byte from memory at address ESI to memory at address EDI, and then incrementsboth pointers by one. Thus, the instruction copies ECX bytes from address ESI to address EDI.
(a) Write the corresponding assembly code in MIPS ISA that accomplishes the same function as this in-struction. You can use any general purpose register. Indicate which MIPS registers you have chosen tocorrespond to the x86 registers used by REP MOVSB. Try to minimize code size as much as possible.
3/29
(b) What is the size of the MIPS assembly code you wrote in (a), in bytes? How does it compare to REPMOVSB in x86 (note: REP MOVSB occupies 2 bytes)?
(c) Assume the contents of the x86 register file are as follows before the execution of the REP MOVSB:
EAX: 0xccccaaaa
EBP: 0x00002222
ECX: 0xFEE1DEAD
EDX: 0xfeed4444
ESI: 0xdecaffff
EDI: 0xdeaddeed
EBP: 0xe0000000
ESP: 0xe0000000
Now, consider the MIPS assembly code you wrote in (a). How many total instructions will be executedby your code to accomplish the same fuction as the single REP MOVSB in x86 accomplishes for thegiven register state?
(d) Assume the contents of the x86 register file are as follows before the execution of the REP MOVSB:
EAX: 0xccccaaaa
EBP: 0x00002222
ECX: 0x00000000
EDX: 0xfeed4444
ESI: 0xdecaffff
EDI: 0xdeaddeed
EBP: 0xe0000000
ESP: 0xe0000000
4/29
Now, answer the same question in (c) for the above register values.
5/29
3 Data Flow Programs
Draw the data flow graph for the fib(n) function from Question 2.1. You may use the following data flownodes in your graph:
• + (addition)
• > (left operand is greater than right operand)
• Copy (copy the value on the input to both outputs)
• BR (branch, with the semantics discussed in class, label the True and False outputs)
You can use constant inputs (e.g., 1) that feed into the nodes. Clearly label all the nodes, programinputs, and program outputs. Try to the use fewest number of data flow nodes possible.
6/29
4 Microarchitecture vs. ISA
a) Briefly explain the difference between the microarchitecture level and the ISA level in the transformationhierarchy. What information does the compiler need to know about the microarchitecture of the machinein order to compile a given program correctly?
b) Classify the following attributes of a machine as either a property of its microarchitecture or ISA:
Microarchitecture? ISA? Attribute
The machine does not have a subtract instructionThe ALU of the machine does not have a subtract unitThe machine does not have condition codesA 5-bit immediate can be specified in an ADD instructionIt takes n cycles to execute an ADD instructionThere are 8 general purpose registersA 2-to-1 mux feeds one of the inputs to ALUThe register file has one input port and two output ports
7/29
5 Performance Metrics
• If a given program runs on a processor with a higher frequency, does it imply that the processor alwaysexecutes more instructions per second (compared to a processor with a lower frequency)? (Use less than10 words.)
• If a processor executes more of a given program’s instructions per second, does it imply that the processoralways finishes the program faster (compared to a processor that executes fewer instructions per second)?(Use less than 10 words.)
8/29
6 Performance Evaluation
Your job is to evaluate the potential performance of two processors, each implementing a different ISA. Theevaluation is based on its performance on a particular benchmark. On the processor implementing ISA A,the best compiled code for this benchmark performs at the rate of 10 IPC. That processor has a 500 MHzclock. On the processor implementing ISA B, the best compiled code for this benchmark performs at therate of 2 IPC. That processor has a 600 MHz clock.
• What is the performance in Millions of Instructions per Second (MIPS) of the processor implementingISA A?
• What is the performance in MIPS of the processor implementing ISA B?
• Which is the higher performance processor: A B Don’t knowBriefly explain your answer.
9/29
7 Single-Cycle Processor Datapath
In this problem, you will modify the single-cycle datapath we built up in Lecture 11 to support the JAL
instruction. The datapath that we will start with is provided below. Your job is to implement the necessarydata and control signals to support the JAL instruction, which we define to have the following semantics:
JAL : R31← PC + 4
PC← PC31...28 || Immediate || 02
Add to the datapath on the next page the necessary data and control signals to implement the JAL instruction.Draw and label all components and wires very clearly (give control signals meaningful names; if selecting asubset of bits from many, specify exactly which bits are selected; and so on).
PC
Instruction memory
Read address
Instruction
4
Add
Instruction
16 32
RegistersWrite register
Read data 1
Read data 2
Read register 1
Read register 2
Data memory
Write data
Read data
Write data
Sign extend
ALU result
ZeroALU
Address
MemRead
MemWrite
RegWrite
ALU operation3
!isStore)
isStore)
isLoad)
ALUSrc)isItype)
MemtoReg)
isLoad)
RegDest)isItype)
10/29
8 LC-3b Microprogramming
As we learned in class, the LC-3b is a microprogrammed design, which means that control signals throughoutthe LC-3b datapath (Patt+Patel, Appendix C, Figure 3) determine what the processor does during any givencycle. The control signals are stored in a memory called the control store, and they must be carefully chosento correctly implement the LC-3b state machine (Patt+Patel, Appendix C, Figure 2). The contents of thecontrol store can be easily described using a 2D spreadsheet with rows representing different LC-3b statesand columns specifying all 35 control signal bits required for each state.
Unfortunately, a clumsy TA has accidentally erased the contents of the control store! Your task is torecover this data manually (i.e., determine every bit in the control store) using your knowledge of the LC-3barchitecture.
Fill out the microcode in the microcode.csv file handed out with this homework. Enter a 1 or a 0 oran X as appropriate for the microinstructions corresponding to each state. We have filled out state 18as an example. Hint: all of the information can be inferred using the information and figures provided inPatt+Patel Appendix C.
11/29
9 REP MOVSB
Let’s say you are the lead architect of the next flagship processor at Advanced Number Devices (AND). Youhave decided that you want to use the LC-3b ISA for your next product, but your customers want a smallersemantic gap and marketing is on your case about it. So, you have decided to implement your favorite x86instruction, REP MOVSB, in LC-3b.
Specifically, you want to implement the following definition for REP MOVSB (in LC-3b parlance): REP-MOVSB SR1, SR2, DR which is encoded in LC-3b machine code as:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1010 DR SR1 0 0 0 SR2
REPMOVSB uses three registers: SR1 (count), SR2 (source), and DR (destination). It moves a bytefrom memory at address SR2 to memory at address DR, and then increments both pointers by one. This isrepeated SR1 times. Thus, the instruction copies SR1 bytes from address SR2 to address DR. Assume thatthe value in SR1 is greater than or equal to zero.
1. Complete the state diagram shown below, using the notation of the LC-3b state diagram. Describeinside each bubble what happens in each state and assign each state an appropriate state number. Addadditional states not present in the original LC-3b design as you see fit.
CMU 18-447 Introduction to Computer Architecture, Spring 2013
HW 3: Microprogramming Wrap-up and Pipelining
Instructor: Prof. Onur MutluTAs: Justin Meza, Yoongu Kim, Jason Lin
Assigned: Mon., 2/11, 2013Due: Mon., 2/25, 2013 (Midnight)
Handin: /afs/ece/class/ece447/handin/hw3
1 Adding the REP MOVSB Instruction to the LC-3b [25 points]
Let’s say you’re the lead architect of the next flagship processor at Advanced Number Devices (AND). You’vedecided that you want to use the LC-3b ISA for your next product, the Flopteron, but your customers wanta smaller semantic gap and marketing is on your case about it. So, you’ve decided to implement your favoritex86 instruction, REP MOVSB, in LC-3b.
Specifically, you want to implement the following definition for REP MOVSB (in LC-3b parlance):
REPMOVSB SR1, SR2, DR
which is encoded in LC-3b machine code as:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 01010 DR SR1 0 0 0 SR2
REPMOVSB uses three registers: SR1 (count), SR2 (source) and DR (destination). It moves a byte from memoryat address SR2 to memory at address DR, and then increments both pointers by one. This is repeated SR1
times. Thus, the instruction copies SR1 bytes from address SR2 to address DR. Assume that the value in SR1
is greater than or equal to zero.
(a) Complete the state diagram shown below, using the notation of the LC-3b state diagram. Describeinside each bubble what happens in each state and assign each state an appropriate state number. Addadditional states not present in the original LC-3b design as you see fit.
To State 18
State Number
10
32
.
.
A
BEN<−IR[11] & N + IR[10] & Z + IR[9] & P[IR[15:12]]
.
.
REPMOVSB
1/4
12/29
13/29
2. Add to the LC-3b datapath any additional structures and any additional control signals needed toimplement REPMOVSB. Clearly label your additional control signals with descriptive names. Describewhat value each control signal would take to control the datapath in a particular way.
14/29
3. Describe any changes you need to make to the LC-3b microsequencer. Add any additional logic andcontrol signals you need. Clearly describe the purpose and function of each signal and the values itwould take to control the microsequencer in a particular way.
15/29
10 Mystery LC-3b Instruction (I)
A pesky engineer has implemented a mystery instruction on the LC-3b! It is your job to determine whatthe instruction does. The mystery instruction is encoded as:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 01010 DR SR1 0 0 0 0 0 0
The modifications we make to the LC-3b datapath and the microsequencer are highlighted in the attachedfigures (see the next two pages). We also provide the original LC-3b state diagram, in case you need it. (Asa reminder, the selection logic for SR2MUX is determined internally based on the instruction.)
The additional control signals are:
GateTEMP1/1: NO, YES
GateTEMP2/1: NO, YES
LD.TEMP1/1: NO, LOAD
LD.TEMP2/1: NO, LOAD
ALUK/3: OR1 (A|0x1), LSHF1 (A<<1), PASSA, PASS0 (Pass value 0), PASS16 (Pass value 16)
COND/4:COND0000 ;UnconditionalCOND0001 ;Memory ReadyCOND0010 ;BranchCOND0011 ;Addressing modeCOND0100 ;Mystery 1COND1000 ;Mystery 2
The microcode for the instruction is given in the table below.State Cond J Asserted Signals
001010 (10) COND0000 001011 ALUK = PASS0, GateALU, LD.REG,DRMUX = DR (IR[11:9])
001011 (11) COND0000 101000 ALUK = PASSA, GateALU, LD.TEMP1,SR1MUX = SR1 (IR[8:6])
101000 (40) COND0000 110010 ALUK = PASS16, GateALU, LD.TEMP2110010 (50) COND1000 101101 ALUK = LSHF1, GateALU, LD.REG,
SR1MUX = DR, DRMUX = DR (IR[11:9])111101 (61) COND0000 101101 ALUK = OR1, GateALU, LD.REG,
SR1MUX = DR, DRMUX = DR (IR[11:9])101101 (45) COND0000 111111 GateTEMP1, LD.TEMP1111111 (63) COND0100 010010 GateTEMP2, LD.TEMP2
Describe what this instruction does.
16/29
17/29
Code:
State 10: DR ← 0
State 11: TEMP1 ← value(SR1)
State 40: TEMP2 ← 16
State 50: DR = DR << 1
if (TEMP1[0] == 0)
goto State 45
else
goto State 61
State 61: DR = DR | 0x1
State 45: TEMP1 = TEMP1 >> 1
State 63: DEC TEMP2
if (TEMP2 == 0)
goto State 18
else
goto State 50
18/29
19/29
20/29
C.4. THE CONTROL STRUCTURE 11DRIR[11:9]111DRMUX(a) SR1SR1MUXIR[11:9]IR[8:6] (b)Logic BENPZNIR[11:9] (c)Figure C.6: Additional logic required to provide control signalsLC-3b to operate correctly with a memory that takes multiple clock cycles to read orstore a value.Suppose it takes memory five cycles to read a value. That is, once MAR containsthe address to be read and the microinstruction asserts READ, it will take five cyclesbefore the contents of the specified location in memory are available to be loaded intoMDR. (Note that the microinstruction asserts READ by means of three control signals:MIO.EN/YES, R.W/RD, and DATA.SIZE/WORD; see Figure C.3.)Recall our discussion in Section C.2 of the function of state 33, which accessesan instruction from memory during the fetch phase of each instruction cycle. For theLC-3b to operate correctly, state 33 must execute five times before moving on to state35. That is, until MDR contains valid data from the memory location specified by thecontents of MAR, we want state 33 to continue to re-execute. After five clock cycles,th h l t d th “ d ” lti i lid d t i MDR th21/29
C.2. THE STATE MACHINE 5R PC<! BaseR To 1812 To 18To 18RRTo 18To 18 To 18 MDR<! SR[7:0]MDR <! MIR <! MDRRDR<! SR1+OP2*set CCDR<! SR1&OP2*set CC [BEN]PC<! MDR 3215 0 01To 18To 18 To 18R R [IR[15:12]]2830R7<! PCMDR<! M[MAR]set CC BEN<! IR[11] & N + IR[10] & Z + IR[9] & P9DR<! SR1 XOR OP2* 4 22To 111011JSR JMP BR1010 To 10 2120 0 1LDBMAR<! B+off6set CCTo 18 MAR<! B+off6DR<! MDRset CCTo 18MDR<! M[MAR]2527 3762 STW STBLEASHFTRAPXORANDADDRTITo 8set CC set CCDR<! PC+LSHF(off9, 1)14 LDWMAR<! B+LSHF(off6,1) MAR<! B+LSHF(off6,1)PC<! PC+LSHF(off9,1)3335DR<! SHF(SR,A,D,amt4)NOTESB+off6 : Base + SEXT[offset6] RMDR<! M[MAR[15:1]’0]DR<! SEXT[BYTE.DATA]R 2931 18, 19 MDR<! SRTo 18R RM[MAR]<! MDR 1623 R R17To 19 24M[MAR]<! MDR**MAR<! LSHF(ZEXT[IR[7:0]],1)15To 18PC+off9 : PC + SEXT[offset9] MAR <! PCPC <! PC + 2*OP2 may be SR2 or SEXT[imm5]** [15:8] or [7:0] depending onMAR[0] [IR[11]]PC<! BaseRPC<! PC+LSHF(off11,1)R7<! PC R7<! PC13 Figure C.2: A state machine for the LC-3b22/29
11 Mystery LC-3b Instruction (II)
An engineer implemented the mystery instruction described below on the LC-3b. Unfortunately, we do notknow what this engineer was thinking, and we can’t figure out what the instruction does. It is your job todetermine this. The mystery instruction is encoded as:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 01010 DR SR1 1 0 1 1 1 1
The instruction is only defined if the value of SR1 is not equal to zero.
The modifications we make to the LC-3b datapath and the microsequencer are highlighted in the attachedfigures (see the next three pages).
We also provide the original LC-3b state diagram, in case you need it.
The additional control signals are:
GateLSHF/1: NO, YES
LD.TEMP/1: NO, LOAD
ALUK/3: AND, ADD, XOR, PASSA, PASSB, DECA (Decrement A)
COND/3:COND0 ;UnconditionalCOND1 ;Memory ReadyCOND2 ;BranchCOND3 ;Addressing modeCOND4 ;Mystery
The microcode for the instruction is given in the table below.State Cond J Asserted Signals
001010 (10) COND0 101000 ALUK = PASSB, GateALU, LD.REG, DRMUX = DR (IR[11:9])101000 (40) COND4 010010 ALUK = PASSA, GateALU, LD.TEMP, SR1MUX = SR1 (IR[8:6])110010 (50) COND0 110011 ALUK = DECA, GateALU, LD.REG, SR1MUX = DR, DRMUX
= DR (IR[11:9])110011 (51) COND4 010010 GateLSHF, LD.TEMP
Describe what this instruction does.
23/29
Code:
State 10: DR = 15
State 40: TEMP = SR1
if (SR1 is negative)
Go to State 18/19 (Fetch)
else
Go to State 50
State 50: DR = DR - 1
State 51: Left Shift TEMP
if (TEMP is negative)
Go to State 18/19 (Fetch)
else
Go to State 50
24/29
25/29
26/29
Initials: 15
DR
IR[11:9]
111
DRMUX
(a)
SR1
SR1MUX
IR[11:9]
IR[8:6]
(b)
Logic BEN
PZN
IR[11:9]
(c)
27/29
16
R
PC<! BaseR
To 18
12
To 18
To 18
RR
To 18
To 18
To 18
MDR<! SR[7:0]
MDR <! M
IR <! MDR
R
DR<! SR1+OP2*set CC
DR<! SR1&OP2*set CC
[BEN]
PC<! MDR
32
1
5
0
0
1To 18
To 18 To 18
R R
[IR[15:12]]
28
30
R7<! PCMDR<! M[MAR]
set CC
BEN<! IR[11] & N + IR[10] & Z + IR[9] & P
9DR<! SR1 XOR OP2*
4
22
To 111011
JSRJMP
BR
1010
To 10
21
200 1
LDB
MAR<! B+off6
set CC
To 18
MAR<! B+off6
DR<! MDRset CC
To 18
MDR<! M[MAR]
25
27
3762
STW STBLEASHF
TRAP
XOR
AND
ADD
RTI
To 8
set CC
set CCDR<! PC+LSHF(off9, 1)
14
LDW
MAR<! B+LSHF(off6,1) MAR<! B+LSHF(off6,1)
PC<! PC+LSHF(off9,1)
33
35
DR<! SHF(SR,A,D,amt4)
NOTESB+off6 : Base + SEXT[offset6]
R
MDR<! M[MAR[15:1]’0]
DR<! SEXT[BYTE.DATA]
R
29
31
18, 19
MDR<! SR
To 18
R R
M[MAR]<! MDR
16
23
R R
17
To 19
24
M[MAR]<! MDR**
MAR<! LSHF(ZEXT[IR[7:0]],1)
15To 18
PC+off9 : PC + SEXT[offset9]
MAR <! PCPC <! PC + 2
*OP2 may be SR2 or SEXT[imm5]** [15:8] or [7:0] depending on
MAR[0]
[IR[11]]
PC<! BaseR
PC<! PC+LSHF(off11,1)
R7<! PC
R7<! PC
13
28/29
MIPS Instruction Summary
Opcode Example Assembly Semantics
add add $1, $2, $3 $1 = $2 + $3
sub sub $1, $2, $3 $1 = $2 - $3
add immediate addi $1, $2, 100 $1 = $2 + 100
add unsigned addu $1, $2, $3 $1 = $2 + $3
subtract unsigned subu $1, $2, $3 $1 = $2 - $3
add immediate unsigned addiu $1, $2, 100 $1 = $2 + 100
multiply mult $2, $3 hi, lo = $2 * $3
multiply unsigned multu $2, $3 hi, lo = $2 * $3
divide div $2, $3 lo = $2/$3, hi = $2 mod $3
divide unsigned divu $2, $3 lo = $2/$3, hi = $2 mod $3
move from hi mfhi $1 $1 = hi
move from low mflo $1 $1 = lo
and and $1, $2, $3 $1 = $2 & $3
or or $1, $2, $3 $1 = $2 | $3
and immediate andi $1, $2, 100 $1 = $2 & 100
or immediate ori $1, $2, 100 $1 = $2 | 100
shift left logical sll $1, $2, 10 $1 = $2 << 10
shift right logical srl $1, $2, 10 $1 = $2 >> 10
load word lw $1, 100($2) $1 = memory[$2 + 100]
store word sw $1, 100($2) memory[$2 + 100] = $1
load upper immediate lui $1, 100 $1 = 100 << 16
branch on equal beq $1, $2, label if ($1 == $2) goto label
branch on not equal bne $1, $2, label if ($1 != $2) goto label
set on less than slt $1, $2, $3 if ($2 < $3) $1 = 1 else $1 = 0
set on less than immediate slti $1, $2, 100 if ($2 < 100) $1 = 1 else $1 = 0
set on less than unsigned sltu $1, $2, $3 if ($2 < $3) $1 = 1 else $1 = 0
set on less than immediate sltui $1, $2, 100 if ($2 < 100) $1 = 1 else $1 = 0
jump j label goto label
jump register jr $31 goto $31
jump and link jal label $31 = PC + 4; goto label
29/29