sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2008 Bart Van Assche |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | bart.vanassche@gmail.com |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include "pub_tool_basics.h" // Addr, SizeT |
| 27 | #include "pub_tool_debuginfo.h" // VG_(get_objname)() |
| 28 | #include "pub_tool_libcassert.h" // tl_assert() |
| 29 | #include "pub_tool_libcbase.h" // VG_(memset) |
| 30 | #include "pub_tool_libcprint.h" // VG_(printf) |
| 31 | #include "pub_tool_machine.h" // VG_(get_IP)() |
| 32 | #include "pub_tool_mallocfree.h" // VG_(malloc), VG_(free) |
| 33 | #include "pub_drd_bitmap.h" |
| 34 | #include "drd_bitmap.h" |
| 35 | #include "drd_error.h" |
| 36 | #include "drd_suppression.h" |
| 37 | |
| 38 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 39 | /* Forward declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 40 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 41 | struct bitmap2; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 42 | |
| 43 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 44 | /* Local function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 45 | |
| 46 | static void bm2_merge(struct bitmap2* const bm2l, |
| 47 | const struct bitmap2* const bm2r); |
| 48 | |
| 49 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 50 | /* Local constants. */ |
| 51 | |
| 52 | static ULong s_bitmap_creation_count; |
| 53 | |
| 54 | |
| 55 | /* Function definitions. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 56 | |
| 57 | struct bitmap* bm_new() |
| 58 | { |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 59 | unsigned i; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 60 | struct bitmap* bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 61 | |
bart | f29205e | 2008-03-25 18:51:06 +0000 | [diff] [blame] | 62 | /* If this assert fails, fix the definition of BITS_PER_BITS_PER_UWORD */ |
| 63 | /* in drd_bitmap.h. */ |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 64 | tl_assert((1 << BITS_PER_BITS_PER_UWORD) == BITS_PER_UWORD); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 65 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 66 | bm = VG_(malloc)(sizeof(*bm)); |
| 67 | tl_assert(bm); |
bart | f29205e | 2008-03-25 18:51:06 +0000 | [diff] [blame] | 68 | /* Cache initialization. a1 is initialized with a value that never can */ |
| 69 | /* match any valid address: the upper ADDR0_BITS bits of a1 are always */ |
| 70 | /* zero for a valid cache entry. */ |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 71 | for (i = 0; i < N_CACHE_ELEM; i++) |
| 72 | { |
bart | f29205e | 2008-03-25 18:51:06 +0000 | [diff] [blame] | 73 | bm->cache[i].a1 = ~(UWord)1; |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 74 | bm->cache[i].bm2 = 0; |
| 75 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 76 | bm->oset = VG_(OSetGen_Create)(0, 0, VG_(malloc), VG_(free)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 77 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 78 | s_bitmap_creation_count++; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 79 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 80 | return bm; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void bm_delete(struct bitmap* const bm) |
| 84 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 85 | struct bitmap2* bm2; |
| 86 | struct bitmap2ref* bm2ref; |
| 87 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 88 | tl_assert(bm); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 89 | |
| 90 | VG_(OSetGen_ResetIter)(bm->oset); |
| 91 | for ( ; (bm2ref = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
| 92 | { |
| 93 | bm2 = bm2ref->bm2; |
| 94 | tl_assert(bm2->refcnt >= 1); |
| 95 | if (--bm2->refcnt == 0) |
| 96 | { |
| 97 | VG_(free)(bm2); |
| 98 | } |
| 99 | } |
| 100 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 101 | VG_(OSetGen_Destroy)(bm->oset); |
| 102 | VG_(free)(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 106 | * Record an access of type access_type at addresses a .. a + size - 1 in |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 107 | * bitmap bm. |
| 108 | */ |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 109 | static |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 110 | void bm_access_range(struct bitmap* const bm, |
bart | 9036dea | 2008-03-13 19:10:06 +0000 | [diff] [blame] | 111 | const Addr a1, const Addr a2, |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 112 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 113 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 114 | Addr b, b_next; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 115 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 116 | tl_assert(bm); |
| 117 | tl_assert(a1 < a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 118 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 119 | for (b = a1; b < a2; b = b_next) |
| 120 | { |
| 121 | Addr b_start; |
| 122 | Addr b_end; |
| 123 | struct bitmap2* bm2; |
| 124 | SPLIT_ADDRESS(b); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 125 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 126 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 127 | if (b_next > a2) |
| 128 | { |
| 129 | b_next = a2; |
| 130 | } |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 131 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 132 | bm2 = bm2_lookup_or_insert_exclusive(bm, b1); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 133 | tl_assert(bm2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 134 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 135 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 136 | b_start = a1; |
| 137 | else |
| 138 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 139 | b_start = (bm2->addr << ADDR0_BITS); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 140 | else |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 141 | break; |
| 142 | tl_assert(a1 <= b_start && b_start <= a2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 143 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 144 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 145 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 146 | else |
| 147 | b_end = a2; |
| 148 | tl_assert(a1 <= b_end && b_end <= a2); |
| 149 | tl_assert(b_start < b_end); |
| 150 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 151 | |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 152 | if (access_type == eLoad) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 153 | { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 154 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++) |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 155 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 156 | bm0_set(bm2->bm1.bm0_r, b0); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 157 | } |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 158 | } |
| 159 | else |
| 160 | { |
| 161 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end - 1) & ADDR0_MASK); b0++) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 162 | { |
| 163 | bm0_set(bm2->bm1.bm0_w, b0); |
| 164 | } |
| 165 | } |
| 166 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 167 | } |
| 168 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 169 | static inline |
| 170 | void bm_access_aligned_load(struct bitmap* const bm, |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 171 | const Addr a1, const SizeT size) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 172 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 173 | struct bitmap2* bm2; |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 174 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 175 | bm2 = bm2_lookup_or_insert_exclusive(bm, a1 >> ADDR0_BITS); |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 176 | bm0_set_range(bm2->bm1.bm0_r, a1 & ADDR0_MASK, size); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static inline |
| 180 | void bm_access_aligned_store(struct bitmap* const bm, |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 181 | const Addr a1, const SizeT size) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 182 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 183 | struct bitmap2* bm2; |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 184 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 185 | bm2 = bm2_lookup_or_insert_exclusive(bm, a1 >> ADDR0_BITS); |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 186 | bm0_set_range(bm2->bm1.bm0_w, a1 & ADDR0_MASK, size); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 187 | } |
| 188 | |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 189 | void bm_access_range_load(struct bitmap* const bm, |
| 190 | const Addr a1, const Addr a2) |
| 191 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 192 | bm_access_range(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 193 | } |
| 194 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 195 | void bm_access_load_1(struct bitmap* const bm, const Addr a1) |
| 196 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 197 | bm_access_aligned_load(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void bm_access_load_2(struct bitmap* const bm, const Addr a1) |
| 201 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 202 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 203 | bm_access_aligned_load(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 204 | else |
| 205 | bm_access_range(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void bm_access_load_4(struct bitmap* const bm, const Addr a1) |
| 209 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 210 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 211 | bm_access_aligned_load(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 212 | else |
| 213 | bm_access_range(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void bm_access_load_8(struct bitmap* const bm, const Addr a1) |
| 217 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 218 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 219 | bm_access_aligned_load(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 220 | else if ((a1 & 3) == 0) |
| 221 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 222 | bm_access_aligned_load(bm, a1 + 0, 4); |
| 223 | bm_access_aligned_load(bm, a1 + 4, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 224 | } |
| 225 | else |
| 226 | bm_access_range(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void bm_access_store_1(struct bitmap* const bm, const Addr a1) |
| 230 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 231 | bm_access_aligned_store(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | void bm_access_store_2(struct bitmap* const bm, const Addr a1) |
| 235 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 236 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 237 | bm_access_aligned_store(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 238 | else |
| 239 | bm_access_range(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void bm_access_store_4(struct bitmap* const bm, const Addr a1) |
| 243 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 244 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 245 | bm_access_aligned_store(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 246 | else |
| 247 | bm_access_range(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void bm_access_store_8(struct bitmap* const bm, const Addr a1) |
| 251 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 252 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 253 | bm_access_aligned_store(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 254 | else if ((a1 & 3) == 0) |
| 255 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 256 | bm_access_aligned_store(bm, a1 + 0, 4); |
| 257 | bm_access_aligned_store(bm, a1 + 4, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 258 | } |
| 259 | else |
| 260 | bm_access_range(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 261 | } |
| 262 | |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 263 | void bm_access_range_store(struct bitmap* const bm, |
| 264 | const Addr a1, const Addr a2) |
| 265 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 266 | bm_access_range(bm, a1, a2, eStore); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | Bool bm_has(const struct bitmap* const bm, const Addr a1, const Addr a2, |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 270 | const BmAccessTypeT access_type) |
| 271 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 272 | Addr b; |
| 273 | for (b = a1; b < a2; b++) |
| 274 | { |
| 275 | if (! bm_has_1(bm, b, access_type)) |
| 276 | { |
| 277 | return False; |
| 278 | } |
| 279 | } |
| 280 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 281 | } |
| 282 | |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame^] | 283 | Bool bm_has_any_load(const struct bitmap* const bm, |
| 284 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 285 | { |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame^] | 286 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 287 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 288 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 289 | |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame^] | 290 | for (b = a1; b < a2; b = b_next) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 291 | { |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame^] | 292 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
| 293 | |
| 294 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 295 | if (b_next > a2) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 296 | { |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame^] | 297 | b_next = a2; |
| 298 | } |
| 299 | |
| 300 | if (bm2) |
| 301 | { |
| 302 | Addr b_start; |
| 303 | Addr b_end; |
| 304 | UWord b0; |
| 305 | const struct bitmap1* const p1 = &bm2->bm1; |
| 306 | |
| 307 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 308 | b_start = a1; |
| 309 | else |
| 310 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 311 | b_start = (bm2->addr << ADDR0_BITS); |
| 312 | else |
| 313 | break; |
| 314 | tl_assert(a1 <= b_start && b_start <= a2); |
| 315 | |
| 316 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 317 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 318 | else |
| 319 | b_end = a2; |
| 320 | tl_assert(a1 <= b_end && b_end <= a2); |
| 321 | tl_assert(b_start < b_end); |
| 322 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 323 | |
| 324 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 325 | { |
| 326 | if (bm0_is_set(p1->bm0_r, b0)) |
| 327 | { |
| 328 | return True; |
| 329 | } |
| 330 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 331 | } |
| 332 | } |
bart | d490707 | 2008-03-30 18:41:07 +0000 | [diff] [blame^] | 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | Bool bm_has_any_store(const struct bitmap* const bm, |
| 337 | const Addr a1, const Addr a2) |
| 338 | { |
| 339 | Addr b, b_next; |
| 340 | |
| 341 | tl_assert(bm); |
| 342 | |
| 343 | for (b = a1; b < a2; b = b_next) |
| 344 | { |
| 345 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
| 346 | |
| 347 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 348 | if (b_next > a2) |
| 349 | { |
| 350 | b_next = a2; |
| 351 | } |
| 352 | |
| 353 | if (bm2) |
| 354 | { |
| 355 | Addr b_start; |
| 356 | Addr b_end; |
| 357 | UWord b0; |
| 358 | const struct bitmap1* const p1 = &bm2->bm1; |
| 359 | |
| 360 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 361 | b_start = a1; |
| 362 | else |
| 363 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 364 | b_start = (bm2->addr << ADDR0_BITS); |
| 365 | else |
| 366 | break; |
| 367 | tl_assert(a1 <= b_start && b_start <= a2); |
| 368 | |
| 369 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 370 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 371 | else |
| 372 | b_end = a2; |
| 373 | tl_assert(a1 <= b_end && b_end <= a2); |
| 374 | tl_assert(b_start < b_end); |
| 375 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
| 376 | |
| 377 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 378 | { |
| 379 | if (bm0_is_set(p1->bm0_w, b0)) |
| 380 | { |
| 381 | return True; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /* Return a non-zero value if there is a read access, write access or both */ |
| 390 | /* to any of the addresses in the range [ a1, a2 [ in bitmap bm. */ |
| 391 | UWord bm_has_any_access(const struct bitmap* const bm, |
| 392 | const Addr a1, |
| 393 | const Addr a2) |
| 394 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 395 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 396 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 397 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 398 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 399 | for (b = a1; b < a2; b = b_next) |
| 400 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 401 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 402 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 403 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 404 | if (b_next > a2) |
| 405 | { |
| 406 | b_next = a2; |
| 407 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 408 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 409 | if (bm2) |
| 410 | { |
| 411 | Addr b_start; |
| 412 | Addr b_end; |
| 413 | UWord b0; |
| 414 | const struct bitmap1* const p1 = &bm2->bm1; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 415 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 416 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 417 | b_start = a1; |
| 418 | else |
| 419 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 420 | b_start = (bm2->addr << ADDR0_BITS); |
| 421 | else |
| 422 | break; |
| 423 | tl_assert(a1 <= b_start && b_start <= a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 424 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 425 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 426 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 427 | else |
| 428 | b_end = a2; |
| 429 | tl_assert(a1 <= b_end && b_end <= a2); |
| 430 | tl_assert(b_start < b_end); |
| 431 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 433 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 434 | { |
| 435 | const UWord mask |
| 436 | = bm0_is_set(p1->bm0_r, b0) | bm0_is_set(p1->bm0_w, b0); |
| 437 | if (mask) |
| 438 | { |
| 439 | return mask; |
| 440 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 441 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Report whether an access of type access_type at address a is recorded in |
| 449 | * bitmap bm. |
| 450 | * @return != 0 means true, and == 0 means false |
| 451 | */ |
| 452 | UWord bm_has_1(const struct bitmap* const bm, |
| 453 | const Addr a, |
| 454 | const BmAccessTypeT access_type) |
| 455 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 456 | const struct bitmap2* p2; |
| 457 | const struct bitmap1* p1; |
| 458 | const UWord* p0; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 459 | const UWord a0 = a & ADDR0_MASK; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 460 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 461 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 462 | |
bart | 11d0b50 | 2008-03-22 16:44:03 +0000 | [diff] [blame] | 463 | p2 = bm2_lookup(bm, a >> ADDR0_BITS); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 464 | if (p2) |
| 465 | { |
| 466 | p1 = &p2->bm1; |
| 467 | p0 = (access_type == eLoad) ? p1->bm0_r : p1->bm0_w; |
| 468 | return bm0_is_set(p0, a0); |
| 469 | } |
| 470 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 471 | } |
| 472 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 473 | void bm_clear(const struct bitmap* const bm, |
| 474 | const Addr a1, |
| 475 | const Addr a2) |
| 476 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 477 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 478 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 479 | tl_assert(bm); |
| 480 | tl_assert(a1); |
| 481 | tl_assert(a1 <= a2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 482 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 483 | for (b = a1; b < a2; b = b_next) |
| 484 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 485 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, b >> ADDR0_BITS); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 486 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 487 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 488 | if (b_next > a2) |
| 489 | { |
| 490 | b_next = a2; |
| 491 | } |
| 492 | |
| 493 | if (p2) |
| 494 | { |
| 495 | Addr c = b; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 496 | /* If the first address in the bitmap that must be cleared does not */ |
bart | 5955f33 | 2008-03-25 17:19:20 +0000 | [diff] [blame] | 497 | /* start on an UWord boundary, start clearing the first addresses. */ |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 498 | if (UWORD_LSB(c)) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 499 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 500 | Addr c_next = UWORD_MSB(c) + BITS_PER_UWORD; |
| 501 | if (c_next > b_next) |
| 502 | c_next = b_next; |
bart | 5955f33 | 2008-03-25 17:19:20 +0000 | [diff] [blame] | 503 | bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, c_next - c); |
| 504 | bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, c_next - c); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 505 | c = c_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 506 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 507 | /* If some UWords have to be cleared entirely, do this now. */ |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 508 | if (UWORD_LSB(c) == 0) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 509 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 510 | const Addr c_next = UWORD_MSB(b_next); |
| 511 | tl_assert(UWORD_LSB(c) == 0); |
| 512 | tl_assert(UWORD_LSB(c_next) == 0); |
| 513 | tl_assert(c_next <= b_next); |
| 514 | tl_assert(c <= c_next); |
| 515 | if (c_next > c) |
| 516 | { |
| 517 | UWord idx = (c & ADDR0_MASK) >> BITS_PER_BITS_PER_UWORD; |
| 518 | VG_(memset)(&p2->bm1.bm0_r[idx], 0, (c_next - c) / 8); |
| 519 | VG_(memset)(&p2->bm1.bm0_w[idx], 0, (c_next - c) / 8); |
| 520 | c = c_next; |
| 521 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 522 | } |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 523 | /* If the last address in the bitmap that must be cleared does not */ |
bart | 5955f33 | 2008-03-25 17:19:20 +0000 | [diff] [blame] | 524 | /* fall on an UWord boundary, clear the last addresses. */ |
| 525 | /* tl_assert(c <= b_next); */ |
| 526 | bm0_clear_range(p2->bm1.bm0_r, c & ADDR0_MASK, b_next - c); |
| 527 | bm0_clear_range(p2->bm1.bm0_w, c & ADDR0_MASK, b_next - c); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 530 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 531 | |
bart | 9c4224c | 2008-03-29 14:40:08 +0000 | [diff] [blame] | 532 | /** Clear all references to loads in bitmap bm starting at address a1 and |
| 533 | * up to but not including address a2. |
| 534 | */ |
| 535 | void bm_clear_load(const struct bitmap* const bm, |
| 536 | const Addr a1, const Addr a2) |
| 537 | { |
| 538 | Addr a; |
| 539 | |
| 540 | for (a = a1; a < a2; a++) |
| 541 | { |
| 542 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, a >> ADDR0_BITS); |
| 543 | if (p2) |
| 544 | { |
| 545 | bm0_clear(p2->bm1.bm0_r, a & ADDR0_MASK); |
| 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /** Clear all references to stores in bitmap bm starting at address a1 and |
| 551 | * up to but not including address a2. |
| 552 | */ |
| 553 | void bm_clear_store(const struct bitmap* const bm, |
| 554 | const Addr a1, const Addr a2) |
| 555 | { |
| 556 | Addr a; |
| 557 | |
| 558 | for (a = a1; a < a2; a++) |
| 559 | { |
| 560 | struct bitmap2* const p2 = bm2_lookup_exclusive(bm, a >> ADDR0_BITS); |
| 561 | if (p2) |
| 562 | { |
| 563 | bm0_clear(p2->bm1.bm0_w, a & ADDR0_MASK); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
bart | 8bf2f8b | 2008-03-30 17:56:43 +0000 | [diff] [blame] | 568 | /** Clear bitmap bm starting at address a1 and up to but not including address |
| 569 | * a2. Return True if and only if any of the addresses was set before |
| 570 | * clearing. |
| 571 | */ |
| 572 | Bool bm_test_and_clear(const struct bitmap* const bm, |
| 573 | const Addr a1, const Addr a2) |
| 574 | { |
| 575 | Bool result; |
| 576 | |
| 577 | result = bm_has_any_access(bm, a1, a2) != 0; |
| 578 | bm_clear(bm, a1, a2); |
| 579 | return result; |
| 580 | } |
| 581 | |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 582 | Bool bm_has_conflict_with(const struct bitmap* const bm, |
| 583 | const Addr a1, const Addr a2, |
| 584 | const BmAccessTypeT access_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 585 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 586 | Addr b, b_next; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 587 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 588 | tl_assert(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 589 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 590 | for (b = a1; b < a2; b = b_next) |
| 591 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 592 | const struct bitmap2* bm2 = bm2_lookup(bm, b >> ADDR0_BITS); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 593 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 594 | b_next = (b & ~ADDR0_MASK) + ADDR0_COUNT; |
| 595 | if (b_next > a2) |
| 596 | { |
| 597 | b_next = a2; |
| 598 | } |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 599 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 600 | if (bm2) |
| 601 | { |
| 602 | Addr b_start; |
| 603 | Addr b_end; |
| 604 | UWord b0; |
| 605 | const struct bitmap1* const p1 = &bm2->bm1; |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 606 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 607 | if ((bm2->addr << ADDR0_BITS) < a1) |
| 608 | b_start = a1; |
| 609 | else |
| 610 | if ((bm2->addr << ADDR0_BITS) < a2) |
| 611 | b_start = (bm2->addr << ADDR0_BITS); |
| 612 | else |
| 613 | break; |
| 614 | tl_assert(a1 <= b_start && b_start <= a2); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 615 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 616 | if ((bm2->addr << ADDR0_BITS) + ADDR0_COUNT < a2) |
| 617 | b_end = (bm2->addr << ADDR0_BITS) + ADDR0_COUNT; |
| 618 | else |
| 619 | b_end = a2; |
| 620 | tl_assert(a1 <= b_end && b_end <= a2); |
| 621 | tl_assert(b_start < b_end); |
| 622 | tl_assert((b_start & ADDR0_MASK) <= ((b_end - 1) & ADDR0_MASK)); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 623 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 624 | for (b0 = b_start & ADDR0_MASK; b0 <= ((b_end-1) & ADDR0_MASK); b0++) |
| 625 | { |
| 626 | if (access_type == eLoad) |
| 627 | { |
| 628 | if (bm0_is_set(p1->bm0_w, b0)) |
| 629 | { |
| 630 | return True; |
| 631 | } |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | tl_assert(access_type == eStore); |
| 636 | if (bm0_is_set(p1->bm0_r, b0) |
| 637 | | bm0_is_set(p1->bm0_w, b0)) |
| 638 | { |
| 639 | return True; |
| 640 | } |
| 641 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 642 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | return False; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 646 | } |
| 647 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 648 | static inline |
| 649 | Bool bm_aligned_load_has_conflict_with(const struct bitmap* const bm, |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 650 | const Addr a1, const SizeT size) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 651 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 652 | const struct bitmap2* bm2; |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 653 | |
bart | 11d0b50 | 2008-03-22 16:44:03 +0000 | [diff] [blame] | 654 | bm2 = bm2_lookup(bm, a1 >> ADDR0_BITS); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 655 | |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 656 | return (bm2 && bm0_is_any_set(bm2->bm1.bm0_w, a1 & ADDR0_MASK, size)); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static inline |
| 660 | Bool bm_aligned_store_has_conflict_with(const struct bitmap* const bm, |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 661 | const Addr a1, const SizeT size) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 662 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 663 | const struct bitmap2* bm2; |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 664 | |
bart | 11d0b50 | 2008-03-22 16:44:03 +0000 | [diff] [blame] | 665 | bm2 = bm2_lookup(bm, a1 >> ADDR0_BITS); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 666 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 667 | if (bm2) |
| 668 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 669 | if (bm0_is_any_set(bm2->bm1.bm0_r, a1 & ADDR0_MASK, size) |
| 670 | | bm0_is_any_set(bm2->bm1.bm0_w, a1 & ADDR0_MASK, size)) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 671 | { |
| 672 | return True; |
| 673 | } |
| 674 | } |
| 675 | return False; |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 676 | } |
| 677 | |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 678 | Bool bm_load_has_conflict_with(const struct bitmap* const bm, |
| 679 | const Addr a1, const Addr a2) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 680 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 681 | return bm_has_conflict_with(bm, a1, a2, eLoad); |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 682 | } |
| 683 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 684 | Bool bm_load_1_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 685 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 686 | return bm_aligned_load_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | Bool bm_load_2_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 690 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 691 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 692 | return bm_aligned_load_has_conflict_with(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 693 | else |
| 694 | return bm_has_conflict_with(bm, a1, a1 + 2, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | Bool bm_load_4_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 698 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 699 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 700 | return bm_aligned_load_has_conflict_with(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 701 | else |
| 702 | return bm_has_conflict_with(bm, a1, a1 + 4, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | Bool bm_load_8_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 706 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 707 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 708 | return bm_aligned_load_has_conflict_with(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 709 | else |
| 710 | return bm_has_conflict_with(bm, a1, a1 + 8, eLoad); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | Bool bm_store_1_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 714 | { |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 715 | return bm_aligned_store_has_conflict_with(bm, a1, 1); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | Bool bm_store_2_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 719 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 720 | if ((a1 & 1) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 721 | return bm_aligned_store_has_conflict_with(bm, a1, 2); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 722 | else |
| 723 | return bm_has_conflict_with(bm, a1, a1 + 2, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | Bool bm_store_4_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 727 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 728 | if ((a1 & 3) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 729 | return bm_aligned_store_has_conflict_with(bm, a1, 4); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 730 | else |
| 731 | return bm_has_conflict_with(bm, a1, a1 + 4, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | Bool bm_store_8_has_conflict_with(const struct bitmap* const bm, const Addr a1) |
| 735 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 736 | if ((a1 & 7) == 0) |
bart | f8bc71d | 2008-03-15 11:42:34 +0000 | [diff] [blame] | 737 | return bm_aligned_store_has_conflict_with(bm, a1, 8); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 738 | else |
| 739 | return bm_has_conflict_with(bm, a1, a1 + 8, eStore); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 740 | } |
| 741 | |
bart | 3655612 | 2008-03-13 19:24:30 +0000 | [diff] [blame] | 742 | Bool bm_store_has_conflict_with(const struct bitmap* const bm, |
| 743 | const Addr a1, const Addr a2) |
| 744 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 745 | return bm_has_conflict_with(bm, a1, a2, eStore); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | void bm_swap(struct bitmap* const bm1, struct bitmap* const bm2) |
| 749 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 750 | OSet* const tmp = bm1->oset; |
| 751 | bm1->oset = bm2->oset; |
| 752 | bm2->oset = tmp; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 753 | } |
| 754 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 755 | /** Merge bitmaps *lhs and *rhs into *lhs. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 756 | void bm_merge2(struct bitmap* const lhs, |
| 757 | const struct bitmap* const rhs) |
| 758 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 759 | struct bitmap2* bm2l; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 760 | struct bitmap2ref* bm2l_ref; |
| 761 | struct bitmap2* bm2r; |
| 762 | const struct bitmap2ref* bm2r_ref; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 763 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 764 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 765 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 766 | for ( ; (bm2r_ref = VG_(OSetGen_Next)(rhs->oset)) != 0; ) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 767 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 768 | bm2r = bm2r_ref->bm2; |
| 769 | bm2l_ref = VG_(OSetGen_Lookup)(lhs->oset, &bm2r->addr); |
| 770 | if (bm2l_ref) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 771 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 772 | bm2l = bm2l_ref->bm2; |
| 773 | if (bm2l != bm2r) |
| 774 | { |
| 775 | if (bm2l->refcnt > 1) |
| 776 | bm2l = bm2_make_exclusive(lhs, bm2l_ref); |
| 777 | bm2_merge(bm2l, bm2r); |
| 778 | } |
| 779 | } |
| 780 | else |
| 781 | { |
| 782 | bm2_insert_addref(lhs, bm2r); |
| 783 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 784 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /** |
| 788 | * Report whether there are any RW / WR / WW patterns in lhs and rhs. |
| 789 | * @param lhs First bitmap. |
| 790 | * @param rhs Bitmap to be compared with lhs. |
| 791 | * @return !=0 if there are data races, == 0 if there are none. |
| 792 | */ |
| 793 | int bm_has_races(const struct bitmap* const lhs, |
| 794 | const struct bitmap* const rhs) |
| 795 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 796 | VG_(OSetGen_ResetIter)(lhs->oset); |
| 797 | VG_(OSetGen_ResetIter)(rhs->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 798 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 799 | for (;;) |
| 800 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 801 | const struct bitmap2ref* bm2l_ref; |
| 802 | const struct bitmap2ref* bm2r_ref; |
| 803 | const struct bitmap2* bm2l; |
| 804 | const struct bitmap2* bm2r; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 805 | const struct bitmap1* bm1l; |
| 806 | const struct bitmap1* bm1r; |
| 807 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 808 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 809 | bm2l_ref = VG_(OSetGen_Next)(lhs->oset); |
| 810 | bm2l = bm2l_ref->bm2; |
| 811 | bm2r_ref = VG_(OSetGen_Next)(rhs->oset); |
| 812 | bm2r = bm2r_ref->bm2; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 813 | while (bm2l && bm2r && bm2l->addr != bm2r->addr) |
| 814 | { |
| 815 | if (bm2l->addr < bm2r->addr) |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 816 | bm2l = (bm2l_ref = VG_(OSetGen_Next)(lhs->oset))->bm2; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 817 | else |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 818 | bm2r = (bm2r_ref = VG_(OSetGen_Next)(rhs->oset))->bm2; |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 819 | } |
| 820 | if (bm2l == 0 || bm2r == 0) |
| 821 | break; |
| 822 | |
| 823 | bm1l = &bm2l->bm1; |
| 824 | bm1r = &bm2r->bm1; |
| 825 | |
| 826 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 827 | { |
| 828 | unsigned b; |
| 829 | for (b = 0; b < BITS_PER_UWORD; b++) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 830 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 831 | UWord const access |
| 832 | = ((bm1l->bm0_r[k] & bm0_mask(b)) ? LHS_R : 0) |
| 833 | | ((bm1l->bm0_w[k] & bm0_mask(b)) ? LHS_W : 0) |
| 834 | | ((bm1r->bm0_r[k] & bm0_mask(b)) ? RHS_R : 0) |
| 835 | | ((bm1r->bm0_w[k] & bm0_mask(b)) ? RHS_W : 0); |
| 836 | Addr const a = MAKE_ADDRESS(bm2l->addr, k * BITS_PER_UWORD | b); |
| 837 | if (HAS_RACE(access) && ! drd_is_suppressed(a, a + 1)) |
| 838 | { |
| 839 | return 1; |
| 840 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 841 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | return 0; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 845 | } |
| 846 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 847 | void bm_print(const struct bitmap* const bm) |
| 848 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 849 | struct bitmap2* bm2; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 850 | struct bitmap2ref* bm2ref; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 851 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 852 | VG_(OSetGen_ResetIter)(bm->oset); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 853 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 854 | for ( ; (bm2ref = VG_(OSetGen_Next)(bm->oset)) != 0; ) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 855 | { |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 856 | const struct bitmap1* bm1; |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 857 | unsigned b; |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 858 | |
| 859 | bm2 = bm2ref->bm2; |
| 860 | bm1 = &bm2->bm1; |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 861 | for (b = 0; b < ADDR0_COUNT; b++) |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 862 | { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 863 | const Addr a = (bm2->addr << ADDR0_BITS) | b; |
| 864 | const Bool r = bm0_is_set(bm1->bm0_r, b) != 0; |
| 865 | const Bool w = bm0_is_set(bm1->bm0_w, b) != 0; |
| 866 | if (r || w) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 867 | { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 868 | VG_(printf)("0x%08lx %c %c\n", |
| 869 | a, |
| 870 | w ? 'W' : ' ', |
| 871 | r ? 'R' : ' '); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 872 | } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | ULong bm_get_bitmap_creation_count(void) |
| 878 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 879 | return s_bitmap_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | ULong bm_get_bitmap2_creation_count(void) |
| 883 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 884 | return s_bitmap2_creation_count; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 885 | } |
| 886 | |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 887 | /** Allocate and initialize a second level bitmap. */ |
| 888 | static struct bitmap2* bm2_new(const UWord a1) |
| 889 | { |
| 890 | struct bitmap2* bm2; |
| 891 | |
| 892 | bm2 = VG_(malloc)(sizeof(*bm2)); |
| 893 | bm2->addr = a1; |
| 894 | bm2->refcnt = 1; |
| 895 | |
| 896 | s_bitmap2_creation_count++; |
| 897 | |
| 898 | return bm2; |
| 899 | } |
| 900 | |
| 901 | /** Make a copy of a shared second level bitmap such that the copy can be |
| 902 | * modified. |
| 903 | * |
| 904 | * @param a1 client address shifted right by ADDR0_BITS. |
| 905 | * @param bm bitmap pointer. |
| 906 | */ |
| 907 | static |
| 908 | struct bitmap2* bm2_make_exclusive(struct bitmap* const bm, |
| 909 | struct bitmap2ref* const bm2ref) |
| 910 | { |
| 911 | UWord a1; |
| 912 | struct bitmap2* bm2; |
| 913 | struct bitmap2* bm2_copy; |
| 914 | |
| 915 | tl_assert(bm); |
| 916 | tl_assert(bm2ref); |
| 917 | bm2 = bm2ref->bm2; |
| 918 | tl_assert(bm2); |
| 919 | tl_assert(bm2->refcnt > 1); |
| 920 | bm2->refcnt--; |
| 921 | tl_assert(bm2->refcnt >= 1); |
| 922 | a1 = bm2->addr; |
| 923 | bm2_copy = bm2_new(a1); |
| 924 | tl_assert(bm2_copy); |
| 925 | tl_assert(bm2_copy->addr == a1); |
| 926 | tl_assert(bm2_copy->refcnt == 1); |
| 927 | VG_(memcpy)(&bm2_copy->bm1, &bm2->bm1, sizeof(bm2->bm1)); |
| 928 | bm2ref->bm2 = bm2_copy; |
| 929 | |
| 930 | bm_update_cache(bm, a1, bm2_copy); |
| 931 | |
| 932 | return bm2_copy; |
| 933 | } |
| 934 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 935 | static void bm2_merge(struct bitmap2* const bm2l, |
| 936 | const struct bitmap2* const bm2r) |
| 937 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 938 | unsigned k; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 939 | |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 940 | tl_assert(bm2l); |
| 941 | tl_assert(bm2r); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 942 | tl_assert(bm2l->addr == bm2r->addr); |
bart | f647d34 | 2008-03-24 19:12:12 +0000 | [diff] [blame] | 943 | tl_assert(bm2l->refcnt == 1); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 944 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 945 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 946 | { |
| 947 | bm2l->bm1.bm0_r[k] |= bm2r->bm1.bm0_r[k]; |
| 948 | } |
| 949 | for (k = 0; k < BITMAP1_UWORD_COUNT; k++) |
| 950 | { |
| 951 | bm2l->bm1.bm0_w[k] |= bm2r->bm1.bm0_w[k]; |
| 952 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | #if 0 |
| 956 | |
| 957 | /* Unit test */ |
| 958 | static |
| 959 | struct { Addr address; SizeT size; BmAccessTypeT access_type; } |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 960 | s_args[] = { |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 961 | { 0 + ADDR0_COUNT, 1, eLoad }, |
| 962 | { 666 + ADDR0_COUNT, 4, eLoad }, |
| 963 | { 667 + ADDR0_COUNT, 2, eStore }, |
bart | 33e56c9 | 2008-03-24 06:41:30 +0000 | [diff] [blame] | 964 | { -2 + 2*ADDR0_COUNT, 1, eStore }, |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 965 | { 0x0001ffffUL, 1, eLoad }, |
| 966 | { 0x0002ffffUL, 1, eLoad }, |
| 967 | { 0x00ffffffUL, 1, eLoad }, |
| 968 | { 0xffffffffUL, 1, eStore }, |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 969 | }; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 970 | |
| 971 | void bm_test(void) |
| 972 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 973 | struct bitmap* bm; |
| 974 | struct bitmap* bm2; |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 975 | unsigned i, j; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 976 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 977 | VG_(printf)("Start of DRD BM unit test.\n"); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 978 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 979 | bm = bm_new(); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 980 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 981 | for (i = 0; i < sizeof(s_args)/sizeof(s_args[0]); i++) |
| 982 | { |
| 983 | bm_access_range(bm, |
| 984 | s_args[i].address, |
| 985 | s_args[i].address + s_args[i].size, |
| 986 | s_args[i].access_type); |
| 987 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 988 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 989 | VG_(printf)("Map contents -- should contain 10 addresses:\n"); |
| 990 | bm_print(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 991 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 992 | for (i = 0; i < sizeof(s_args)/sizeof(s_args[0]); i++) |
| 993 | { |
| 994 | for (j = 0; j < s_args[i].size; j++) |
| 995 | { |
| 996 | tl_assert(bm_has_1(bm, s_args[i].address + j, s_args[i].access_type)); |
| 997 | } |
| 998 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 999 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1000 | VG_(printf)("Merge result:\n"); |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 1001 | bm2 = bm_new(); |
| 1002 | bm_merge2(bm2, bm); |
| 1003 | bm_merge2(bm2, bm); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1004 | bm_print(bm); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1005 | |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 1006 | VG_(printf)("Deleting bitmap bm\n"); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1007 | bm_delete(bm); |
bart | 0008f5b | 2008-03-22 17:07:39 +0000 | [diff] [blame] | 1008 | VG_(printf)("Deleting bitmap bm2\n"); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1009 | bm_delete(bm2); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1010 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 1011 | VG_(printf)("End of DRD BM unit test.\n"); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1012 | } |
| 1013 | #endif |