Lines Matching refs:wsu
186 static WordVec* new_WV_of_size ( WordSetU* wsu, UWord sz ) in new_WV_of_size() argument
190 wv = wsu->alloc( wsu->cc, sizeof(WordVec) ); in new_WV_of_size()
191 wv->owner = wsu; in new_WV_of_size()
195 wv->words = wsu->alloc( wsu->cc, (SizeT)sz * sizeof(UWord) ); in new_WV_of_size()
239 static void ensure_ix2vec_space ( WordSetU* wsu ) in ensure_ix2vec_space() argument
243 tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); in ensure_ix2vec_space()
244 if (wsu->ix2vec_used < wsu->ix2vec_size) in ensure_ix2vec_space()
246 new_sz = 2 * wsu->ix2vec_size; in ensure_ix2vec_space()
248 new_vec = wsu->alloc( wsu->cc, new_sz * sizeof(WordVec*) ); in ensure_ix2vec_space()
250 for (i = 0; i < wsu->ix2vec_size; i++) in ensure_ix2vec_space()
251 new_vec[i] = wsu->ix2vec[i]; in ensure_ix2vec_space()
252 if (wsu->ix2vec) in ensure_ix2vec_space()
253 wsu->dealloc(wsu->ix2vec); in ensure_ix2vec_space()
254 wsu->ix2vec = new_vec; in ensure_ix2vec_space()
255 wsu->ix2vec_size = new_sz; in ensure_ix2vec_space()
260 static inline Bool is_dead ( WordSetU* wsu, WordVec* wv ) in is_dead() argument
265 return (WordVec**)wv >= &(wsu->ix2vec[1]) in is_dead()
266 && (WordVec**)wv < &(wsu->ix2vec[wsu->ix2vec_size]); in is_dead()
272 static WordVec* do_ix2vec ( WordSetU* wsu, WordSet ws ) in do_ix2vec() argument
275 tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); in do_ix2vec()
276 if (wsu->ix2vec_used > 0) in do_ix2vec()
277 tl_assert(wsu->ix2vec); in do_ix2vec()
280 tl_assert(ws < wsu->ix2vec_used); /* XXX */ in do_ix2vec()
281 wv = wsu->ix2vec[ws]; in do_ix2vec()
284 tl_assert(!is_dead(wsu,wv)); in do_ix2vec()
285 tl_assert(wv->owner == wsu); /* YYY */ in do_ix2vec()
290 static WordVec* do_ix2vec_with_dead ( WordSetU* wsu, WordSet ws ) in do_ix2vec_with_dead() argument
293 tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); in do_ix2vec_with_dead()
294 if (wsu->ix2vec_used > 0) in do_ix2vec_with_dead()
295 tl_assert(wsu->ix2vec); in do_ix2vec_with_dead()
298 tl_assert(ws < wsu->ix2vec_used); /* XXX */ in do_ix2vec_with_dead()
299 wv = wsu->ix2vec[ws]; in do_ix2vec_with_dead()
301 if (is_dead(wsu,wv)) in do_ix2vec_with_dead()
304 tl_assert(wv->owner == wsu); /* YYY */ in do_ix2vec_with_dead()
312 static WordSet add_or_dealloc_WordVec( WordSetU* wsu, WordVec* wv_new ) in add_or_dealloc_WordVec() argument
320 tl_assert(wv_new->owner == wsu); in add_or_dealloc_WordVec()
321 have = VG_(lookupFM)( wsu->vec2ix, in add_or_dealloc_WordVec()
327 tl_assert(wv_old->owner == wsu); in add_or_dealloc_WordVec()
328 tl_assert(ix_old < wsu->ix2vec_used); in add_or_dealloc_WordVec()
329 tl_assert(wsu->ix2vec[ix_old] == wv_old); in add_or_dealloc_WordVec()
332 } else if (wsu->ix2vec_free) { in add_or_dealloc_WordVec()
334 tl_assert(is_dead(wsu,(WordVec*)wsu->ix2vec_free)); in add_or_dealloc_WordVec()
335 ws = wsu->ix2vec_free - &(wsu->ix2vec[0]); in add_or_dealloc_WordVec()
336 tl_assert(wsu->ix2vec[ws] == NULL || is_dead(wsu,wsu->ix2vec[ws])); in add_or_dealloc_WordVec()
337 wsu->ix2vec_free = (WordVec **) wsu->ix2vec[ws]; in add_or_dealloc_WordVec()
338 wsu->ix2vec[ws] = wv_new; in add_or_dealloc_WordVec()
339 VG_(addToFM)( wsu->vec2ix, (UWord)wv_new, ws ); in add_or_dealloc_WordVec()
340 if (HG_DEBUG) VG_(printf)("aodW %s re-use free %d %p\n", wsu->cc, (Int)ws, wv_new ); in add_or_dealloc_WordVec()
343 ensure_ix2vec_space( wsu ); in add_or_dealloc_WordVec()
344 tl_assert(wsu->ix2vec); in add_or_dealloc_WordVec()
345 tl_assert(wsu->ix2vec_used < wsu->ix2vec_size); in add_or_dealloc_WordVec()
346 wsu->ix2vec[wsu->ix2vec_used] = wv_new; in add_or_dealloc_WordVec()
347 VG_(addToFM)( wsu->vec2ix, (Word)wv_new, (Word)wsu->ix2vec_used ); in add_or_dealloc_WordVec()
348 if (HG_DEBUG) VG_(printf)("aodW %s %d %p\n", wsu->cc, (Int)wsu->ix2vec_used, wv_new ); in add_or_dealloc_WordVec()
349 wsu->ix2vec_used++; in add_or_dealloc_WordVec()
350 tl_assert(wsu->ix2vec_used <= wsu->ix2vec_size); in add_or_dealloc_WordVec()
351 return (WordSet)(wsu->ix2vec_used - 1); in add_or_dealloc_WordVec()
361 WordSetU* wsu; in HG_() local
364 wsu = alloc_nofail( cc, sizeof(WordSetU) ); in HG_()
365 VG_(memset)( wsu, 0, sizeof(WordSetU) ); in HG_()
366 wsu->alloc = alloc_nofail; in HG_()
367 wsu->cc = cc; in HG_()
368 wsu->dealloc = dealloc; in HG_()
369 wsu->vec2ix = VG_(newFM)( alloc_nofail, cc, in HG_()
371 wsu->ix2vec_used = 0; in HG_()
372 wsu->ix2vec_size = 0; in HG_()
373 wsu->ix2vec = NULL; in HG_()
374 wsu->ix2vec_free = NULL; in HG_()
375 WCache_INIT(wsu->cache_addTo, cacheSize); in HG_()
376 WCache_INIT(wsu->cache_delFrom, cacheSize); in HG_()
377 WCache_INIT(wsu->cache_intersect, cacheSize); in HG_()
378 WCache_INIT(wsu->cache_minus, cacheSize); in HG_()
379 empty = new_WV_of_size( wsu, 0 ); in HG_()
380 wsu->empty = add_or_dealloc_WordVec( wsu, empty ); in HG_()
382 return wsu; in HG_()
385 void HG_(deleteWordSetU) ( WordSetU* wsu ) in HG_()
387 void (*dealloc)(void*) = wsu->dealloc; in HG_()
388 tl_assert(wsu->vec2ix); in HG_()
389 VG_(deleteFM)( wsu->vec2ix, delete_WV_for_FM, NULL/*val-finalizer*/ ); in HG_()
390 if (wsu->ix2vec) in HG_()
391 dealloc(wsu->ix2vec); in HG_()
392 dealloc(wsu); in HG_()
395 WordSet HG_(emptyWS) ( WordSetU* wsu ) in HG_()
397 return wsu->empty; in HG_()
400 Bool HG_(isEmptyWS) ( WordSetU* wsu, WordSet ws ) in HG_()
402 WordVec* wv = do_ix2vec( wsu, ws ); in HG_()
403 wsu->n_isEmpty++; in HG_()
405 tl_assert(ws == wsu->empty); in HG_()
408 tl_assert(ws != wsu->empty); in HG_()
413 Bool HG_(isSingletonWS) ( WordSetU* wsu, WordSet ws, UWord w ) in HG_()
416 tl_assert(wsu); in HG_()
417 wsu->n_isSingleton++; in HG_()
418 wv = do_ix2vec( wsu, ws ); in HG_()
422 UWord HG_(cardinalityWS) ( WordSetU* wsu, WordSet ws ) in HG_()
425 tl_assert(wsu); in HG_()
426 wv = do_ix2vec( wsu, ws ); in HG_()
431 UWord HG_(anyElementOfWS) ( WordSetU* wsu, WordSet ws ) in HG_()
434 tl_assert(wsu); in HG_()
435 wsu->n_anyElementOf++; in HG_()
436 wv = do_ix2vec( wsu, ws ); in HG_()
441 UWord HG_(cardinalityWSU) ( WordSetU* wsu ) in HG_()
443 tl_assert(wsu); in HG_()
444 return wsu->ix2vec_used; in HG_()
448 WordSetU* wsu, WordSet ws ) in HG_()
451 if (HG_DEBUG) VG_(printf)("getPayloadWS %s %d\n", wsu->cc, (Int)ws); in HG_()
452 tl_assert(wsu); in HG_()
453 wv = do_ix2vec( wsu, ws ); in HG_()
459 void HG_(dieWS) ( WordSetU* wsu, WordSet ws ) in HG_()
461 WordVec* wv = do_ix2vec_with_dead( wsu, ws ); in HG_()
465 if (HG_DEBUG) VG_(printf)("dieWS %s %d %p\n", wsu->cc, (Int)ws, wv); in HG_()
473 wsu->n_die++; in HG_()
476 wsu->ix2vec[ws] = (WordVec*) wsu->ix2vec_free; in HG_()
477 wsu->ix2vec_free = &wsu->ix2vec[ws]; in HG_()
479 VG_(delFromFM) ( wsu->vec2ix, in HG_()
489 wsu->cache_addTo.inUse = 0; in HG_()
490 wsu->cache_delFrom.inUse = 0; in HG_()
491 wsu->cache_intersect.inUse = 0; in HG_()
492 wsu->cache_minus.inUse = 0; in HG_()
495 Bool HG_(plausibleWS) ( WordSetU* wsu, WordSet ws ) in HG_()
497 if (wsu == NULL) return False; in HG_()
498 if (ws < 0 || ws >= wsu->ix2vec_used) in HG_()
503 Bool HG_(saneWS_SLOW) ( WordSetU* wsu, WordSet ws ) in HG_()
507 if (wsu == NULL) return False; in HG_()
508 if (ws < 0 || ws >= wsu->ix2vec_used) in HG_()
510 wv = do_ix2vec( wsu, ws ); in HG_()
512 if (wv->owner != wsu) return False; in HG_()
523 Bool HG_(elemWS) ( WordSetU* wsu, WordSet ws, UWord w ) in HG_()
526 WordVec* wv = do_ix2vec( wsu, ws ); in HG_()
527 wsu->n_elem++; in HG_()
535 WordSet HG_(doubletonWS) ( WordSetU* wsu, UWord w1, UWord w2 ) in HG_()
538 wsu->n_doubleton++; in HG_()
540 wv = new_WV_of_size(wsu, 1); in HG_()
544 wv = new_WV_of_size(wsu, 2); in HG_()
550 wv = new_WV_of_size(wsu, 2); in HG_()
554 return add_or_dealloc_WordVec( wsu, wv ); in HG_()
557 WordSet HG_(singletonWS) ( WordSetU* wsu, UWord w ) in HG_()
559 return HG_(doubletonWS)( wsu, w, w ); in HG_()
562 WordSet HG_(isSubsetOf) ( WordSetU* wsu, WordSet small, WordSet big ) in HG_()
564 wsu->n_isSubsetOf++; in HG_()
565 return small == HG_(intersectWS)( wsu, small, big ); in HG_()
568 void HG_(ppWS) ( WordSetU* wsu, WordSet ws ) in HG_()
572 tl_assert(wsu); in HG_()
573 wv = do_ix2vec( wsu, ws ); in HG_()
583 void HG_(ppWSUstats) ( WordSetU* wsu, const HChar* name ) in HG_()
587 wsu->n_add, wsu->n_add_uncached); in HG_()
589 wsu->n_del, wsu->n_del_uncached); in HG_()
590 VG_(printf)(" union %10lu\n", wsu->n_union); in HG_()
593 wsu->n_intersect, wsu->n_intersect_uncached); in HG_()
595 wsu->n_minus, wsu->n_minus_uncached); in HG_()
596 VG_(printf)(" elem %10lu\n", wsu->n_elem); in HG_()
597 VG_(printf)(" doubleton %10lu\n", wsu->n_doubleton); in HG_()
598 VG_(printf)(" isEmpty %10lu\n", wsu->n_isEmpty); in HG_()
599 VG_(printf)(" isSingleton %10lu\n", wsu->n_isSingleton); in HG_()
600 VG_(printf)(" anyElementOf %10lu\n", wsu->n_anyElementOf); in HG_()
601 VG_(printf)(" isSubsetOf %10lu\n", wsu->n_isSubsetOf); in HG_()
602 VG_(printf)(" dieWS %10lu\n", wsu->n_die); in HG_()
605 WordSet HG_(addToWS) ( WordSetU* wsu, WordSet ws, UWord w ) in HG_()
612 wsu->n_add++; in HG_()
613 WCache_LOOKUP_AND_RETURN(WordSet, wsu->cache_addTo, ws, w); in HG_()
614 wsu->n_add_uncached++; in HG_()
617 wv = do_ix2vec( wsu, ws ); in HG_()
625 wv_new = new_WV_of_size( wsu, wv->size + 1 ); in HG_()
638 result = add_or_dealloc_WordVec( wsu, wv_new ); in HG_()
642 WCache_UPDATE(wsu->cache_addTo, ws, w, result); in HG_()
646 WordSet HG_(delFromWS) ( WordSetU* wsu, WordSet ws, UWord w ) in HG_()
651 WordVec* wv = do_ix2vec( wsu, ws ); in HG_()
653 wsu->n_del++; in HG_()
657 tl_assert(ws == wsu->empty); in HG_()
661 WCache_LOOKUP_AND_RETURN(WordSet, wsu->cache_delFrom, ws, w); in HG_()
662 wsu->n_del_uncached++; in HG_()
678 wv_new = new_WV_of_size( wsu, wv->size - 1 ); in HG_()
687 result = add_or_dealloc_WordVec( wsu, wv_new ); in HG_()
689 tl_assert(result == wsu->empty); in HG_()
693 WCache_UPDATE(wsu->cache_delFrom, ws, w, result); in HG_()
697 WordSet HG_(unionWS) ( WordSetU* wsu, WordSet ws1, WordSet ws2 ) in HG_()
701 WordVec* wv1 = do_ix2vec( wsu, ws1 ); in HG_()
702 WordVec* wv2 = do_ix2vec( wsu, ws2 ); in HG_()
703 wsu->n_union++; in HG_()
730 wv_new = new_WV_of_size( wsu, sz ); in HG_()
764 return add_or_dealloc_WordVec( wsu, wv_new ); in HG_()
767 WordSet HG_(intersectWS) ( WordSetU* wsu, WordSet ws1, WordSet ws2 ) in HG_()
775 wsu->n_intersect++; in HG_()
788 WCache_LOOKUP_AND_RETURN(WordSet, wsu->cache_intersect, ws1, ws2); in HG_()
789 wsu->n_intersect_uncached++; in HG_()
791 wv1 = do_ix2vec( wsu, ws1 ); in HG_()
792 wv2 = do_ix2vec( wsu, ws2 ); in HG_()
813 wv_new = new_WV_of_size( wsu, sz ); in HG_()
837 ws_new = add_or_dealloc_WordVec( wsu, wv_new ); in HG_()
839 tl_assert(ws_new == wsu->empty); in HG_()
843 WCache_UPDATE(wsu->cache_intersect, ws1, ws2, ws_new); in HG_()
848 WordSet HG_(minusWS) ( WordSetU* wsu, WordSet ws1, WordSet ws2 ) in HG_()
856 wsu->n_minus++; in HG_()
857 WCache_LOOKUP_AND_RETURN(WordSet, wsu->cache_minus, ws1, ws2); in HG_()
858 wsu->n_minus_uncached++; in HG_()
860 wv1 = do_ix2vec( wsu, ws1 ); in HG_()
861 wv2 = do_ix2vec( wsu, ws2 ); in HG_()
885 wv_new = new_WV_of_size( wsu, sz ); in HG_()
913 ws_new = add_or_dealloc_WordVec( wsu, wv_new ); in HG_()
915 tl_assert(ws_new == wsu->empty); in HG_()
919 WCache_UPDATE(wsu->cache_minus, ws1, ws2, ws_new); in HG_()
925 void show_WS ( WordSetU* wsu, WordSet ws ) in show_WS() argument
928 WordVec* wv = do_ix2vec( wsu, ws ); in show_WS()