Bug 1890750 - Part 1: Include NATIVE_JIT_ENTRY in FunctionFlags::HasJitEntryFlags...
[gecko.git] / js / src / jit / BitSet.cpp
blobb791ea387c5201230f89be9c0bbbbe698ddcd617
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"
9 #include <string.h>
11 #include "jit/JitAllocPolicy.h"
13 using namespace js;
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);
20 if (!bits_) {
21 return false;
24 memset(bits_, 0, sizeRequired);
26 return true;
29 bool BitSet::empty() const {
30 MOZ_ASSERT(bits_);
31 const uint32_t* bits = bits_;
32 for (unsigned int i = 0, e = numWords(); i < e; i++) {
33 if (bits[i]) {
34 return false;
37 return true;
40 void BitSet::insertAll(const BitSet& other) {
41 MOZ_ASSERT(bits_);
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) {
53 MOZ_ASSERT(bits_);
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) {
65 MOZ_ASSERT(bits_);
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) {
78 MOZ_ASSERT(bits_);
79 MOZ_ASSERT(other.numBits_ == numBits_);
80 MOZ_ASSERT(other.bits_);
82 bool changed = false;
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]) {
91 changed = true;
94 return changed;
97 void BitSet::complement() {
98 MOZ_ASSERT(bits_);
99 uint32_t* bits = bits_;
100 for (unsigned int i = 0, e = numWords(); i < e; i++) {
101 bits[i] = ~bits[i];
105 void BitSet::clear() {
106 MOZ_ASSERT(bits_);
107 uint32_t* bits = bits_;
108 for (unsigned int i = 0, e = numWords(); i < e; i++) {
109 bits[i] = 0;