MCPcopy Create free account
hub / github.com/activeloopai/deeplake / count_set_bits

Method count_set_bits

cpp/icm/bit_vector.hpp:1978–2012  ·  view source on GitHub ↗

Population count - optimized block-level operation

Source from the content-addressed store, hash-verified

1976
1977 // Population count - optimized block-level operation
1978 int64_t count_set_bits() const
1979 {
1980 // Get direct access to the underlying blocks
1981 const block_type* blocks = original_bv_->data() + start_block_;
1982 int64_t num_blocks = end_block_ - start_block_;
1983
1984 int64_t count = 0;
1985 const auto& features = base::system_report::get_cpu_features();
1986
1987 // Use the same optimization logic as bit_vector
1988 if (features.has_popcnt) {
1989#ifdef __x86_64__
1990 count = count_set_bits_x86_popcnt_blocks(blocks, num_blocks);
1991#elif defined(__aarch64__)
1992 count = count_set_bits_arm_popcnt_blocks(blocks, num_blocks);
1993#else
1994 count = count_set_bits_builtin_blocks(blocks, num_blocks);
1995#endif
1996 } else {
1997 count = count_set_bits_software_blocks(blocks, num_blocks);
1998 }
1999
2000 // Adjust for unused bits in last block if it's partial
2001 if (end_bit_offset_ != 0) {
2002 block_type last_block_mask = (block_type(1) << end_bit_offset_) - 1;
2003 block_type unused_block = blocks[num_blocks - 1] & ~last_block_mask;
2004#ifdef _MSC_VER
2005 count -= __popcnt64(unused_block);
2006#else
2007 count -= __builtin_popcountll(unused_block);
2008#endif
2009 }
2010
2011 return count;
2012 }
2013
2014 // Find operations - map to global indices
2015 int64_t find_first_set() const

Callers

nothing calls this directly

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected