CSC 252: Computer Organization Spring 2020: Lecture 5

CSC 252: Computer Organization Spring 2020: Lecture 5

CSC 252: Computer Organization Spring 2020: Lecture 5 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Carnegie Mellon Announcement • Programming Assignment 1 is due soon • Details: https://www.cs.rochester.edu/courses/252/ spring2020/labs/assignment1.html • Due on Jan. 31, 11:59 PM • You have 3 slip days Today Due !2 Carnegie Mellon Announcement • Programming assignment 1 is in C language. Seek help from TAs. • TAs are best positioned to answer your questions about programming assignments!!! • Programming assignments do NOT repeat the lecture materials. They ask you to synthesize what you have learned from the lectures and work out something new. !3 Carnegie Mellon Floating Point Review v = (–1)s x 1.frac x 2E s exp frac !4 Carnegie Mellon Floating Point Review s exp frac Value Value s E v = (–1) x 1.frac x 2 0 000 00 0.00 x 2-2 0 Denormalized 0 000 11 0.11 x 2-2 3/16 s exp frac • Denormalized (exp == 000) • E = (exp + 1) – bias • M = 0.frac !4 Carnegie Mellon Floating Point Review s exp frac Value Value s E v = (–1) x 1.frac x 2 0 000 00 0.00 x 2-2 0 Denormalized 0 000 11 0.11 x 2-2 3/16 s exp frac 0 001 00 1.00 x 2-2 1/4 0 001 11 1.11 x 2-2 7/16 0 010 00 1.00 x 2-1 1/2 • Denormalized (exp == 000) 0 010 11 1.11 x 2-1 7/8 • E = (exp + 1) – bias Normalized 0 100 00 1.00 x 20 1 0 • M = 0.frac 0 100 11 1.11 x 2 1 3/4 0 101 00 1.00 x 21 2 Normalized (exp != 000) • 0 101 11 1.11 x 21 3 1/2 • E = exp – bias 0 110 00 1.00 x 22 4 • M = 1.frac 0 110 11 1.11 x 22 7 !4 Carnegie Mellon Floating Point Review s exp frac Value Value s E v = (–1) x 1.frac x 2 0 000 00 0.00 x 2-2 0 Denormalized 0 000 11 0.11 x 2-2 3/16 s exp frac 0 001 00 1.00 x 2-2 1/4 0 001 11 1.11 x 2-2 7/16 0 010 00 1.00 x 2-1 1/2 • Denormalized (exp == 000) 0 010 11 1.11 x 2-1 7/8 • E = (exp + 1) – bias Normalized 0 100 00 1.00 x 20 1 0 • M = 0.frac 0 100 11 1.11 x 2 1 3/4 0 101 00 1.00 x 21 2 Normalized (exp != 000) • 0 101 11 1.11 x 21 3 1/2 • E = exp – bias 0 110 00 1.00 x 22 4 • M = 1.frac 0 110 11 1.11 x 22 7 0 111 00 infinite infinite Special Value 0 111 11 NaN NaN !4 Carnegie Mellon Floating Point Review s exp frac Value Value 0 000 00 0.00 x 2-2 0 Denormalized 0 000 11 0.11 x 2-2 3/16 0 001 00 1.00 x 2-2 1/4 0 001 11 1.11 x 2-2 7/16 0 010 00 1.00 x 2-1 1/2 0 010 11 1.11 x 2-1 7/8 Normalized 0 100 00 1.00 x 20 1 0 100 11 1.11 x 20 1 3/4 0 101 00 1.00 x 21 2 0 101 11 1.11 x 21 3 1/2 0 110 00 1.00 x 22 4 0 110 11 1.11 x 22 7 0 111 00 infinite infinite Special Value 0 111 11 NaN NaN !5 Carnegie Mellon Floating Point Review s exp frac Value Value If you do an integer increment 0 000 00 0.00 x 2-2 0 • Denormalized on a positive FP number, you 0 000 11 0.11 x 2-2 3/16 get the next larger FP number. 0 001 00 1.00 x 2-2 1/4 0 001 11 1.11 x 2-2 7/16 0 010 00 1.00 x 2-1 1/2 0 010 11 1.11 x 2-1 7/8 Normalized 0 100 00 1.00 x 20 1 0 100 11 1.11 x 20 1 3/4 0 101 00 1.00 x 21 2 0 101 11 1.11 x 21 3 1/2 0 110 00 1.00 x 22 4 0 110 11 1.11 x 22 7 0 111 00 infinite infinite Special Value 0 111 11 NaN NaN !5 Carnegie Mellon Floating Point Review s exp frac Value Value If you do an integer increment 0 000 00 0.00 x 2-2 0 • Denormalized on a positive FP number, you 0 000 11 0.11 x 2-2 3/16 get the next larger FP number. 0 001 00 1.00 x 2-2 1/4 • Bit patterns representing non- 0 001 11 1.11 x 2-2 7/16 negative numbers are ordered 0 010 00 1.00 x 2-1 1/2 the same way as integers, so 0 010 11 1.11 x 2-1 7/8 could use regular integer Normalized 0 100 00 1.00 x 20 1 comparison. 0 100 11 1.11 x 20 1 3/4 0 101 00 1.00 x 21 2 0 101 11 1.11 x 21 3 1/2 0 110 00 1.00 x 22 4 0 110 11 1.11 x 22 7 0 111 00 infinite infinite Special Value 0 111 11 NaN NaN !5 Carnegie Mellon Floating Point Review s exp frac Value Value If you do an integer increment 0 000 00 0.00 x 2-2 0 • Denormalized on a positive FP number, you 0 000 11 0.11 x 2-2 3/16 get the next larger FP number. 0 001 00 1.00 x 2-2 1/4 • Bit patterns representing non- 0 001 11 1.11 x 2-2 7/16 negative numbers are ordered 0 010 00 1.00 x 2-1 1/2 the same way as integers, so 0 010 11 1.11 x 2-1 7/8 could use regular integer Normalized 0 100 00 1.00 x 20 1 comparison. 0 100 11 1.11 x 20 1 3/4 • You don’t get this property if: 0 101 00 1.00 x 21 2 • exp is interpreted as signed 0 101 11 1.11 x 21 3 1/2 • exp and frac are swapped 0 110 00 1.00 x 22 4 0 110 11 1.11 x 22 7 0 111 00 infinite infinite Special Value 0 111 11 NaN NaN !5 Carnegie Mellon IEEE 754 Floating Point Standard " Single precision: 32 bits! s exp frac 1 8-bit 23-bit " Double precision: 64 bits s exp frac 1 11-bit 52-bit " In C language! •float$single precision! •double$double precision #6 Carnegie Mellon Floating Point in C 32-bit Machine C Data Max Value Bits Max Value Type (Decimal) char 8 27 - 1 127 short 16 215 - 1 32767 Fixed point 31 (implicit binary point){ int 32 2 - 1 2147483647 long 64 263 - 1 ~9.2 × 1018 SP floating point float 32 (2 - 2-23) × 2127 ~3.4 × 1038 DP floating point double 64 (2 - 2-52) × 21023 ~1.8 × 10308 !7 Carnegie Mellon Floating Point in C 32-bit Machine C Data Max Value Bits Max Value Type (Decimal) char 8 27 - 1 127 short 16 215 - 1 32767 Fixed point 31 (implicit binary point){ int 32 2 - 1 2147483647 long 64 263 - 1 ~9.2 × 1018 SP floating point float 32 (2 - 2-23) × 2127 ~3.4 × 1038 DP floating point double 64 (2 - 2-52) × 21023 ~1.8 × 10308 • To represent 231 in fixed-point, you need at least 32 bits • Because fixed-point is a weighted positional representation • In floating-point, we directly encode the exponent • Floating point is based on scientific notation • Encoding 31 only needs 7 bits in the exp field !7 Carnegie Mellon Floating Point Conversions/Casting in C • double/float → int • Truncates fractional part • Like rounding toward zero • Not defined when out of range or NaN !8 Carnegie Mellon Floating Point Conversions/Casting in C • double/float → int • Truncates fractional part • Like rounding toward zero • Not defined when out of range or NaN • int → float s exp frac 1 8-bit 23-bit !8 Carnegie Mellon Floating Point Conversions/Casting in C • double/float → int • Truncates fractional part • Like rounding toward zero • Not defined when out of range or NaN • int → float • Can’t guarantee exact casting. Will round according to rounding mode s exp frac 1 8-bit 23-bit !8 Carnegie Mellon Floating Point Conversions/Casting in C • double/float → int • Truncates fractional part • Like rounding toward zero • Not defined when out of range or NaN • int → float • Can’t guarantee exact casting. Will round according to rounding mode s exp frac 1 8-bit 23-bit • int → double s exp frac 1 11-bit 52-bit !8 Carnegie Mellon Floating Point Conversions/Casting in C • double/float → int • Truncates fractional part • Like rounding toward zero • Not defined when out of range or NaN • int → float • Can’t guarantee exact casting. Will round according to rounding mode s exp frac 1 8-bit 23-bit • int → double • Exact conversion s exp frac 1 11-bit 52-bit !8 How Does Pointer Work in C??? char a = 4; char b = 3; char* c; c = &a; b += (*c); !9 How Does Pointer Work in C??? char a = 4; Memory Memory char b = 3; Content Address char* c; 0x10 c = &a; 0x11 b += (*c); … 0x16 … !9 How Does Pointer Work in C??? char a = 4; Memory Memory char b = 3; Content Address char* c; 0x10 c = &a; 0x11 b += (*c); … 0x16 … !9 How Does Pointer Work in C??? char a = 4; C Memory Memory char b = 3; Variable Content Address char* c; a 4 0x10 c = &a; 0x11 b += (*c); … 0x16 … !9 How Does Pointer Work in C??? char a = 4; C Memory Memory char b = 3; Variable Content Address char* c; a 4 0x10 c = &a; 0x11 b += (*c); … 0x16 … !9 How Does Pointer Work in C??? char a = 4; C Memory Memory char b = 3; Variable Content Address char* c; a 4 0x10 c = &a; b 3 0x11 b += (*c); … 0x16 … !9 How Does Pointer Work in C??? char a = 4; C Memory Memory char b = 3; Variable Content Address char* c; a 4 0x10 c = &a; b 3 0x11 b += (*c); … 0x16 … !9 How Does Pointer Work in C??? char a = 4; C Memory Memory char b = 3; Variable Content Address char* c; a 4 0x10 c = &a; b 3 0x11 b += (*c); • The content of a pointer … variable is memory address.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    143 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us