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