Wk2

160 flashcardsby Sam
Study these flashcardsFree · spaced repetition · iPhone, Android, Mac & web

All cards

1
What two things must a computer instruction encode?
The operation (opcode) and the operands
2
What are the typical fields of a three-operand ALU instruction?
Opcode, options/data type, src1, src2 and dst
3
What does the opcode encode?
The operation to perform, e.g. add, subtract, multiply
4
How many bits is an opcode field typically?
3 or 4 bits
5
What does the data type field of an instruction specify?
The operand type, e.g. int, unsigned, long, float, double
6
What might the options field of an instruction specify?
Whether to set the ALU flags
7
What do the operand fields of an instruction encode?
Registers or constants
8
What is a register file?
The collection of general purpose registers
9
How many operands does a binary ALU instruction need?
Three: two sources and one destination
10
How many operands does a unary ALU instruction need?
Two: one source and one destination
11
Which of these are unary ALU operations?
  • NEG
  • NOT
  • MOV
  • ADD
12
Which of these are binary ALU operations?
  • ADD
  • XOR
  • LSHIFT
  • NEG
13
Give an example of an instruction with no operands
NOP (no operation)
14
Why are there separate shift instructions for signed and unsigned numbers?
Signed right shifts must preserve the sign bit
15
In some architectures, which operand is the destination?
The first operand, e.g. ADD R2, R0, R1
16
What does the Z flag indicate?
The result was zero
17
What does the N flag indicate?
The result was negative
18
What does the C flag indicate?
The result had a carry (unsigned overflow)
19
What does the V flag indicate?
The result had a signed overflow
20
Where are the ALU flags stored?
In the status register (SR, CPSR, PS or PSW)
21
What three things can an operand be?
A register, a constant or a memory location
22
How many bits encode a register operand for R registers?
$\log_2 R$
23
How many bits encode a register operand with 32 registers?
5
24
How many bits encode three register operands with 16 registers?
12 (4 bits each)
25
How many bits are needed to encode 8 addressing modes?
3
26
What is an addressing mode?
A specification of how to interpret an operand
27
What is register addressing?
The operand is stored in a register
28
What is immediate addressing?
A constant is stored in the instruction
29
What is direct addressing?
The memory address is stored in the instruction
30
What is the effective address in direct addressing?
The immediate constant
31
What is register indirect (deferred) addressing?
The memory address is stored in a register
32
Which addressing mode corresponds to the C dereference operator?
Register indirect
33
Which memory addressing mode has the shortest encoding?
Register indirect (only the base register number is encoded)
34
What is displacement addressing?
Address = base register + small constant
35
How many bits does displacement addressing need with D-bit displacement and B base registers?
$D + \log_2 B$
36
What is indexed addressing?
Address = base register + index register
37
What is indexed addressing useful for?
Indexing into arrays
38
How many bits does indexed addressing need with B base and I index registers?
$\log_2 B + \log_2 I$
39
What is autoincrement addressing?
Register indirect, with the register incremented or decremented before or after access
40
What is the RTL for MOV *R7++, R0?
R0 <- M[R7]; R7 <- R7 + 1
41
What is the RTL for MOV *--R7, R0?
R7 <- R7 - 1; R0 <- M[R7]
42
What is the RTL for MOV *(R7 + 4), R0?
R0 <- M[R7 + 4]
43
Why are autoincrement modes popular with DSPs?
They step through arrays without extra increment instructions
44
What special autoincrement feature do DSPs have?
Wrap-around, for circular buffers
45
Which processors have many addressing modes: CISC or RISC?
CISC
46
Why don't RISC processors support direct memory addressing?
Encoding full addresses doesn't fit in a fixed-length instruction
47
How many bits would three direct 32-bit memory operands need?
96 bits
48
Why do CISC instructions have variable lengths?
Memory addresses need many more bits than register numbers
49
What is the advantage of CISC variable-length instructions?
Few operand restrictions, so they're easy for assembly programmers
50
What is the disadvantage of variable-length instructions?
They're harder to fetch, decode and pipeline
51
Why do RISC architectures use fixed-length instructions?
They are important for pipelining
52
What problem do fixed-length instructions create?
Large constants and addresses don't fit in one instruction
53
What are the two strategies for loading large constants on RISC?
Synthesise them with multiple instructions, or load them from a literal pool
54
What is constant synthesis?
Building a large constant from smaller immediates using shifts and ORs
55
What instruction count does naive 32-bit constant synthesis need?
4 (two immediate loads, a shift and an OR)
56
What instruction speeds up constant synthesis on many RISCs?
A load-high instruction like MOVHI
57
How does ARM Thumb synthesise 0x1000?
MOV R0, #128 then LSLS R0, R0, #5
58
What is a literal pool?
Constants and addresses stored at the end of a function, too big for an instruction
59
How are literal pool values accessed?
PC-relative indirect addressing with an offset
60
What is the RTL for loading from a literal pool?
R0 <- M[PC + offset]
61
What constants can ARM encode directly in an instruction?
Small integers, or 8-bit patterns with an arbitrary shift
62
How does ARM read a variable at an arbitrary memory address?
Load its address from the literal pool into a register, then use register indirect
63
Why does large constant encoding favour a load/store ISA?
There's little room left in the instruction for other operands
64
What were early ISAs designed for?
Making assembly language programming simple
65
Which of these are typical CISC features?
  • Many data types like BCD and bit fields
  • Complex instructions like CRC and polynomial evaluation
  • Many addressing modes
  • Fixed-length instructions
