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