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