title: Settings Multiple bits at Once in a Bitset
body: <p>I am working on a toy file system, I am using a <code>bitset</code> to keep track of used and unused pages. I am using an <code>array</code> of <code>int</code>s (in order to use GCC's built in bit ops.) to represent the <code>bitset</code>. I am not using the <code>std::bitset</code> as it will not be available on the final environment (embedded system.). </p>
  
  <p>Now according to Linux <code>perf</code> during the tests allocating files takes 35% of runtime of this, 45% of the time is lost setting bits using,</p>
  
  <pre><code>#define BIT_SET(a,b) ((a) |= (1ULL&lt;&lt;(b)))
  </code></pre>
  
  <p>inside a loop. According to perf 42% of the time is lost in <code>or</code>. Deleting is a bit faster but then most time is lost in <code>and</code> operation to clear the bits toggling the bits using xor did not made any difference.</p>
  
  <p>Basically I am wondering if there are smarter ways to set multiple bits in one go. If user requests 10 pages of space just set all bits in one go, but the problem is space can span <code>word</code> boundries. or any GCC/Clang instrinsics that I should be aware of?</p>