home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / dsp / 2060 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  2.1 KB

  1. Xref: sparky comp.dsp:2060 comp.sys.next.programmer:5885
  2. Newsgroups: comp.dsp,comp.sys.next.programmer
  3. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!phaedrus
  4. From: phaedrus@leland.Stanford.EDU (Avery Wang)
  5. Subject: Fast arccos for the DSP 56001 code here
  6. Message-ID: <1992Aug31.155659.21355@leland.Stanford.EDU>
  7. Sender: news@leland.Stanford.EDU (Mr News)
  8. Organization: DSG, Stanford University, CA 94305 USA
  9. Date: Mon, 31 Aug 92 15:56:59 GMT
  10. Lines: 49
  11.  
  12. Hi DSP hackers-
  13. A few months ago I wrote a simple inverse-table lookup algorithm for an inverse
  14. cosine on the DSP 56001 from Motorola.  The output is normalized to between 0
  15. and 127 = (0 to Pi).  You get 7 bits of accuracy, which is all you can really
  16. get from an inverse Sine-ROM lookup.  Incidentally, this algorithm can be
  17. easily adapted to do an inverse table lookup on any monotonically decreasing
  18. function in tabular form (128 elements).
  19.  
  20. All I ask is for you to send me email telling me that you think it's useful, so 
  21. I'll feel good  and be encouraged to put more stuff on the net in the future.
  22.  
  23. =======================================================================
  24. ;   arccos.asm
  25. ;   Calculates the arc-cosine of the input to 8 bits.
  26. ;   The output is between 0 and +127 and is in a
  27. ;
  28. ;   Copyright! February 20,1992
  29. ;   Free for non-profit usage
  30. ;
  31. ;   Avery Wang                         
  32. ;   Ruhr-Uni-Bochum
  33. ;   Institut fuer Neuroinformatik
  34. ;   ND03, Postfach 102148
  35. ;   W-4630 Bochum
  36. ;   Germany
  37. ;   avery@neuroinformatik.ruhr-uni-bochum.de  or
  38. ;   awang@isl.stanford.edu
  39.  
  40. ; uses the Sine-ROM and simply does an inverse table lookup.
  41. ; input and output are in a
  42. ; uses a,b,x0,y0,r6,r7,n7
  43. arccos macro
  44.     move #$140,r7           ;offset
  45.     move r7,r6
  46.     move #$40,n7            ;guess
  47.     move n7,b
  48.     do #7,_arccos_loop
  49.         move (r6)+n7                  ;update guess
  50.         asr b       a,x0    y:(r6),y0 ;make increment smaller, lookup cosine
  51.         cmp y0,a    b,n7
  52.         tlt x0,a    r6,r7       ;dummy move, if arg>table value, keep old guess
  53.         nop
  54. _arccos_loop
  55.     move r7,a
  56.     move #$140,y0
  57.     sub  y0,a                           ;result is here
  58.  
  59.     endm
  60.  
  61.