maskbits.h revision 1.1 1 /*-
2 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * from: @(#)maskbits.h 8.2 (Berkeley) 3/21/94
34 * $Id: maskbits.h,v 1.1 1994/05/23 05:59:05 mycroft Exp $
35 */
36
37 /*
38 * Derived from X11R4
39 */
40
41 /* the following notes use the following conventions:
42 SCREEN LEFT SCREEN RIGHT
43 in this file and maskbits.c, left and right refer to screen coordinates,
44 NOT bit numbering in registers.
45
46 starttab[n]
47 bits[0,n-1] = 0 bits[n,31] = 1
48 endtab[n] =
49 bits[0,n-1] = 1 bits[n,31] = 0
50
51 maskbits(x, w, startmask, endmask, nlw)
52 for a span of width w starting at position x, returns
53 a mask for ragged bits at start, mask for ragged bits at end,
54 and the number of whole longwords between the ends.
55
56 */
57
58 #define maskbits(x, w, startmask, endmask, nlw) \
59 startmask = starttab[(x)&0x1f]; \
60 endmask = endtab[((x)+(w)) & 0x1f]; \
61 if (startmask) \
62 nlw = (((w) - (32 - ((x)&0x1f))) >> 5); \
63 else \
64 nlw = (w) >> 5;
65
66 #define FASTGETBITS(psrc, x, w, dst) \
67 asm ("bfextu %3{%1:%2},%0" \
68 : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
69
70 #define FASTPUTBITS(src, x, w, pdst) \
71 asm ("bfins %3,%0{%1:%2}" \
72 : "=o" (*(char *)(pdst)) \
73 : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
74
75 #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
76 { \
77 register unsigned int _tmpsrc, _tmpdst; \
78 FASTGETBITS(pdst, dstbit, width, _tmpdst); \
79 FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
80 DoRop(_tmpdst, rop, _tmpsrc, _tmpdst); \
81 FASTPUTBITS(_tmpdst, dstbit, width, pdst); \
82 }
83
84 #define getandputrop0(psrc, srcbit, width, pdst, rop) \
85 getandputrop(psrc, srcbit, 0, width, pdst, rop)
86
87 #define getunalignedword(psrc, x, dst) { \
88 register int _tmp; \
89 FASTGETBITS(psrc, x, 32, _tmp); \
90 dst = _tmp; \
91 }
92
93 #define fnCLEAR(src, dst) (0)
94 #define fnCOPY(src, dst) (src)
95 #define fnXOR(src, dst) (src ^ dst)
96 #define fnCOPYINVERTED(src, dst)(~src)
97
98 #define DoRop(result, alu, src, dst) \
99 { \
100 if (alu == RR_COPY) \
101 result = fnCOPY (src, dst); \
102 else \
103 switch (alu) \
104 { \
105 case RR_CLEAR: \
106 result = fnCLEAR (src, dst); \
107 break; \
108 case RR_XOR: \
109 result = fnXOR (src, dst); \
110 break; \
111 case RR_COPYINVERTED: \
112 result = fnCOPYINVERTED (src, dst); \
113 break; \
114 } \
115 }
116