Skip to content

Commit b07947e

Browse files
committed
Fix name ambiguity
1 parent fb9ec4b commit b07947e

4 files changed

Lines changed: 72 additions & 69 deletions

File tree

include/xsimd/arch/common/xsimd_common_logical.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ namespace xsimd
2929
template <class A, class T>
3030
XSIMD_INLINE size_t count(batch_bool<T, A> const& self, requires_arch<common>) noexcept
3131
{
32-
return xsimd::popcount(self.mask());
32+
return xsimd::detail::popcount(self.mask());
3333
}
3434

3535
template <class A, class T>
3636
XSIMD_INLINE size_t countl_zero(batch_bool<T, A> const& self, requires_arch<common>) noexcept
3737
{
3838
constexpr size_t unused_bits = sizeof(uint64_t) * CHAR_BIT - batch_bool<T, A>::size;
3939
constexpr uint64_t lower_mask = ((uint64_t)1 << batch_bool<T, A>::size) - 1;
40-
return xsimd::countl_zero(self.mask() & lower_mask) - unused_bits;
40+
return xsimd::detail::countl_zero(self.mask() & lower_mask) - unused_bits;
4141
}
4242

4343
template <class A, class T>
4444
XSIMD_INLINE size_t countl_one(batch_bool<T, A> const& self, requires_arch<common>) noexcept
4545
{
4646
constexpr size_t unused_bits = sizeof(uint64_t) * CHAR_BIT - batch_bool<T, A>::size;
4747
constexpr uint64_t upper_mask = ~(((uint64_t)1 << batch_bool<T, A>::size) - 1);
48-
return xsimd::countl_one(self.mask() | upper_mask) - unused_bits;
48+
return xsimd::detail::countl_one(self.mask() | upper_mask) - unused_bits;
4949
}
5050

5151
template <class A, class T>
5252
XSIMD_INLINE size_t countr_zero(batch_bool<T, A> const& self, requires_arch<common>) noexcept
5353
{
5454
constexpr uint64_t stop = (uint64_t)1 << batch_bool<T, A>::size;
55-
return xsimd::countr_zero(self.mask() | stop);
55+
return xsimd::detail::countr_zero(self.mask() | stop);
5656
}
5757

5858
template <class A, class T>
5959
XSIMD_INLINE size_t countr_one(batch_bool<T, A> const& self, requires_arch<common>) noexcept
6060
{
6161
constexpr uint64_t stop = ~((uint64_t)1 << batch_bool<T, A>::size);
62-
return xsimd::countr_one(self.mask() & stop);
62+
return xsimd::detail::countr_one(self.mask() & stop);
6363
}
6464

6565
// from mask

include/xsimd/arch/xsimd_neon.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,31 +3367,31 @@ namespace xsimd
33673367
{
33683368
uint8x8_t narrowed = vshrn_n_u16(vreinterpretq_u16_u8(self), 4);
33693369
uint64_t result = vget_lane_u64(vreinterpret_u64_u8(narrowed), 0);
3370-
return xsimd::popcount(result) / 4;
3370+
return xsimd::detail::popcount(result) / 4;
33713371
}
33723372

33733373
template <class A, class T, detail::enable_sized_t<T, 2> = 0>
33743374
XSIMD_INLINE size_t count(batch_bool<T, A> const& self, requires_arch<neon>) noexcept
33753375
{
33763376
uint8x8_t narrowed = vmovn_u16(self);
33773377
uint64_t result = vget_lane_u64(vreinterpret_u64_u8(narrowed), 0);
3378-
return xsimd::popcount(result) / 8;
3378+
return xsimd::detail::popcount(result) / 8;
33793379
}
33803380

33813381
template <class A, class T, detail::enable_sized_t<T, 4> = 0>
33823382
XSIMD_INLINE size_t count(batch_bool<T, A> const& self, requires_arch<neon>) noexcept
33833383
{
33843384
uint16x4_t narrowed = vmovn_u32(self);
33853385
uint64_t result = vget_lane_u64(vreinterpret_u64_u8(narrowed), 0);
3386-
return xsimd::popcount(result) / 16;
3386+
return xsimd::detail::popcount(result) / 16;
33873387
}
33883388

