Comparch 03
Comparch 03
Comparch 03
2
Design Point
A set of design considerations and their importance
leads to tradeoffs in both ISA and uarch
Considerations Problem
Cost Algorithm
Performance Program
Runtime System
(VM, OS, MM)
ISA
Microarchitecture
Logic
Circuits
Electrons
Runtime System
(VM, OS, MM)
ISA
Microarchitecture
Logic
Circuits
Electrons
7
Tradeoffs: Soul of Computer Architecture
ISA-level tradeoffs
Microarchitecture-level tradeoffs
8
Readings
P&H, Chapter 4, Sections 4.1-4.4
P&P, revised Appendix A – LC3b datapath and
microprogrammed operation
9
ISA Principles and Tradeoffs
10
WHAT IS AN INSTRUCTION?
11
Instruction
Basic element of the HW/SW interface
Consists of
opcode: what the instruction does
operands: who it is to do it to
12
ARM
13
Set of Instructions, Encoding, and Spec
Example from LC-3b ISA
http://www.ece.utexas.e
du/~patt/11s.460N/hand
outs/new_byte.pdf
x86 Manual
14
Bit Steering in Alpha
15
ISA ELEMENTS & TRADEOFFS
16
Demonstrate Factorial example by x86 & ARM
17
1. Instruction processing style
Specifies the number of “operands” an instruction “operates”
on and how it does so
0, 1, 2, 3 address machines
0-address: stack machine (push A, pop A, op)
1-address: accumulator machine (ld A, st A, op A)
2-address: 2-operand machine (one is both source and dest)
3-address: 3-operand machine (source and dest are separate)
Tradeoffs? See your homework question
Larger operate instructions vs. more executed operations
Code size vs. execution time vs. on-chip memory space
18
An Example: Stack Machine
+ Small instruction size (no operands needed for operate
instructions)
Simpler logic
Compact code
19
An Example: Stack Machine Operation
20
Other Examples
PDP-11: A 2-address machine
PDP-11 ADD: 4-bit opcode, 26-bit operand specifiers
Why? Limited bits to specify an instruction
Disadvantage: One source operand is always clobbered with
the result of the instruction
How do you ensure you preserve the old value of the source?
21
2. Data types
Definition: Representation of information for which there
are instructions that operate on the representation
22
Data Type Tradeoffs
What is the benefit of having more or high-level data types
in the ISA?
What is the disadvantage?
24
4. Registers
How many
Size of each register
25
Evolution of Register Architecture
Accumulator
a legacy from the “adding” machine days
27
6. Addressing Mode
Load/store vs. memory architectures
28
Addressing Mode
Addressing modes specify how to obtain the operands
Displacement mov ax, [1000]
use immediate value as address
Register Indirect: mov ax, [esi]
use register as address
Displaced or based: mov ax, [bx][si]
use base register and index register as address
Indexed: mov ax, var1[esi]
use as address
29
What Are the Benefits of Different Addressing Modes?
Another example of programmer vs. microarchitect tradeoff
Disadvantage:
More work for the compiler
Which is faster?
30
7. Instruction Length
Fixed length: Length of all instructions the same
+ Easier to decode single instruction in hardware
+ Easier to decode multiple instructions concurrently
-- Wasted bits in instructions (Why is this bad?)
-- Harder-to-extend ISA (how to add new instructions?)
Variable length: Length of instructions different
(determined by opcode and sub-opcode)
+ Compact encoding (Why is this good?)
Intel 432: Huffman encoding (sort of). 6 to 321 bit instructions. How?
-- More logic to decode a single instruction
-- Harder to decode multiple instructions concurrently
Tradeoffs
Code size (memory space, bandwidth, latency) vs. hardware complexity
ISA extensibility and expressiveness vs. hardware complexity
Performance? Energy? Smaller code vs. ease of decode
31
8. Uniform Decode
Uniform decode: Same bits in each instruction correspond
to the same meaning
Opcode is always in the same location
Same with operand specifiers, immediate values, …
Non-uniform decode
E.g., opcode can be the 1st-7th byte in x86
+ More compact and powerful instruction format
-- More complex decode logic
32
A Note on Length and Uniformity
Uniform decode usually goes with fixed length
33
9. Aligned vs. Unaligned access
The CPU ALWAYS reads at it's word size (4-bytes on a 32-bit processor), so when you do
an unaligned address access --on a processor that supports it-- the processor is going to
read multiple words. The CPU will read each word of memory that your requested
address straddles. This causes an amplification of up to 2x the number of memory
transactions required to access the requested data.
Because of this, it can very easily be slower to read two bytes than four. For example,
say you have a struct in memory that looks like this:
struct mystruct {
char c; // one byte
int i; // four bytes
short s; // two bytes
}
X86 handle Unaligned access, and MIPs deal only with Aligned access otherwise, it will
give address exception
34
10. Complex vs. Simple Instructions
Complex instruction: An instruction does a lot of work, e.g.
many operations
Insert in a doubly linked list
String copy
35
Complex vs. Simple Instructions
Advantages of Complex instructions
+ Denser encoding smaller code size better memory
utilization, saves off-chip bandwidth, better cache hit rate
(better packing of instructions)
+ Simpler compiler: no need to optimize small instructions as
much
36
ISA-level Tradeoffs: Semantic Gap
Where to place the ISA? Semantic gap
Closer to high-level language (HLL) Small semantic gap,
complex instructions
Closer to hardware control signals? Large semantic gap,
simple instructions
37
Small versus Large Semantic Gap
CISC vs. RISC
Complex instruction set computer complex instructions
Initially motivated by “not good enough” code generation
Reduced instruction set computer simple instructions
John Cocke, mid 1970s, IBM 801
Goal: enable better compiler control and optimization
RISC motivated by
Simplifying the hardware lower cost, higher frequency
Enabling the compiler to optimize the code better
Find fine-grained parallelism to reduce stalls
38
How High or Low Can You Go?
Very large semantic gap
Each instruction specifies the complete set of control signals in
the machine
Compiler generates control signals
Open microcode (John Cocke, circa 1970s)
Gave way to optimizing compilers
39
A Note on RISC vs. CISC
Usually, …
RISC
Simple instructions
Fixed length
Uniform decode
Few addressing modes
CISC
Complex instructions
Variable length
Non-uniform decode
Many addressing modes
40
ISA EVOLUTION
41
A Note on ISA Evolution
ISAs have evolved to reflect/satisfy the concerns of the day
Examples:
Limited on-chip and off-chip memory size
Limited compiler optimization technology
Limited memory bandwidth
Need for specialization in important applications (e.g., MMX)
42
43
Effect of Translation
One can translate from one ISA to another ISA to change
the semantic gap tradeoffs
Examples
Intel’s and AMD’s x86 implementations translate x86
instructions into programmer-invisible microoperations (simple
instructions) in hardware
Transmeta’s x86 implementations translated x86 instructions
into “secret” VLIW instructions in software (code morphing
software)
44