xref: /netbsd-src/sys/arch/hp300/dev/maskbits.h (revision b04b7da8930ebfed797851d525b42255aa4806de)
1*b04b7da8Stsutsui /*	$NetBSD: maskbits.h,v 1.9 2011/02/06 18:26:52 tsutsui Exp $	*/
2*b04b7da8Stsutsui /*	$OpenBSD: maskbits.h,v 1.6 2006/08/05 09:58:56 miod Exp $	*/
3*b04b7da8Stsutsui /*	NetBSD: maskbits.h,v 1.3 1997/03/31 07:37:28 scottr Exp 	*/
4132b4143Scgd 
5c1e1831bSmycroft /*-
6c1e1831bSmycroft  * Copyright (c) 1994
7c1e1831bSmycroft  *	The Regents of the University of California.  All rights reserved.
8c1e1831bSmycroft  *
9c1e1831bSmycroft  * Redistribution and use in source and binary forms, with or without
10c1e1831bSmycroft  * modification, are permitted provided that the following conditions
11c1e1831bSmycroft  * are met:
12c1e1831bSmycroft  * 1. Redistributions of source code must retain the above copyright
13c1e1831bSmycroft  *    notice, this list of conditions and the following disclaimer.
14c1e1831bSmycroft  * 2. Redistributions in binary form must reproduce the above copyright
15c1e1831bSmycroft  *    notice, this list of conditions and the following disclaimer in the
16c1e1831bSmycroft  *    documentation and/or other materials provided with the distribution.
17aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
18c1e1831bSmycroft  *    may be used to endorse or promote products derived from this software
19c1e1831bSmycroft  *    without specific prior written permission.
20c1e1831bSmycroft  *
21c1e1831bSmycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22c1e1831bSmycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23c1e1831bSmycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24c1e1831bSmycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25c1e1831bSmycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26c1e1831bSmycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27c1e1831bSmycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28c1e1831bSmycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29c1e1831bSmycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30c1e1831bSmycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31c1e1831bSmycroft  * SUCH DAMAGE.
32c1e1831bSmycroft  *
33132b4143Scgd  *	@(#)maskbits.h	8.2 (Berkeley) 3/21/94
34c1e1831bSmycroft  */
35c1e1831bSmycroft 
36c1e1831bSmycroft /*
37c1e1831bSmycroft  * Derived from X11R4
38c1e1831bSmycroft  */
39c1e1831bSmycroft 
40c1e1831bSmycroft /* the following notes use the following conventions:
41c1e1831bSmycroft SCREEN LEFT				SCREEN RIGHT
42c1e1831bSmycroft in this file and maskbits.c, left and right refer to screen coordinates,
43c1e1831bSmycroft NOT bit numbering in registers.
44c1e1831bSmycroft 
45*b04b7da8Stsutsui rasops_lmask[n]
46c1e1831bSmycroft 	bits[0,n-1] = 0	bits[n,31] = 1
47*b04b7da8Stsutsui rasops_rmask[n] =
48c1e1831bSmycroft 	bits[0,n-1] = 1	bits[n,31] = 0
49c1e1831bSmycroft 
50c1e1831bSmycroft maskbits(x, w, startmask, endmask, nlw)
51c1e1831bSmycroft 	for a span of width w starting at position x, returns
52c1e1831bSmycroft a mask for ragged bits at start, mask for ragged bits at end,
53c1e1831bSmycroft and the number of whole longwords between the ends.
54c1e1831bSmycroft 
55c1e1831bSmycroft */
56c1e1831bSmycroft 
57c1e1831bSmycroft #define maskbits(x, w, startmask, endmask, nlw)				\
589834d093Stsutsui do {									\
59*b04b7da8Stsutsui 	startmask = rasops_lmask[(x) & 0x1f];				\
60*b04b7da8Stsutsui 	endmask = rasops_rmask[((x) + (w)) & 0x1f];			\
61c1e1831bSmycroft 	if (startmask)							\
62c1e1831bSmycroft 		nlw = (((w) - (32 - ((x) & 0x1f))) >> 5);		\
63c1e1831bSmycroft 	else								\
649834d093Stsutsui 		nlw = (w) >> 5;						\
659834d093Stsutsui } while (/* CONSTCOND */ 0)
66c1e1831bSmycroft 
67c1e1831bSmycroft #define FASTGETBITS(psrc, x, w, dst)					\
68*b04b7da8Stsutsui     asm ("bfextu %3{%1:%2},%0"						\
69c1e1831bSmycroft     : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
70c1e1831bSmycroft 
71c1e1831bSmycroft #define FASTPUTBITS(src, x, w, pdst)					\
72*b04b7da8Stsutsui     asm ("bfins %3,%0{%1:%2}"						\
73c1e1831bSmycroft 	 : "=o" (*(char *)(pdst))					\
74e9ec9562Sgmcgarry 	 : "di" (x), "di" (w), "d" (src))
75c1e1831bSmycroft 
76c1e1831bSmycroft #define getandputrop(psrc, srcbit, dstbit, width, pdst, rop)		\
779834d093Stsutsui do {									\
78*b04b7da8Stsutsui 	unsigned int _tmpdst;						\
79*b04b7da8Stsutsui 	if (rop == RR_CLEAR)						\
80*b04b7da8Stsutsui 		_tmpdst = 0;						\
81*b04b7da8Stsutsui 	else								\
82*b04b7da8Stsutsui 		FASTGETBITS(psrc, srcbit, width, _tmpdst);		\
83c1e1831bSmycroft 	FASTPUTBITS(_tmpdst, dstbit, width, pdst);			\
849834d093Stsutsui } while (/* CONSTCOND */ 0)
85c1e1831bSmycroft 
869834d093Stsutsui #define getunalignedword(psrc, x, dst)					\
879834d093Stsutsui do {									\
88c008fc0aSscottr         int _tmp;							\
89c1e1831bSmycroft         FASTGETBITS(psrc, x, 32, _tmp);					\
90c1e1831bSmycroft         dst = _tmp;							\
919834d093Stsutsui } while (/* CONSTCOND */ 0)
92