• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/ssBackEnd/ssb_bitmap.h

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: ssb_bitmap.h,v 1.1.1.1 2006-01-31 16:35:49 afrodri Exp $
00053  *
00054  * $Log: not supported by cvs2svn $
00055  * Revision 1.1  2004/08/05 23:51:44  arodrig6
00056  * grabed files from SS and broke up some of them
00057  *
00058  * Revision 1.1.1.1  2000/03/07 05:15:16  karu
00059  * this is the repository created for my own maintanence.
00060  * created when spec95 (lisp and compress worked).
00061  * compress still had the scanf("%i") problem
00062  * DIFF from the repository I am using alongwith ramdass on /projects
00063  * need to merge the two sometime :-)
00064  *
00065  * Revision 1.1.1.1  2000/02/25 21:02:49  karu
00066  * creating cvs repository for ss3-ppc
00067  *
00068  * Revision 1.4  1998/08/27 07:45:12  taustin
00069  * BITMAP_COUNT_ONES() added
00070  * BITMAP_NOT() fixed
00071  *
00072  * Revision 1.3  1997/03/11  01:06:06  taustin
00073  * updated copyright
00074  * long/int tweaks made for ALPHA target support
00075  *
00076  * Revision 1.1  1996/12/05  18:44:19  taustin
00077  * Initial revision
00078  *
00079  */
00080 
00081 #ifndef BITMAP_H
00082 #define BITMAP_H
00083 
00084 /* BITMAPs:
00085      BMAP: int * to an array of ints
00086      SZ: number of ints in the bitmap
00087 */
00088 
00089 /* declare a bitmap type */
00090 #define BITMAP_SIZE(BITS)       (((BITS)+31)/32)
00091 #define BITMAP_TYPE(BITS, NAME) unsigned int (NAME)[BITMAP_SIZE(BITS)]
00092 
00093 typedef unsigned int BITMAP_ENT_TYPE;
00094 typedef unsigned int *BITMAP_PTR_TYPE;
00095 
00096 /* set entire bitmap */
00097 #define BITMAP_SET_MAP(BMAP, SZ)                                \
00098   { int i; for (i=0; i<(SZ); i++) (BMAP)[i] = 0xffffffff; }
00099 
00100 /* clear entire bitmap */
00101 #define BITMAP_CLEAR_MAP(BMAP, SZ)                              \
00102   { int i; for (i=0; i<(SZ); i++) (BMAP)[i] = 0; }
00103 
00104 /* set bit BIT in bitmap BMAP, returns BMAP */
00105 #define BITMAP_SET(BMAP, SZ, BIT)                               \
00106   (((BMAP)[(BIT)/32] |= (1 << ((BIT) % 32))), (BMAP))
00107 
00108 /* clear bit BIT in bitmap BMAP, returns BMAP */
00109 #define BITMAP_CLEAR(BMAP, SZ, BIT)                             \
00110   (((BMAP)[(BIT)/32] &= ~(1 << ((BIT) % 32))), (BMAP))
00111 
00112 /* copy bitmap SRC to DEST */
00113 #define BITMAP_COPY(DESTMAP, SRCMAP, SZ)                        \
00114   { int i; for (i=0; i<(SZ); i++) (DESTMAP)[i] = (SRCMAP)[i]; }
00115 
00116 /* store bitmap B2 OP B3 into B1 */
00117 #define __BITMAP_OP(B1, B2, B3, SZ, OP)                         \
00118   { int i; for (i=0; i<(SZ); i++) (B1)[i] = (B2)[i] OP (B3)[i]; }
00119 
00120 /* store bitmap B2 | B3 into B1 */
00121 #define BITMAP_IOR(B1, B2, B3, SZ)                              \
00122   __BITMAP_OP(B1, B2, B3, SZ, |)
00123 
00124 /* store bitmap B2 ^ B3 into B1 */
00125 #define BITMAP_XOR(B1, B2, B3, SZ)                              \
00126   __BITMAP_OP(B1, B2, B3, SZ, ^)
00127 
00128 /* store bitmap B2 & B3 into B1 */
00129 #define BITMAP_AND(B1, B2, B3, SZ)                              \
00130   __BITMAP_OP(B1, B2, B3, SZ, &)
00131 
00132 /* store ~B2 into B1 */
00133 #define BITMAP_NOT(B1, B2, SZ)                                  \
00134   { int i; for (i=0; i<(SZ); i++) (B1)[i] = ~((B2)[i]); }
00135 
00136 /* return non-zero if bitmap is empty */
00137 #define BITMAP_EMPTY_P(BMAP, SZ)                                \
00138   ({ int i, res=0; for (i=0; i<(SZ); i++) res |= (BMAP)[i]; !res; })
00139 
00140 /* return non-zero if the intersection of bitmaps B1 and B2 is non-empty */
00141 #define BITMAP_DISJOINT_P(B1, B2, SZ)                           \
00142   ({ int i, res=0; for (i=0; i<(SZ); i++) res |= (B1)[i] & (B2)[i]; !res; })
00143 
00144 /* return non-zero if bit BIT is set in bitmap BMAP */
00145 #define BITMAP_SET_P(BMAP, SZ, BIT)                             \
00146   (((BMAP)[(BIT)/32] & (1 << ((BIT) % 32))) != 0)
00147 
00148 /* return non-zero if bit BIT is clear in bitmap BMAP */
00149 #define BITMAP_CLEAR_P(BMAP, SZ, BIT)                           \
00150   (!BMAP_SET_P((BMAP), (SZ), (BIT)))
00151 
00152 /* count the number of bits set in BMAP */
00153 #define BITMAP_COUNT_ONES(BMAP, SZ)                             \
00154 ({                                                              \
00155   int i, j, n = 0;                                              \
00156   for (i = 0; i < (SZ) ; i++)                                   \
00157     {                                                           \
00158       unsigned int word = (BMAP)[i];                            \
00159       for (j=0; j < (sizeof(unsigned int)*8); j++)              \
00160         {                                                       \
00161           unsigned int new_val, old_val = word;                 \
00162           word >>= 1;                                           \
00163           new_val = word << 1;                                  \
00164           if (old_val != new_val)                               \
00165             n++;                                                \
00166         }                                                       \
00167     }                                                           \
00168   n;                                                            \
00169 })
00170 
00171 #endif /* BITMAP_H */
00172 

Generated on Fri Oct 22 2010 11:02:24 for SST by  doxygen 1.7.1