Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

Size: px
Start display at page:

Download "Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng"

Transcription

1 Slide Set 11 for ENCM 369 Winter 2015 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2015

2 ENCM 369 W15 Section 01 Slide Set 11 slide 2/69 Contents Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

3 ENCM 369 W15 Section 01 Slide Set 11 slide 3/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

4 ENCM 369 W15 Section 01 Slide Set 11 slide 4/69 Integer Multiplication and Division So far in ENCM 369, we ve looked in detail at integer addition and subtraction, and also at use of left-shift instructions for multiplication by powers of two. Obviously, many computer programs need to do multiplication of integers that are not powers of two, and some programs need to do integer division.

5 ENCM 369 W15 Section 01 Slide Set 11 slide 5/69 However, the basics of integer multiplication and division with computers are relatively easy to learn by reading textbooks and online material, and lecture time in ENCM 369 in Winter 2015 is now very scarce. So lecture content will skip integer multiplication and division, and move on to floating-point numbers. Please go to the ENCM 369 Winter 2015 Home Page, then click on Page with links to PDFs of handouts and other documents used in both lecture sections to find slides on integer multiplication and division. You can expect that a small number of marks on the 2015 final exam will be related to basic understanding of MIPS integer multiplication and division instructions.

6 ENCM 369 W15 Section 01 Slide Set 11 slide 6/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

7 ENCM 369 W15 Section 01 Slide Set 11 slide 7/69 Introduction to floating-point numbers Floating-point is the generic name given to the kinds of numbers you ve seen in C and C++ with types double and float. Section in the textbook is about the basic concepts of floating-point numbers. Section provides a very brief introduction to MIPS floating-point registers and instructions.

8 ENCM 369 W15 Section 01 Slide Set 11 slide 8/69 Scientific Notation This is a format that engineering students should be very familiar with! Example: mol 1 Example: C Floating-point representation has the same structure as scientific notation, but floating-point typically uses base two, not base ten.

9 ENCM 369 W15 Section 01 Slide Set 11 slide 9/69 Introductory floating-point example A programmer gives a value to a constant in some C code: const double electron_charge = e-19; The C compiler will use the base ten constant in the C code to create a base two constant a computer can work with. When the program runs, the number the computer uses is two , which is very close to but not exactly equal to

10 ENCM 369 W15 Section 01 Slide Set 11 slide 10/69 Names for parts of a non-zero floating-point number sign significand fraction two exponent The significand includes bits from both sides of the binary point. Another name for significand is mantissa. (Note: This is not base ten, so we should not use the term decimal point!) The fraction is the part of the significand that is to the right of the binary point. So the fraction represents some number that is 0 but < 1.

11 ENCM 369 W15 Section 01 Slide Set 11 slide 11/69 Normalized non-zero floating-point numbers In normalized form, an f-p number must have a single 1 bit immediately to the left of the binary point, and no other 1 bits left of the binary point. Therefore, the significand of a normalized number must be 1.0 and must also be < 10.0 two. (In English: greater than or equal to one, strictly less than two.)

12 ENCM 369 W15 Section 01 Slide Set 11 slide 12/69 Normalized non-zero f-p numbers: examples Which of the following are in normalized form? A two B two C two D two E two

13 ENCM 369 W15 Section 01 Slide Set 11 slide 13/69 Example conversion from base ten to base-two floating-point What is ten expressed as a normalized f-p number? What are the sign, significand, fraction, and exponent of this normalized f-p number?

14 ENCM 369 W15 Section 01 Slide Set 11 slide 14/69 Standard organizations for bits of floating-point numbers For computer hardware to work with f-p numbers there must be precise rules about how to encode these numbers. The most usual overall sizes for f-p numbers are 32 bits or 64 bits, but other sizes (e.g., 16, 80, or 128 bits) are possible. We need one bit for the sign and some number of bits for information about the exponent; the remaining bits can be used for information about the significand.

15 ENCM 369 W15 Section 01 Slide Set 11 slide 15/69 Sign information for non-zero f-p numbers This requires a single bit. A sign bit of 0 is used for positive numbers. A sign bit of 1 is used for negative numbers.

16 ENCM 369 W15 Section 01 Slide Set 11 slide 16/69 Exponent information for a non-zero f-p numbers Exponents in f-p numbers are signed integers! f-p numbers with small magnitudes will have negative exponents. So of course two s complement is used for exponents, right...? WRONG! In fact, an alternate system for signed integers, called biased notation, is used for exponents in f-p numbers. (This fact explains why many introductions to two s-complement systems state that two s complement is almost always used for signed integers in modern digital hardware.)

17 ENCM 369 W15 Section 01 Slide Set 11 slide 17/69 How does biased notation work? The biased exponent is equal to the actual exponent plus some number called a bias. The bias is chosen so that roughly half the allowable actual exponents are negative, and roughly half are positive. Example: The bias for an 8-bit exponent is 127 ten, or 0111_1111 two. If the actual exponent is 3 ten, what is the biased exponent in base ten and base two?

18 ENCM 369 W15 Section 01 Slide Set 11 slide 18/69 Why is biased notation used for exponents in f-p numbers? It turns out that biased notation helps with the design of relatively small, speedy circuits to decide whether one f-p number is less than another f-p number. (We won t study the details of that in ENCM 369.) Also, it s useful that the bit pattern for an actual exponent of zero is not a sequence of zero bits then a sequence of zero bits can have a different, special meaning.

