home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / CBGRX100.ZIP / CONTRIB / LIBGRX / SRC / MEMCOPY.H < prev    next >
Text File  |  1992-04-10  |  10KB  |  286 lines

  1. /** 
  2.  ** MEMCOPY.H 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #ifndef _MEMCOPY_H_
  25. #define _MEMCOPY_H_
  26.  
  27. #ifdef  __TURBOC__
  28. #pragma inline
  29. #endif
  30.  
  31. /*
  32.  * utilities -- other files may define them too
  33.  */
  34. #ifndef _SaveDS
  35.  
  36. #ifdef  __TURBOC__
  37. #define _ClrDir()    asm cld
  38. #define _SetDir()    asm std
  39. #define _SaveDS()    asm push ds
  40. #define _RestoreDS()    asm pop  ds
  41. #endif
  42.  
  43. #ifdef  __GNUC__
  44. #define _ASV        asm volatile
  45. #define _ClrDir()    _ASV("cld")
  46. #define _SetDir()    _ASV("std")
  47. #define _SaveDS()
  48. #define _RestoreDS()
  49. #endif
  50.  
  51. #endif  /* _SaveDS */
  52.  
  53. /*
  54.  * copy a pixel row
  55.  */
  56. #ifdef  __TURBOC__
  57. #define _MC_ROWCPY_(dstp,srcp,len,SZ) do {                    \
  58.     _CX = len;                                \
  59.     asm les        di,DWORD PTR dstp;                        \
  60.     asm lds        si,DWORD PTR srcp;                        \
  61.     asm rep        movs##SZ;                            \
  62. } while(0)
  63. #endif
  64.  
  65. #ifdef  __GNUC__
  66. #define _MC_ROWCPY_(dstp,srcp,len,SZ) _ASV(                 "\n\
  67.     movl    %0,%%edi                          \n\
  68.     movl    %1,%%esi                          \n\
  69.     movl    %2,%%ecx                          \n\
  70.     rep                                  \n\
  71.     movs"#SZ"                               "\
  72.     : /* NOTHING */                                \
  73.     : "g" (dstp), "g" (srcp), "g" (len)                    \
  74.     : "di", "si", "cx"                            \
  75. )
  76. #endif
  77.  
  78. #define _RowCpyB(ID,dstp,srcp,len)    _MC_ROWCPY_(dstp,srcp,len,b)
  79. #define _RowCpyW(ID,dstp,srcp,len)    _MC_ROWCPY_(dstp,srcp,len,w)
  80. #define _RowCpyL(ID,dstp,srcp,len)    _MC_ROWCPY_(dstp,srcp,len,l)
  81.  
  82. /*
  83.  * copy a pixel row with logical operations
  84.  */
  85. #ifdef  __TURBOC__
  86. #define _MC_ROWCPYOPR_(dstp,srcp,len,OPR,REG,SZ,ID) do {            \
  87.     _CX = len;                                \
  88.     asm les        di,DWORD PTR dstp;                        \
  89.     asm lds        si,DWORD PTR srcp;                        \
  90. MC_RowCpy##ID##Loop:                                \
  91.     asm lods##SZ;                                \
  92.     asm OPR        REG,es:[di];                        \
  93.     asm stos##SZ;                                \
  94.     asm loop    MC_RowCpy##ID##Loop;                    \
  95. } while(0)
  96. #endif
  97.  
  98. #ifdef  __GNUC__
  99. #define _MC_ROWCPYOPR_(dstp,srcp,len,OPR,REG,SZ,ID) _ASV(         "\n\
  100.     movl    %0,%%edi                          \n\
  101.     movl    %1,%%esi                          \n\
  102.     movl    %2,%%ecx                          \n\
  103. L_MC_RowCpy"#ID"Loop:                              \n\
  104.     lods"#SZ"                              \n\
  105.     "#OPR #SZ"  (%%edi),%%"#REG"                      \n\
  106.     stos"#SZ"                              \n\
  107.     loop    L_MC_RowCpy"#ID"Loop                       "\
  108.     : /* NOTHING */                                \
  109.     : "g" (dstp), "g" (srcp), "g" (len)                    \
  110.     : "di", "si", "cx", "ax"                        \
  111. )
  112. #endif
  113.  
  114. #define _RowCpyXorB(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,xor,al,b,ID##XB)
  115. #define _RowCpyOrB(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,or,al,b,ID##OB)
  116. #define _RowCpyAndB(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,and,al,b,ID##AB)
  117.  
  118. #define _RowCpyXorW(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,xor,ax,w,ID##XW)
  119. #define _RowCpyOrW(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,or,ax,w,ID##OW)
  120. #define _RowCpyAndW(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,and,ax,w,ID##AW)
  121.  
  122. #define _RowCpyXorL(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,xor,eax,l,ID##XL)
  123. #define _RowCpyOrL(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,or,eax,l,ID##OL)
  124. #define _RowCpyAndL(ID,dstp,srcp,len)    _MC_ROWCPYOPR_(dstp,srcp,len,and,eax,l,ID##AL)
  125.  
  126. /*
  127.  * copy a pixel column with logical operations
  128.  */
  129. #ifdef  __TURBOC__
  130. #define _MC_COLCPYOPR_(dstp,doff,srcp,soff,hgt,OPR,REG,SZ,ID) do {        \
  131.     _BX = soff;                                \
  132.     _DX = doff;                                \
  133.     _CX = hgt;                                \
  134.     asm les        di,DWORD PTR dstp;                        \
  135.     asm lds        di,DWORD PTR srcp;                        \
  136. MC_ColCpy##ID##Loop:                                \
  137.     asm mov        REG,ds:[si];                        \
  138.     asm OPR        es:[di],REG;                        \
  139.     asm add        di,dx;                            \
  140.     asm add        si,bx;                            \
  141.     asm loop    MC_ColCpy##ID##Loop;                    \
  142. } while(0)
  143. #endif
  144.  
  145. #ifdef  __GNUC__
  146. #define _MC_COLCPYOPR_(dstp,doff,srcp,soff,hgt,OPR,REG,SZ,ID) _ASV(     "\n\
  147.     movl    %0,%%edi                          \n\
  148.     movl    %1,%%edx                          \n\
  149.     movl    %2,%%esi                          \n\
  150.     movl    %3,%%ebx                          \n\
  151.     movl    %4,%%ecx                          \n\
  152. L_MC_ColCpy"#ID"Loop:                              \n\
  153.     mov"#SZ"    (%%esi),%%"#REG"                      \n\
  154.     "#OPR #SZ"  %%"#REG",(%%edi)                      \n\
  155.     addl    %%edx,%%edi                          \n\
  156.     addl    %%ebx,%%esi                          \n\
  157.     loop    L_MC_ColCpy"#ID"Loop                       "\
  158.     : /* NOTHING */                                \
  159.     : "g" (dstp), "g" (doff), "g" (srcp), "g" (soff), "g" (hgt)        \
  160.     : "di", "si", "dx", "cx", "bx", "ax"                    \
  161. )
  162. #endif
  163.  
  164. #define _ColCpyB(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,mov,al,b,ID##B)
  165. #define _ColCpyXorB(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,xor,al,b,ID##XB)
  166. #define _ColCpyOrB(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,or,al,b,ID##OB)
  167. #define _ColCpyAndB(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,and,al,b,ID##AB)
  168.  
  169. #define _ColCpyW(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,mov,ax,w,ID##W)
  170. #define _ColCpyXorW(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,xor,ax,w,ID##XW)
  171. #define _ColCpyOrW(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,or,ax,w,ID##OW)
  172. #define _ColCpyAndW(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,and,ax,w,ID##AW)
  173.  
  174. #define _ColCpyL(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,mov,eax,l,ID##L)
  175. #define _ColCpyXorL(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,xor,eax,l,ID##XL)
  176. #define _ColCpyOrL(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,or,eax,l,ID##OL)
  177. #define _ColCpyAndL(ID,dp,do,sp,so,h)    _MC_COLCPYOPR_(dp,do,sp,so,h,and,eax,l,ID##AL)
  178.  
  179. /*
  180.  * copy a pixel block
  181.  */
  182. #ifdef  __TURBOC__
  183. #define _MC_BLKCPY_(dstp,doff,srcp,soff,wdt,hgt,SZ,ID) do {            \
  184.     _BX = soff;                                \
  185.     _DX = doff;                                \
  186.     _AX = hgt;                                \
  187.     asm les        di,DWORD PTR dstp;                        \
  188.     asm lds        si,DWORD PTR srcp;                        \
  189. MC_BlkCpy##ID##Loop:                                \
  190.     asm mov        cx,WORD  PTR wdt;                        \
  191.     asm rep        movs##SZ;                            \
  192.     asm add        di,dx;                            \
  193.     asm add        si,bx;                            \
  194.     asm dec        ax;                                \
  195.     asm jnz        MC_BlkCpy##ID##Loop;                    \
  196. } while(0)
  197. #endif
  198.  
  199. #ifdef  __GNUC__
  200. #define _MC_BLKCPY_(dstp,doff,srcp,soff,wdt,hgt,SZ,ID) _ASV(         "\n\
  201.     movl    %0,%%edi                          \n\
  202.     movl    %1,%%edx                          \n\
  203.     movl    %2,%%esi                          \n\
  204.     movl    %3,%%ebx                          \n\
  205.     movl    %5,%%eax                          \n\
  206. L_MC_BlkCpy"#ID"Loop:                              \n\
  207.     movl    %4,%%ecx                          \n\
  208.     rep                                  \n\
  209.     movs"#SZ"                              \n\
  210.     addl    %%edx,%%edi                          \n\
  211.     addl    %%ebx,%%esi                          \n\
  212.     decl    %%eax                              \n\
  213.     jnz    L_MC_BlkCpy"#ID"Loop                       "\
  214.     : /* NOTHING */                                \
  215.     : "g" (dstp), "g" (doff),                        \
  216.       "g" (srcp), "g" (soff),                        \
  217.       "g" (wdt),  "g" (hgt)                            \
  218.     : "di", "si", "dx", "cx", "bx", "ax"                    \
  219. )
  220. #endif
  221.  
  222. #define _BlkCpyB(ID,dp,do,sp,so,wd,hg)  _MC_BLKCPY_(dp,do,sp,so,wd,hg,b,ID##B)
  223. #define _BlkCpyW(ID,dp,do,sp,so,wd,hg)  _MC_BLKCPY_(dp,do,sp,so,wd,hg,w,ID##W)
  224. #define _BlkCpyL(ID,dp,do,sp,so,wd,hg)  _MC_BLKCPY_(dp,do,sp,so,wd,hg,l,ID##L)
  225.  
  226. /*
  227.  * copy a pixel block with logical operations
  228.  */
  229. #ifdef  __TURBOC__
  230. #define _MC_BLKCPYOPR_(dstp,doff,srcp,soff,wdt,hgt,OPR,REG,SZ,ID) do {        \
  231.     _DX = hgt;                                \
  232.     asm les        di,DWORD PTR dstp;                        \
  233.     asm lds        si,DWORD PTR srcp;                        \
  234. MC_BlkCpy##ID##VertLoop:                            \
  235.     asm mov        cx,WORD  PTR wdt;                        \
  236. MC_BlkCpy##ID##LineLoop:                            \
  237.     asm lods##SZ;                                \
  238.     asm OPR        REG,es:[di];                        \
  239.     asm stos##SZ;                                \
  240.     asm loop    MC_BlkCpy##ID##LineLoop;                    \
  241.     asm add        di,WORD PTR doff;                        \
  242.     asm add        si,WORD PTR soff;                        \
  243.     asm dec        dx;                                \
  244.     asm jnz        MC_BlkCpy##ID##VertLoop;                    \
  245. } while(0)
  246. #endif
  247.  
  248. #ifdef  __GNUC__
  249. #define _MC_BLKCPYOPR_(dstp,doff,srcp,soff,wdt,hgt,OPR,REG,SZ,ID) _ASV(  "\n\
  250.     movl    %0,%%edi                          \n\
  251.     movl    %2,%%esi                          \n\
  252.     movl    %5,%%edx                          \n\
  253. L_MC_BlkCpy"#ID"VertLoop:                          \n\
  254.     movl    %4,%%ecx                          \n\
  255. L_MC_BlkCpy"#ID"LineLoop:                          \n\
  256.     lods"#SZ"                              \n\
  257.     "#OPR #SZ"  (%%edi),%%"#REG"                      \n\
  258.     stos"#SZ"                              \n\
  259.     loop    L_MC_BlkCpy"#ID"LineLoop                  \n\
  260.     addl    %1,%%edi                          \n\
  261.     addl    %3,%%esi                          \n\
  262.     decl    %%edx                              \n\
  263.     jne    L_MC_BlkCpy"#ID"VertLoop                   "\
  264.     : /* NOTHING */                                \
  265.     : "g" (dstp), "g" (doff),                        \
  266.       "g" (srcp), "g" (soff),                        \
  267.       "g" (wdt),  "g" (hgt)                            \
  268.     : "di", "si", "dx", "cx", "ax"                        \
  269. )
  270. #endif
  271.  
  272. #define _BlkCpyXorB(ID,dp,do,sp,so,W,H) _MC_BLKCPYOPR_(dp,do,sp,so,W,H,xor,al,b,ID##XB)
  273. #define _BlkCpyOrB(ID,dp,do,sp,so,W,H)  _MC_BLKCPYOPR_(dp,do,sp,so,W,H,or,al,b,ID##OB)
  274. #define _BlkCpyAndB(ID,dp,do,sp,so,W,H) _MC_BLKCPYOPR_(dp,do,sp,so,W,H,and,al,b,ID##AB)
  275.  
  276. #define _BlkCpyXorW(ID,dp,do,sp,so,W,H) _MC_BLKCPYOPR_(dp,do,sp,so,W,H,xor,ax,w,ID##XW)
  277. #define _BlkCpyOrW(ID,dp,do,sp,so,W,H)  _MC_BLKCPYOPR_(dp,do,sp,so,W,H,or,ax,w,ID##OW)
  278. #define _BlkCpyAndW(ID,dp,do,sp,so,W,H) _MC_BLKCPYOPR_(dp,do,sp,so,W,H,and,ax,w,ID##AW)
  279.  
  280. #define _BlkCpyXorL(ID,dp,do,sp,so,W,H) _MC_BLKCPYOPR_(dp,do,sp,so,W,H,xor,eax,l,ID##XL)
  281. #define _BlkCpyOrL(ID,dp,do,sp,so,W,H)  _MC_BLKCPYOPR_(dp,do,sp,so,W,H,or,eax,l,ID##OL)
  282. #define _BlkCpyAndL(ID,dp,do,sp,so,W,H) _MC_BLKCPYOPR_(dp,do,sp,so,W,H,and,eax,l,ID##AL)
  283.  
  284. #endif  /* whole file */
  285.  
  286.