33893389
template <class A, class T, detail::enable_sized_t<T, 8> = 0>
33903390
XSIMD_INLINE size_t count(batch_bool<T, A> const& self, requires_arch<neon>) noexcept
33913391
{
33923392
uint32x2_t narrowed = vmovn_u64(self);
33933393
uint64_t result = vget_lane_u64(vreinterpret_u64_u8(narrowed), 0);
3394-
return xsimd::popcount(result) / 32;
3394+
return xsimd::detail::popcount(result) / 32;
33953395
}
33963396

33973397
#define WRAP_MASK_OP(OP) \
@@ -3411,7 +3411,7 @@ namespace xsimd
34113411
} \
34123412
\
34133413
uint64_t result = vget_lane_u64(vreinterpret_u64_u8(narrowed), 0); \
3414-
return xsimd::OP(result) / 4; \
3414+
return xsimd::detail::OP(result) / 4; \
34153415
} \
34163416
template <class A, class T, detail::enable_sized_t<T, 2> = 0> \
34173417
XSIMD_INLINE size_t OP(batch_bool<T, A> const& self, requires_arch<neon>) noexcept \
@@ -3423,7 +3423,7 @@ namespace xsimd
34233423
} \
34243424
\
34253425
uint64_t result = vget_lane_u64(vreinterpret_u64_u8(narrowed), 0); \
3426-
return xsimd::OP(result) / 8; \
3426+
return xsimd::detail::OP(result) / 8; \
34273427
} \
34283428
template <class A, class T, detail::enable_sized_t<T, 4> = 0> \
34293429
XSIMD_INLINE size_t OP(batch_bool<T, A> const& self, requires_arch<neon>) noexcept \
@@ -3435,7 +3435,7 @@ namespace xsimd
34353435
} \
34363436
\
34373437
uint64_t result = vget_lane_u64(vreinterpret_u64_u16(narrowed), 0); \
3438-
return xsimd::OP(result) / 16; \
3438+
return xsimd::detail::OP(result) / 16; \
34393439
} \
34403440
template <class A, class T, detail::enable_sized_t<T, 8> = 0> \
34413441
XSIMD_INLINE size_t OP(batch_bool<T, A> const& self, requires_arch<neon>) noexcept \
@@ -3447,7 +3447,7 @@ namespace xsimd
34473447
} \
34483448
\
34493449
uint64_t result = vget_lane_u64(vreinterpret_u64_u32(narrowed), 0); \
3450-
return xsimd::OP(result) / 32; \
3450+
return xsimd::detail::OP(result) / 32; \
34513451
}
34523452

34533453
WRAP_MASK_OP(countl_zero)

include/xsimd/types/xsimd_bit.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
namespace xsimd
2222
{
23-
// FIXME: We could do better by dispatching to the appropriate popcount instruction
24-
// depending on the arch.
25-
26-
template <class T, class = std::enable_if_t<std::is_unsigned<T>::value>>
27-
int popcount(T x)
23+
namespace detail
2824
{
25+
// FIXME: We could do better by dispatching to the appropriate popcount instruction
26+
// depending on the arch.
27+
28+
template <class T, class = std::enable_if_t<std::is_unsigned<T>::value>>
29+
int popcount(T x)
30+
{
2931
#if XSIMD_HAS_BUILTIN(__builtin_popcountg)
3032
return __builtin_popcountg(x);
3133
#else
@@ -193,6 +195,7 @@ namespace xsimd
193195
return countr_zero(T(~x));
194196
}
195197

198+
}
196199
}
197200

198201
#endif