19 ENCM 369 W15 Section 01 Slide Set 11 slide 19/69 Significand information for a non-zero, normalized f-p number 1 XXX XXX We know this bit will be a 1. Any pattern of 1 s and 0 s is possible here. There is no need to encode the entire significand. Instead we can record only the bits of the fraction. Leaving out the 1 bit from the left of the binary point allows more precision in the fraction.

20 ENCM 369 W15 Section 01 Slide Set 11 slide 20/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

21 ENCM 369 W15 Section 01 Slide Set 11 slide 21/69 MIPS formats for 32-bit and 64-bit f-p numbers bit 31 sign bit bits biased exponent bits 22 0 fraction bit 63 sign bit bits biased exponent bits 51 0 fraction Exponent bias for 32-bit format: 127 ten = 0111_1111 two. Exponent bias for 64-bit format: 1023 ten = 011_1111_1111 two.

22 ENCM 369 W15 Section 01 Slide Set 11 slide 22/69 MIPS formats for 32-bit and 64-bit f-p numbers The 32-bit format is called single precision. The 64-bit format is called double precision. We ll see later that MIPS instruction mnemonics for single-precision operations end in.s, as in mov.s, while the mnemonics for double-precision operations end in.d, as in add.d.

23 ENCM 369 W15 Section 01 Slide Set 11 slide 23/69 Example: How is ten encoded in 32-bit and 64-bit formats? From previous work: = = two = two three (normalized) For each of the 32-bit and 64-bit formats, what are the bit patterns for the biased exponents? What are the complete bit patterns for the f-p numbers?

24 ENCM 369 W15 Section 01 Slide Set 11 slide 24/69 More examples How would ten be encoded in the 32-bit format? How would ten be encoded in the 32-bit format? What base ten number does the 32-bit pattern 1_0111_1110_11_[21 zeros] represent?

25 ENCM 369 W15 Section 01 Slide Set 11 slide 25/69 How to represent zero in f-p formats A special rule says that if all exponent and fraction bits are zero, the number being represented is 0.0. So, what are the representations of 0.0 in 32-bit and 64-bit formats?

26 ENCM 369 W15 Section 01 Slide Set 11 slide 26/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

27 ENCM 369 W15 Section 01 Slide Set 11 slide 27/69 IEEE standards for floating-point numbers and arithmetic (1) IEEE: Institute of Electrical and Electronics Engineers IEEE 754 and IEEE floating-point are informal names for both the original IEEE standard and the revised IEEE standard. Prior to the development of the IEEE standard, different companies produced a wide variety of incompatible schemes for floating-point numbers.

28 ENCM 369 W15 Section 01 Slide Set 11 slide 28/69 IEEE standards for floating-point numbers and arithmetic (2) Modern computer architectures (if they have f-p at all) typically implement part or all of IEEE standard f-p. MIPS follows the IEEE standard for 32-bit and 64-bit f-p types. The same is true for x86, x86-64, ARM and many other architectures. (So examples in earlier slides were not really MIPS-specific they would also be correct for many other architectures.) In C and C++, float is typically 32-bit IEEE f-p, and double is typically 64-bit IEEE f-p.

29 ENCM 369 W15 Section 01 Slide Set 11 slide 29/69 Scope of IEEE f-p standards In addition to 32-bit and 64-bit formats, various other formats are specified, for example, 16-bit and 128-bit formats. There are detailed rules for arithmetic comparison, addition, multiplication, and many other operations. There are detailed rules for rounding choosing an approximate value when exact results can t be represented.

30 ENCM 369 W15 Section 01 Slide Set 11 slide 30/69 Special IEEE f-p bit patterns exponent bits fraction bits meaning all 0 s all 0 s number is 0.0, as seen already all 0 s at least one denormalized number 1 bit all 1 s all 0 s ±infinity, depending all 1 s at least one 1 bit on sign bit NaN: not a number If the exponent field of an IEEE f-p bit pattern has at least one 0 bit and at least one 1 bit, the bit pattern represents a normal, non-zero f-p number.

31 ENCM 369 W15 Section 01 Slide Set 11 slide 31/69 Denormalized numbers These are non-zero numbers with magnitudes so tiny that they can t be represented in the normal sign-exponent-fraction format. Example: in the 32-bit format. The range of biased exponents is 0000_0001 two to 1111_1110 two, that is, 1 to 254 ten, which allows encoding of actual exponents from 126 ten to +127 ten. We will NOT study the details of the denormalized number format in ENCM 369. (However, if you re curious, is represented as in the 32-bit format.)

32 ENCM 369 W15 Section 01 Slide Set 11 slide 32/69 Infinity IEEE standard f-p arithmetic specifies many ways to generate ±infinity. Some common examples... x / 0.0 generates + if x > 0.0. x / 0.0 generates if x < 0.0. If a and b are regular f-p numbers but the everyday math product a b is too large in magnitude to be an f-p number, then a * b will be ±, depending on the signs of a and b.

33 ENCM 369 W15 Section 01 Slide Set 11 slide 33/69 NaN: not a number NaN is specified as the result for many computations where not even ±infinity makes sense as a result. Examples / 0.0 infinity / infinity sqrt(x), where x < 0.0 asin(x), where x > 1.0 or x < 1.0 (asin is the C library inverse sine function.) arithmetic operation with one or more NaNs as inputs, e.g., x, where x is NaN

