Sign in

username:

password:



Not a member?

Search motoroladsp



Search tips

Subscribe to motoroladsp



motoroladsp by Keywords

56303 | 563xx | 5680 | 56805 | 5680x | 56F80 | 56F800DEMO | 56F805 | 56f807 | 56F830 | ADC | Bootloader | Codec | CodeWarrior | CW5 | CW6 | Debugger | DSP56303 | DSP56303EVM | DSP563xx | DSP5680 | DSP56800 | DSP56807 | DSP56858 | DSP56858EVM | DSP56F803 | DSP56F805 | DSP56F807 | DSP56F80x | DSP56F826 | DSP56F827 | DSP56F8xx | EVM | FFT | Flash_over_jtag | GPIO | Interrupt | Interrupts | JTAG | LCD | Linker | MCF5307 | Metrowerks | Modulus | MSCAN | PCMaster | PWM | Quad | Rif | RTOS | SDK | SPI

Discussion Groups

Technical discussions about Freescale (Motorola) DSPs (including the DSP56000, DSP56300, DSP56600, 56800 DSPs).

  

Post a new Thread

LOG2NRM.ASM - "ralph.harry" - Feb 26 15:54:13 2008



Hi to all,

I was looking at a piece of code available on the net to compute log2(x)
for any number x between 2^-23 and 1.

This code is a macro included in the file called LOG2NRM.ASM:

log2nrm macro
;
;       This program calculates the base 2 logarithm of an unnormalized
;       24 bit fraction "x" in register A and returns a scaled fraction
;       "y" in register A.
;
;       y = log2(x)/32.0        where   2**(-23) =< x < 1.0
;                                       -23/32 =< y < 0.0
;
;       Note - "x" must be a non-zero, positive fraction.
;
;       Three steps are required.
;
;       1. Normalize "x" so that 0.5 =< A < 1.0.
;       2. Calculate the log2(A).
;       3. Divide the result by 32.0
;
;
;       Step 1 - Normalize A to get value between .5 and 1.0
;
  clb      a,b
  normf    b1,a
  move    #pcoef,r1       ;point to polynomial coefficients for log2
  move    a,x0            ;put normalized number in x0
;
;       Step 2 - Calculate LOG2 by polynomial approximation.  8 Bit
accuracy.
;
;       LOG2(x) = 4.0* (-.3372223 x*x + .9981958 x - .6626105)
;                           a2             a1            a0
;       where  0.5 <= x < 1.0
;
;       r1 initially points to the coefficients in y memory in the
;       order: a1,a2,a0
;
  nop
  nop
  mpyr    x0,x0,a  y:(r1)+,y0     ;x**2, get a1
  nop
  mpy     x0,y0,a  a,x1 y:(r1)+,y0        ;a1*x, mv x**2, get a2
  mac     x1,y0,a  y:(r1)+,y0     ;a2* x**2, get a0
  add     y0,a                    ;add in a0

;
;       Step 3 - Divide result by 32.
;
  asl     #3,a,a
  move    b1,b0
  dec     b
  nop
  move    b0,a2                   ;new sign = characteristic

  asr     #6,a,a
  rnd     a                       ;round result
  endm
I don't understand precisely what's happening in Step 3. Especially this
part commented as 'new sign = characteristic'...

Would someone be so kind to explain me?

Thanks - Ralph


(You need to be a member of motoroladsp -- send a blank email to motoroladsp-subscribe@yahoogroups.com )