Propeller Manual

Table Of Contents
Appendix B: Math Samples and Function Tables
form is quite natural and efficient, as it lends a ‘linear’ simplicity to what is actually
logarithmic.
The code examples given below use each tables’ samples verbatim. Higher resolution could
be achieved by linearly interpolating between table samples, since the slope change is very
slight from sample to sample. The cost, though, would be larger code and lower execution
speed.
Log Table ($C000-$CFFF)
The log table contains data used to convert unsigned numbers into base-2 exponents.
The log table is comprised of 2,048 unsigned words which make up the base-2 fractional
exponents of numbers. To use this table, you must first determine the integer portion of the
exponent of the number you are converting. This is simply the leading bit position. For
$60000000 this would be 30 ($1E). This integer portion will always fit within 5 bits. Isolate
these 5 bits into the result so that they occupy bit positions 20..16. In our case of $60000000,
we would now have a partial result of $001E0000. Next, top-justify and isolate the first 11
bits below the leading bit into positions 11..1. This would be $0800 for our example. Add
$C000 for the log table base and you now have the actual word address of the fractional
exponent. By reading the word at $C800, we get the value $95C0. Adding this into the partial
result yields $001E95C0 – that's $60000000 in exponent form. Note that bits 20..16 make up
the integer portion of the exponent, while bits 15..0 make up the fractional portion, with bit
15 being the ½, bit 14 being the ¼, and so on, down to bit 0. The exponent can now be
manipulated by adding, subtracting, and shifting. Always insure that your math operations
will never drive the exponent below 0 or cause it to overflow bit 20. Otherwise, it may not
convert back to a number correctly.
Here is a routine that will convert an unsigned number into its base-2 exponent using the log
table:
' Convert number to exponent
'
' on entry: num holds 32-bit unsigned value
' on exit: exp holds 21-bit exponent with 5 integer bits and 16 fractional bits
'
numexp mov exp,#0 'clear exponent
test num,num4 wz 'get integer portion of exponent
muxnz exp,exp4 'while top-justifying number
if_z shl num,#16
test num,num3 wz
muxnz exp,exp3
if_z shl num,#8
Page 382 · Propeller Manual v1.1