home *** CD-ROM | disk | FTP | other *** search
/ Microsoft DirectX SDK 6.1 / Dx6_1_Gold.iso / dxf / samples / multimedia / ddraw / src / memtime / timing.c < prev   
Encoding:
C/C++ Source or Header  |  1998-07-08  |  7.9 KB  |  235 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 - 1997 Microsoft Corporation.  All Rights Reserved.
  29. ;;
  30. ;;---------------------------------------------------------------------------*/
  31.  
  32. #include "windows.h"
  33.  
  34. _cdecl VertMemSto_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count);
  35. _cdecl DwordMemCopy_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count);
  36. _cdecl ByteMemCopy_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count);
  37. _cdecl DwordMemFill_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count);
  38. _cdecl ByteMemFill_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count);
  39.  
  40. // fill a verticale byte colum of memory (either system or video)
  41.  
  42. VertMemSto_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count)
  43. {
  44.     _asm
  45.     {
  46.         mov     ebx, pSource    ;; this is only here so the assembler doesn't tell me about un-used parameters. (I'm to lazy to figure out how to turn the warning off)
  47.  
  48.         mov     ebx, Count      ;; ebx = number of times to copy the buffers
  49.         mov     eax, Pitch      ;; eax = the pitch of the dest
  50.  
  51. top_o_loop1:
  52.         mov     edx, pDest      ;; edx = pointer to the dest
  53.         mov     ecx, sWidth 
  54. VerLine1:
  55.         mov     edi, edx        ;; load the pDest       
  56.         mov     esi, Height
  57. pixel1:
  58.         mov     byte ptr[edi],0 ;; store the byte (zeros are nice)
  59.         add     edi, eax        ;; skip to the next line
  60.         dec     esi             ;; are we done with this colum?
  61.         jnz     pixel1
  62.  
  63.         inc     edx             ;; we did the colum. increment the pDest by one
  64.         dec     ecx             ;; are we done with all the colums?
  65.         jnz     VerLine1
  66.  
  67.         dec     ebx             ;; did we do it the correct number of times?
  68.         jnz     top_o_loop1
  69.  
  70.         mov     eax, Count      ;; return the number of bytes we filled
  71.         imul    eax, sWidth
  72.         imul    eax, Height
  73.     }
  74. }
  75.  
  76. // Copy from system memory to Video memory and
  77. // cope with pitch.
  78.  
  79. DwordMemCopy_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD pitch, DWORD Count)
  80. {
  81.     _asm
  82.     {
  83.         mov     ebx, Count      ;; do the copy this many times
  84.         mov     edx, sWidth     ;; set up the number of Dwords per scanline
  85.         shr     edx, 2
  86.  
  87. top_o_loop2:
  88.         push    ebx                ;; every screen
  89.         mov     ebx, pDest
  90.         mov     esi, pSource    ;; the source is linear data
  91.         mov     eax, Height     ;; number of lines
  92.         push    ebp
  93.         mov     ebp, pitch
  94. scan_line2:
  95.         mov     edi, ebx        ;; get a dest pointer to this scan line
  96.         mov     ecx, edx        ;; reset our dword count
  97.         rep     movsd
  98.         add     ebx, ebp        ;; add in the offset to the next scan line
  99.  
  100.         dec     eax
  101.         jnz     scan_line2
  102.  
  103.         pop     ebp             ;; we've done a whole screen
  104.         pop     ebx
  105.         dec     ebx             ;; do another screen (till we're done)
  106.         jnz     top_o_loop2
  107.  
  108.         mov     eax, edx        ;; the width
  109.         shl     eax, 2          ;; in bytes
  110.         imul    eax, Height     ;; * height
  111.         imul    eax, Count      ;; * number of screens we copied
  112.     }
  113. }
  114.  
  115. // Copy from system memory to Video memory (in BYTES)
  116. // and cope with pitch.
  117.  
  118. ByteMemCopy_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD pitch, DWORD Count)
  119. {
  120.     _asm
  121.     {
  122.         mov     ebx, Count      ;; do the copy this many times
  123.         mov     edx, sWidth     ;; set up the number of bytes per scanline
  124.  
  125. top_o_loop3:
  126.         push    ebx             ;; every screen
  127.         mov     ebx, pDest
  128.         mov     esi, pSource    ;; the source is linear data
  129.         mov     eax, Height     ;; number of lines
  130.         push    ebp
  131.         mov     ebp, pitch
  132. scan_line3:
  133.         mov     edi, ebx        ;; get a dest pointer to this scan line
  134.         mov     ecx, edx        ;; reset our dword count
  135.         rep     movsb
  136.         add     ebx, ebp        ;; add in the offset to the next scan line
  137.  
  138.         dec     eax
  139.         jnz     scan_line3
  140.  
  141.         pop     ebp             ;; we've done a whole screen
  142.         pop     ebx
  143.         dec     ebx             ;; do another screen (till we're done)
  144.         jnz     top_o_loop3
  145.  
  146.         mov     eax, edx        ;; the width
  147.         imul    eax, Height     ;; * height
  148.         imul    eax, Count      ;; * number of screens we copied
  149.     }
  150. }
  151.  
  152. // fill memory (video or system) with 0s (DOWRD fill)
  153.  
  154. DwordMemFill_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count)
  155. {
  156.     _asm
  157.     {
  158.         mov     ebx, pSource    ;; this is only here so the assembler doesn't tell me about un-used parameters. (I'm to lazy to figure out how to turn the warning off)
  159.         mov     ebx, Count              
  160.         xor     eax, eax
  161.         mov     edx, sWidth     ;; we want a dword count
  162.         shr     edx, 2
  163.  
  164. screen4:
  165.         mov     esi, pDest      ;; re-load the dest
  166.         push    ebx
  167.         mov     ebx, Height     ;; re-load the height
  168.         push    ebp
  169.         mov     ebp, Pitch      ;; put this in a register
  170.         
  171. line4:
  172.         mov     edi, esi        ;; get the new line
  173.         mov     ecx, edx        ;; load the count
  174.         rep     stosd           ;; store the data (eax = 0)
  175.  
  176.         add     esi, ebp        ;; add the pitch into the pDest
  177.  
  178.         dec     ebx             ;; are we done with the screen?
  179.         jnz     line4
  180.  
  181.         pop     ebp
  182.         pop     ebx
  183.         dec     ebx             ;; did we do it the requested number of times?
  184.         jnz     screen4
  185.  
  186.         mov     eax, Count      ;; return how many bytes we filled      
  187.         imul    eax, sWidth
  188.         imul    eax, Height
  189.     }
  190. }
  191.  
  192. // fill memory (video or system) with 0s (DOWRD fill)
  193.  
  194. // same thing as above, just do it in bytes.
  195. // only 2 lines change. Whata waste of code space.
  196. // good thing it's only a test app
  197.  
  198. ByteMemFill_Pitch(DWORD pSource, DWORD pDest, DWORD Height, DWORD sWidth, DWORD Pitch, DWORD Count)
  199. {
  200.     _asm
  201.     {
  202.         mov     ebx, pSource    ;; this is here so masm wont choke.
  203.  
  204.         mov     ebx, Count
  205.         xor     eax, eax
  206.         mov     edx, sWidth
  207.  
  208. screen5:
  209.         mov     esi, pDest
  210.         push    ebx
  211.         mov     ebx, Height
  212.         push    ebp
  213.         mov     ebp, Pitch
  214.         
  215. line5:
  216.         mov     edi, esi
  217.         mov     ecx, edx
  218.         rep     stosb
  219.  
  220.         add     esi, ebp
  221.  
  222.         dec     ebx
  223.         jnz     line5
  224.  
  225.         pop     ebp
  226.         pop     ebx
  227.         dec     ebx
  228.         jnz     screen5
  229.  
  230.         mov     eax, Count
  231.         imul    eax, sWidth
  232.         imul    eax, Height
  233.     }
  234. }
  235.