CS 61C Summer 2012 Discussion 6 – FP and Performance

Floating Point Modes In floating point arithmetic, two extra bits are used to the far right of the significand, called the guard and round bits. At the end of the arithmetic calculation, these bits are rounded off. We always round towards the closer digit (i.e. 0.00-0.49  0 and 0.51-0.99  1). The only interesting case is when we are smack-dab in the middle. IEEE 754 defines 4 rounding modes to determine how the extra two two bits are used: 1) Towards +∞ 2) Towards -∞ 3) Truncate 4) Unbiased rounds “up”: rounds “down”: rounds towards 0: rounds to even

1.5010  210 1.5010  110 1.5010  110 1.5010  210

-1.5010  -110 -1.5010  -210 -1.5010  -110 -1.5010  -210

2.5010  310 2.5010 210 2.5010  210 2.5010  210 Note: Rounding does not necessarily have to be to an ! Can round to any arbitrary digit such as 0.125  0.1 or 16.45  20. Rounding Exercises Round the following binary to the nearest integer using each of the four modes, when needed:

0.002 0.012 0.102 0.112 1.002 1.012 1.102 1.112 Half-way? +∞ -∞ Zero Even

Single Precision Floating Point:

31 30 23 22 0 Exponent Significand Meaning S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF 0 0 0 (with an exponent bias of 127) 0 Non-zero Denorm Double Precision Floating Point: 1~254 Anything Float 63 62 52 51 0 255 0 Infinity S EEEEEEEEEEE FFFFFFFFFF...FFFFFFFF 255 Non-zero NaN (with an exponent bias of 1023)

Floating Point Exercises Convert the following numbers into binary (not float). 1.5 0.25 0.8 -16.5

Give the best hex representation of the following numbers (using single precision floats): 1.0 -7.5 (1.0/3.0) (186.334/0.0)

What is the value of the following single precision floats? 0x0 0xff94beef 0x1

CS 61C Summer 2012 Discussion 6 – FP and Performance

Performance Metrics

A processor’s performance is determined by more than just the clock speed.

CPU time = Instruction Count * CPI * clock period

(seconds/program) = (instructions/program)*(cycles/instruction)*(seconds/cycle)

Exercises You are the lead developer of a new video game at AE, Inc. The graphics are quite sexy, but the frame rates (performance) are horrible. Doubly unfortunately, you have to show it off at a shareholder meeting tomorrow. What do you do?

1) You need to render your latest and greatest über-l33t animation. If your rendering software contains the following mix of instructions, which processor is the best choice?

Operation Frequency A’s CPI B’s CPI ’s CPI ALU 30% 1 1 1 Load 30% 3 5 3 Store 20% 2 3 4 Branch 20% 3 2 2

2) What if the processors had different clock speeds? Assume A is a 1 Ghz processor, B is a 1.5 Ghz processor, and C is a 750 Mhz processor.

3) But wait, these processors are made by different manufacturers, and use different instruction sets. So the renderer (for the different architectures) takes a different of instructions on each. Which is best if your main loop on A averages 1000 instructions; on B it averages 800 instructions; and on C it averages 1200 instructions?