js/src/jit/BitSet.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     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 using namespace js;
    10 using namespace js::jit;
    12 BitSet *
    13 BitSet::New(TempAllocator &alloc, unsigned int numBits)
    14 {
    15     BitSet *result = new(alloc) BitSet(numBits);
    16     if (!result->init(alloc))
    17         return nullptr;
    18     return result;
    19 }
    21 bool
    22 BitSet::init(TempAllocator &alloc)
    23 {
    24     size_t sizeRequired = numWords() * sizeof(*bits_);
    26     bits_ = (uint32_t *)alloc.allocate(sizeRequired);
    27     if (!bits_)
    28         return false;
    30     memset(bits_, 0, sizeRequired);
    32     return true;
    33 }
    35 bool
    36 BitSet::empty() const
    37 {
    38     JS_ASSERT(bits_);
    39     const uint32_t *bits = bits_;
    40     for (unsigned int i = 0, e = numWords(); i < e; i++) {
    41         if (bits[i])
    42             return false;
    43     }
    44     return true;
    45 }
    47 void
    48 BitSet::insertAll(const BitSet *other)
    49 {
    50     JS_ASSERT(bits_);
    51     JS_ASSERT(other->numBits_ == numBits_);
    52     JS_ASSERT(other->bits_);
    54     uint32_t *bits = bits_;
    55     const uint32_t *otherBits = other->bits_;
    56     for (unsigned int i = 0, e = numWords(); i < e; i++)
    57         bits[i] |= otherBits[i];
    58 }
    60 void
    61 BitSet::removeAll(const BitSet *other)
    62 {
    63     JS_ASSERT(bits_);
    64     JS_ASSERT(other->numBits_ == numBits_);
    65     JS_ASSERT(other->bits_);
    67     uint32_t *bits = bits_;
    68     const uint32_t *otherBits = other->bits_;
    69     for (unsigned int i = 0, e = numWords(); i < e; i++)
    70         bits[i] &= ~otherBits[i];
    71 }
    73 void
    74 BitSet::intersect(const BitSet *other)
    75 {
    76     JS_ASSERT(bits_);
    77     JS_ASSERT(other->numBits_ == numBits_);
    78     JS_ASSERT(other->bits_);
    80     uint32_t *bits = bits_;
    81     const uint32_t *otherBits = other->bits_;
    82     for (unsigned int i = 0, e = numWords(); i < e; i++)
    83         bits[i] &= otherBits[i];
    84 }
    86 // returns true if the intersection caused the contents of the set to change.
    87 bool
    88 BitSet::fixedPointIntersect(const BitSet *other)
    89 {
    90     JS_ASSERT(bits_);
    91     JS_ASSERT(other->numBits_ == numBits_);
    92     JS_ASSERT(other->bits_);
    94     bool changed = false;
    96     uint32_t *bits = bits_;
    97     const uint32_t *otherBits = other->bits_;
    98     for (unsigned int i = 0, e = numWords(); i < e; i++) {
    99         uint32_t old = bits[i];
   100         bits[i] &= otherBits[i];
   102         if (!changed && old != bits[i])
   103             changed = true;
   104     }
   105     return changed;
   106 }
   108 void
   109 BitSet::complement()
   110 {
   111     JS_ASSERT(bits_);
   112     uint32_t *bits = bits_;
   113     for (unsigned int i = 0, e = numWords(); i < e; i++)
   114         bits[i] = ~bits[i];
   115 }
   117 void
   118 BitSet::clear()
   119 {
   120     JS_ASSERT(bits_);
   121     uint32_t *bits = bits_;
   122     for (unsigned int i = 0, e = numWords(); i < e; i++)
   123         bits[i] = 0;
   124 }

mercurial