maskbits.h revision 1.8.88.1 1 1.8.88.1 rmind /* $NetBSD: maskbits.h,v 1.8.88.1 2011/03/05 20:50:22 rmind Exp $ */
2 1.8.88.1 rmind /* $OpenBSD: maskbits.h,v 1.6 2006/08/05 09:58:56 miod Exp $ */
3 1.8.88.1 rmind /* NetBSD: maskbits.h,v 1.3 1997/03/31 07:37:28 scottr Exp */
4 1.2 cgd
5 1.1 mycroft /*-
6 1.1 mycroft * Copyright (c) 1994
7 1.1 mycroft * The Regents of the University of California. All rights reserved.
8 1.1 mycroft *
9 1.1 mycroft * Redistribution and use in source and binary forms, with or without
10 1.1 mycroft * modification, are permitted provided that the following conditions
11 1.1 mycroft * are met:
12 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
13 1.1 mycroft * notice, this list of conditions and the following disclaimer.
14 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
16 1.1 mycroft * documentation and/or other materials provided with the distribution.
17 1.5 agc * 3. 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.2 cgd * @(#)maskbits.h 8.2 (Berkeley) 3/21/94
34 1.1 mycroft */
35 1.1 mycroft
36 1.1 mycroft /*
37 1.1 mycroft * Derived from X11R4
38 1.1 mycroft */
39 1.1 mycroft
40 1.1 mycroft /* the following notes use the following conventions:
41 1.1 mycroft SCREEN LEFT SCREEN RIGHT
42 1.1 mycroft in this file and maskbits.c, left and right refer to screen coordinates,
43 1.1 mycroft NOT bit numbering in registers.
44 1.1 mycroft
45 1.8.88.1 rmind rasops_lmask[n]
46 1.1 mycroft bits[0,n-1] = 0 bits[n,31] = 1
47 1.8.88.1 rmind rasops_rmask[n] =
48 1.1 mycroft bits[0,n-1] = 1 bits[n,31] = 0
49 1.1 mycroft
50 1.1 mycroft maskbits(x, w, startmask, endmask, nlw)
51 1.1 mycroft for a span of width w starting at position x, returns
52 1.1 mycroft a mask for ragged bits at start, mask for ragged bits at end,
53 1.1 mycroft and the number of whole longwords between the ends.
54 1.1 mycroft
55 1.1 mycroft */
56 1.1 mycroft
57 1.8 tsutsui #define maskbits(x, w, startmask, endmask, nlw) \
58 1.8 tsutsui do { \
59 1.8.88.1 rmind startmask = rasops_lmask[(x) & 0x1f]; \
60 1.8.88.1 rmind endmask = rasops_rmask[((x) + (w)) & 0x1f]; \
61 1.8 tsutsui if (startmask) \
62 1.8.88.1 rmind nlw = (((w) - (32 - ((x) & 0x1f))) >> 5); \
63 1.8 tsutsui else \
64 1.8 tsutsui nlw = (w) >> 5; \
65 1.8 tsutsui } while (/* CONSTCOND */ 0)
66 1.8 tsutsui
67 1.8 tsutsui #define FASTGETBITS(psrc, x, w, dst) \
68 1.8.88.1 rmind asm ("bfextu %3{%1:%2},%0" \
69 1.8.88.1 rmind : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
70 1.8 tsutsui
71 1.8 tsutsui #define FASTPUTBITS(src, x, w, pdst) \
72 1.8.88.1 rmind asm ("bfins %3,%0{%1:%2}" \
73 1.8.88.1 rmind : "=o" (*(char *)(pdst)) \
74 1.8.88.1 rmind : "di" (x), "di" (w), "d" (src))
75 1.8 tsutsui
76 1.8 tsutsui #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
77 1.8 tsutsui do { \
78 1.8.88.1 rmind unsigned int _tmpdst; \
79 1.8.88.1 rmind if (rop == RR_CLEAR) \
80 1.8.88.1 rmind _tmpdst = 0; \
81 1.8.88.1 rmind else \
82 1.8.88.1 rmind FASTGETBITS(psrc, srcbit, width, _tmpdst); \
83 1.8 tsutsui FASTPUTBITS(_tmpdst, dstbit, width, pdst); \
84 1.8 tsutsui } while (/* CONSTCOND */ 0)
85 1.1 mycroft
86 1.8 tsutsui #define getunalignedword(psrc, x, dst) \
87 1.8 tsutsui do { \
88 1.8.88.1 rmind int _tmp; \
89 1.8.88.1 rmind FASTGETBITS(psrc, x, 32, _tmp); \
90 1.8.88.1 rmind dst = _tmp; \
91 1.8 tsutsui } while (/* CONSTCOND */ 0)
92