34 ENCM 369 W15 Section 01 Slide Set 11 slide 34/69 Demonstration of f-p infinity In everyday math, = 4,330,747,000 and ( ) 3 = #include <stdio.h> int main(void) { int i = 1630; double d1 = , d2 = 5.7e102; printf("%d cubed is %d\n", i, i * i * i); printf("%.1f cubed is %.1f\n", d1, d1 * d1 * d1); printf("%g cubed is %g\n", d2, d2 * d2 * d2); return 0; } Program output cubed is cubed is e+102 cubed is inf

35 ENCM 369 W15 Section 01 Slide Set 11 slide 35/69 Demonstration of Not a Number #include <math.h> #include <stdio.h> int main(void) { double a = 1.0, b = 2.0, c = 2.0; double sqrt_of_d, r1, r2; sqrt_of_d = sqrt(b * b * a * c); r1 = (-b + sqrt_of_d) / (2.0 * a); r2 = (-b - sqrt_of_d) / (2.0 * a); printf("r1 = %g, r2 = %g\n", r1, r2); return 0; } Program output... r1 = -nan, r2 = -nan

36 ENCM 369 W15 Section 01 Slide Set 11 slide 36/69 The usefulness of infinity and NaN Recall that for integer addition, subtraction, and multiplication, C and C++ systems usually will NOT tell you that results are wrong because magnitudes of numbers got out of hand. Results of ±infinity or NaN in floating-point computation clearly indicate that something has gone wrong. This is helpful! Of course, absence of ±infinity and NaN does NOT prove that your program s results are correct!

37 ENCM 369 W15 Section 01 Slide Set 11 slide 37/69 ENCM 369 Lecture Document: Floating-Point Format Examples Please read this document carefully. Here are some brief notes on what you will see: π cannot be represented exactly in f-p format. (This is probably not a surprise.) 0.6 cannot be represented exactly in f-p format. (This might be surprising.) 32-bit and 64-bit f-p approximations are given for π and 0.6. f-p bit patterns for 1.0 are given; they are very different from integer bit patterns for 1.

38 ENCM 369 W15 Section 01 Slide Set 11 slide 38/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

39 ENCM 369 W15 Section 01 Slide Set 11 slide 39/69 Floating-point registers Most processor architectures that have f-p instructions have a set of floating-point registers (FPRs) that is separate from the set of general-purpose registers (GPRs). Important: Most f-p instructions have only FPRs as sources and destination! But there have to be a few instructions for copying data between FPRs and GPRs, or between FPRs and memory.

40 ENCM 369 W15 Section 01 Slide Set 11 slide 40/69 MIPS FPRs There are bit double-precision FPRs: $f0, $f2, $f4,..., $f28, $f30. (Note that odd numbers are not allowed for names of these double-precision registers.) There are bit single-precision FPRs: $f0, $f1, $f2,..., $f30, $f31. Attention: Unlike the set of GPRs, where $zero has special behaviour, none of the FPRs hold a constant value of 0.0. Section in the textbook suggests names such as $fv0, $fv1, $ft0 $ft3, and so on for the 64-bit FPRs. Those names do not work in MARS!

41 ENCM 369 W15 Section 01 Slide Set 11 slide 41/69 MIPS FPR organization: Each 64-bit FPR shares bits with two 32-bit FPRs... purple: 64-bit double-precision FPRs green: 32-bit single-precision FPRs $f0 $f1 $f0 $f2 $f3 $f2 $f30 $f31 $f30

42 ENCM 369 W15 Section 01 Slide Set 11 slide 42/69 Each 64-bit MIPS FPR shares bits with two 32-bit FPRs: Detailed example 63 bit number within 64-bit $f bit number within bit number within 32-bit $f5 32-bit $f4 A program using the 64-bit $f4 for a double variable must not at the same time use the 32-bit $f4 or $f5 for a float variable!

43 ENCM 369 W15 Section 01 Slide Set 11 slide 43/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

44 ENCM 369 W15 Section 01 Slide Set 11 slide 44/69 Coprocessor 1: The MIPS term for floating-point unit In the old days, when dinosaurs roamed, and processor chips only had hundreds of thousands of transistors (or less), f-p units were literally coprocessors. The main processor and the f-p unit were separate chips with separate sockets on a motherboard. Example: Intel (main processor) and (f-p unit).

45 ENCM 369 W15 Section 01 Slide Set 11 slide 45/69 Coprocessor 1, continued In 2015, a single chip (with hundreds of millions of transistors) can have 2 or 4 or 8 cores; each core has a main processor, its own floating-point unit, and a lot of other stuff. Students in ENCM 369 need to know that coprocessor 1 means floating-point unit, because c1 shows up in the mnemonics for many MIPS f-p instructions, and because the Coproc 1 tab in MARS is where you need to look to find values of FPRs.

