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