<<

What Is ISA? Instruction set architecture is the structure of a that a machine language Lecture 3: Instruction Set programmer (or a compiler) must understand Architecture to write a correct (timing independent) program for that machine. ISA types, register usage, memory For IBM System/360, 1964 addressing, endian and alignment, quantitative evaluation Class ISA types: Stack, Accumulator, and General-purpose register ISA is mature and stable „ Why do we study it?

1 2

Stack Accumulator

The accumulator provides an Implicit operands on stack implicit input, and is the Ex. C = A + B implicit place to store the Push A result. Push B Ex. C = A + B Add Load R1, A Pop C Add R3, R1, B Good code density; used in Store R3, c 60’s-70’s; now in Java VM Used before 1980

3 4

General-purpose Registers Variants of GRP Architecture

General-purpose registers are preferred by Number of operands in ALU instructions: two or compilers three „ Reduce memory traffic Add R1, R2, R3 Add R1, R2 „ Improve program speed Maximal number of operands in ALU instructions: „ Improve code density Usage of general-purpose registers zero, one, two, or three Load R1, A Load R1, A „ Holding temporal variables in expression evaluation „ Passing parameters Load R2, B Add R3, R1, B „ Holding variables Add R3, R1, R2 GPR and RISC and CISC Three popular combinations „ RISC ISA is extensively used for desktop, server, and „ register-register (load-store): 0 memory, 3 operands embedded: MIPS, PowerPC, UltraSPARC, ARM, MIPS16, „ register-memory: 1 memory, 2 operands Thumb „ memory-memory: 2 memories, 2 operands; or 3 memories, 3 „ CISC: IBM 360/370, an VAX, Intel 80x86 operands

5 6

1 Register-memory Register-register (Load-store)

There is no implicit operand Both operands are registers One input operand is Values in memory must be register, and one in memory loaded into a register and Ex. C = A + B stored back Load R1, A Ex. C = A + B Add R3, R1, B Load R1, A Store R3, C Load R2, B Processors include VAX, Add R3, R1, R2 80x86 Store R3, C Processors: MIPS, SPARC

7 8

How Many Registers? ISA and Performance

If the number of registers increase: CPU time = #inst × CPI × cycle time

RISC with Register-Register instructions × Allocate more variables in registers (fast accesses) × Simple, fix-length instruction encoding × Reducing code spill × Simple code generation × Regularity in CPI × Reducing memory traffic Ø Higher instruction counts Ø Lower instruction density

Ø Longer register specifiers (difficult encoding) CISC with Register-memory instructions Ø Increasing register access time (physical registers) × No extra load in accessing data in memory × Easy encoding Ø More registers to save in context switch Ø Operands being not equivalent Ø Restricted #registers due to encoding Ø Irregularity in CPI MIPS64: 32 general-purpose registers

9 10

Memory Addressing Little or Big: Where to Start?

Instructions see registers, constant values, and memory Byte ordering: decides how to specify an object to access Where is the first „ Object can be memory location, register, or a constant byte? Number 0x5678 „ Memory addressing is complicated Little-endian Big-endian Memory addressing involves many factors Big-endian:IBM, „ Memory addressing mode „ Object size SPARC, Mororola „ byte ordering „ alignment Little-endian: Intel, DEC For a memory location, its effective address is calculated in a certain form of register content, immediate address, and PC, Supporting both: 00000003 5 8 as specified by the addressing mode MIPS, PowerPC 00000002 6 7 00000001 7 6 00000000 8 5

11 12

2 Alignment MIPS Data Addressing Modes

Align n-byte objects on n-byte Register boundaries (n = 1, 2, 4, 8) ADD $16, $7, $8

One align position, n-1 misaligned Immediate positions ADDI $17, $7, 100 Misaligned access is undiserable Displacement „ Expensive logic, slow references LW $18, 100($9) Aligning in registers may be necessary for bytes and half words Only the three are supported for data addressing

13 14

Storage Used by Compilers Memory Addressing Seen in CISC

Register storage Direct (absolute) ADD R1, (1001) „ Holding temporal variables in expression Register indirect SUB R2, (R1) evaluation „ Passing parameters Indexed ADD R1, (R2 + R3) „ Holding variables Scaled SUB R2, 100(R2)[R3] Autoincrement ADD R1, (R2)+ Memory storages consists of Autodecrement SUB R2, -(R1) „ Stack: to hold local variables „ Global data area: to hold statically declared Memory indirect ADD R1, @(R3) objects (see textbook p98) „ Heap: to hold dynamic objects And more …

15 16

Choosing of Memory Addressing Modes How Often Are Those Address Modes?

Choosing complex addressing modes × Close to addressing in high-level language × May reduce instruction counts (thus fast) Ø Increase implementation complexity (may increase cycle time) Ø Increase CPI

RISC ISA comes with simple memory addressing, and CISC ISA with complex ones Usage of address modes, VAX machine, SPEC89

17 18

3 Usage of Immediate Operands In RISC Immediate Size in RISC

Alpha, SPEC CINT2000 & CFP2000 Alpha, SPEC CINT2000 & CFP2000 19 20

Displacement Size in RISC Operands size, type and format

In MIPS Opcode encodes operand size „ Ex. ADD for signed integer, ADDU for unsigned integer, ADD.D for double-precision FP Most common types include „ Integer: complement binary numbers „ Character: ASCII „ Floating point: IEEE standard 754, single-precision or double-precision Decimal format „ 4-bits for one decimal digit (0-9), one byte for two decimal digits „ Necessary for business applications Fixed Point format in DSP processors: „ Representing fractions in (-1, +1) „ 11000101 = -0.1000101 Displacement bit size: Alpha ISA, SPEC fixed point 2 CPU2000 Integer and FP 21 22

Dynamic Instruction Mix (MIPS) Compiler Effects SPEC2K Int SPEC2K FP Load 26% 15% Store 10% 2% Add 19% 23% Compare 5% 2% Cond br 12% 4% Cond mv 2% 0% Jump 1% 0% LOGIC 18% 4% Architectures change for the needs of compilers FP load 15% • How do compilers use registers? How many? FP store 7% • How do compilers use addressing modes? FP others 19% • Anything that compilers do not like? 23 24

4