46 ENCM 369 W15 Section 01 Slide Set 11 slide 46/69 Some important MIPS c1 instructions what mnemonic stands for / mnemonic operation performed mtc1 move to coprocessor 1 / copy 32 bits from GPR to 32-bit FPR mfc1 move from coprocessor 1 / copy 32 bits from 32-bit FPR to GPR lwc1 load word to coprocessor 1 / copy 32 bits from memory to 32-bit FPR swc1 store word from coprocessor 1 / copy 32 bits from 32-bit FPR to memory ldc1 load double to coprocessor 1 / copy 64 bits from memory to 64-bit FPR sdc1 store double from coprocessor 1 / copy 64 bits from 64-bit FPR to memory

47 ENCM 369 W15 Section 01 Slide Set 11 slide 47/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

48 ENCM 369 W15 Section 01 Slide Set 11 slide 48/69 Example translation #1 from C code to MIPS f-p instructions x = i + y; x and y are of type double in $f2 and $f4, and i is of type int in $s0. WRONG ANSWER: addu $f2, $s0, $f4 Why is this a wrong answer? What would be correct code? Let s trace the correct code assuming that $s0 contains 2 and $f4 contains 1.5.

49 ENCM 369 W15 Section 01 Slide Set 11 slide 49/69 Example translation #2 from C code to MIPS f-p instructions if (x < y) x = y; x and y are of type double in $f2 and $f4. WRONG ANSWER: slt $t0, $f2, $f4 bne $t0, $zero, L1 add.d $f2, $f4, $zero L1: Why is this a wrong answer? What would be correct code?

50 ENCM 369 W15 Section 01 Slide Set 11 slide 50/69 F-P comparisons in MIPS: How to compare? type is d for double precision, s for single precision... Instruction Test c.lt. type FPR1, FPR2 is FPR1 < FPR2? c.le. type FPR1, FPR2 is FPR1 FPR2? c.eq. type FPR1, FPR2 is FPR1 = FPR2? slt puts its result in a GPR. Where does an f-p comparison put its result?

51 ENCM 369 W15 Section 01 Slide Set 11 slide 51/69 F-P comparisons in MIPS: How to branch? bc1t: branch if coprocessor 1 flag is true. bc1f: branch if coprocessor 1 flag is false. Messy detail: Actually, MIPS has eight separate coprocessor 1 flag bits, but by default c.lt.d, c.le.d, c.eq.d, c.lt.s, c.le.s, c.eq.s, bc1t and bc1f all access the same single flag bit.

52 ENCM 369 W15 Section 01 Slide Set 11 slide 52/69 Key things to learn from examples #1 and #2 Do NOT assume that f-p instructions are organized just like integer instructions! Mixing types often works in C arithmetic expressions but usually DOESN T work in assembly language arithmetic instructions. Before writing f-p MARS code in Lab 12, carefully study f-p instruction documentation provided along with the lab instructions.

53 ENCM 369 W15 Section 01 Slide Set 11 slide 53/69 Register-use conventions and FPRs in ENCM 369 Students are expected to know conventions related to use of GPRs. Use of FPRs makes register-use conventions much more complicated. We ll use simplified register-use conventions for FPRs; each lab and final-exam f-p programming problem will give a description of FPR-use conventions needed for that problem.

54 ENCM 369 W15 Section 01 Slide Set 11 slide 54/69 Addresses live in GPRs, never in FPRs! void foo(void) { double d; double *p; } more code What kind of register should be used for d? What kind of register should be used for p?

55 ENCM 369 W15 Section 01 Slide Set 11 slide 55/69 More detail about MIPS f-p programming There won t be any more lecture time spent on details of MIPS floating-point instructions. You ll learn about the most frequently-used f-p instructions by doing Lab 12.

56 ENCM 369 W15 Section 01 Slide Set 11 slide 56/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

57 ENCM 369 W15 Section 01 Slide Set 11 slide 57/69 The minifloat type (as introduced in Lab 12) This is an 8-bit f-p type similar to the IEEE 754 types, but with tiny, tiny exponent and fraction fields... bit 7: sign bit bits 6-4: biased exponent bits 3-0: fraction Minifloat is useless for practical computation, but good for classroom examples and pencil-and-paper lab exercises. The exponent bias is 3 ten = 011 two.

58 ENCM 369 W15 Section 01 Slide Set 11 slide 58/69 Let s try to understand f-p addition by adding two minifloats... (Similar steps would be needed for 32- or 64-bit addition, but we would have to keep track of a lot more bits!) Bits of a are ; bits of b are a represents ten ; b represents ten. (Check these values yourself!) So, how to compute the best possible minifloat result for a + b?

59 ENCM 369 W15 Section 01 Slide Set 11 slide 59/69 Rounding errors in f-p arithmetic Both rounded results in the minifloat addition example are approximations to the exact sum, which is ten. The same kind of rounding errors will occur in 32- and 64-bit f-p arithmetic operations. Relative sizes of rounding errors decrease as the number of fraction bits increases.

60 ENCM 369 W15 Section 01 Slide Set 11 slide 60/69 Floating-point hardware example: Adder (Unfortunately this year s textbook doesn t have any example circuits for f-p arithmetic.) An f-p adder would have to implement all the steps we ve just seen in minifloat addition: comparing exponents of the two inputs shifting the input with the smaller exponent adding normalizing the sum rounding the sum Note how much more complicated this is than a simple integer adder!

61 ENCM 369 W15 Section 01 Slide Set 11 slide 61/69 Floating-point hardware concepts: Just a couple of remarks f-p arithmetic circuits are significantly larger and more complex than integer arithmetic circuits. But modern f-p circuits are very fast, because f-p performance has been a key selling point for processors and other digital hardware... games and video processing for consumers high-speed number-crunching for science and industry

