"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

bitmap.h

Go to the documentation of this file.
00001 /* 
00002  * bitmap.h - bit mask manipulation macros
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *  
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  * 
00009  * Copyright (C) 1994, 1995, 1996, 1997, 1998 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the consequences of its
00014  * use. 
00015  * 
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  * 
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: bitmap.h,v 1.1.1.1 2000/05/26 15:18:57 taustin Exp $
00053  *
00054  * $Log: bitmap.h,v $
00055  * Revision 1.1.1.1  2000/05/26 15:18:57  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.4  1998/08/27 07:45:12  taustin
00060  * BITMAP_COUNT_ONES() added
00061  * BITMAP_NOT() fixed
00062  *
00063  * Revision 1.3  1997/03/11  01:06:06  taustin
00064  * updated copyright
00065  * long/int tweaks made for ALPHA target support
00066  *
00067  * Revision 1.1  1996/12/05  18:44:19  taustin
00068  * Initial revision
00069  *
00070  */
00071 
00072 #ifndef BITMAP_H
00073 #define BITMAP_H
00074 
00075 /* BITMAPs:
00076      BMAP: int * to an array of ints
00077      SZ: number of ints in the bitmap
00078 */
00079 
00080 /* declare a bitmap type */
00081 #define BITMAP_SIZE(BITS)       (((BITS)+31)/32)
00082 #define BITMAP_TYPE(BITS, NAME) unsigned int (NAME)[BITMAP_SIZE(BITS)]
00083 
00084 typedef unsigned int BITMAP_ENT_TYPE;
00085 typedef unsigned int *BITMAP_PTR_TYPE;
00086 
00087 /* set entire bitmap */
00088 #define BITMAP_SET_MAP(BMAP, SZ)                                \
00089   { int i; for (i=0; i<(SZ); i++) (BMAP)[i] = 0xffffffff; }
00090 
00091 /* clear entire bitmap */
00092 #define BITMAP_CLEAR_MAP(BMAP, SZ)                              \
00093   { int i; for (i=0; i<(SZ); i++) (BMAP)[i] = 0; }
00094 
00095 /* set bit BIT in bitmap BMAP, returns BMAP */
00096 #define BITMAP_SET(BMAP, SZ, BIT)                               \
00097   (((BMAP)[(BIT)/32] |= (1 << ((BIT) % 32))), (BMAP))
00098 
00099 /* clear bit BIT in bitmap BMAP, returns BMAP */
00100 #define BITMAP_CLEAR(BMAP, SZ, BIT)                             \
00101   (((BMAP)[(BIT)/32] &= ~(1 << ((BIT) % 32))), (BMAP))
00102 
00103 /* copy bitmap SRC to DEST */
00104 #define BITMAP_COPY(DESTMAP, SRCMAP, SZ)                        \
00105   { int i; for (i=0; i<(SZ); i++) (DESTMAP)[i] = (SRCMAP)[i]; }
00106 
00107 /* store bitmap B2 OP B3 into B1 */
00108 #define __BITMAP_OP(B1, B2, B3, SZ, OP)                         \
00109   { int i; for (i=0; i<(SZ); i++) (B1)[i] = (B2)[i] OP (B3)[i]; }
00110 
00111 /* store bitmap B2 | B3 into B1 */
00112 #define BITMAP_IOR(B1, B2, B3, SZ)                              \
00113   __BITMAP_OP(B1, B2, B3, SZ, |)
00114 
00115 /* store bitmap B2 ^ B3 into B1 */
00116 #define BITMAP_XOR(B1, B2, B3, SZ)                              \
00117   __BITMAP_OP(B1, B2, B3, SZ, ^)
00118 
00119 /* store bitmap B2 & B3 into B1 */
00120 #define BITMAP_AND(B1, B2, B3, SZ)                              \
00121   __BITMAP_OP(B1, B2, B3, SZ, &)
00122 
00123 /* store ~B2 into B1 */
00124 #define BITMAP_NOT(B1, B2, SZ)                                  \
00125   { int i; for (i=0; i<(SZ); i++) (B1)[i] = ~((B2)[i]); }
00126 
00127 /* return non-zero if bitmap is empty */
00128 #define BITMAP_EMPTY_P(BMAP, SZ)                                \
00129   ({ int i, res=0; for (i=0; i<(SZ); i++) res |= (BMAP)[i]; !res; })
00130 
00131 /* return non-zero if the intersection of bitmaps B1 and B2 is non-empty */
00132 #define BITMAP_DISJOINT_P(B1, B2, SZ)                           \
00133   ({ int i, res=0; for (i=0; i<(SZ); i++) res |= (B1)[i] & (B2)[i]; !res; })
00134 
00135 /* return non-zero if bit BIT is set in bitmap BMAP */
00136 #define BITMAP_SET_P(BMAP, SZ, BIT)                             \
00137   (((BMAP)[(BIT)/32] & (1 << ((BIT) % 32))) != 0)
00138 
00139 /* return non-zero if bit BIT is clear in bitmap BMAP */
00140 #define BITMAP_CLEAR_P(BMAP, SZ, BIT)                           \
00141   (!BMAP_SET_P((BMAP), (SZ), (BIT)))
00142 
00143 /* count the number of bits set in BMAP */
00144 #define BITMAP_COUNT_ONES(BMAP, SZ)                             \
00145 ({                                                              \
00146   int i, j, n = 0;                                              \
00147   for (i = 0; i < (SZ) ; i++)                                   \
00148     {                                                           \
00149       unsigned int word = (BMAP)[i];                            \
00150       for (j=0; j < (sizeof(unsigned int)*8); j++)              \
00151         {                                                       \
00152           unsigned int new_val, old_val = word;                 \
00153           word >>= 1;                                           \
00154           new_val = word << 1;                                  \
00155           if (old_val != new_val)                               \
00156             n++;                                                \
00157         }                                                       \
00158     }                                                           \
00159   n;                                                            \
00160 })
00161 
00162 #endif /* BITMAP_H */
00163 


UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214