home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / MMXTASM0.ZIP / MANDELMX.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-02-10  |  3.7 KB  |  162 lines

  1. ;// MMx Mandelbrot (first real application test)
  2. ideal
  3. p586
  4. p587
  5. locals __
  6.  
  7. %nolist
  8. smart
  9. warn icg
  10. nowarn  mcp
  11. warn pro
  12. multerrs
  13.  
  14. include "mmx.ash"
  15. %list
  16.  
  17. STACKSIZE       equ     4096
  18.  
  19. INTEGER         equ     4
  20. PREC            equ     ((16-1)-INTEGER)
  21.  
  22. ResX            equ     320
  23. ResY            equ     200
  24.  
  25. RMIN            equ     (-220 shl PREC)/100
  26. RMAX            equ     (110 shl PREC)/100
  27. IMIN            equ     (-120 shl PREC)/100
  28. IMAX            equ     (120 shl PREC)/100
  29.  
  30. DELTAR          equ     ((RMAX-RMIN)/ResX)
  31. DELTAI          equ     ((IMAX-IMIN)/ResY)
  32.  
  33.  
  34. segment         _DATA use16 para public 'DATA'
  35.  
  36. fatal_error     db      "Fatal memory allocation error.",13,10,'$'
  37. nommx           db      "Sorry, you NEED an MMx CPU to try this out",13,10,'$'
  38. align qword
  39. _mm2            MMxMem  < ?, < IMIN, RMIN > >
  40. _mm3            MMxMem  < ?, < DELTAI, RMIN > >
  41. _mm4            MMxMem  < ?, < 0, DELTAR > >
  42. negmask         MMxMem  < ?, ?, < 1, 1, -1, 1 > >
  43. oddword         MMxMem  < ?, ?, < -1, 0, -1, 0 > >
  44. evenword        MMxMem  < ?, ?, < 0, -1, 0, -1 > >
  45. check           MMxMem  < ?, < 255, (4 SHL PREC)-1 > >
  46. align word
  47.  
  48. ends            _DATA
  49.  
  50.  
  51. segment         _TEXT use16 para public 'CODE'
  52.         assume cs:_TEXT, ds:_DATA
  53.  
  54. start:          mov   ax,es
  55.         mov   bx,ss
  56.         add   bx,STACKSIZE/16
  57.         sub   bx,ax
  58.         mov   ah,4ah
  59.         int   21h
  60.         jnc   short __ok
  61.         mov   dx,offset fatal_error
  62. __print:        mov   ah,9
  63.         int   21h
  64.         mov   ax,4cffh
  65.         int   21h
  66.  
  67. __ok:           mov   ax,_DATA
  68.         mov   ds,ax
  69.         mov   sp,STACKSIZE
  70.         mov   bp,sp
  71.  
  72. ;// check for MMX subsystem (why???)
  73.         pushfd
  74.         pop   eax
  75.         mov   ebx,eax
  76.         xor   eax,1000000000000000000000b
  77.         push  eax
  78.         popfd
  79.         pushfd
  80.         pop   eax
  81.         cmp   eax,ebx
  82.         jz    short __bailout
  83.         mov   eax,1
  84.         cpuid
  85.         test  edx,100000000000000000000000b
  86.         jnz   short __mmxok
  87. __bailout:      mov   dx,offset nommx
  88.         jmp   short __print
  89.  
  90. __mmxok:        mov   ax,13h
  91.         int   10h
  92.         mov   ax,0a000h
  93.         mov   es,ax
  94.  
  95.         emms
  96.  
  97.         xor   edx,edx
  98.         movq  mm2,[mmword _mm2] ;//      rMin      iMin
  99.         movq  mm3,[mmword _mm3] ;//      0         iInc
  100.         packssdw mm2,mm2        ;// rMin iMin rMin iMin
  101.         movq  mm4,[mmword _mm4] ;//      rInc      iMin
  102.         packssdw mm3,mm3        ;// rMin iInc rMin iInc
  103.         packssdw mm4,mm4        ;// rInc 0    rInc 0
  104.  
  105. _loopy:         xor   cx,cx
  106.  
  107. _loopx:         pxor  mm5,mm5
  108.         movq  mm0,mm2
  109.         mov   eax,1
  110.  
  111. _iter:          movq  mm1,mm0                   ;//  rel  imag  rel  imag
  112.         pmullw mm1,[mmword negmask]     ;//  rel -imag  rel  imag
  113.         movq  mm6,mm0
  114.         pmaddwd mm1,mm0
  115.         psrlq mm0,16                    ;//  0    rel   imag  rel
  116.         pand  mm0,[mmword oddword]      ;//  0    rel   0     rel
  117.         psrad mm1,PREC
  118.         punpckldq mm5,mm1               ;//  check       curcount
  119.         pmaddwd mm0,mm6                 ;//  0+rel*imag 0+rel*imag
  120.         pcmpgtd mm5,[mmword check]
  121.         psrlq mm1,32                    ;//             0 res.rel
  122.         packssdw mm5,mm5
  123.         psrad mm0,PREC-1
  124.         movd  ebx,mm5
  125.         cmp   ebx,0
  126.         jne   short _doneiter
  127.         inc   ax
  128.         punpckldq mm0,mm1               ;//     res.rel  res.imag
  129.         movd  mm5,eax
  130.         packssdw mm0,mm0        ;// res.rel res.imag res.rel res.imag
  131.         paddsw mm0,mm2          ;// z^2+c
  132.         jmp   short _iter
  133. _doneiter:      lea   edi,[edx*4+edx]
  134.         paddsw mm2,mm4          ;// add rInc
  135.         shl   di,6
  136.         add   di,cx
  137.         inc   cx
  138.         mov   [es:di],al
  139.         cmp   cx,ResX
  140.         jne   short _loopx
  141.         inc   dx
  142.         pand  mm2,[mmword oddword] ;// rel 0 rel 0
  143.         cmp   dx,ResY
  144.         paddsw mm2,mm3          ;// add iInc
  145.         jne   short _loopy
  146.  
  147.         emms
  148.         mov   ax,0
  149.         int   16h
  150.         mov   ax,3
  151.         int   10h
  152.  
  153.         mov   ax,4c00h
  154.         int   21h
  155.  
  156. ends            _TEXT
  157.  
  158. segment         _STACK stack 'STACK'
  159. ends            _STACK
  160.  
  161. end start
  162.