62 ENCM 369 W15 Section 01 Slide Set 11 slide 62/69 Remember this: F-P math is usually approximate /* Classic mistake: Counting using fractions... */ double x; for (x = 0.1; x <= 0.3; x += 0.1) printf("x is %f\n", x); Expected output... x is x is x is Actual output... x is x is What went wrong here?

63 ENCM 369 W15 Section 01 Slide Set 11 slide 63/69 Outline of Slide Set 11 Integer Multiplication and Division Introduction to Floating-Point Numbers MIPS Formats for F-P Numbers IEEE Floating-Point Standards MIPS Floating-Point Registers Coprocessor 1 Translating C F-P Code to to MIPS A.L. Quick Overview of F-P Algorithms and Hardware Some Data and Remarks about Speed of Arithmetic

64 ENCM 369 W15 Section 01 Slide Set 11 slide 64/69 Some Data and Remarks about Speed of Arithmetic See the lecture document called Arithmetic Performance Examples. Let s make some notes about the copy_test and op_test functions. Computer used: 2009 MacBook Pro with 2013 version of C compiler from Apple.

65 ENCM 369 W15 Section 01 Slide Set 11 slide 65/69 Speed of Arithmetic: Observations (1) copy_test runs at the same speed for int, double and float. This isn t surprising x86 and x86-64 D-caches are designed to allow reading or writing 64-bit data in a single access. Addition, multiplication and shifts are almost free for this particular arrangement of C code and C compiler op_test never takes much more time than copy_test, except when OP_CHOICE asks for division.

66 ENCM 369 W15 Section 01 Slide Set 11 slide 66/69 Speed of Arithmetic: Observations (2) Multiplication is approximately as fast as addition for all three types. Using a shift to multiply ints by 512 = 2 9 was not significantly faster than using multiplication performance of integer multipliers in modern hardware is very good. Division, for all three types, is terribly slow compared to addition and multiplication.

67 ENCM 369 W15 Section 01 Slide Set 11 slide 67/69 Speed of Arithmetic: Observations (3) f-p addition and multiplication are sometimes faster and never very much slower than corresponding integer operations. Except for division, double-precision math seems to be just as fast as single-precision math.

68 ENCM 369 W15 Section 01 Slide Set 11 slide 68/69 Speed of Arithmetic: Programming Ideas (1) With current processors, do not prefer integer arithmetic over f-p just to get a speed increase. (Many years ago, f-p arithmetic was usually much slower than integer arithmetic.) Try to avoid division in loops where your programs spend a lot of time.

69 ENCM 369 W15 Section 01 Slide Set 11 slide 69/69 Speed of Arithmetic: Programming Ideas (2) Relative performance for different types and different operations is highly processor-dependent. Technology can change a lot within just a few years! So don t rely on results obtained using a 2009 x86-64 processor to guide your number-crunching designs on ARM (or some other hardware) in 2018! Try different data types and algorithms and measure performance.

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng Slide Set 5 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Integer Multiplication and Division

Integer Multiplication and Division Integer Multiplication and Division for ENCM 369: Computer Organization Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 208 Integer

More information

Floating Point COE 308. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

Floating Point COE 308. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals Floating Point COE 38 Computer Architecture Prof. Muhamed Mudawar Computer Engineering Department King Fahd University of Petroleum and Minerals Presentation Outline Floating-Point Numbers IEEE 754 Floating-Point

More information

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 5 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary February 2018 ENCM 369 Winter 2018 Section

More information

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Slide Set 1 (corrected)

Slide Set 1 (corrected) Slide Set 1 (corrected) for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018

More information

Lecture 10: Floating Point, Digital Design

Lecture 10: Floating Point, Digital Design Lecture 10: Floating Point, Digital Design Today s topics: FP arithmetic Intro to Boolean functions 1 Examples Final representation: (-1) S x (1 + Fraction) x 2 (Exponent Bias) Represent -0.75 ten in single

More information

3.5 Floating Point: Overview

3.5 Floating Point: Overview 3.5 Floating Point: Overview Floating point (FP) numbers Scientific notation Decimal scientific notation Binary scientific notation IEEE 754 FP Standard Floating point representation inside a computer

More information

Slide Set 7. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng

Slide Set 7. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng Slide Set 7 for ENCM 501 in Winter Term, 2017 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2017 ENCM 501 W17 Lectures: Slide

More information

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point Chapter 3 Part 2 Arithmetic for Computers Floating Point Floating Point Representation for non integral numbers Including very small and very large numbers 4,600,000,000 or 4.6 x 10 9 0.0000000000000000000000000166

More information

Written Homework 3. Floating-Point Example (1/2)

Written Homework 3. Floating-Point Example (1/2) Written Homework 3 Assigned on Tuesday, Feb 19 Due Time: 11:59pm, Feb 26 on Tuesday Problems: 3.22, 3.23, 3.24, 3.41, 3.43 Note: You have 1 week to work on homework 3. 3 Floating-Point Example (1/2) Q:

More information

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture) COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you

More information

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng Slide Set 1 for ENEL 339 Fall 2014 Lecture Section 02 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2014 ENEL 353 F14 Section

More information

Floating Point Arithmetic