test/test_bit.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ struct bit_test
2323
void test_popcount()
2424
{
2525
// Zero
26-
CHECK_EQ(xsimd::popcount(T(0)), 0);
26+
CHECK_EQ(xsimd::detail::popcount(T(0)), 0);
2727

2828
// All bits set
29-
CHECK_EQ(xsimd::popcount(T(~T(0))), bits::value);
29+
CHECK_EQ(xsimd::detail::popcount(T(~T(0))), bits::value);
3030

3131
// Single bit patterns - all should have popcount of 1
3232
for (int i = 0; i < bits::value; ++i)
3333
{
3434
T value = T(T(1) << i);
3535
INFO("popcount(1 << " << i << ")");
36-
CHECK_EQ(xsimd::popcount(value), 1);
36+
CHECK_EQ(xsimd::detail::popcount(value), 1);
3737
}
3838

3939
// Powers of 2 minus 1 - known popcounts
4040
for (int i = 1; i < bits::value; ++i)
4141
{
4242
T value = T((T(1) << i) - 1);
4343
INFO("popcount((1 << " << i << ") - 1)");
44-
CHECK_EQ(xsimd::popcount(value), i);
44+
CHECK_EQ(xsimd::detail::popcount(value), i);
4545
}
4646

4747
// Alternating patterns
@@ -55,37 +55,37 @@ struct bit_test
5555
pattern_55 |= T(0x55) << (i * 8);
5656
}
5757
INFO("popcount(0xAA...)");
58-
CHECK_EQ(xsimd::popcount(pattern_aa), bits::value / 2);
58+
CHECK_EQ(xsimd::detail::popcount(pattern_aa), bits::value / 2);
5959
INFO("popcount(0x55...)");
60-
CHECK_EQ(xsimd::popcount(pattern_55), bits::value / 2);
60+
CHECK_EQ(xsimd::detail::popcount(pattern_55), bits::value / 2);
6161
}
6262

6363
// Specific test cases
64-
CHECK_EQ(xsimd::popcount(T(1)), 1);
65-
CHECK_EQ(xsimd::popcount(T(3)), 2);
66-
CHECK_EQ(xsimd::popcount(T(7)), 3);
67-
CHECK_EQ(xsimd::popcount(T(15)), 4);
64+
CHECK_EQ(xsimd::detail::popcount(T(1)), 1);
65+
CHECK_EQ(xsimd::detail::popcount(T(3)), 2);
66+
CHECK_EQ(xsimd::detail::popcount(T(7)), 3);
67+
CHECK_EQ(xsimd::detail::popcount(T(15)), 4);
6868
}
6969

7070
void test_countl_zero()
7171
{
7272
// Zero should have all leading zeros
73-
CHECK_EQ(xsimd::countl_zero(T(0)), bits::value);
73+
CHECK_EQ(xsimd::detail::countl_zero(T(0)), bits::value);
7474

7575
// All bits set should have 0 leading zeros
76-
CHECK_EQ(xsimd::countl_zero(T(~T(0))), 0);
76+
CHECK_EQ(xsimd::detail::countl_zero(T(~T(0))), 0);
7777

7878
// MSB set should have 0 leading zeros
7979
T msb = T(1) << (bits::value - 1);
80-
CHECK_EQ(xsimd::countl_zero(msb), 0);
80+
CHECK_EQ(xsimd::detail::countl_zero(msb), 0);
8181

8282
// Powers of 2
8383
for (int i = 0; i < bits::value; ++i)
8484
{
8585
T value = T(T(1) << i);
8686
int expected = bits::value - i - 1;
8787
INFO("countl_zero(1 << " << i << ")");
88-
CHECK_EQ(xsimd::countl_zero(value), expected);
88+
CHECK_EQ(xsimd::detail::countl_zero(value), expected);
8989
}
9090

9191
// Sequential patterns (1, 3, 7, 15, ...)
@@ -94,122 +94,122 @@ struct bit_test
9494
T value = T((T(1) << i) - 1);
9595
int expected = bits::value - i;
9696
INFO("countl_zero((1 << " << i << ") - 1)");
97-
CHECK_EQ(xsimd::countl_zero(value), expected);
97+
CHECK_EQ(xsimd::detail::countl_zero(value), expected);
9898
}
9999

100100
// Specific values
101-
CHECK_EQ(xsimd::countl_zero(T(1)), bits::value - 1);
102-
CHECK_EQ(xsimd::countl_zero(T(2)), bits::value - 2);
103-
CHECK_EQ(xsimd::countl_zero(T(4)), bits::value - 3);
101+
CHECK_EQ(xsimd::detail::countl_zero(T(1)), bits::value - 1);
102+
CHECK_EQ(xsimd::detail::countl_zero(T(2)), bits::value - 2);
103+
CHECK_EQ(xsimd::detail::countl_zero(T(4)), bits::value - 3);
104104
}
105105

