Appendix A Flashcards

1
Q

Instruction set architectures classification

A

By internal storage:

  • accumulator architecture - operands are implicitly in accumulator
  • stack architecture - operands are implicitly on top of the stack
  • general-purpose register architecture - only explicit operands

By accessing memory and registers:

  • register-memory architecture - any instruction can access memory
  • load-store architecture - load and store instructions to access memory
  • memory-memory architecture - not used anymore, all operands in memory

One special type is also extended accumulator or special-purpose register computers - more registers than just accumulator

Currently mostly used are general purpose register architectures - registers are faster than memories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many registers are sufficient?

A

Depends on the effectivity of the compiler, some compilers allocate GP registers for different purposes such as expression evaluation (e.g. x86 stores the result of the 8-bit division in AL and modulus in AH).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Types of GPR architectures

A

By number of operands:

  • 2 operand format - one operand is both source and destination of the operation
  • 3 operand format - one result operand, two src operands

By number of memory operands:
- multiple different amounts - from all three to none

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Memory access types

A

byte - 8 bits
half word -16 bits
words - 32 bits
double words - 64 bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Byte ordering

A

Big Endian - highest bits are in the end - 0,1,2,3,4,5,6,7

Little Endian - lowest bits are in the end - 7,6,5,4,3,2,1,0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Memory alignment

A