Floating Point Arithmetic Floating Point Arithmetic Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

More information

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Floating Point Arithmetic. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Floating Point Arithmetic Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Floating Point (1) Representation for non-integral numbers Including very

More information

Floating Point Arithmetic

Floating Point Arithmetic Floating Point Arithmetic ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals [Adapted from

More information

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENEL 353 Fall 2017 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2017 SN s ENEL 353 Fall 2017 Slide Set 1 slide

More information

Lecture 10: Floating Point, Digital Design

Lecture 10: Floating Point, Digital Design Lecture 10: Floating Point, Digital Design Today s topics: FP arithmetic Intro to Boolean functions 1 Examples Final representation: (-1) S x (1 + Fraction) x 2 (Exponent Bias) Represent -0.75 ten in single

More information

Arithmetic for Computers. Hwansoo Han

Arithmetic for Computers. Hwansoo Han Arithmetic for Computers Hwansoo Han Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

More information

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 9 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization. Data Representation COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

More information

9 Floating-Point. 9.1 Objectives. 9.2 Floating-Point Number Representation. Value = ± (1.F) 2 2 E Bias

9 Floating-Point. 9.1 Objectives. 9.2 Floating-Point Number Representation. Value = ± (1.F) 2 2 E Bias 9 Floating-Point 9.1 Objectives After completing this lab, you will: Understand Floating-Point Number Representation (IEEE 754 Standard) Understand the MIPS Floating-Point Unit Write Programs using the

More information

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs Slide Set 2 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Chapter 3 Arithmetic for Computers (Part 2)

Chapter 3 Arithmetic for Computers (Part 2) Department of Electr rical Eng ineering, Chapter 3 Arithmetic for Computers (Part 2) 王振傑 (Chen-Chieh Wang) ccwang@mail.ee.ncku.edu.tw ncku edu Depar rtment of Electr rical Eng ineering, Feng-Chia Unive

More information

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

ENCM 369 Winter 2019 Lab 6 for the Week of February 25 page of ENCM 369 Winter 29 Lab 6 for the Week of February 25 Steve Norman Department of Electrical & Computer Engineering University of Calgary February 29 Lab instructions and other documents for ENCM

More information

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9 slide 2/41 Contents Slide Set 9 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014

More information

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers Chapter 03: Computer Arithmetic Lesson 09: Arithmetic using floating point numbers Objective To understand arithmetic operations in case of floating point numbers 2 Multiplication of Floating Point Numbers

More information

Arithmetic. Chapter 3 Computer Organization and Design

Arithmetic. Chapter 3 Computer Organization and Design Arithmetic Chapter 3 Computer Organization and Design Addition Addition is similar to decimals 0000 0111 + 0000 0101 = 0000 1100 Subtraction (negate) 0000 0111 + 1111 1011 = 0000 0010 Over(under)flow For

More information

What Every Programmer Should Know About Floating-Point Arithmetic

What Every Programmer Should Know About Floating-Point Arithmetic What Every Programmer Should Know About Floating-Point Arithmetic Last updated: October 15, 2015 Contents 1 Why don t my numbers add up? 3 2 Basic Answers 3 2.1 Why don t my numbers, like 0.1 + 0.2 add

More information

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right. Floating-point Arithmetic Reading: pp. 312-328 Floating-Point Representation Non-scientific floating point numbers: A non-integer can be represented as: 2 4 2 3 2 2 2 1 2 0.2-1 2-2 2-3 2-4 where you sum

More information

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3 Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Instructor: Nicole Hynes nicole.hynes@rutgers.edu 1 Fixed Point Numbers Fixed point number: integer part

More information

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 4: Floating Point Required Reading Assignment: Chapter 2 of CS:APP (3 rd edition) by Randy Bryant & Dave O Hallaron Assignments for This Week: Lab 1 18-600

More information

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction 1 Floating Point The World is Not Just Integers Programming languages support numbers with fraction Called floating-point numbers Examples: 3.14159265 (π) 2.71828 (e) 0.000000001 or 1.0 10 9 (seconds in

More information

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS

Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS Lecture 13: (Integer Multiplication and Division) FLOATING POINT NUMBERS Lecture 13 Floating Point I (1) Fall 2005 Integer Multiplication (1/3) Paper and pencil example (unsigned): Multiplicand 1000 8

More information

Integers and Floating Point

Integers and Floating Point CMPE12 More about Numbers Integers and Floating Point (Rest of Textbook Chapter 2 plus more)" Review: Unsigned Integer A string of 0s and 1s that represent a positive integer." String is X n-1, X n-2,

More information

Representing and Manipulating Floating Points. Jo, Heeseung

Representing and Manipulating Floating Points. Jo, Heeseung Representing and Manipulating Floating Points Jo, Heeseung The Problem How to represent fractional values with finite number of bits? 0.1 0.612 3.14159265358979323846264338327950288... 2 Fractional Binary

More information

Chapter 3. Arithmetic Text: P&H rev

Chapter 3. Arithmetic Text: P&H rev Chapter 3 Arithmetic Text: P&H rev3.29.16 Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation

More information

ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design ECE232: Hardware Organization and Design Lecture 11: Floating Point & Floating Point Addition Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Last time: Single Precision Format

More information

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1.1 Introduction Given that digital logic and memory devices are based on two electrical states (on and off), it is natural to use a number

More information

CSCI 402: Computer Architectures. Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI.

CSCI 402: Computer Architectures. Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI. CSCI 402: Computer Architectures Arithmetic for Computers (4) Fengguang Song Department of Computer & Information Science IUPUI Homework 4 Assigned on Feb 22, Thursday Due Time: 11:59pm, March 5 on Monday

More information

CHW 261: Logic Design

CHW 261: Logic Design CHW 261: Logic Design Instructors: Prof. Hala Zayed Dr. Ahmed Shalaby http://www.bu.edu.eg/staff/halazayed14 http://bu.edu.eg/staff/ahmedshalaby14# Slide 1 Slide 2 Slide 3 Digital Fundamentals CHAPTER

More information

Floating-Point Arithmetic

Floating-Point Arithmetic Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } L11 Floating Point 1 What is the problem? Many numeric applications require numbers over a VERY large range. (e.g. nanoseconds to centuries)

More information

Floating-Point Arithmetic

Floating-Point Arithmetic Floating-Point Arithmetic if ((A + A) - A == A) { SelfDestruct() } Reading: Study Chapter 4. L12 Multiplication 1 Why Floating Point? Aren t Integers enough? Many applications require numbers with a VERY

More information

Divide: Paper & Pencil

Divide: Paper & Pencil Divide: Paper & Pencil 1001 Quotient Divisor 1000 1001010 Dividend -1000 10 101 1010 1000 10 Remainder See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or

More information

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 1 slide 2/43

More information

Floating Point Numbers. Lecture 9 CAP

Floating Point Numbers. Lecture 9 CAP Floating Point Numbers Lecture 9 CAP 3103 06-16-2014 Review of Numbers Computers are made to deal with numbers What can we represent in N bits? 2 N things, and no more! They could be Unsigned integers:

More information

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai Introduction to Computer Systems Recitation 2 May 29, 2014 Marjorie Carlson Aditya Gupta Shailin Desai 1 Agenda! Goal: translate any real number (plus some!) into and out of machine representation.! Integers!

More information

xx.yyyy Lecture #11 Floating Point II Summary (single precision): Precision and Accuracy Fractional Powers of 2 Representation of Fractions

xx.yyyy Lecture #11 Floating Point II Summary (single precision): Precision and Accuracy Fractional Powers of 2 Representation of Fractions CS61C L11 Floating Point II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II 2007-7-12 Scott Beamer, Instructor Sony & Nintendo make E3 News www.nytimes.com Review

More information

Floating Point Numbers

Floating Point Numbers Floating Point Numbers Summer 8 Fractional numbers Fractional numbers fixed point Floating point numbers the IEEE 7 floating point standard Floating point operations Rounding modes CMPE Summer 8 Slides

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II Scott Beamer, Instructor Sony & Nintendo make E3 News 2007-7-12 CS61C L11 Floating Point II (1) www.nytimes.com Review

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University

Representing and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

More information

Data Representation Floating Point

Data Representation Floating Point Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

More information

FLOATING POINT NUMBERS

FLOATING POINT NUMBERS Exponential Notation FLOATING POINT NUMBERS Englander Ch. 5 The following are equivalent representations of 1,234 123,400.0 x 10-2 12,340.0 x 10-1 1,234.0 x 10 0 123.4 x 10 1 12.34 x 10 2 1.234 x 10 3

More information

Thomas Polzer Institut für Technische Informatik

Thomas Polzer Institut für Technische Informatik Thomas Polzer tpolzer@ecs.tuwien.ac.at Institut für Technische Informatik Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers VO

More information

Slides for Lecture 6

Slides for Lecture 6 Slides for Lecture 6 ENCM 501: Principles of Computer Architecture Winter 2014 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 28 January,

More information

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That 1. Introduction You have seen situations in which the way numbers are stored in a computer affects a program. For example, in the

More information

Signed umbers. Sign/Magnitude otation

Signed umbers. Sign/Magnitude otation Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

More information

Data Representation Floating Point

Data Representation Floating Point Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Floating Point Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for this lecture are based

More information

UC Berkeley CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UC Berkeley CS61C : Machine Structures Lecture 16 Floating Point II 2010-02-26 TA Michael Greenbaum www.cs.berkeley.edu/~cs61c-tf Research without Google would be like life

More information

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Signed Multiplication Multiply the positives Negate result if signs of operand are different Another Improvement Save on space: Put multiplier in product saves on speed: only single shift needed Figure: Improved hardware for multiplication Signed Multiplication Multiply the positives Negate result

More information

Floating Point January 24, 2008

Floating Point January 24, 2008 15-213 The course that gives CMU its Zip! Floating Point January 24, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties class04.ppt 15-213, S 08 Floating

More information

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

More information

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 4 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 4 slide

More information

Giving credit where credit is due

Giving credit where credit is due JDEP 284H Foundations of Computer Systems Floating Point Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created by Drs. Bryant

More information

Chapter Three. Arithmetic

Chapter Three. Arithmetic Chapter Three 1 Arithmetic Where we've been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing

More information

IEEE Standard 754 for Binary Floating-Point Arithmetic.

IEEE Standard 754 for Binary Floating-Point Arithmetic. CS61C L11 Floating Point II (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #11 Floating Point II 2005-10-05 There is one handout today at the front and back of the room! Lecturer

More information

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

Digital Fundamentals

Digital Fundamentals Digital Fundamentals Tenth Edition Floyd Chapter 2 2009 Pearson Education, Upper 2008 Pearson Saddle River, Education NJ 07458. All Rights Reserved Decimal Numbers The position of each digit in a weighted

More information

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. ! Floating point Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties Next time! The machine model Chris Riesbeck, Fall 2011 Checkpoint IEEE Floating point Floating

More information

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science) Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science) Floating Point Background: Fractional binary numbers IEEE floating point standard: Definition Example and properties

