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 2003/09/18 00:57:54 panalyzer Exp $ 00053 * 00054 * $Log: bitmap.h,v $ 00055 * Revision 1.1.1.1 2003/09/18 00:57:54 panalyzer 00056 * 00057 * 00058 * Revision 1.1.1.1 2003/09/18 00:18:43 panalyzer 00059 * 00060 * 00061 * Revision 1.1.1.1 2003/09/16 18:48:14 gdm 00062 * 00063 * 00064 * Revision 1.1.1.1 2000/11/29 14:53:54 cu-cs 00065 * Grand unification of arm sources. 00066 * 00067 * 00068 * Revision 1.1.1.1 2000/05/26 15:18:57 taustin 00069 * SimpleScalar Tool Set 00070 * 00071 * 00072 * Revision 1.4 1998/08/27 07:45:12 taustin 00073 * BITMAP_COUNT_ONES() added 00074 * BITMAP_NOT() fixed 00075 * 00076 * Revision 1.3 1997/03/11 01:06:06 taustin 00077 * updated copyright 00078 * long/int tweaks made for ALPHA target support 00079 * 00080 * Revision 1.1 1996/12/05 18:44:19 taustin 00081 * Initial revision 00082 * 00083 */ 00084 00085 #ifndef BITMAP_H 00086 #define BITMAP_H 00087 00088 /* BITMAPs: 00089 BMAP: int * to an array of ints 00090 SZ: number of ints in the bitmap 00091 */ 00092 00093 /* declare a bitmap type */ 00094 #define BITMAP_SIZE(BITS) (((BITS)+31)/32) 00095 #define BITMAP_TYPE(BITS, NAME) unsigned int (NAME)[BITMAP_SIZE(BITS)] 00096 00097 typedef unsigned int BITMAP_ENT_TYPE; 00098 typedef unsigned int *BITMAP_PTR_TYPE; 00099 00100 /* set entire bitmap */ 00101 #define BITMAP_SET_MAP(BMAP, SZ) \ 00102 { int i; for (i=0; i<(SZ); i++) (BMAP)[i] = 0xffffffff; } 00103 00104 /* clear entire bitmap */ 00105 #define BITMAP_CLEAR_MAP(BMAP, SZ) \ 00106 { int i; for (i=0; i<(SZ); i++) (BMAP)[i] = 0; } 00107 00108 /* set bit BIT in bitmap BMAP, returns BMAP */ 00109 #define BITMAP_SET(BMAP, SZ, BIT) \ 00110 (((BMAP)[(BIT)/32] |= (1 << ((BIT) % 32))), (BMAP)) 00111 00112 /* clear bit BIT in bitmap BMAP, returns BMAP */ 00113 #define BITMAP_CLEAR(BMAP, SZ, BIT) \ 00114 (((BMAP)[(BIT)/32] &= ~(1 << ((BIT) % 32))), (BMAP)) 00115 00116 /* copy bitmap SRC to DEST */ 00117 #define BITMAP_COPY(DESTMAP, SRCMAP, SZ) \ 00118 { int i; for (i=0; i<(SZ); i++) (DESTMAP)[i] = (SRCMAP)[i]; } 00119 00120 /* store bitmap B2 OP B3 into B1 */ 00121 #define __BITMAP_OP(B1, B2, B3, SZ, OP) \ 00122 { int i; for (i=0; i<(SZ); i++) (B1)[i] = (B2)[i] OP (B3)[i]; } 00123 00124 /* store bitmap B2 | B3 into B1 */ 00125 #define BITMAP_IOR(B1, B2, B3, SZ) \ 00126 __BITMAP_OP(B1, B2, B3, SZ, |) 00127 00128 /* store bitmap B2 ^ B3 into B1 */ 00129 #define BITMAP_XOR(B1, B2, B3, SZ) \ 00130 __BITMAP_OP(B1, B2, B3, SZ, ^) 00131 00132 /* store bitmap B2 & B3 into B1 */ 00133 #define BITMAP_AND(B1, B2, B3, SZ) \ 00134 __BITMAP_OP(B1, B2, B3, SZ, &) 00135 00136 /* store ~B2 into B1 */ 00137 #define BITMAP_NOT(B1, B2, SZ) \ 00138 { int i; for (i=0; i<(SZ); i++) (B1)[i] = ~((B2)[i]); } 00139 00140 /* return non-zero if bitmap is empty */ 00141 #define BITMAP_EMPTY_P(BMAP, SZ) \ 00142 ({ int i, res=0; for (i=0; i<(SZ); i++) res |= (BMAP)[i]; !res; }) 00143 00144 /* return non-zero if the intersection of bitmaps B1 and B2 is non-empty */ 00145 #define BITMAP_DISJOINT_P(B1, B2, SZ) \ 00146 ({ int i, res=0; for (i=0; i<(SZ); i++) res |= (B1)[i] & (B2)[i]; !res; }) 00147 00148 /* return non-zero if bit BIT is set in bitmap BMAP */ 00149 #define BITMAP_SET_P(BMAP, SZ, BIT) \ 00150 (((BMAP)[(BIT)/32] & (1 << ((BIT) % 32))) != 0) 00151 00152 /* return non-zero if bit BIT is clear in bitmap BMAP */ 00153 #define BITMAP_CLEAR_P(BMAP, SZ, BIT) \ 00154 (!BMAP_SET_P((BMAP), (SZ), (BIT))) 00155 00156 /* count the number of bits set in BMAP */ 00157 #define BITMAP_COUNT_ONES(BMAP, SZ) \ 00158 ({ \ 00159 int i, j, n = 0; \ 00160 for (i = 0; i < (SZ) ; i++) \ 00161 { \ 00162 unsigned int word = (BMAP)[i]; \ 00163 for (j=0; j < (sizeof(unsigned int)*8); j++) \ 00164 { \ 00165 unsigned int new_val, old_val = word; \ 00166 word >>= 1; \ 00167 new_val = word << 1; \ 00168 if (old_val != new_val) \ 00169 n++; \ 00170 } \ 00171 } \ 00172 n; \ 00173 }) 00174 00175 #endif /* BITMAP_H */ 00176