Home | History | Annotate | Line # | Download | only in rasops
rasops_masks.h revision 1.1
      1  1.1  ad /* 	$NetBSD: rasops_masks.h,v 1.1 1999/04/26 04:27:48 ad Exp $ */
      2  1.1  ad 
      3  1.1  ad /*
      4  1.1  ad  * Copyright (c) 1999 Andy Doran <ad (at) NetBSD.org>
      5  1.1  ad  * All rights reserved.
      6  1.1  ad  *
      7  1.1  ad  * Redistribution and use in source and binary forms, with or without
      8  1.1  ad  * modification, are permitted provided that the following conditions
      9  1.1  ad  * are met:
     10  1.1  ad  * 1. Redistributions of source code must retain the above copyright
     11  1.1  ad  *    notice, this list of conditions and the following disclaimer.
     12  1.1  ad  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  ad  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  ad  *    documentation and/or other materials provided with the distribution.
     15  1.1  ad  *
     16  1.1  ad  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.1  ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1  ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1  ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.1  ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1  ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1  ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1  ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1  ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  ad  * SUCH DAMAGE.
     27  1.1  ad  *
     28  1.1  ad  */
     29  1.1  ad 
     30  1.1  ad #ifndef _RASOPS_MASKS_H_
     31  1.1  ad #define _RASOPS_MASKS_H_ 1
     32  1.1  ad 
     33  1.1  ad #include <sys/types.h>
     34  1.1  ad #include <machine/endian.h>
     35  1.1  ad 
     36  1.1  ad /*
     37  1.1  ad  * Convenience macros. To get around the problem of dealing with properly
     38  1.1  ad  * ordered bits on little-endian machines, we just convert everything to
     39  1.1  ad  * big-endian and back again when we're done.
     40  1.1  ad  *
     41  1.1  ad  * MBL: move bits left
     42  1.1  ad  * MBR: move bits right
     43  1.1  ad  * MBE: make big-endian
     44  1.1  ad  */
     45  1.1  ad #if BYTE_ORDER == BIG_ENDIAN
     46  1.1  ad 
     47  1.1  ad #define MBL(x,y)	((y) > 31 ? 0 : (x) >> (y))
     48  1.1  ad #define MBR(x,y)    	((y) > 31 ? 0 : (x) << (y))
     49  1.1  ad #define MBE(x)		(x)
     50  1.1  ad 
     51  1.1  ad #else
     52  1.1  ad 
     53  1.1  ad #define MBL(x,y)    	((y) > 31 ? 0 : MBE(MBE(x) << (y)))
     54  1.1  ad #define MBR(x,y)    	((y) > 31 ? 0 : MBE(MBE(x) >> (y)))
     55  1.1  ad #define MBE(x)		( (((x) & 0x000000FFU) << 24) \
     56  1.1  ad                         | (((x) & 0x0000FF00U) <<  8) \
     57  1.1  ad                         | (((x) & 0x00FF0000U) >>  8) \
     58  1.1  ad                         | (((x) & 0xFF000000U) >> 24) )
     59  1.1  ad #endif
     60  1.1  ad 
     61  1.1  ad /*
     62  1.1  ad  * Using GETBITS() and PUTBITS() inside a loop mightn't be such a good idea.
     63  1.1  ad  * There's probably some CSE and strength-reduction that the compiler won't
     64  1.1  ad  * even think about - really should have a few assumptions/separate cases.
     65  1.1  ad  */
     66  1.1  ad 
     67  1.1  ad /* Get a number of bits ( <= 32 ) from *sp and store in dw */
     68  1.1  ad #define GETBITS(sp, x, w, dw) do { \
     69  1.1  ad     dw = MBL(*(sp), (x)); \
     70  1.1  ad     if (((x) + (w)) > 32) \
     71  1.1  ad 	dw |= (MBR((sp)[1], 32 - (x))); \
     72  1.1  ad } while(0);
     73  1.1  ad 
     74  1.1  ad /* Put a number of bits ( <= 32 ) from sw to *dp */
     75  1.1  ad #define PUTBITS(sw, x, w, dp) do { \
     76  1.1  ad     int n = (x) + (w) - 32; \
     77  1.1  ad     \
     78  1.1  ad     if (n <= 0) { \
     79  1.1  ad 	n = rasops_pmask[x & 31][w & 31]; \
     80  1.1  ad 	*(dp) = (*(dp) & ~n) | (MBR(sw, x) & n); \
     81  1.1  ad     } else { \
     82  1.1  ad 	*(dp) = (*(dp) & rasops_rmask[x]) | (MBR((sw), x)); \
     83  1.1  ad 	(dp)[1] = ((dp)[1] & rasops_rmask[n]) | \
     84  1.1  ad 		(MBL(sw, 32-(x)) & rasops_lmask[n]); \
     85  1.1  ad     } \
     86  1.1  ad } while(0);
     87  1.1  ad 
     88  1.1  ad /* rasops_masks.c */
     89  1.1  ad extern int32_t	rasops_lmask[32+1];
     90  1.1  ad extern int32_t	rasops_rmask[32+1];
     91  1.1  ad extern int32_t	rasops_pmask[32][32];
     92  1.1  ad #ifdef notyet
     93  1.1  ad extern int32_t	rasops_lbmask[4+1];
     94  1.1  ad extern int32_t	rasops_rbmask[4+1];
     95  1.1  ad #endif
     96  1.1  ad 
     97  1.1  ad #endif /* _RASOPS_MASKS_H_ */
     98