More information

Module 2: Computer Arithmetic

Module 2: Computer Arithmetic Module 2: Computer Arithmetic 1 B O O K : C O M P U T E R O R G A N I Z A T I O N A N D D E S I G N, 3 E D, D A V I D L. P A T T E R S O N A N D J O H N L. H A N N E S S Y, M O R G A N K A U F M A N N

More information

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with

More information

95% of the folks out there are completely clueless about floating-point.

95% of the folks out there are completely clueless about floating-point. CS61C L11 Floating Point (1) Instructor Paul Pearce inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Well, not quite yet. A UC Davis student (shown left) is attempting to standardize hella

More information

UCB CS61C : Machine Structures

UCB CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Instructor Paul Pearce Lecture 11 Floating Point 2010-07-08 Well, not quite yet. A UC Davis student (shown left) is attempting to standardize

More information

Floating Point. What can be represented in N bits? 0 to 2N-1. 9,349,398,989,787,762,244,859,087, x 1067

Floating Point. What can be represented in N bits? 0 to 2N-1. 9,349,398,989,787,762,244,859,087, x 1067 MIPS Floating Point Operations Cptr280 Dr Curtis Nelson Floating Point What can be represented in N bits? Unsigned 2 s Complement 0 to 2N-1-2N-1 to 2N-1-1 But, what about- Very large numbers? 9,349,398,989,787,762,244,859,087,678