66
What does BCD stand for?
Binary coded decimal
67
What is memory indirect addressing?
R0 <- M[M[R1]], i.e. a pointer to a pointer
68
What was found about complex CISC instructions?
They were rarely used and made the CPU hard to optimise
69
What is the 80/20 observation about instruction sets?
80% of the time only 20% of the instructions are used
70
How do rarely used instructions hurt performance?
Supporting them adds complexity that penalises common instructions
71
What is the best measure of computer performance?
Time to execute a benchmark suite, e.g. SPEC
72
What is the program execution time formula?
$T = \text{IC} \times \text{CPI} \times \frac{1}{\text{Clock Rate}}$
73
What does CPI stand for?
Clock cycles per instruction
74
What does instruction count depend on?
The ISA and compiler technology
75
What does CPI depend on?
The processor organisation and ISA
76
What does clock rate depend on?
Hardware technology and processor organisation
77
What is the MIPS formula?
$\text{MIPS} = \frac{\text{Clock Rate}}{\text{CPI} \times 10^6}$
78
Why is MIPS a misleading performance measure?
It ignores how many instructions are needed to do a task
79
Why is watts/MIP a poor estimate of battery life?
Energy per program also depends on instruction count
80
What is Amdahl's Rule?
Make the common case fast
81
What is the Amdahl's Rule execution time formula?
$T_{new} = T_{old}\left[(1 - U) + \frac{U}{S}\right]$
82
What is the Amdahl's Rule overall speedup formula?
$S_{overall} = \frac{1}{(1 - U) + U/S}$
83
What is the overall speedup of a 10× enhancement used 50% of the time?
About 1.82
84
What is the overall speedup of a 2× enhancement used 90% of the time?
About 1.82
85
What is the overall speedup of a 4× enhancement used 60% of the time?
About 1.82
86
Feature A: speedup 2, used 20%; B: speedup 5, used 50%. Which is better?
B (1.67 vs 1.11)
87
What is microcoding?
Executing each instruction as a sequence of micro-instructions
88
What is microcode?
A lower-level machine language
89
What are the micro-steps to execute an instruction?
Fetch, decode, read operands, execute, write result, update PC
90
What does MAR stand for?
Memory address register
91
What does MDR stand for?
Memory data register
92
What does IR stand for?
Instruction register
93
What are the micro-steps to fetch an instruction?
MAR <- PC; wait for memory; IR <- memory
94
How is the PC incremented in a simple microcoded CPU?
Through the ALU: A <- PC; B <- instruction size; PC <- Y
95
What did RISC remove?
Unused instructions, data types and addressing modes
96
What is the prime motivation for RISC?
Improving performance through pipelining
97
What CPI does RISC aim for?
1
98
How does RISC achieve a CPI of 1?
Pipelining and a dedicated adder for the PC
99
Why can RISC CPUs reach higher clock speeds?
They are simpler, e.g. hardwired rather than microcoded
100
What is the main cost of RISC?
A higher instruction count
101
Which of these are RISC characteristics?
  • Single-cycle instructions
  • Fixed-length instructions
  • Load/store architecture
  • Many addressing modes
