home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / MEMTIME / TIMING.ASM < prev    next >
Assembly Source File  |  1996-08-28  |  8KB  |  269 lines

  1. ;;--------------------------------------------------------------------------;
  2. ;;
  3. ;;  File: timing.asm
  4. ;;
  5. ;;  Description:
  6. ;;      This asm file is various methods of memory copies
  7. ;;      that copy the same data over and over for timing
  8. ;;      tests. They all assume DWORD alignment.
  9. ;;      They all take:
  10. ;;              Source. The source buffer to copy from
  11. ;;              Dest.   The dest buffer to copy to.
  12. ;;              Height. The hight of both the source and dest buffers
  13. ;;              Width.  The width of both the source and dest buffers
  14. ;;              Pitch.  The pitch of the dest buffer ONLY. The source
  15. ;;                      buffer assumes the pitch = width.
  16. ;;              Count.  The number of times you want to do the copy.
  17. ;;      They all return:
  18. ;;              The number of bytes copied
  19. ;;
  20. ;;
  21. ;;  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  22. ;;  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  23. ;;  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  24. ;;  PURPOSE.
  25. ;;
  26. ;;---------------------------------------------------------------------------
  27. ;;
  28. ;;  Copyright (c) 1994 - 1996 Microsoft Corporation.  All Rights Reserved.
  29. ;;
  30. ;;---------------------------------------------------------------------------
  31. .386
  32. .MODEL FLAT
  33.  
  34.  
  35.  
  36.  
  37. .CODE
  38.  
  39.  
  40. ;; fill a verticale byte colum of memory (either system or video)
  41.  
  42. VertMemSto_Pitch PROC C PUBLIC Uses ESI EDI EBX EDX ECX,
  43.         pSource:DWORD, \        ;; this isn't used, but it's gotta be here so I can
  44.         pDest:DWORD, \          ;; use it in a jump table
  45.         Height:DWORD, \
  46.         sWidth:DWORD, \
  47.         Pitch:DWORD, \
  48.         Count:DWORD
  49.  
  50.         mov     ebx, pSource    ;; this is only here so the assembler doesn't tell
  51.                                 ;; me about un-used parameters. (I'm to lazy to
  52.                                 ;; figure out how to turn the warning off)
  53.  
  54.         mov     ebx, Count      ;; ebx = number of times to copy the buffers
  55.         mov     eax, Pitch      ;; eax = the pitch of the dest
  56.  
  57. top_o_loop:
  58.         mov     edx, pDest      ;; edx = pointer to the dest
  59.         mov     ecx, sWidth 
  60. VerLine:
  61.         mov     edi, edx        ;; load the pDest       
  62.         mov     esi, Height
  63. pixel:
  64.         mov     byte ptr [edi], 0       ;; store the byte (0's are nice)
  65.         add     edi, eax        ;; skip to the next line
  66.         dec     esi             ;; are we done with this colum?
  67.         jnz     pixel
  68.  
  69.         inc     edx             ;; we did the colum. increment the pDest by one
  70.         dec     ecx             ;; are we done with all the colums?
  71.         jnz     VerLine
  72.  
  73.         dec     ebx             ;; did we do it the correct number of times?
  74.         jnz     top_o_loop
  75.  
  76.         mov     eax, Count      ;; return the number of bytes we filled
  77.         imul    eax, sWidth
  78.         imul    eax, Height
  79.         
  80.         ret
  81. VertMemSto_Pitch ENDP
  82.  
  83. ; Copy from system memory to Video memory and
  84. ; cope with pitch.
  85.  
  86. DwordMemCopy_Pitch PROC C PUBLIC USES ESI EDI EBX ECX EDX, \
  87.         pSource:DWORD, \
  88.         pDest:DWORD, \
  89.         Height:DWORD, \
  90.         sWidth:DWORD, \
  91.         Pitch:DWORD, \
  92.         Count:DWORD
  93.  
  94.         mov     ebx, Count      ;; do the copy this many times
  95.         mov     edx, sWidth     ;; set up the number of Dwords per scanline
  96.         shr     edx, 2
  97.  
  98. top_o_loop:                     ;; every screen
  99.         push    ebx
  100.         mov     ebx, pDest
  101.         mov     esi, pSource    ;; the source is linear data
  102.         mov     eax, Height     ;; number of lines
  103.         push    ebp
  104.         mov     ebp, pitch
  105. scan_line:
  106.         mov     edi, ebx        ;; get a dest pointer to this scan line
  107.         mov     ecx, edx        ;; reset our dword count
  108.         rep     movsd
  109.         add     ebx, ebp        ;; add in the offset to the next scan line
  110.  
  111.         dec     eax
  112.         jnz     scan_line
  113.  
  114.         pop     ebp             ;; we've done a whole screen
  115.         pop     ebx
  116.         dec     ebx             ;; do another screen (till we're done)
  117.         jnz     top_o_loop
  118.  
  119.         mov     eax, edx        ;; the width
  120.         shl     eax, 2          ;; in bytes
  121.         imul    eax, Height     ;; * height
  122.         imul    eax, Count      ;; * number of screens we copied
  123.  
  124.         ret
  125.  
  126. DwordMemCopy_Pitch ENDP
  127.  
  128. ; Copy from system memory to Video memory (in BYTES)
  129. ; and cope with pitch.
  130.  
  131. ByteMemCopy_Pitch PROC C PUBLIC USES ESI EDI EBX ECX EDX, \
  132.         pSource:DWORD, \
  133.         pDest:DWORD, \
  134.         Height:DWORD, \
  135.         sWidth:DWORD, \
  136.         Pitch:DWORD, \
  137.         Count:DWORD
  138.  
  139.         mov     ebx, Count      ;; do the copy this many times
  140.         mov     edx, sWidth     ;; set up the number of bytes per scanline
  141.  
  142. top_o_loop:                     ;; every screen
  143.         push    ebx
  144.         mov     ebx, pDest
  145.         mov     esi, pSource    ;; the source is linear data
  146.         mov     eax, Height     ;; number of lines
  147.         push    ebp
  148.         mov     ebp, pitch
  149. scan_line:
  150.         mov     edi, ebx        ;; get a dest pointer to this scan line
  151.         mov     ecx, edx        ;; reset our dword count
  152.         rep     movsb
  153.         add     ebx, ebp        ;; add in the offset to the next scan line
  154.  
  155.         dec     eax
  156.         jnz     scan_line
  157.  
  158.         pop     ebp             ;; we've done a whole screen
  159.         pop     ebx
  160.         dec     ebx             ;; do another screen (till we're done)
  161.         jnz     top_o_loop
  162.  
  163.         mov     eax, edx        ;; the width
  164.         imul    eax, Height     ;; * height
  165.         imul    eax, Count      ;; * number of screens we copied
  166.  
  167.         ret
  168.  
  169. ByteMemCopy_Pitch ENDP
  170.  
  171. ;; fill memory (video or system) with 0s (DOWRD fill)
  172.  
  173. DwordMemFill_Pitch PROC C PUBLIC USES ESI EDI EBX ECX EDX, \
  174.         pSource:DWORD, \
  175.         pDest:DWORD, \
  176.         Height:DWORD, \
  177.         sWidth:DWORD, \
  178.         Pitch:DWORD, \
  179.         Count:DWORD
  180.  
  181.         mov     ebx, pSource    ;; this is only here so the assembler doesn't tell
  182.                                 ;; me about un-used parameters. (I'm to lazy to
  183.                                 ;; figure out how to turn the warning off)
  184.         mov     ebx, Count              
  185.         xor     eax, eax
  186.         mov     edx, sWidth     ;; we want a dword count
  187.         shr     edx, 2
  188.  
  189. screen:
  190.         mov     esi, pDest      ;; re-load the dest
  191.         push    ebx
  192.         mov     ebx, Height     ;; re-load the height
  193.         push    ebp
  194.         mov     ebp, Pitch      ;; put this in a register
  195.         
  196. line:
  197.         mov     edi, esi        ;; get the new line
  198.         mov     ecx, edx        ;; load the count
  199.         rep     stosd           ;; store the data (eax = 0)
  200.  
  201.         add     esi, ebp        ;; add the pitch into the pDest
  202.  
  203.         dec     ebx             ;; are we done with the screen?
  204.         jnz     line
  205.  
  206.         pop     ebp
  207.         pop     ebx
  208.         dec     ebx             ;; did we do it the requested number of times?
  209.         jnz     screen
  210.  
  211.         mov     eax, Count      ;; return how many bytes we filled      
  212.         imul    eax, sWidth
  213.         imul    eax, Height
  214.  
  215.         ret
  216. DwordMemFill_Pitch ENDP
  217.  
  218. ;; fill memory (video or system) with 0s (DOWRD fill)
  219.  
  220. ;; same thing as above, just do it in bytes.
  221. ;; only 2 lines change. Whata waste of code space.
  222. ;; good thing it's only a test app
  223.  
  224. ByteMemFill_Pitch PROC C PUBLIC USES ESI EDI EBX ECX EDX, \
  225.         pSource:DWORD, \
  226.         pDest:DWORD, \
  227.         Height:DWORD, \
  228.         sWidth:DWORD, \
  229.         Pitch:DWORD, \
  230.         Count:DWORD
  231.  
  232.         mov     ebx, pSource    ;; this is here so masm wont choke.
  233.  
  234.         mov     ebx, Count
  235.         xor     eax, eax
  236.         mov     edx, sWidth
  237.  
  238. screen:
  239.         mov     esi, pDest
  240.         push    ebx
  241.         mov     ebx, Height
  242.         push    ebp
  243.         mov     ebp, Pitch
  244.         
  245. line:
  246.         mov     edi, esi
  247.         mov     ecx, edx
  248.         rep     stosb
  249.  
  250.         add     esi, ebp
  251.  
  252.         dec     ebx
  253.         jnz     line
  254.  
  255.         pop     ebp
  256.         pop     ebx
  257.         dec     ebx
  258.         jnz     screen
  259.  
  260.         mov     eax, Count
  261.         imul    eax, sWidth
  262.         imul    eax, Height
  263.  
  264.         ret
  265. ByteMemFill_Pitch ENDP
  266. END
  267.  
  268.  
  269.