ECE 331 Hardware Organization and Design Professor Jay Taneja UMass ECE - jtaneja@umass.edu Discussion 5 2/22/2018
Today s Discussion Topics Program Concepts Floating Point Floating Point Conversion Floating Point Special Cases
1 M I P S Reference Data CORE INSTRUCTION SET OPCODE FOR- / FUNCT NAME, MNEMONIC MAT OPERATION (in Verilog) (Hex) Add add R R[rd] = R[rs] + R[rt] (1) 0 / 20 hex Add Immediate addi I R[rt] = R[rs] + SignExtImm (1,2) 8 hex Add Imm. Unsigned addiu I R[rt] = R[rs] + SignExtImm (2) 9 hex Add Unsigned addu R R[rd] = R[rs] + R[rt] 0 / 21 hex And and R R[rd] = R[rs] & R[rt] 0 / 24 hex And Immediate andi I R[rt] = R[rs] & ZeroExtImm (3) c hex if(r[rs]==r[rt]) Branch On Equal beq I 4 PC=PC+4+BranchAddr (4) hex if(r[rs]!=r[rt]) Branch On Not Equal bne I 5 PC=PC+4+BranchAddr (4) hex Jump j J PC=JumpAddr (5) 2 hex Jump And Link jal J R[31]=PC+8;PC=JumpAddr (5) 3 hex Jump Register jr R PC=R[rs] 0 / 08 hex R[rt]={24 b0,m[r[rs] Load Byte Unsigned lbu I 24 +SignExtImm](7:0)} (2) hex Load Halfword R[rt]={16 b0,m[r[rs] lhu I 25 Unsigned +SignExtImm](15:0)} (2) hex Load Linked ll I R[rt] = M[R[rs]+SignExtImm] (2,7) 30 hex NAME NUMBER USE $zero 0 The Constant Value 0 $at 1 Assembler Temporary $v0-$v1 2-3 Values for Function Results and Expression Evaluation $a0-$a3 4-7 Arguments $t0-$t7 8-15 Temporaries $s0-$s7 16-23 Saved Temporaries $t8-$t9 24-25 Temporaries $k0-$k1 26-27 Reserved for OS Kernel $gp 28 Global Pointer $sp 29 Stack Pointer $fp 30 Frame Pointer $ra 31 Return Address Load Upper Imm. lui I R[rt] = {imm, 16 b0} f hex Load Word lw I R[rt] = M[R[rs]+SignExtImm] (2) 23 hex Nor nor R R[rd] = ~ (R[rs] R[rt]) 0 / 27 hex Or or R R[rd] = R[rs] R[rt] R[rt](15:0) (2) 0 / 25 hex Or Store Immediate Word sw I R[rt] M[R[rs]+SignExtImm] = ZeroExtImm = R[rt] (3) (2) 2b d hex Subtract sub R R[rd] = R[rs] - R[rt] (1) 0 / 22 hex 0 / 23
Program Concepts Program Counter ($pc) register that contains the address of the instruction currently being executed Stack Pointer ($sp) register that contains the address of the top of the stack (memory set aside for a program s computations) Frame Pointer ($fp) register that contains the address of the previous top of the stack from before the current procedure
Parts of a Floating Point Number -0.9876 x 10-3 Exponent Sign of mantissa Location of decimal point Mantissa Sign of exponent Base Mantissa is also called Significand ECE232: Floating Point 12
Single Precision Format Note that the exponent has no explicit sign bit Base? 32 bits M: Mantissa (23 bits) E: Exponent (8 bits) S: Sign of mantissa (1 bit) ECE232: Floating Point 13
Working with normalization (single precision) S {0,1} (1-bit) 1 E 254 (8-bits unsigned integer); Bias = 127 0.0000 0000 0000 0000 0000 000 f base-2 < 0.1111 1111 1111 1111 1111 111 Formula provides for the full range of possible floating point numbers. F S = (-1) 1. f * 2 E-Bias 2-2 2-1 2 0 2 1 2 2 2 3 0.25 0.5 1.0 2.0 4.0 8.0 ECE232: Floating Point 17
IEEE Floating-Point Format single: 8 bits double: 11 bits S Exponent single: 23 bits double: 52 bits Fraction x = (-1) S (1+ Fraction) 2 (Exponent -Bias) S: sign bit (0 Þ non-negative, 1 Þ negative) Normalize significand: 1.0 significand < 2.0 Always has a leading pre-binary-point 1 bit, so no need to represent it explicitly (hidden bit) Significand is Fraction with the 1. restored Exponent: excess representation: actual exponent + Bias Ensures exponent is unsigned Single: Bias = 127; Double: Bias = 1203 1023 ECE232: Floating Point 18
Categories of Floating Point Representation Depending on the value of the exponent and fraction, the floating point number can take on different meanings ECE232: Floating Point 22
An0ther Single precision example 0 10000010 11010000000000000000000 1.1101 2 130 127 = 3 0 = positive mantissa +1.1101 2 x 2 3 = 1110.1 2 = 14.5 10 ECE232: Floating Point 10
Floating Point Special Representations S E-127 F = (-1) 1. f * 2 1 1. < 2 f 1 E 254 (single precision) Single Precision Double Precision Object represented Exponent Fraction Exponent Fraction 0 0 0 0 0 0 nonzero 0 nonzero ± denormalized number 1-254 Anything 1-2046 Anything ± floating point number 255 0 2047 0 ± infinity 255 nonzero 2047 nonzero NaN (not a number) ECE232: Floating Point 15
1 M I P S Reference Data CORE INSTRUCTION SET OPCODE FOR- / FUNCT NAME, MNEMONIC MAT OPERATION (in Verilog) (Hex) Add add R R[rd] = R[rs] + R[rt] (1) 0 / 20 hex Add Immediate addi I R[rt] = R[rs] + SignExtImm (1,2) 8 hex Add Imm. Unsigned addiu I R[rt] = R[rs] + SignExtImm (2) 9 hex Add Unsigned addu R R[rd] = R[rs] + R[rt] 0 / 21 hex And and R R[rd] = R[rs] & R[rt] 0 / 24 hex And Immediate andi I R[rt] = R[rs] & ZeroExtImm (3) c hex if(r[rs]==r[rt]) Branch On Equal beq I 4 PC=PC+4+BranchAddr (4) hex if(r[rs]!=r[rt]) Branch On Not Equal bne I 5 PC=PC+4+BranchAddr (4) hex Jump j J PC=JumpAddr (5) 2 hex Jump And Link jal J R[31]=PC+8;PC=JumpAddr (5) 3 hex Jump Register jr R PC=R[rs] 0 / 08 hex R[rt]={24 b0,m[r[rs] Load Byte Unsigned lbu I 24 +SignExtImm](7:0)} (2) hex Load Halfword R[rt]={16 b0,m[r[rs] lhu I 25 Unsigned +SignExtImm](15:0)} (2) hex Load Linked ll I R[rt] = M[R[rs]+SignExtImm] (2,7) 30 hex NAME NUMBER USE $zero 0 The Constant Value 0 $at 1 Assembler Temporary $v0-$v1 2-3 Values for Function Results and Expression Evaluation $a0-$a3 4-7 Arguments $t0-$t7 8-15 Temporaries $s0-$s7 16-23 Saved Temporaries $t8-$t9 24-25 Temporaries $k0-$k1 26-27 Reserved for OS Kernel $gp 28 Global Pointer $sp 29 Stack Pointer $fp 30 Frame Pointer $ra 31 Return Address Load Upper Imm. lui I R[rt] = {imm, 16 b0} f hex Load Word lw I R[rt] = M[R[rs]+SignExtImm] (2) 23 hex Nor nor R R[rd] = ~ (R[rs] R[rt]) 0 / 27 hex Or or R R[rd] = R[rs] R[rt] R[rt](15:0) (2) 0 / 25 hex Or Store Immediate Word sw I R[rt] M[R[rs]+SignExtImm] = ZeroExtImm = R[rt] (3) (2) 2b d hex Subtract sub R R[rd] = R[rs] - R[rt] (1) 0 / 22 hex 0 / 23
Floating Point Special Representations S E-127 F = (-1) 1. f * 2 1 1. f < 2 There are two Zeroes, ±0, and two Infinities ± NaN (Not-a-Number) may have a sign and have a non-zero fraction - used for program diagnostics NaNs and Infinities have all 1s in the Exp field, E=255. F+ =, F/ =0 ECE232: Floating Point 14 Source: I. Koren, Computer Arithmetic Algorithms, 2nd Edition, 2002
IEEE Floating-Point Format single: 8 bits double: 11 bits S Exponent single: 23 bits double: 52 bits Fraction x = (-1) S (1+ Fraction) 2 (Exponent -Bias) S: sign bit (0 Þ non-negative, 1 Þ negative) Normalize significand: 1.0 significand < 2.0 Always has a leading pre-binary-point 1 bit, so no need to represent it explicitly (hidden bit) Significand is Fraction with the 1. restored Exponent: excess representation: actual exponent + Bias Ensures exponent is unsigned Single: Bias = 127; Double: Bias = 1203 ECE232: Floating Point 18
An0ther Single precision example 0 10000010 11010000000000000000000 1.1101 2 130 127 = 3 0 = positive mantissa +1.1101 2 x 2 3 = 1110.1 2 = 14.5 10 ECE232: Floating Point 10
Floating Point Special Representations S E-127 F = (-1) 1. f * 2 1 1. f < 2 There are two Zeroes, ±0, and two Infinities ± NaN (Not-a-Number) may have a sign and have a non-zero fraction - used for program diagnostics NaNs and Infinities have all 1s in the Exp field, E=255. F+ =, F/ =0 ECE232: Floating Point 14 Source: I. Koren, Computer Arithmetic Algorithms, 2nd Edition, 2002
Floating Point Special Representations S E-127 F = (-1) 1. f * 2 1 1. < 2 f 1 E 254 (single precision) Single Precision Double Precision Object represented Exponent Fraction Exponent Fraction 0 0 0 0 0 0 nonzero 0 nonzero ± denormalized number 1-254 Anything 1-2046 Anything ± floating point number 255 0 2047 0 ± infinity 255 nonzero 2047 nonzero NaN (not a number) ECE232: Floating Point 15