102
Why do RISC architectures have many registers?
Only load/store access memory, so registers hold temporary operands
103
Why should RISC instructions be no wider than the data bus?
So each instruction can be fetched in one cycle
104
What bottleneck does RISC worsen?
The memoryus bottleneck, from more instruction fetches
105
How is the RISC memory bottleneck mitigated?
Cache memory
106
CISC: 100 MHz, CPI 4, IC $10^9$. What is the execution time?
40 s
107
RISC: 200 MHz, CPI 1, IC $2 \times 10^9$. What is the execution time?
10 s
108
Why is the RISC example faster than the CISC example?
Mostly due to its lower CPI
109
Is the instruction count larger for CISC or RISC?
RISC
110
Is the CPI higher for CISC or RISC?
CISC
111
Do RISC architectures necessarily have fewer instructions?
No, the instructions are less complex, not necessarily fewer
112
How can CPI be below 1?
Superscalar or VLIW architectures executing several instructions at once
113
What is a superscalar processor?
One that fetches and executes several instructions at once using multiple ALUs
114
What does VLIW stand for?
Very Long Instruction Word
115
Why are modern x86 (CISC) processors fast?
They convert instructions into simpler micro-instructions that are pipelined
116
What is the goal of pipelining?
To reduce CPI by overlapping the execution of instructions
117
What kind of parallelism is pipelining?
Instruction-level parallelism (ILP)
118
For best pipeline performance, how should stage times compare?
Each stage should take about the same time
119
What are the five stages of the example CPU pipeline?
Fetch, Decode, Read, Execute, Write
120
What happens in the Fetch stage?
The instruction is fetched from memory: IR <- M[PC]
121
What happens in the Decode stage?
The opcode and operands are determined
122
What happens in the Read stage?
Source operands are read from the register file
123
What happens in the Execute stage?
The ALU performs the operation
124
What happens in the Write stage?
The result is written to the destination
125
What is the latency and ideal CPI of a 5-stage pipeline?
Latency 5 cycles; CPI 1
126
What is the ideal CPI of a pipelined processor?
1
127
What are the three types of pipeline hazard?
Resource (structural), data and control
128
What is a resource hazard?
Two pipeline stages need the same resource at the same time
129
Which resources commonly cause resource hazards?
Memory and the ALU
130
What happens when a resource hazard occurs?
A stage is stalled, creating a pipeline bubble
131
What is a pipeline bubble?
An empty slot in the pipeline caused by a stall
132
What is the effect of pipeline stalls on CPI?
They increase the average CPI
133
Why does a LOAD cause a resource hazard on a Princeton architecture?
The Fetch stage and the LOAD's memory read compete for the single memory
134
How do processors avoid instruction/data memory resource hazards?
Separate instruction and data caches
135
Which instruction needs multiple ALU passes, causing a resource hazard?
Division, typically N cycles for N-bit operands
136
What is a data hazard?
An instruction depends on data from a previous instruction still in the pipeline
137
What is a RAW hazard?
Read-after-write: I2 reads a result before I1 has written it
138
What dependency causes a RAW hazard?
A true dependency
139
Which data hazard is most common?
RAW
140
Why does MUL R7,R8,R0 then ADD R0,R8,R1 cause a stall?
R0 is written in stage 5 for I1 but read in stage 3 for I2
141
What is a WAR hazard?
Write-after-read: I2 overwrites an operand before I1 has read it
142
What dependency causes a WAR hazard?
An anti-dependency
143
Why are WAR hazards uncommon in typical pipelines?
Operands are read in an earlier stage than results are written
144
When can WAR hazards occur?
With out-of-order execution or autoincrement addressing
145
What is a WAW hazard?
Write-after-write: writes happen in the wrong order
146
What dependency causes a WAW hazard?
An output dependency
147
When can WAW dependencies arise in code?
When a compiler isn't optimising
148
When is a WAW hazard a problem?
With out-of-order or superscalar execution, not a normal pipeline
149
I1: STORE R6, *R1; I3: MUL R10, R9, R1. What dependency is R1?
An anti-dependency (I1 reads R1, I3 writes it)
150
What is static hazard detection?
Hazard handling by the compiler
151
How does a compiler handle hazards?
Insert NOPs or reorder instructions
152
What is dynamic hazard detection?
Hazard handling by the processor at run time
153
How does a processor handle hazards dynamically?
Stall with a pipeline interlock, or reorder instructions out of order
154
What is a pipeline interlock?
Hardware that stalls an instruction until its hazard clears
155
What is a pipeline without interlocks called?
An exposed or open pipeline
156
What is data forwarding?
Using bypass multiplexers to pass results directly to following instructions
157
What is the purpose of data forwarding?
To reduce hazard delays
158
What is a load delay slot?
The extra cycle (or more) before a loaded value can be used
159
What is the disadvantage of a long pipeline?
Hazards and stalls cost more cycles
160
Why do some CPUs have very long pipelines?
Shorter stages allow a higher clock rate
Study all 160 cards for free