Skip to content
Permalink
Browse files

Use __popcnt64 instead of __builtin_popcountll if _MSC_VER is defined

  • Loading branch information
s-yata committed Nov 27, 2019
1 parent 4e62cad commit d63becb2701b1780e68e514c0e2859d478677f2a
Showing with 15 additions and 3 deletions.
  1. +15 −3 louds-trie.cpp
@@ -1,13 +1,25 @@
#include "louds-trie.hpp"

#include <x86intrin.h>
#ifdef _MSC_VER
#include <intrin.h>
#else // _MSC_VER
#include <x86intrin.h>
#endif // _MSC_VER

#include <cassert>
#include <vector>

namespace louds {
namespace {

uint64_t Popcnt(uint64_t x) {
#ifdef _MSC_VER
return __popcnt64(x);
#else // _MSC_VER
return __builtin_popcountll(x);
#endif // _MSC_VER
}

struct BitVector {
struct Rank {
uint32_t abs_hi;
@@ -63,7 +75,7 @@ struct BitVector {

uint64_t word_id = (block_id * 4) + j;
uint64_t word = words[word_id];
uint64_t n_pops = __builtin_popcountll(word);
uint64_t n_pops = Popcnt(word);
uint64_t new_n_ones = n_ones + n_pops;
if (((n_ones + 255) / 256) != ((new_n_ones + 255) / 256)) {
uint64_t count = n_ones;
@@ -94,7 +106,7 @@ struct BitVector {
if (rel_id != 0) {
n += ranks[rank_id].rels[rel_id - 1];
}
n += __builtin_popcountll(words[word_id] & ((1UL << bit_id) - 1));
n += Popcnt(words[word_id] & ((1UL << bit_id) - 1));
return n;
}
// select returns the position of the (i+1)-th 1-bit.

0 comments on commit d63becb

Please sign in to comment.
You can’t perform that action at this time.