106106
void test_countl_one()
107107
{
108108
// Zero should have 0 leading ones
109-
CHECK_EQ(xsimd::countl_one(T(0)), 0);
109+
CHECK_EQ(xsimd::detail::countl_one(T(0)), 0);
110110

111111
// All bits set should have all leading ones
112-
CHECK_EQ(xsimd::countl_one(T(~T(0))), bits::value);
112+
CHECK_EQ(xsimd::detail::countl_one(T(~T(0))), bits::value);
113113

114114
// MSB clear, rest set should have 0 leading ones
115115
T pattern = T(~(T(1) << (bits::value - 1)));
116-
CHECK_EQ(xsimd::countl_one(pattern), 0);
116+
CHECK_EQ(xsimd::detail::countl_one(pattern), 0);
117117

118118
// Inverted powers of 2
119119
for (int i = 0; i < bits::value; ++i)
120120
{
121121
T value = T(~(T(1) << i));
122122
int expected = (i == bits::value - 1) ? 0 : bits::value - i - 1;
123123
INFO("countl_one(~(1 << " << i << "))");
124-
CHECK_EQ(xsimd::countl_one(value), expected);
124+
CHECK_EQ(xsimd::detail::countl_one(value), expected);
125125
}
126126

127127
// Patterns with known leading ones
128128
for (int i = 1; i <= bits::value; ++i)
129129
{
130130
T value = T(T(~T(0)) << (bits::value - i));
131131
INFO("countl_one(~0 << " << (bits::value - i) << ")");
132-
CHECK_EQ(xsimd::countl_one(value), i);
132+
CHECK_EQ(xsimd::detail::countl_one(value), i);
133133
}
134134

135135
// Specific values
136-
CHECK_EQ(xsimd::countl_one(T(~T(1))), bits::value - 1);
137-
CHECK_EQ(xsimd::countl_one(T(~T(3))), bits::value - 2);
136+
CHECK_EQ(xsimd::detail::countl_one(T(~T(1))), bits::value - 1);
137+
CHECK_EQ(xsimd::detail::countl_one(T(~T(3))), bits::value - 2);
138138
}
139139

140140
void test_countr_zero()
141141
{
142142
// Zero should have all trailing zeros
143-
CHECK_EQ(xsimd::countr_zero(T(0)), bits::value);
143+
CHECK_EQ(xsimd::detail::countr_zero(T(0)), bits::value);
144144

145145
// All bits set should have 0 trailing zeros
146-
CHECK_EQ(xsimd::countr_zero(T(~T(0))), 0);
146+
CHECK_EQ(xsimd::detail::countr_zero(T(~T(0))), 0);
147147

148148
// Odd numbers should have 0 trailing zeros
149-
CHECK_EQ(xsimd::countr_zero(T(1)), 0);
150-
CHECK_EQ(xsimd::countr_zero(T(3)), 0);
151-
CHECK_EQ(xsimd::countr_zero(T(5)), 0);
152-
CHECK_EQ(xsimd::countr_zero(T(7)), 0);
149+
CHECK_EQ(xsimd::detail::countr_zero(T(1)), 0);
150+
CHECK_EQ(xsimd::detail::countr_zero(T(3)), 0);
151+
CHECK_EQ(xsimd::detail::countr_zero(T(5)), 0);
152+
CHECK_EQ(xsimd::detail::countr_zero(T(7)), 0);
153153

154154
// Powers of 2
155155
for (int i = 0; i < bits::value; ++i)
156156
{
157157
T value = T(1) << i;
158158
INFO("countr_zero(1 << " << i << ")");
159-
CHECK_EQ(xsimd::countr_zero(value), i);
159+
CHECK_EQ(xsimd::detail::countr_zero(value), i);
160160
}
161161

162162
// Even numbers with known factors
163-
CHECK_EQ(xsimd::countr_zero(T(2)), 1);
164-
CHECK_EQ(xsimd::countr_zero(T(4)), 2);
165-
CHECK_EQ(xsimd::countr_zero(T(6)), 1);
166-
CHECK_EQ(xsimd::countr_zero(T(8)), 3);
167-
CHECK_EQ(xsimd::countr_zero(T(12)), 2);
168-
CHECK_EQ(xsimd::countr_zero(T(16)), 4);
163+
CHECK_EQ(xsimd::detail::countr_zero(T(2)), 1);
164+
CHECK_EQ(xsimd::detail::countr_zero(T(4)), 2);
165+
CHECK_EQ(xsimd::detail::countr_zero(T(6)), 1);
166+
CHECK_EQ(xsimd::detail::countr_zero(T(8)), 3);
167+
CHECK_EQ(xsimd::detail::countr_zero(T(12)), 2);
168+
CHECK_EQ(xsimd::detail::countr_zero(T(16)), 4);
169169

170170
// Specific patterns
171171
for (int i = 1; i < bits::value; ++i)
172172
{
173173
T value = T(~T(0)) << i;
174174
INFO("countr_zero(~0 << " << i << ")");
175-
CHECK_EQ(xsimd::countr_zero(value), i);
175+
CHECK_EQ(xsimd::detail::countr_zero(value), i);
176176
}
177177
}
178178

179179
void test_countr_one()
180180
{
181181
// Zero should have 0 trailing ones
182-
CHECK_EQ(xsimd::countr_one(T(0)), 0);
182+
CHECK_EQ(xsimd::detail::countr_one(T(0)), 0);
183183

184184
// All bits set should have all trailing ones
185-
CHECK_EQ(xsimd::countr_one(T(~T(0))), bits::value);
185+
CHECK_EQ(xsimd::detail::countr_one(T(~T(0))), bits::value);
186186

187187
// Even numbers should have 0 trailing ones
188-
CHECK_EQ(xsimd::countr_one(T(2)), 0);
189-
CHECK_EQ(xsimd::countr_one(T(4)), 0);
190-
CHECK_EQ(xsimd::countr_one(T(6)), 0);
188+
CHECK_EQ(xsimd::detail::countr_one(T(2)), 0);
189+
CHECK_EQ(xsimd::detail::countr_one(T(4)), 0);
190+
CHECK_EQ(xsimd::detail::countr_one(T(6)), 0);
191191

192192
// Powers of 2 minus 1
193193
for (int i = 1; i < bits::value; ++i)
194194
{
195195
T value = T((T(1) << i) - 1);
196196
INFO("countr_one((1 << " << i << ") - 1)");
197-
CHECK_EQ(xsimd::countr_one(value), i);
197+
CHECK_EQ(xsimd::detail::countr_one(value), i);
198198
}
199199

200200
// Specific values
201-
CHECK_EQ(xsimd::countr_one(T(1)), 1);
202-
CHECK_EQ(xsimd::countr_one(T(3)), 2);
203-
CHECK_EQ(xsimd::countr_one(T(7)), 3);
204-
CHECK_EQ(xsimd::countr_one(T(15)), 4);
205-
CHECK_EQ(xsimd::countr_one(T(31)), 5);
201+
CHECK_EQ(xsimd::detail::countr_one(T(1)), 1);
202+
CHECK_EQ(xsimd::detail::countr_one(T(3)), 2);
203+
CHECK_EQ(xsimd::detail::countr_one(T(7)), 3);
204+
CHECK_EQ(xsimd::detail::countr_one(T(15)), 4);
205+
CHECK_EQ(xsimd::detail::countr_one(T(31)), 5);
206206

207207
// Inverted powers of 2 minus 1
208208
for (int i = 1; i < bits::value; ++i)
209209
{
210210
T value = T(~((T(1) << i) - 1));
211211
INFO("countr_one(~((1 << " << i << ") - 1))");
212-
CHECK_EQ(xsimd::countr_one(value), 0);
212+
CHECK_EQ(xsimd::detail::countr_one(value), 0);
213213
}
214214
}
215215
};

0 commit comments

Comments
 (0)