1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "jit/BitSet.h"
11 #include "jit/JitAllocPolicy.h"
14 using namespace js::jit
;
16 bool BitSet::init(TempAllocator
& alloc
) {
17 size_t sizeRequired
= numWords() * sizeof(*bits_
);
19 bits_
= (uint32_t*)alloc
.allocate(sizeRequired
);
24 memset(bits_
, 0, sizeRequired
);
29 bool BitSet::empty() const {
31 const uint32_t* bits
= bits_
;
32 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {
40 void BitSet::insertAll(const BitSet
& other
) {
42 MOZ_ASSERT(other
.numBits_
== numBits_
);
43 MOZ_ASSERT(other
.bits_
);
45 uint32_t* bits
= bits_
;
46 const uint32_t* otherBits
= other
.bits_
;
47 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {
48 bits
[i
] |= otherBits
[i
];
52 void BitSet::removeAll(const BitSet
& other
) {
54 MOZ_ASSERT(other
.numBits_
== numBits_
);
55 MOZ_ASSERT(other
.bits_
);
57 uint32_t* bits
= bits_
;
58 const uint32_t* otherBits
= other
.bits_
;
59 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {
60 bits
[i
] &= ~otherBits
[i
];
64 void BitSet::intersect(const BitSet
& other
) {
66 MOZ_ASSERT(other
.numBits_
== numBits_
);
67 MOZ_ASSERT(other
.bits_
);
69 uint32_t* bits
= bits_
;
70 const uint32_t* otherBits
= other
.bits_
;
71 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {
72 bits
[i
] &= otherBits
[i
];
76 // returns true if the intersection caused the contents of the set to change.
77 bool BitSet::fixedPointIntersect(const BitSet
& other
) {
79 MOZ_ASSERT(other
.numBits_
== numBits_
);
80 MOZ_ASSERT(other
.bits_
);
84 uint32_t* bits
= bits_
;
85 const uint32_t* otherBits
= other
.bits_
;
86 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {
87 uint32_t old
= bits
[i
];
88 bits
[i
] &= otherBits
[i
];
90 if (!changed
&& old
!= bits
[i
]) {
97 void BitSet::complement() {
99 uint32_t* bits
= bits_
;
100 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {
105 void BitSet::clear() {
107 uint32_t* bits
= bits_
;
108 for (unsigned int i
= 0, e
= numWords(); i
< e
; i
++) {