Lecture 5 Fixed Point Vs Floating Point Q-Format Number Representation
Lecture 5 Fixed Point Vs Floating Point Q-Format Number Representation
Lecture 5 Fixed Point Vs Floating Point Q-Format Number Representation
Objectives:
N-1
S
imaginary
binary point
N-1
S
imaginary
binary point
5-1
Q-format notation
Q-format representation:
if N=16, 15 bit fractional representation
Rule:
Q m + Qm
Qm x Q n
Q
Q
Q15 format
31
Q30
Q15
16
00
0000
0000
0000
Rounding:
if r = 0, round down,
r = 1, round up
15
r
rounding by addition a '1' here
16
15
31
Q30
m+n
15
5-2
MPY A3,A4,A6
NOP
ADDK 4000h,A6
SHR A6,15,A6
STH A6,*A7
; A3 x A4 A6
; Delay slot
; rounding add
; truncate bottom 15 bits
; A6 mem[A7]
5-3
5-4
5-5
single
precision
23 22
8-bit exp
double
precision
23-bit frac
20 19
11-bit exp
0 31
52-bit frac
Even register (e.g. A4)
5-6
5-7
5-8
Examples
Problems of Q-format
Convert 5.75 to SP FP
22
Convert 0.1 to DP FP
0.1 to binary: 1.10011001(1001 repeats) x 2-4
exponent in bias-1023 is 1023-4 = 1019 = 011 1111 1011b
The fractional part is .10011001...1010 after we drop the hidden 1 bit and
rounding
Answer: 0 01111111011 1001100 ...1001 1010 = 3FB9 9999 9999 999A
(hex).
5-9
Q12 7.50195
Q12 7.25
Q24 54.38916
5 - 10
Special SP numbers
IEEE floating point standard has a set of special numbers:
Special
value
+0
-0
1
2
+Inf
-Inf
NaN
LFPN
SFPN
5 - 11
Sign (s)
0
1
0
0
0
1
x
0
0
Exponent
(e)
0
0
127
128
255
255
255
254
1
Fraction
(f)
0
0
0
0
0
0
Nonzero
All 1s
All 0s
Hex
Value
Decimal
value
0x0000 0000
0.0
-0.0
1.0
2.0
+
-
not a number
3.40282347 e+38
1.17549435e-38
0x8000 0000
0x3F80 0000
0x4000 0000
0x7F80 0000
0xFF80 0000
0x7FFF FFFF
0x7F7F FFFF
0x0080 0000
5 - 12
Special DP numbers
Hex
Value
Decimal
value
P
E
R
I
P
H
E
R
A
L
S
External
Memory
0.0
-0.0
1.0
2.0
-
not a number
1.7976931348623157 e+308
2.2250738585072014 e-308
Internal Buses
.D1 .D2
.M1 .M2
.L1 .L2
.S1 .S2
Regs (B0-B15/31)
Exponent
(e)
0
0
1023
1024
2047
2047
2047
2046
1
Regs (A0-A15/31)
Special
value
+0
-0
1
2
+Inf
-Inf
NaN
LFPN
SFPN
Internal
Memory
CPU
Lecture 5 - Fixed point vs Floating point
5 - 13
5 - 14
.S
.L
.D
.M
5 - 15
ADD
ADDK
ADD2
AND
B
CLR
EXT
MV
MVC
MVK
MVKH
NEG
NOT
OR
SET
SHL
SHR
SSHL
SUB
SUB2
XOR
ZERO
ABSSP
ABSDP
CMPGTSP
CMPEQSP
CMPLTSP
CMPGTDP
CMPEQDP
CMPLTDP
RCPSP
RCPDP
RSQRSP
RSQRDP
SPDP
.D Unit
ADD
NEG
ADDAB (B/H/W) STB
(B/H/W)
LDB
(B/H/W) SUB
LDDW
SUBAB (B/H/W)
MV
ZERO
.L Unit
ABS
ADD
AND
CMPEQ
CMPGT
CMPLT
LMBD
MV
NEG
NORM
NOT
OR
SADD
SAT
SSUB
SUB
SUBC
XOR
ZERO
MPY
MPYH
MPYLH
MPYHL
SMPY
SMPYH
ADDSP
ADDDP
SUBSP
SUBDP
INTSP
INTDP
SPINT
DPINT
SPRTUNC
DPTRUNC
DPSP
.M Unit
MPYSP
MPYDP
MPYI
MPYID
No Unit Used
NOP
IDLE
5 - 16
Data
path A
Data
path B
5 - 17