OLD | NEW |
1 //===- subzero/src/IceBitVector.h - Inline bit vector. ----------*- C++ -*-===// | 1 //===- subzero/src/IceBitVector.h - Inline bit vector. ----------*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT }; | 253 enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT }; |
254 | 254 |
255 static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32, | 255 static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32, |
256 "Unsupported word size"); | 256 "Unsupported word size"); |
257 | 257 |
258 BitWord *Bits; // Actual bits. | 258 BitWord *Bits; // Actual bits. |
259 unsigned Size; // Size of bitvector in bits. | 259 unsigned Size; // Size of bitvector in bits. |
260 unsigned Capacity; // Size of allocated memory in BitWord. | 260 unsigned Capacity; // Size of allocated memory in BitWord. |
261 Allocator Alloc; | 261 Allocator Alloc; |
262 | 262 |
| 263 uint64_t alignTo(uint64_t Value, uint64_t Align) { |
| 264 #ifdef PNACL_LLVM |
| 265 return llvm::RoundUpToAlignment(Value, Align); |
| 266 #else // !PNACL_LLVM |
| 267 return llvm::alignTo(Value, Align); |
| 268 #endif // !PNACL_LLVM |
| 269 } |
| 270 |
263 public: | 271 public: |
264 typedef unsigned size_type; | 272 typedef unsigned size_type; |
265 // Encapsulation of a single bit. | 273 // Encapsulation of a single bit. |
266 class reference { | 274 class reference { |
267 friend class BitVectorTmpl; | 275 friend class BitVectorTmpl; |
268 | 276 |
269 BitWord *WordRef; | 277 BitWord *WordRef; |
270 unsigned BitPos; | 278 unsigned BitPos; |
271 | 279 |
272 reference(); // Undefined | 280 reference(); // Undefined |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 if (I / BITWORD_SIZE == E / BITWORD_SIZE) { | 470 if (I / BITWORD_SIZE == E / BITWORD_SIZE) { |
463 BitWord EMask = 1UL << (E % BITWORD_SIZE); | 471 BitWord EMask = 1UL << (E % BITWORD_SIZE); |
464 BitWord IMask = 1UL << (I % BITWORD_SIZE); | 472 BitWord IMask = 1UL << (I % BITWORD_SIZE); |
465 BitWord Mask = EMask - IMask; | 473 BitWord Mask = EMask - IMask; |
466 Bits[I / BITWORD_SIZE] |= Mask; | 474 Bits[I / BITWORD_SIZE] |= Mask; |
467 return *this; | 475 return *this; |
468 } | 476 } |
469 | 477 |
470 BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE); | 478 BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE); |
471 Bits[I / BITWORD_SIZE] |= PrefixMask; | 479 Bits[I / BITWORD_SIZE] |= PrefixMask; |
472 I = llvm::RoundUpToAlignment(I, BITWORD_SIZE); | 480 I = alignTo(I, BITWORD_SIZE); |
473 | 481 |
474 for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE) | 482 for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE) |
475 Bits[I / BITWORD_SIZE] = ~0UL; | 483 Bits[I / BITWORD_SIZE] = ~0UL; |
476 | 484 |
477 BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; | 485 BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; |
478 if (I < E) | 486 if (I < E) |
479 Bits[I / BITWORD_SIZE] |= PostfixMask; | 487 Bits[I / BITWORD_SIZE] |= PostfixMask; |
480 | 488 |
481 return *this; | 489 return *this; |
482 } | 490 } |
(...skipping 19 matching lines...) Expand all Loading... |
502 if (I / BITWORD_SIZE == E / BITWORD_SIZE) { | 510 if (I / BITWORD_SIZE == E / BITWORD_SIZE) { |
503 BitWord EMask = 1UL << (E % BITWORD_SIZE); | 511 BitWord EMask = 1UL << (E % BITWORD_SIZE); |
504 BitWord IMask = 1UL << (I % BITWORD_SIZE); | 512 BitWord IMask = 1UL << (I % BITWORD_SIZE); |
505 BitWord Mask = EMask - IMask; | 513 BitWord Mask = EMask - IMask; |
506 Bits[I / BITWORD_SIZE] &= ~Mask; | 514 Bits[I / BITWORD_SIZE] &= ~Mask; |
507 return *this; | 515 return *this; |
508 } | 516 } |
509 | 517 |
510 BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE); | 518 BitWord PrefixMask = ~0UL << (I % BITWORD_SIZE); |
511 Bits[I / BITWORD_SIZE] &= ~PrefixMask; | 519 Bits[I / BITWORD_SIZE] &= ~PrefixMask; |
512 I = llvm::RoundUpToAlignment(I, BITWORD_SIZE); | 520 I = alignTo(I, BITWORD_SIZE); |
513 | 521 |
514 for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE) | 522 for (; I + BITWORD_SIZE <= E; I += BITWORD_SIZE) |
515 Bits[I / BITWORD_SIZE] = 0UL; | 523 Bits[I / BITWORD_SIZE] = 0UL; |
516 | 524 |
517 BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; | 525 BitWord PostfixMask = (1UL << (E % BITWORD_SIZE)) - 1; |
518 if (I < E) | 526 if (I < E) |
519 Bits[I / BITWORD_SIZE] &= ~PostfixMask; | 527 Bits[I / BITWORD_SIZE] &= ~PostfixMask; |
520 | 528 |
521 return *this; | 529 return *this; |
522 } | 530 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 | 821 |
814 namespace std { | 822 namespace std { |
815 /// Implement std::swap in terms of BitVectorTmpl swap. | 823 /// Implement std::swap in terms of BitVectorTmpl swap. |
816 template <template <typename> class AT> | 824 template <template <typename> class AT> |
817 inline void swap(Ice::BitVectorTmpl<AT> &LHS, Ice::BitVectorTmpl<AT> &RHS) { | 825 inline void swap(Ice::BitVectorTmpl<AT> &LHS, Ice::BitVectorTmpl<AT> &RHS) { |
818 LHS.swap(RHS); | 826 LHS.swap(RHS); |
819 } | 827 } |
820 } | 828 } |
821 | 829 |
822 #endif // SUBZERO_SRC_ICEBITVECTOR_H | 830 #endif // SUBZERO_SRC_ICEBITVECTOR_H |
OLD | NEW |