RISC vs CISC Instruction Sets CS 740 Alpha Processors Reduced Instruction Set Computer RISC Simple instructions with regular formats Key Idea make the common case fast infrequent operations can be synthesized using multiple instructions Sept 13 2007 Assumes compiler will do optimizations Topics e g scalar optimization register allocation scheduling etc ISA designed for compilers not assembly language programmers Alpha instruction set A 2nd Generation RISC Instruction Set Architecture Designed for superscalar processors i e 1 inst per cycle avoids some of the pitfalls of earlier RISC ISAs e g delay slots Designed as a 64 bit ISA from the start Very high performance machines in their day 2 32 General Purpose Registers v0 t0 t1 t2 t3 t4 t5 t6 t7 s0 s1 s2 s3 s4 s5 s6 fp Return value from integer functions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Temporaries not preserved across procedure calls Callee saved Frame pointer or callee saved 3 a0 a1 a2 a3 a4 a5 t8 t9 t10 t11 ra pv t12 AT gp sp zero 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 CS 740 F 07 Instruction Formats Arithmetic Operations all register operands addq 1 7 5 with a literal operand addq 1 15 5 Integer arguments Branches a single source register bne 1 label Temporaries Jumps Return address Current proc addr or Temp Reserved for assembler Global pointer Stack pointer Always zero one source one dest reg jsr 26 1 hint Loads Stores ldq 1 16 30 CS 740 F 07 4 Page 1 6 5 Opcode Ra 5 3 1 6 5 8 Opcode Ra Lit 6 5 Opcode Ra 7 Rb SBZ 0 Func 1 7 1 Func 21 Displacement 6 5 5 16 Opcode Ra Rb Hint 6 5 5 16 Opcode Ra Rb Offset CS 740 F 07 5 Rc 5 Rc Returning a Value from a Procedure C Code Pointer Examples Compiled to Assembly long int test2 long int x long int y return x x x y y y C Code align 3 globl test2 ent test2 test2 frame 30 0 26 0 prologue 0 addq 16 16 1 addq 1 16 1 addq 17 17 0 addq 0 17 0 subq 1 0 0 ret 31 26 1 end test2 Place result in 0 5 CS 740 F 07 Annotated Assembly long int iaddp long int xp long int yp int x xp int y yp return x y iaddp void incr long int sum long int v long int old sum long int new old val sum new incr arefl int arefi int a long int i return a i arefi ldq 1 0 16 addq 1 17 1 stq 1 0 16 ret 31 26 1 1 sum 1 v sum 1 return CS 740 F 07 Branches Annotated Assembly long int arefl long int a long int i return a i 1 xp 0 yp return with a value x y 6 Array Indexing C Code ldq 1 0 16 ldq 0 0 17 addq 1 0 0 ret 31 26 1 Conditional Branches bCond Ra label Cond branch condition relative to zero beq Equal Ra bne Not Equal Ra bgt Greater Than Ra bge Greater Than or Equal Ra blt Less Than Ra ble Less Than or Equal Ra Register value is typically set by a comparison s8addq 17 16 17 17 8 i a 0 ldq 0 0 17 return val a i ret 31 26 1 return s4addq 17 16 17 17 4 i a 0 ldl 0 0 17 return val a i ret 31 26 1 return 0 0 0 0 0 0 instruction Unconditional Branches br label 7 CS 740 F 07 8 Page 2 CS 740 F 07 Conditional Branches Conditional Move Instructions Comparison Instructions Motivation Format cmpCond Ra Rb Rc Cond comparison condition Ra relative to Rb cmpeq cmplt cmple cmpult cmpule Equal Less Than Less Than or Equal Unsigned Less Than Unsigned Less Than or Equal C Code conditional branches tend to disrupt pipelining hurt performance Basic Idea Rc Ra Rb Rc Ra Rb Rc Ra Rb Rc uRa uRb Rc uRa uRb conditional moves can replace branches in some cases avoids disrupting the flow of control Mechanism cmovCond Ra Rb Rc Annotated Assembly long int condbr long int x long int y long int v 0 if x y v x x x y return v Cond comparison condition Ra is compared with zero same conditions as a conditional branch eq ne gt ge lt le if Ra Cond zero then copy Rb into Rc condbr bis 31 31 0 cmple 16 17 1 bne 1 45 addq 16 16 0 addq 0 16 0 addq 0 17 0 v 0 x y if so branch v x x v x v y ret 31 26 1 return v Psuedo code example if x 0 z y 9 CS 740 F 07 cmovgt x y z 10 Jumps CS 740 F 07 Procedure Calls Returns Maintain the return address in a special register 26 Procedure call Characteristics transfer of control is unconditional target address is specified by a register Format bsr 26 label jsr 26 Ra jmp Ra Rb Hint Save return addr in 26 branch to label Save return addr in 26 jump to address in Ra Procedure return Rb contains the target address for now don t worry about the meaning of Ra or Hint synonyms for jmp jsr ret ret 31 26 Jump to address in 26 C Code Annotated Assembly long int caller return callee long int callee return 5L 11 45 CS 740 F 07 12 Page 3 caller 0x800 bsr 26 callee 0x804 callee 0x918 bis 31 5 0 0x91c ret 31 26 1 save return addr 0x804 in 26 branch to callee return value 5 jump to addr in 26 CS 740 F 07
View Full Document
Unlocking...