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

  1. /* Combined Purdue/PurduePlus patches, level 2.1, 1/24/89 */
  2. /***********************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its
  9. documentation for any purpose and without fee is hereby granted,
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. /* $XConsortium: maskbits.h,v 1.26 91/07/09 19:44:24 keith Exp $ */
  26. #include "X.h"
  27. #include "Xmd.h"
  28. #include "servermd.h"
  29.  
  30. extern unsigned int starttab[];
  31. extern unsigned int endtab[];
  32. extern unsigned partmasks[32][32];
  33. extern unsigned int rmask[];
  34. extern unsigned int mask[];
  35.  
  36.  
  37. /* the following notes use the following conventions:
  38. SCREEN LEFT                SCREEN RIGHT
  39. in this file and maskbits.c, left and right refer to screen coordinates,
  40. NOT bit numbering in registers.
  41.  
  42. starttab[n]
  43.     bits[0,n-1] = 0    bits[n,31] = 1
  44. endtab[n] =
  45.     bits[0,n-1] = 1    bits[n,31] = 0
  46.  
  47. startpartial[], endpartial[]
  48.     these are used as accelerators for doing putbits and masking out
  49. bits that are all contained between longword boudaries.  the extra
  50. 256 bytes of data seems a small price to pay -- code is smaller,
  51. and narrow things (e.g. window borders) go faster.
  52.  
  53. the names may seem misleading; they are derived not from which end
  54. of the word the bits are turned on, but at which end of a scanline
  55. the table tends to be used.
  56.  
  57. look at the tables and macros to understand boundary conditions.
  58. (careful readers will note that starttab[n] = ~endtab[n] for n != 0)
  59.  
  60. -----------------------------------------------------------------------
  61. these two macros depend on the screen's bit ordering.
  62. in both of them x is a screen position.  they are used to
  63. combine bits collected from multiple longwords into a
  64. single destination longword, and to unpack a single
  65. source longword into multiple destinations.
  66.  
  67. SCRLEFT(dst, x)
  68.     takes dst[x, 32] and moves them to dst[0, 32-x]
  69.     the contents of the rest of dst are 0.
  70.     this is a right shift on LSBFirst (forward-thinking)
  71.     machines like the VAX, and left shift on MSBFirst
  72.     (backwards) machines like the 680x0 and pc/rt.
  73.  
  74. SCRRIGHT(dst, x)
  75.     takes dst[0,x] and moves them to dst[32-x, 32]
  76.     the contents of the rest of dst are 0.
  77.     this is a left shift on LSBFirst, right shift
  78.     on MSBFirst.
  79.  
  80.  
  81. the remaining macros are cpu-independent; all bit order dependencies
  82. are built into the tables and the two macros above.
  83.  
  84. maskbits(x, w, startmask, endmask, nlw)
  85.     for a span of width w starting at position x, returns
  86. a mask for ragged bits at start, mask for ragged bits at end,
  87. and the number of whole longwords between the ends.
  88.  
  89. maskpartialbits(x, w, mask)
  90.     works like maskbits(), except all the bits are in the
  91.     same longword (i.e. (x&0x1f + w) <= 32)
  92.  
  93. mask32bits(x, w, startmask, endmask, nlw)
  94.     as maskbits, but does not calculate nlw.  it is used by
  95.     mfbGlyphBlt to put down glyphs <= 32 bits wide.
  96.  
  97. -------------------------------------------------------------------
  98.  
  99. NOTE
  100.     any pointers passe to the following 4 macros are
  101.     guranteed to be 32-bit aligned.
  102.     The only non-32-bit-aligned references ever made are
  103.     to font glyphs, and those are made with getleftbits()
  104.     and getshiftedleftbits (qq.v.)
  105.  
  106. getbits(psrc, x, w, dst)
  107.     starting at position x in psrc (x < 32), collect w
  108.     bits and put them in the screen left portion of dst.
  109.     psrc is a longword pointer.  this may span longword boundaries.
  110.     it special-cases fetching all w bits from one longword.
  111.  
  112.     +--------+--------+        +--------+
  113.     |    | m |n|      |    ==>     | m |n|  |
  114.     +--------+--------+        +--------+
  115.         x      x+w            0     w
  116.     psrc     psrc+1            dst
  117.             m = 32 - x
  118.             n = w - m
  119.  
  120.     implementation:
  121.     get m bits, move to screen-left of dst, zeroing rest of dst;
  122.     get n bits from next word, move screen-right by m, zeroing
  123.          lower m bits of word.
  124.     OR the two things together.
  125.  
  126. putbits(src, x, w, pdst)
  127.     starting at position x in pdst, put down the screen-leftmost
  128.     w bits of src.  pdst is a longword pointer.  this may
  129.     span longword boundaries.
  130.     it special-cases putting all w bits into the same longword.
  131.  
  132.     +--------+            +--------+--------+
  133.     | m |n|  |        ==>    |    | m |n|      |
  134.     +--------+            +--------+--------+
  135.     0     w                     x     x+w
  136.     dst                pdst     pdst+1
  137.             m = 32 - x
  138.             n = w - m
  139.  
  140.     implementation:
  141.     get m bits, shift screen-right by x, zero screen-leftmost x
  142.         bits; zero rightmost m bits of *pdst and OR in stuff
  143.         from before the semicolon.
  144.     shift src screen-left by m, zero bits n-32;
  145.         zero leftmost n bits of *(pdst+1) and OR in the
  146.         stuff from before the semicolon.
  147.  
  148. putbitsrop(src, x, w, pdst, ROP)
  149.     like putbits but calls DoRop with the rasterop ROP (see mfb.h for
  150.     DoRop)
  151.  
  152. putbitsrrop(src, x, w, pdst, ROP)
  153.     like putbits but calls DoRRop with the reduced rasterop ROP
  154.     (see mfb.h for DoRRop)
  155.  
  156. -----------------------------------------------------------------------
  157.     The two macros below are used only for getting bits from glyphs
  158. in fonts, and glyphs in fonts are gotten only with the following two
  159. mcros.
  160.     You should tune these macros toyour font format and cpu
  161. byte ordering.
  162.  
  163. NOTE
  164. getleftbits(psrc, w, dst)
  165.     get the leftmost w (w<=32) bits from *psrc and put them
  166.     in dst.  this is used by the mfbGlyphBlt code for glyphs
  167.     <=32 bits wide.
  168.     psrc is declared (unsigned char *)
  169.  
  170.     psrc is NOT guaranteed to be 32-bit aligned.  on  many
  171.     machines this will cause problems, so there are several
  172.     versions of this macro.
  173.  
  174.     this macro is called ONLY for getting bits from font glyphs,
  175.     and depends on the server-natural font padding.
  176.  
  177.     for blazing text performance, you want this macro
  178.     to touch memory as infrequently as possible (e.g.
  179.     fetch longwords) and as efficiently as possible
  180.     (e.g. don't fetch misaligned longwords)
  181.  
  182. getshiftedleftbits(psrc, offset, w, dst)
  183.     used by the font code; like getleftbits, but shifts the
  184.     bits SCRLEFT by offset.
  185.     this is implemented portably, calling getleftbits()
  186.     and SCRLEFT().
  187.     psrc is declared (unsigned char *).
  188. */
  189.  
  190. /* to match CFB and allow algorithm sharing ... */
  191.  
  192. #define PPW    32
  193. #define PLST    31
  194. #define PIM    0x1f
  195. #define PWSH    5
  196. #define PSZ    1
  197. #define PMSK    0x01
  198. #define BitLeft(b,s)    SCRLEFT(b,s)
  199. #define BitRight(b,s)    SCRRIGHT(b,s)
  200.  
  201. #if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
  202. #define LONG2CHARS(x) (x)
  203. #else
  204. /*
  205.  *  the unsigned case below is for compilers like
  206.  *  the Danbury C and i386cc
  207.  */
  208. #define LONG2CHARS( x ) ( ( ( ( x ) & 0x000000FF ) << 0x18 ) \
  209.                       | ( ( ( x ) & 0x0000FF00 ) << 0x08 ) \
  210.                       | ( ( ( x ) & 0x00FF0000 ) >> 0x08 ) \
  211.                       | ( ( ( x ) & (unsigned long)0xFF000000 ) >> 0x18 ) )
  212. #endif
  213.  
  214. #ifdef STRICT_ANSI_SHIFT
  215. #define SHL(x,y)    ((y) >= 32 ? 0 : LONG2CHARS(LONG2CHARS(x) << (y)))
  216. #define SHR(x,y)    ((y) >= 32 ? 0 : LONG2CHARS(LONG2CHARS(x) >> (y)))
  217. #else
  218. #define SHL(x,y)    LONG2CHARS(LONG2CHARS(x) << (y))
  219. #define SHR(x,y)    LONG2CHARS(LONG2CHARS(x) >> (y))
  220. #endif
  221.  
  222. #if (BITMAP_BIT_ORDER == MSBFirst)    /* pc/rt, 680x0 */
  223. #define SCRLEFT(lw, n)    SHL((unsigned int)(lw),(n))
  224. #define SCRRIGHT(lw, n)    SHR((unsigned int)(lw),(n))
  225. #else                    /* vax, intel */
  226. #define SCRLEFT(lw, n)    SHR((unsigned int)(lw),(n))
  227. #define SCRRIGHT(lw, n)    SHL((unsigned int)(lw),(n))
  228. #endif
  229.  
  230. #define DoRRop(alu, src, dst) \
  231. (((alu) == RROP_BLACK) ? ((dst) & ~(src)) : \
  232.  ((alu) == RROP_WHITE) ? ((dst) | (src)) : \
  233.  ((alu) == RROP_INVERT) ? ((dst) ^ (src)) : \
  234.   (dst))
  235.  
  236. /* A generalized form of a x4 Duff's Device */
  237. #define Duff(counter, block) { \
  238.   while (counter >= 4) {\
  239.      { block; } \
  240.      { block; } \
  241.      { block; } \
  242.      { block; } \
  243.      counter -= 4; \
  244.   } \
  245.      switch (counter & 3) { \
  246.      case 3:    { block; } \
  247.      case 2:    { block; } \
  248.      case 1:    { block; } \
  249.      case 0: \
  250.      counter = 0; \
  251.    } \
  252. }
  253. #define maskbits(x, w, startmask, endmask, nlw) \
  254.     startmask = starttab[(x)&0x1f]; \
  255.     endmask = endtab[((x)+(w)) & 0x1f]; \
  256.     if (startmask) \
  257.     nlw = (((w) - (32 - ((x)&0x1f))) >> 5); \
  258.     else \
  259.     nlw = (w) >> 5;
  260.  
  261. #define maskpartialbits(x, w, mask) \
  262.     mask = partmasks[(x)&0x1f][(w)&0x1f];
  263.  
  264. #define mask32bits(x, w, startmask, endmask) \
  265.     startmask = starttab[(x)&0x1f]; \
  266.     endmask = endtab[((x)+(w)) & 0x1f];
  267.  
  268. #ifdef __GNUC__
  269. #ifdef vax
  270. #define FASTGETBITS(psrc,x,w,dst) \
  271.     __asm ("extzv %1,%2,%3,%0" \
  272.      : "=g" (dst) \
  273.      : "g" (x), "g" (w), "m" (*(char *)(psrc)))
  274. #define getbits(psrc,x,w,dst) FASTGETBITS(psrc,x,w,dst)
  275.  
  276. #define FASTPUTBITS(src, x, w, pdst) \
  277.     __asm ("insv %3,%1,%2,%0" \
  278.      : "=m" (*(char *)(pdst)) \
  279.      : "g" (x), "g" (w), "g" (src))
  280. #define putbits(src, x, w, pdst) FASTPUTBITS(src, x, w, pdst)
  281. #endif /* vax */
  282. #ifdef mc68020
  283. #define FASTGETBITS(psrc, x, w, dst) \
  284.     __asm ("bfextu %3{%1:%2},%0" \
  285.     : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
  286.  
  287. #define getbits(psrc,x,w,dst) \
  288. { \
  289.     FASTGETBITS(psrc, x, w, dst);\
  290.     dst = SHL(dst,(32-(w))); \
  291. }
  292.  
  293. #define FASTPUTBITS(src, x, w, pdst) \
  294.     __asm ("bfins %3,%0{%1:%2}" \
  295.      : "=o" (*(char *)(pdst)) \
  296.      : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
  297.  
  298. #define putbits(src, x, w, pdst) FASTPUTBITS(SHR((src),32-(w)), x, w, pdst)
  299.  
  300. #endif /* mc68020 */
  301. #endif /* __GNUC__ */
  302.  
  303. /*  The following flag is used to override a bugfix for sun 3/60+CG4 machines,
  304.  */
  305.  
  306. /*  We don't need to be careful about this unless we're dealing with sun3's 
  307.  *  We will default its usage for those who do not know anything, but will
  308.  *  override its effect if the machine doesn't look like a sun3 
  309.  */
  310. #if !defined(mc68020) || !defined(sun)
  311. #define NO_3_60_CG4
  312. #endif
  313.  
  314. /* This is gross.  We want to #define u_putbits as something which can be used
  315.  * in the case of the 3/60+CG4, but if we use /bin/cc or are on another
  316.  * machine type, we want nothing to do with u_putbits.  What a hastle.  Here
  317.  * I used slo_putbits as something which either u_putbits or putbits could be
  318.  * defined as.
  319.  *
  320.  * putbits gets it iff it is not already defined with FASTPUTBITS above.
  321.  * u_putbits gets it if we have FASTPUTBITS (putbits) from above and have not
  322.  *     overridden the NO_3_60_CG4 flag.
  323.  */
  324.  
  325. #define slo_putbits(src, x, w, pdst) \
  326. { \
  327.     register int n = (x)+(w)-32; \
  328.     \
  329.     if (n <= 0) \
  330.     { \
  331.     register int tmpmask; \
  332.     maskpartialbits((x), (w), tmpmask); \
  333.     *(pdst) = (*(pdst) & ~tmpmask) | \
  334.         (SCRRIGHT(src, x) & tmpmask); \
  335.     } \
  336.     else \
  337.     { \
  338.     *(pdst) = (*(pdst) & endtab[x]) | (SCRRIGHT((src), x)); \
  339.     (pdst)[1] = ((pdst)[1] & starttab[n]) | \
  340.         (SCRLEFT(src, 32-(x)) & endtab[n]); \
  341.     } \
  342. }
  343.  
  344. #if defined(putbits) && !defined(NO_3_60_CG4)
  345. #define u_putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
  346. #else
  347. #define u_putbits(src, x, w, pdst) putbits(src, x, w, pdst)
  348. #endif
  349.  
  350. #if !defined(putbits) 
  351. #define putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
  352. #endif
  353.  
  354. /* Now if we have not gotten any really good bitfield macros, try some
  355.  * moderately fast macros.  Alas, I don't know how to do asm instructions
  356.  * without gcc.
  357.  */
  358.  
  359. #ifndef getbits
  360. #define getbits(psrc, x, w, dst) \
  361. { \
  362.     dst = SCRLEFT(*(psrc), (x)); \
  363.     if ( ((x) + (w)) > 32) \
  364.     dst |= (SCRRIGHT(*((psrc)+1), 32-(x))); \
  365. }
  366. #endif
  367.  
  368. /*  We have to special-case putbitsrop because of 3/60+CG4 combos
  369.  */
  370.  
  371. #define u_putbitsrop(src, x, w, pdst, rop) \
  372. {\
  373.     register int t1, t2; \
  374.     register int n = (x)+(w)-32; \
  375.     \
  376.     t1 = SCRRIGHT((src), (x)); \
  377.     DoRop(t2, rop, t1, *(pdst)); \
  378.     \
  379.     if (n <= 0) \
  380.     { \
  381.     register int tmpmask; \
  382.     \
  383.     maskpartialbits((x), (w), tmpmask); \
  384.     *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
  385.     } \
  386.     else \
  387.     { \
  388.     int m = 32-(x); \
  389.     *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
  390.     t1 = SCRLEFT((src), m); \
  391.     DoRop(t2, rop, t1, (pdst)[1]); \
  392.     (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
  393.     } \
  394. }
  395.  
  396. /* If our getbits and putbits are FAST enough,
  397.  * do this brute force, it's faster
  398.  */
  399.  
  400. #if defined(FASTPUTBITS) && defined(FASTGETBITS) && defined(NO_3_60_CG4)
  401. #if (BITMAP_BIT_ORDER == MSBFirst)
  402. #define putbitsrop(src, x, w, pdst, rop) \
  403. { \
  404.   register int _tmp, _tmp2; \
  405.   FASTGETBITS(pdst, x, w, _tmp); \
  406.   _tmp2 = SCRRIGHT(src, 32-(w)); \
  407.   DoRop(_tmp, rop, _tmp2, _tmp) \
  408.   FASTPUTBITS(_tmp, x, w, pdst); \
  409. }
  410. #define putbitsrrop(src, x, w, pdst, rop) \
  411. { \
  412.   register int _tmp, _tmp2; \
  413.  \
  414.   FASTGETBITS(pdst, x, w, _tmp); \
  415.   _tmp2 = SCRRIGHT(src, 32-(w)); \
  416.   _tmp= DoRRop(rop, _tmp2, _tmp); \
  417.   FASTPUTBITS(_tmp, x, w, pdst); \
  418. }
  419. #undef u_putbitsrop
  420. #else
  421. #define putbitsrop(src, x, w, pdst, rop) \
  422. { \
  423.   register int _tmp; \
  424.   FASTGETBITS(pdst, x, w, _tmp); \
  425.   DoRop(_tmp, rop, src, _tmp) \
  426.   FASTPUTBITS(_tmp, x, w, pdst); \
  427. }
  428. #define putbitsrrop(src, x, w, pdst, rop) \
  429. { \
  430.   register int _tmp; \
  431.  \
  432.   FASTGETBITS(pdst, x, w, _tmp); \
  433.   _tmp= DoRRop(rop, src, _tmp); \
  434.   FASTPUTBITS(_tmp, x, w, pdst); \
  435. }
  436. #undef u_putbitsrop
  437. #endif
  438. #endif
  439.  
  440. #ifndef putbitsrop
  441. #define putbitsrop(src, x, w, pdst, rop)  u_putbitsrop(src, x, w, pdst, rop)
  442. #endif 
  443.  
  444. #ifndef putbitsrrop
  445. #define putbitsrrop(src, x, w, pdst, rop) \
  446. {\
  447.     register int t1, t2; \
  448.     register int n = (x)+(w)-32; \
  449.     \
  450.     t1 = SCRRIGHT((src), (x)); \
  451.     t2 = DoRRop(rop, t1, *(pdst)); \
  452.     \
  453.     if (n <= 0) \
  454.     { \
  455.     register int tmpmask; \
  456.     \
  457.     maskpartialbits((x), (w), tmpmask); \
  458.     *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
  459.     } \
  460.     else \
  461.     { \
  462.     int m = 32-(x); \
  463.     *(pdst) = (*(pdst) & endtab[x]) | (t2 & starttab[x]); \
  464.     t1 = SCRLEFT((src), m); \
  465.     t2 = DoRRop(rop, t1, (pdst)[1]); \
  466.     (pdst)[1] = ((pdst)[1] & starttab[n]) | (t2 & endtab[n]); \
  467.     } \
  468. }
  469. #endif
  470.  
  471. #if GETLEFTBITS_ALIGNMENT == 1
  472. #define getleftbits(psrc, w, dst)    dst = *((unsigned int *) psrc)
  473. #endif /* GETLEFTBITS_ALIGNMENT == 1 */
  474.  
  475. #if GETLEFTBITS_ALIGNMENT == 2
  476. #define getleftbits(psrc, w, dst) \
  477.     { \
  478.     if ( ((int)(psrc)) & 0x01 ) \
  479.         getbits( ((unsigned int *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
  480.     else \
  481.         getbits(psrc, 0, w, dst);
  482.     }
  483. #endif /* GETLEFTBITS_ALIGNMENT == 2 */
  484.  
  485. #if GETLEFTBITS_ALIGNMENT == 4
  486. #define getleftbits(psrc, w, dst) \
  487.     { \
  488.     int off, off_b; \
  489.     off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
  490.     getbits( \
  491.         (unsigned int *)( ((char *)(psrc)) - off), \
  492.         (off_b), (w), (dst) \
  493.            ); \
  494.     }
  495. #endif /* GETLEFTBITS_ALIGNMENT == 4 */
  496.  
  497.  
  498. #define getshiftedleftbits(psrc, offset, w, dst) \
  499.     getleftbits((psrc), (w), (dst)); \
  500.     dst = SCRLEFT((dst), (offset));
  501.  
  502. /* FASTGETBITS and FASTPUTBITS are not necessarily correct implementations of
  503.  * getbits and putbits, but they work if used together.
  504.  *
  505.  * On a MSBFirst machine, a cpu bitfield extract instruction (like bfextu)
  506.  * could normally assign its result to a long word register in the screen
  507.  * right position.  This saves canceling register shifts by not fighting the
  508.  * natural cpu byte order.
  509.  *
  510.  * Unfortunately, these fail on a 3/60+CG4 and cannot be used unmodified. Sigh.
  511.  */
  512. #if defined(FASTGETBITS) && defined(FASTPUTBITS)
  513. #ifdef NO_3_60_CG4
  514. #define u_FASTPUT(aa, bb, cc, dd)  FASTPUTBITS(aa, bb, cc, dd)
  515. #else
  516. #define u_FASTPUT(aa, bb, cc, dd)  u_putbits(SCRLEFT(aa, 32-(cc)), bb, cc, dd)
  517. #endif
  518.  
  519. #define getandputbits(psrc, srcbit, dstbit, width, pdst) \
  520. { \
  521.     register unsigned int _tmpbits; \
  522.     FASTGETBITS(psrc, srcbit, width, _tmpbits); \
  523.     u_FASTPUT(_tmpbits, dstbit, width, pdst); \
  524. }
  525.  
  526. #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
  527. { \
  528.   register unsigned int _tmpsrc, _tmpdst; \
  529.   FASTGETBITS(pdst, dstbit, width, _tmpdst); \
  530.   FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
  531.   DoRop(_tmpdst, rop, _tmpsrc, _tmpdst); \
  532.   u_FASTPUT(_tmpdst, dstbit, width, pdst); \
  533. }
  534.  
  535. #define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
  536. { \
  537.   register unsigned int _tmpsrc, _tmpdst; \
  538.   FASTGETBITS(pdst, dstbit, width, _tmpdst); \
  539.   FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
  540.   _tmpdst = DoRRop(rop, _tmpsrc, _tmpdst); \
  541.   u_FASTPUT(_tmpdst, dstbit, width, pdst); \
  542. }
  543.  
  544. #define getandputbits0(psrc, srcbit, width, pdst) \
  545.     getandputbits(psrc, srcbit, 0, width, pdst)
  546.  
  547. #define getandputrop0(psrc, srcbit, width, pdst, rop) \
  548.         getandputrop(psrc, srcbit, 0, width, pdst, rop)
  549.  
  550. #define getandputrrop0(psrc, srcbit, width, pdst, rop) \
  551.         getandputrrop(psrc, srcbit, 0, width, pdst, rop)
  552.  
  553.  
  554. #else /* Slow poke */
  555.  
  556. /* pairs of getbits/putbits happen frequently. Some of the code can
  557.  * be shared or avoided in a few specific instances.  It gets us a
  558.  * small advantage, so we do it.  The getandput...0 macros are the only ones
  559.  * which speed things here.  The others are here for compatibility w/the above
  560.  * FAST ones
  561.  */
  562.  
  563. #define getandputbits(psrc, srcbit, dstbit, width, pdst) \
  564. { \
  565.     register unsigned int _tmpbits; \
  566.     getbits(psrc, srcbit, width, _tmpbits); \
  567.     putbits(_tmpbits, dstbit, width, pdst); \
  568. }
  569.  
  570. #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
  571. { \
  572.     register unsigned int _tmpbits; \
  573.     getbits(psrc, srcbit, width, _tmpbits) \
  574.     putbitsrop(_tmpbits, dstbit, width, pdst, rop) \
  575. }
  576.  
  577. #define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
  578. { \
  579.     register unsigned int _tmpbits; \
  580.     getbits(psrc, srcbit, width, _tmpbits) \
  581.     putbitsrrop(_tmpbits, dstbit, width, pdst, rop) \
  582. }
  583.  
  584.  
  585. #define getandputbits0(psrc, sbindex, width, pdst) \
  586. {            /* unroll the whole damn thing to see how it * behaves */ \
  587.     register int          _flag = 32 - (sbindex); \
  588.     register unsigned int _src; \
  589.  \
  590.     _src = SCRLEFT (*(psrc), (sbindex)); \
  591.     if ((width) > _flag) \
  592.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  593.  \
  594.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  595. }
  596.  
  597.  
  598. #define getandputrop0(psrc, sbindex, width, pdst, rop) \
  599. {            \
  600.     register int          _flag = 32 - (sbindex); \
  601.     register unsigned int _src; \
  602.  \
  603.     _src = SCRLEFT (*(psrc), (sbindex)); \
  604.     if ((width) > _flag) \
  605.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  606.     DoRop(_src, rop, _src, *(pdst)); \
  607.  \
  608.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  609. }
  610.  
  611. #define getandputrrop0(psrc, sbindex, width, pdst, rop) \
  612. { \
  613.     int             _flag = 32 - (sbindex); \
  614.     register unsigned int _src; \
  615.  \
  616.     _src = SCRLEFT (*(psrc), (sbindex)); \
  617.     if ((width) > _flag) \
  618.     _src |=  SCRRIGHT (*((psrc) + 1), _flag); \
  619.     _src = DoRRop(rop, _src, *(pdst)); \
  620.  \
  621.     *(pdst) = (*(pdst) & starttab[(width)]) | (_src & endtab[(width)]); \
  622. }
  623.  
  624. #endif  /* FASTGETBITS && FASTPUTBITS */
  625.