home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 1843.dms / in.adf / Mandelbrot / mandelbitmasks2.asm < prev    next >
Encoding:
Assembly Source File  |  1992-03-31  |  6.4 KB  |  247 lines

  1. \ Copyright 1989 NerveWare
  2. \ No portion of this code may used for commercial purposes,
  3. \ nor may any executable version of this code be disributed for 
  4. \ commercial purposes without the author's express written permission.
  5. \ This code is shareware, all rights reserved.
  6.  
  7. \ Nick Didkovsky                    2/17/89
  8.  
  9. \              MandelBitMasks2.ASM
  10.  
  11.  
  12. \ This file is used to tag pixels as being already calculated or not, as 
  13. \ well as for membership in the mandelbrot set. 
  14.  
  15. getmodule includes
  16.  
  17.  include? mandel-width VariScreen.JF
  18.  include? MandelMax MandelShift2.ASM
  19.  
  20. decimal
  21.  
  22. ANEW task-MandelBitMasks_ASM
  23.  
  24. decimal
  25.  
  26. \ mark-table is used to set bits for pixels already generated
  27. \ mandeltable is used to set those pixels which also are in the mandelbrot set
  28.  
  29. VARIABLE mark-table
  30. VARIABLE mandel-table
  31.  
  32. 32000 CONSTANT table-size 
  33.  
  34. \ ************************ ALLOCATE TABLES  *******************************
  35.  
  36. : INIT.TABLES ( -- )
  37.   mark-table off
  38.   mandel-table off
  39.   MEMF_CLEAR table-size allocblock ?dup 
  40.         if mark-table ! cr ." MARK-TABLE allocated successfully" cr
  41.         else ." can't allocate MARK-TABLE!" cr abort 
  42.         then
  43.   MEMF_CLEAR table-size allocblock ?dup 
  44.         if mandel-table ! ." MANDEL-TABLE allocated successfully" cr
  45.         else ." can't allocate MANDEL-TABLE!" cr abort 
  46.         then
  47. ;
  48.  
  49. : FREE.TABLES
  50.   mark-table @ ?dup IF freeblock  cr ." mark-table freed" cr THEN
  51.   mandel-table @ ?dup IF freeblock  ." mandel-table freed" cr THEN
  52. ;
  53.  
  54. \ reset all bytes to zero
  55.  
  56. : CLEAR.TABLES ( -- )
  57.   mark-table @ table-size erase
  58.   mandel-table @ table-size erase
  59. ;
  60.  
  61. : LOOK.TABLES ( -- )
  62. cr ." MARK-TABLE" cr
  63. mark-table @ 50 dump
  64. cr ." MANDEL-TABLE" cr
  65. mandel-table @ 50 dump
  66. ;
  67.  
  68. \ *************************** BIT MASKS *********************************
  69. \ Eight pixels tagged per byte.  BIT-MASKS is used to single out the bit 
  70. \ in a byte associated with the pixel we want to tag.
  71.  
  72. CREATE BIT-MASKS  1 C, 2 C, 4 C, 8 C, 16 C, 32 C, 64 C, 128 C,
  73.  
  74. \ sets a bit at byte address of mark-table with bitmask.
  75. \ 3.04 sec for 64000 of these
  76.  : CSET     ( mask ^mark-table -- )  TUCK  C@  OR  SWAP C!  ; 
  77.  
  78. \ 2.16 sec for 64000 of these
  79. ASM CSET.ASM ( mask ^mark-table -- )
  80. move.l    tos,d0
  81. moveq.l    #0,tos
  82. move.b    $0(org,d0.l),tos     \ c@ to tos
  83. or.l    tos,(dsp)        \ OR gives newmask on (dsp)
  84. move.l    d0,tos
  85. move.b    $3(dsp),$0(org,tos.l)    \ c!
  86. addq.l    #$4,dsp         \ nip 
  87. move.l    (dsp)+,tos        \ drop
  88. END-CODE
  89.  
  90. \ given a pixel offset, returns a bit mask and address offset into table.
  91. \ 64000 calls take 3.70 sec 
  92. : GET-MASK   ( offset -- mask address-offset)
  93.   bit-masks ( -- offset ^table)
  94.   over      ( -- offset ^table offset)
  95.   7 and     ( -- offset ^table offset-AND-7)
  96.   +         ( -- offset ^table+offset-AND-7)
  97.   c@        ( -- offset byte.at.^table+offsetAND7)
  98.   swap      ( -- byte.at.^table+offsetAND7 offset)
  99.   3 -shift  ( -- byte.at.^table+offsetAND7 offset-3shifted)
  100. ;
  101.  
  102. \ 64000 calls take 2.98 sec
  103. ASM GET-MASK.ASM ( offset -- mask address-offset)
  104. callcfa    bit-masks        \ ( -- offset ^table)
  105. move.l    (dsp),d1        \ ( -- offset ^table), copy offset to d1
  106. and.l    #$7,d1            \ fancy quick modulo 8, offset-AND-7 in d1
  107. add.l    tos,d1            \ ( -- offset ^table) ^table+offsetAND7 in d1
  108. moveq.l    #0,tos            \ ( -- offset 0 ) c@ prep
  109. move.b    $0(org,d1.l),tos    \ byte.at^table+offsetAND7 to TOS
  110. move.l    (dsp),d1        \ move (dsp) to data reg to do asr
  111. asr.l    #$3,d1            \ asl to d1
  112. move.l    tos,(dsp)        \ switch these guys around to conform to 
  113. move.l    d1,tos             \ stack diagram
  114. end-code
  115.  
  116. \ returns mask and MARK-TABLE address associated with a pixel.
  117. : PIXEL#>MASK  ( Pixel# -- mask ^MARK-TABLE)
  118.   get-mask.asm mark-table @ +  ; 
  119.  
  120. \ returns mask and MANDEL-TABLE address associated with a pixel.
  121. : PIXEL#>MANDELMASK  ( Pixel# -- mask ^MANDEL-TABLE)
  122.   get-mask.asm mandel-table @ +  ; 
  123.  
  124. \ used to tag a bit in both tables
  125. : PIXEL#>MASK.BOTH ( pixel# -- mask ^mandel-table mask ^mark-table)
  126.   get-mask.asm 2dup ( -- mask addr-off mask addr-off)
  127.   mark-table @ + >r >r
  128.   mandel-table @ + r> r>
  129. ;
  130.  
  131. \ ************************ SET.PIXEL, GET.PIXEL ****************************
  132.  
  133. \ mark a pixel with a bit in MARK-TABLE
  134. : SET.PIXEL ( pixel# -- )
  135.   \ pixel#>mask 
  136.   get-mask.asm mark-table @ + 
  137.   dup>r c@ or r> cset.asm  
  138. ;
  139.  
  140. \ check if a pixel has been marked in MARK-TABLE
  141. : GET.PIXEL ( pixel# -- mask | 0)
  142. \  pixel#>mask 
  143.   get-mask.asm mark-table @ + 
  144.   c@ and
  145. ;
  146.  
  147. \ if the pixel turns out to be a mandelbrot pixel, mark it in both tables!
  148. : SET.MANDELBROT.PIXEL ( pixel# -- )
  149. \  pixel#>mask.both  ( -- mask addr mask addr)
  150.   get-mask.asm 2dup ( -- mask addr-off mask addr-off)
  151.   mark-table @ + >r >r
  152.   mandel-table @ + r> r>
  153.   dup>r c@ or r> cset.asm
  154.   dup>r c@ or r> cset.asm
  155. ;
  156.  
  157. \ check if a pixel has been marked in MANDELBROT-TABLE
  158. : GET.MANDELBROT.PIXEL ( pixel# -- mask | 0)
  159. \  pixel#>mandelmask
  160.   get-mask.asm mandel-table @ +  c@ and
  161. ;
  162.  
  163. \ ***************************** POINT>PIXEL# ********************************
  164.  
  165. \ take an x,y and convert to pixel# depending on mandel-width
  166. \ 64000 calls to this takes 2.36 sec
  167. ASM POINT>PIXEL# ( x y -- pixel#)
  168. callcfa     mandel-width
  169. move.l        $0(org,tos.l),tos
  170. move.l         (dsp)+,d0
  171. muls.l        tos,d0
  172. add.l        (dsp)+,d0
  173. move.l        d0,tos
  174. end-code
  175.  
  176. \ mark non-mandelbrot pixel associated with (x,y) in mark-table
  177. : MARK.NON.POINT ( x y -- )
  178.   point>pixel# 
  179.   get-mask.asm mark-table @ + 
  180.   dup>r c@ or r> cset.asm  
  181. \ set.pixel
  182. ;
  183.  
  184. \ mark mandelbrot pixel associated with (x,y) in mandel-table
  185. : MARK.MANDELBROT.POINT ( x y -- )
  186.   point>pixel# 
  187.   get-mask.asm 2dup ( -- mask addr-off mask addr-off)
  188.   mark-table @ + >r >r
  189.   mandel-table @ + r> r>
  190.   dup>r c@ or r> cset.asm
  191.   dup>r c@ or r> cset.asm
  192. \ set.mandelbrot.pixel 
  193. ;
  194.  
  195. : MARK.POINT ( x y iterations -- )
  196.   mandelmax = IF mark.mandelbrot.point ELSE mark.non.point THEN ;
  197.  
  198. : GET.POINT ( x y -- mask | 0)
  199.   point>pixel# 
  200.   get-mask.asm mark-table @ + 
  201.   c@ and
  202. \ get.pixel
  203. ;
  204.  
  205. : GET.MANDELBROT.POINT ( x y -- mask | 0)
  206.   point>pixel# 
  207.   get-mask.asm mandel-table @ +  c@ and
  208. \ get.mandelbrot.pixel 
  209. ;
  210.  
  211.   
  212. \ ******************************** BENCHMARKS *****************************
  213.  
  214. \ 64000 loops take 7.92 sec
  215. \ with cset.asm now takes 6.3 sec
  216. : BENCH.SET.PIXEL ( #loops -- )
  217.   0 do
  218.     400 set.pixel
  219.   loop
  220. ;
  221.  
  222. \ 64000 loops take 5.60 sec
  223. \ with get-mask.asm now takes 4.84 sec
  224. : BENCH.GET.PIXEL ( #loops -- )
  225.   0 do
  226.     400 get.pixel drop
  227.   loop
  228. ;
  229.  
  230. \ 64000 loops take 12.88 sec.
  231. \ with asm takes 10.48 sec
  232. : BENCH.SET.MPIXEL ( #loops -- )
  233.   0 do
  234.     400 set.mandelbrot.pixel
  235.   loop
  236. ;
  237.  
  238. \ 64000 loops take 5.56 sec
  239. \ with asm takes 4.84 sec
  240. : BENCH.GET.MPIXEL ( #loops -- )
  241.   0 do
  242.     400 get.mandelbrot.pixel drop
  243.   loop
  244. ;
  245.  
  246.  
  247.