More information

8/30/2016. In Binary, We Have A Binary Point. ECE 120: Introduction to Computing. Fixed-Point Representations Support Fractions

8/30/2016. In Binary, We Have A Binary Point. ECE 120: Introduction to Computing. Fixed-Point Representations Support Fractions University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Fixed- and Floating-Point Representations In Binary, We Have A Binary Point Let

More information

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754 Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that

More information

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.

Floating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers. class04.ppt 15-213 The course that gives CMU its Zip! Topics Floating Point Jan 22, 2004 IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Floating Point Puzzles For

More information

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column 1's column 10's column 100's column 1000's column 1's column 2's column 4's column 8's column Number Systems Decimal numbers 5374 10 = Binary numbers 1101 2 = Chapter 1 1's column 10's column 100's

More information

Number Systems and Computer Arithmetic

Number Systems and Computer Arithmetic Number Systems and Computer Arithmetic Counting to four billion two fingers at a time What do all those bits mean now? bits (011011011100010...01) instruction R-format I-format... integer data number text

More information

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754 Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that

More information

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia Floating Point CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun http://xkcd.com/899/

More information

System Programming CISC 360. Floating Point September 16, 2008

System Programming CISC 360. Floating Point September 16, 2008 System Programming CISC 360 Floating Point September 16, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Powerpoint Lecture Notes for Computer Systems:

More information

15213 Recitation 2: Floating Point

15213 Recitation 2: Floating Point 15213 Recitation 2: Floating Point 1 Introduction This handout will introduce and test your knowledge of the floating point representation of real numbers, as defined by the IEEE standard. This information

More information

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia Floating Point CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan Administrivia Lab

More information

Numeric Encodings Prof. James L. Frankel Harvard University

Numeric Encodings Prof. James L. Frankel Harvard University Numeric Encodings Prof. James L. Frankel Harvard University Version of 10:19 PM 12-Sep-2017 Copyright 2017, 2016 James L. Frankel. All rights reserved. Representation of Positive & Negative Integral and

More information

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties

Systems I. Floating Point. Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Systems I Floating Point Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties IEEE Floating Point IEEE Standard 754 Established in 1985 as uniform standard for

More information

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy. Math 340 Fall 2014, Victor Matveev Binary system, round-off errors, loss of significance, and double precision accuracy. 1. Bits and the binary number system A bit is one digit in a binary representation

More information

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Chapter 3 Data Representation

Chapter 3 Data Representation Chapter 3 Data Representation The focus of this chapter is the representation of data in a digital computer. We begin with a review of several number systems (decimal, binary, octal, and hexadecimal) and

More information

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

COMPUTER ORGANIZATION AND DESIGN

COMPUTER ORGANIZATION AND DESIGN COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers Arithmetic for Computers Operations on integers Addition and subtraction Multiplication

More information

Floating Point. CSE 351 Autumn Instructor: Justin Hsia

Floating Point. CSE 351 Autumn Instructor: Justin Hsia Floating Point CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/571/

More information

Numerical computing. How computers store real numbers and the problems that result

Numerical computing. How computers store real numbers and the problems that result Numerical computing How computers store real numbers and the problems that result The scientific method Theory: Mathematical equations provide a description or model Experiment Inference from data Test

More information

Representing and Manipulating Floating Points

Representing and Manipulating Floating Points Representing and Manipulating Floating Points Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE23: Introduction to Computer Systems, Spring 218,

More information