Used for accesses higher than byte - memory is then aligned by the module operation where address if address mod access size => s = 0 (e.g. for word access address 0 and 4 is aligned and address such as 2, or 6 is misaligned access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Addrsessing modes

A

Acutal address is called effective address

Modes:

  • register - value is in register
  • immidiate - constants, operand is actual value
  • displacement - memory[constant + regValue]
  • register indirect - memory[regValue]
  • indexed - memory[reg1Value + reg2Value]
  • direct/absolute - memory[constant]
  • memory indirect - memory[memory[regValue]]
  • autoincrement/autodecrement - memory[regValue = regValue + d/regValue = regValue - d]
  • scaled - memory[constant + reg1Value + reg2Value*d]

regValue - value in register
reg1Value, reg2Value - multiple registers value
d - displacement
constant - constant value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Types of operands

A

character - 8 bits
half word - 16 bits
word - 32 bits
single-precision floating-point - 32 bits
double-precision floating-point - 64 bits

Decimal operands

  • packed and binary coded decimals - 4 bits encode 0 - 9 and 2 digits are packed in each byte
  • numeric character strings - unpacked decimals
  • used to precisely repersent decimals which are difficult to represent in binary (e.g. 0.1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Operations in instruction sets

A
  • Arithmetic and logic operations - e.g. add, subtract, multiply, divide, or, and
  • Data transfer - load-store
  • Control - branch, jump, etc.
  • System - operating system call, virtual memory management
  • Floating point - floating point operations - add, subtract, multiply, divide…
  • Decimal - decimal add, decimal multiply, decimal to character conversions
  • String - string move, string compare
  • Graphics - pixel and vertex operations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Control flow instructions types

A

conditional branches
jumps
procedure calls
procedure returns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Adddressing modes for control flow

A
  1. PC-relative - adding displacement to program counter (PC)
    - position independent
    - instructions don`t need to be fully loaded
    - usually smaller jumps
    Register indirect jumps - when jump address is unknown at compilation time
  2. case or switch statements
  3. virtual functions or methods
  4. higher-order functions or function pointers
  5. dynamically shared libraries
    They all usually load jump address from memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Condition branch options

A
  • Condition code - tests special bits set by ALU operations, possibly under program control
  • Condition register/limited comparison - tests arbitrary register with the result of a simple comparison
  • Compare and branch - Compare is part of the branch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Procedure invocation - saving processor state

A

Storing the whole processor state in other registers (older architectures). Using load and store operations to store processor`s state (newer architectures).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Caller saving vs. Callee saving

A

In caller saving calling procedure is responsible to save the state of the processor.
In callee saving called procedure is responsible for saving the state of the processor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Encoding instructions - considerations

A
  1. desire to have as many registers and addressing modes as possible
  2. impact of the register and addressing modes on the average instruction size and average program size
  3. instructions encoded into lengths that are easy to handle in a pipelined implementation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Instruction sizes

A

Variable - instructions can have different sizes - x86, VAX
Fixed - instructions have the same length - RISC V, ARM, MIPS
Hybrid - instructions have different lengths however, there are only few different sizes of instructions. The size is specified by the opcode

17
Q

Compilers - golas

A

Goal:
1. valid programs must be compiled correctly
2. speed of compiled code
Other goals:
- fast compilation, debugging support, interoperability among other languages

18
Q

Compilers - structure

A

Front end per language

  • Dependencies - language dependent, machine independent
  • Function - transforms language to common intermediate form

High-level optimizations

  • Dependencies - Somewhat language dependent, largely machine independent
  • Function - loop transformation, procedure inlining…

Global optimizer

  • Dependencies -Small language dependencies, machine dependencies slight
  • Function - Including global and local optimizations + register allocations

Code generator

  • Dependencies - Highly machine dependent, language independent
  • Function - Detailed instruction selection and machine-dependent optimizations, may be included or followd by assembler
19
Q

Compilers - phase ordering problem

A

Transformations can cause irreversible change of the program structure. Thus compilers need to choose some procedures, or loops to expand inline before knowing their sizes.

20
Q

Compiler - optimizations

A
  • High-level optimizations - source is fed to later optimization passes
  • Local optimizations - optimizing code only within straight-line code fragment (basic block)
  • Global optimizations - extends optimizations accross branches and introduces a set of transformations aimed at optimizing loops
  • Register allocation - associates registers with operands
  • Processor-dependent optimizations - attempt to take advantage of specific architectural knowledge
21
Q

Register allocation

A
  • based on technique of graph colouring
  • goal is to achieve 100% allocation of the registers for active variables
  • NP-complete problem
  • Works best with at least 16 GP registers
22
Q

Compiler - optimizations 2

A
  • High-level - at or near source level - processor independent
    • procedure integration - replace procedure call by its body
  • Local - within straight line code
    • common subexpression elimination
    • Constant propagation
    • Stack height reduction
  • Global - across a branch
    • global common subexpression elimination
    • copy propagation
    • code motion
    • induction variable elimination
  • Processor-dependent - depends on processor knowledge
    • Strength reduction
    • Pipeline scheduling
    • Branch offset optimization
23
Q

Allocating data

A

Stack - allocates local variables

  • grows and shrinks according to calls and returns
  • objects addressed relative to stack pointer
  • primarily used for scalars

Global data area

  • statically declared objects
  • arrays and other aggregated structures

Heap

  • dynamically created structures
  • access through pointers
24
Q

Register allocation

A
  • more effective for stack allocated ojbects rather than global variables
  • almost impossible to use for heap-allocated objects => accessed via pointers
  • aliased variables (in stack and global data area) are difficult to register-allocate
25
Q

Basic principle in architecture

A

frequent cases fast, rare cases correct

26
Q

Helping compiler writer

A
  • Provide regularity - when it makes sense, data types, instructions and addressing modes should be orthogonal. Orthogonal => independent. E.g. for every instruction if it can run in one addressing mode, it should be capable to run also in different addressing modes
  • Provide primitives, not solutions - special features to support a higher-languages are usually ineffective, or unusable
  • Simplify trade-offs among alternatives
  • Provide instructions that bind the quantities known at compile time as constants
27
Q

Multimedia instructions

A

SIMD - lot of problems, not much used, ignores basic principles to help the compiler writer
Alternatives - MMX, AltiVec, SSE

28
Q

Addressing in vector processors

A

Vector computers provide strided addressing, gather/scatter addressing, register indirect addressing in multiple registers

29
Q

Risc-V - registers

A

32 64-bit GPRs - x0..x31 - integer registers
32 FPRs - can hold 32-bit single-precision, or 64-bit double-precision
x0 is always 0

30
Q

Risc-V - data types

A

Integer - 8, 16, 32 and 64-bit
Floating-point - 32 single-precision, 64 double precision
Operations work on 64-bit integers and 32 and 64 bit single or double precision
When using smaller integer operations that 64 bits, zeros, or sign bits are appended

31
Q

Risc-V - addressing types

A

immidiate or displacement both with 12-bit wide fields
register indirect - placing 0 to the 12-bit displacement
absolute adressing - using x0 as base register

32
Q

Risc-V - addressing architecture

A

byte addressable memory
load-store architecture
aligned and unaligned memory accesses - unaligned access may run extremly slow

33
Q

Risc-V - instruction format

A

Fixed instruction length
Two addressing modes encoded in the opcode
7 bit primary opcode
12 bits for immidiate values, displacement, or PC-relative branches

34
Q

Risc-V - instruction types

A

R-type - register-register value - rd destination register, rs1 - register 1, rs2 register 2

I-type - immidiate values - rd - destination, rs1 - first source base register, immediate - value displacement

S-type - store, compare and branch - rs1 - base register first source, rs2 - data source to store second source, immediate - displacement offset

U-type - jump and link, jump and link registers - rd - register destination for return PC, rs1 - target address for jump and link register, immidiate - target address for jump and link