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