UNCC-IESLecture23 - Fixed Point Math
UNCC-IESLecture23 - Fixed Point Math
and
Other Optimizations
Addition, Subtraction
– Radix point stays where it started +
– …so we can treat fixed point numbers like integers
Multiplication
– Radix point moves left by F digits
– … so we need to normalize result afterwards,
shifting the result right by F digits
6.2 Format
10 001010.00
* * 1.25 *000001.01
12.5 00000000 1100.1000
Division
– Quotient is integer, may want to convert back to fixed point by
shifting
– Radix point doesn’t move in remainder
Division
– To make quotient have same format as dividend and divisor,
multiply dividend by 2F (shift left by F bits)
– Quotient is in fixed point format now
! ""
#$ %
! &&
Math
'(( )* +*
,-. )* /*
0- )* * &&
( 1 )* %* ""
230 )* 4*
8.4 Format
10 0000 1010.0000
* + 1.5 +0000 0001.1000
11.5 00000000 1100.1000
4.4 Format
9.0625 1001.0001
* * 6.5 *0110.1000
58.90625 0011 1010.1110 1000
Assembler: Assembler:
! "
! " #
$ %
# ##
$ %
( (
' ( )( ' ( )(
! ( )
) #* !
) #*
##
( ##
) )
+ ) #* ## + ) #* ##
( #(
, - . as: , -&.
123 4
#
( 123 4"&5
– r = c/2*3.14 is wrong! Evaluates to r = (c/2) * 3.14
#
( 123 4 "&5
– Avoids a divide error
– However, 2*3.14 is loaded as DP leading to extra operations
• convert c to DP
• DP divide
• convert quotient to SP
#
( 123 4 " &5
– Avoids extra operations
) ) #
()