home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mergerop.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  5.9 KB  |  186 lines

  1. /*
  2.  * $XConsortium: mergerop.h,v 1.7 91/07/18 22:54:58 keith Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. #ifndef _MERGEROP_H_
  27. #define _MERGEROP_H_
  28.  
  29. #ifndef GXcopy
  30. #include "X.h"
  31. #endif
  32.  
  33. typedef struct _mergeRopBits {
  34.     unsigned long   ca1, cx1, ca2, cx2;
  35. } mergeRopRec, *mergeRopPtr;
  36.  
  37. extern mergeRopRec    mergeRopBits[16];
  38.  
  39. #define DeclareMergeRop() unsigned long   _ca1, _cx1, _ca2, _cx2;
  40. #define DeclarePrebuiltMergeRop()    unsigned long    _cca, _ccx;
  41.  
  42. #if PPW != 32    /* cfb */
  43. #define InitializeMergeRop(alu,pm) {\
  44.     unsigned long   _pm; \
  45.     mergeRopPtr  _bits; \
  46.     _pm = PFILL(pm); \
  47.     _bits = &mergeRopBits[alu]; \
  48.     _ca1 = _bits->ca1 &  _pm; \
  49.     _cx1 = _bits->cx1 | ~_pm; \
  50.     _ca2 = _bits->ca2 &  _pm; \
  51.     _cx2 = _bits->cx2 &  _pm; \
  52. }
  53. #endif
  54.  
  55. #if PPW == 32    /* mfb */
  56. #define InitializeMergeRop(alu,pm) {\
  57.     mergeRopPtr  _bits; \
  58.     _bits = &mergeRopBits[alu]; \
  59.     _ca1 = _bits->ca1; \
  60.     _cx1 = _bits->cx1; \
  61.     _ca2 = _bits->ca2; \
  62.     _cx2 = _bits->cx2; \
  63. }
  64. #endif
  65.  
  66. /* AND has higher precedence than XOR */
  67.  
  68. #define DoMergeRop(src, dst) \
  69.     ((dst) & ((src) & _ca1 ^ _cx1) ^ ((src) & _ca2 ^ _cx2))
  70.  
  71. #define DoPrebuiltMergeRop(dst) ((dst) & _cca ^ _ccx)
  72.  
  73. #define DoMaskPrebuiltMergeRop(dst,mask) \
  74.     ((dst) & (_cca | ~(mask)) ^ (_ccx & (mask)))
  75.  
  76. #define PrebuildMergeRop(src) ((_cca = (src) & _ca1 ^ _cx1), \
  77.                    (_ccx = (src) & _ca2 ^ _cx2))
  78.  
  79. #define DoMaskMergeRop(src, dst, mask) \
  80.     ((dst) & (((src) & _ca1 ^ _cx1) | ~(mask)) ^ (((src) & _ca2 ^ _cx2) & (mask)))
  81.  
  82. #ifndef MROP
  83. #define MROP 0
  84. #endif
  85.  
  86. #define Mclear        (1<<GXclear)
  87. #define Mand        (1<<GXand)
  88. #define MandReverse    (1<<GXandReverse)
  89. #define Mcopy        (1<<GXcopy)
  90. #define MandInverted    (1<<GXandInverted)
  91. #define Mnoop        (1<<GXnoop)
  92. #define Mxor        (1<<GXxor)
  93. #define Mor        (1<<GXor)
  94. #define Mnor        (1<<GXnor)
  95. #define Mequiv        (1<<GXequiv)
  96. #define Minvert        (1<<GXinvert)
  97. #define MorReverse    (1<<GXorReverse)
  98. #define McopyInverted    (1<<GXcopyInverted)
  99. #define MorInverted    (1<<GXorInverted)
  100. #define Mnand        (1<<GXnand)
  101. #define Mset        (1<<GXset)
  102.  
  103. #if (MROP) == Mcopy
  104. #define MROP_DECLARE()
  105. #define MROP_DECLARE_REG()
  106. #define MROP_INITIALIZE(alu,pm)
  107. #define MROP_SOLID(src,dst)    (src)
  108. #define MROP_MASK(src,dst,mask)    ((dst) & ~(mask) | (src) & (mask))
  109. #define MROP_NAME(prefix)    MROP_NAME_CAT(prefix,Copy)
  110. #endif
  111.  
  112. #if (MROP) == McopyInverted
  113. #define MROP_DECLARE()
  114. #define MROP_DECLARE_REG()
  115. #define MROP_INITIALIZE(alu,pm)
  116. #define MROP_SOLID(src,dst)    (~(src))
  117. #define MROP_MASK(src,dst,mask)    ((dst) & ~(mask) | (~(src)) & (mask))
  118. #define MROP_NAME(prefix)    MROP_NAME_CAT(prefix,CopyInverted)
  119. #endif
  120.  
  121. #if (MROP) == Mxor
  122. #define MROP_DECLARE()
  123. #define MROP_DECLARE_REG()
  124. #define MROP_INITIALIZE(alu,pm)
  125. #define MROP_SOLID(src,dst)    ((src) ^ (dst))
  126. #define MROP_MASK(src,dst,mask)    (((src) & (mask)) ^ (dst))
  127. #define MROP_NAME(prefix)    MROP_NAME_CAT(prefix,Xor)
  128. #endif
  129.  
  130. #if (MROP) == Mor
  131. #define MROP_DECLARE()
  132. #define MROP_DECLARE_REG()
  133. #define MROP_INITIALIZE(alu,pm)
  134. #define MROP_SOLID(src,dst)    ((src) | (dst))
  135. #define MROP_MASK(src,dst,mask)    (((src) & (mask)) | (dst))
  136. #define MROP_NAME(prefix)    MROP_NAME_CAT(prefix,Or)
  137. #endif
  138.  
  139. #if (MROP) == (Mcopy|Mxor|MandReverse|Mor)
  140. #define MROP_DECLARE()    unsigned long _ca1, _cx1;
  141. #define MROP_DECLARE_REG()    register MROP_DECLARE()
  142. #define MROP_INITIALIZE(alu,pm)    { \
  143.     mergeRopPtr  _bits; \
  144.     _bits = &mergeRopBits[alu]; \
  145.     _ca1 = _bits->ca1; \
  146.     _cx1 = _bits->cx1; \
  147. }
  148. #define MROP_SOLID(src,dst) \
  149.     ((dst) & ((src) & _ca1 ^ _cx1) ^ (src))
  150. #define MROP_MASK(src,dst,mask)    \
  151.     ((dst) & (((src) & _ca1 ^ _cx1) | ~(mask)) ^ ((src) & (mask)))
  152. #define MROP_NAME(prefix)    MROP_NAME_CAT(prefix,CopyXorAndReverseOr)
  153. #define MROP_PREBUILD(src)    PrebuildMergeRop(src)
  154. #define MROP_PREBUILT_DECLARE()    DeclarePrebuiltMergeRop()
  155. #define MROP_PREBUILT_SOLID(src,dst)    DoPrebuiltMergeRop(dst)
  156. #define MROP_PREBUILT_MASK(src,dst,mask)    DoMaskPrebuiltMergeRop(dst,mask)
  157. #endif
  158.  
  159. #if (MROP) == 0
  160. #define MROP_DECLARE()    DeclareMergeRop()
  161. #define MROP_DECLARE_REG()    register DeclareMergeRop()
  162. #define MROP_INITIALIZE(alu,pm)    InitializeMergeRop(alu,pm)
  163. #define MROP_SOLID(src,dst)    DoMergeRop(src,dst)
  164. #define MROP_MASK(src,dst,mask)    DoMaskMergeRop(src, dst, mask)
  165. #define MROP_NAME(prefix)    MROP_NAME_CAT(prefix,General)
  166. #define MROP_PREBUILD(src)    PrebuildMergeRop(src)
  167. #define MROP_PREBUILT_DECLARE()    DeclarePrebuiltMergeRop()
  168. #define MROP_PREBUILT_SOLID(src,dst)    DoPrebuiltMergeRop(dst)
  169. #define MROP_PREBUILT_MASK(src,dst,mask)    DoMaskPrebuiltMergeRop(dst,mask)
  170. #endif
  171.  
  172. #ifndef MROP_PREBUILD
  173. #define MROP_PREBUILD(src)
  174. #define MROP_PREBUILT_DECLARE()
  175. #define MROP_PREBUILT_SOLID(src,dst)    MROP_SOLID(src,dst)
  176. #define MROP_PREBUILT_MASK(src,dst,mask)    MROP_MASK(src,dst,mask)
  177. #endif
  178.  
  179. #if __STDC__ && !defined(UNIXCPP)
  180. #define MROP_NAME_CAT(prefix,suffix)    prefix##suffix
  181. #else
  182. #define MROP_NAME_CAT(prefix,suffix)    prefix/**/suffix
  183. #endif
  184.  
  185. #endif
  186.