Skip to content

Commit 17a568e

Browse files
committed
Fixing API
1 parent 884ac2b commit 17a568e

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

docs/source/api/bitwise_operators_index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Bitwise operators
4040
+---------------------------------------+----------------------------------------------------+
4141
| :cpp:func:`bitwise_andnot` | per slot bitwise and not |
4242
+---------------------------------------+----------------------------------------------------+
43-
| :cpp:func:`bitwise_lshift` | per slot bitwise and |
43+
| :cpp:func:`bitwise_lshift` | per slot bitwise left shift |
4444
+---------------------------------------+----------------------------------------------------+
45-
| :cpp:func:`bitwise_rshift` | per slot bitwise and not |
45+
| :cpp:func:`bitwise_rshift` | per slot bitwise right shift |
4646
+---------------------------------------+----------------------------------------------------+
4747
| :cpp:func:`rotr` | per slot rotate right |
4848
+---------------------------------------+----------------------------------------------------+

include/xsimd/arch/common/xsimd_common_arithmetic.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ namespace xsimd
3434
{ return x << y; },
3535
self, other);
3636
}
37-
template <int shift, class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
37+
template <size_t shift, class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
3838
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, requires_arch<common>) noexcept
3939
{
40+
static_assert(shift < std::numeric_limits<T>::digits, "shift must be less than the number of bits in T");
4041
return bitwise_lshift(self, shift, A {});
4142
}
4243

@@ -48,9 +49,10 @@ namespace xsimd
4849
{ return x >> y; },
4950
self, other);
5051
}
51-
template <int shift, class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
52+
template <size_t shift, class A, class T, class /*=typename std::enable_if<std::is_integral<T>::value, void>::type*/>
5253
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, requires_arch<common>) noexcept
5354
{
55+
static_assert(shift < std::numeric_limits<T>::digits, "shift must be less than the number of bits in T");
5456
return bitwise_rshift(self, shift, A {});
5557
}
5658

@@ -193,9 +195,10 @@ namespace xsimd
193195
constexpr auto N = std::numeric_limits<T>::digits;
194196
return (self << other) | (self >> (N - other));
195197
}
196-
template <int count, class A, class T>
198+
template <size_t count, class A, class T>
197199
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, requires_arch<common>) noexcept
198200
{
201+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
199202
constexpr auto N = std::numeric_limits<T>::digits;
200203
return bitwise_lshift<count>(self) | bitwise_rshift<N - count>(self);
201204
}
@@ -207,9 +210,10 @@ namespace xsimd
207210
constexpr auto N = std::numeric_limits<T>::digits;
208211
return (self >> other) | (self << (N - other));
209212
}
210-
template <int count, class A, class T>
213+
template <size_t count, class A, class T>
211214
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, requires_arch<common>) noexcept
212215
{
216+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
213217
constexpr auto N = std::numeric_limits<T>::digits;
214218
return bitwise_rshift<count>(self) | bitwise_lshift<N - count>(self);
215219
}

include/xsimd/arch/xsimd_avx2.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "../types/xsimd_avx2_register.hpp"
1919

20+
#include <limits>
21+
2022
namespace xsimd
2123
{
2224

@@ -172,9 +174,10 @@ namespace xsimd
172174
}
173175
}
174176

175-
template <int shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
177+
template <size_t shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
176178
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, requires_arch<avx2>) noexcept
177179
{
180+
static_assert(shift < std::numeric_limits<T>::digits, "Shift amount must be less than the number of value bits in the type");
178181
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
179182
{
180183
return _mm256_slli_epi16(self, shift);
@@ -269,9 +272,10 @@ namespace xsimd
269272
}
270273
}
271274

272-
template <int shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
275+
template <size_t shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
273276
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, requires_arch<avx2>) noexcept
274277
{
278+
static_assert(shift < std::numeric_limits<T>::digits, "Shift amount must be less than the number of value bits in the type");
275279
if (std::is_signed<T>::value)
276280
{
277281
XSIMD_IF_CONSTEXPR(sizeof(T) == 1)

include/xsimd/arch/xsimd_avx512f.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,10 @@ namespace xsimd
585585
{
586586
return rotl(self, batch<T, A>(other), A {});
587587
}
588-
template <int count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
588+
template <size_t count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
589589
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, requires_arch<avx512f>) noexcept
590590
{
591+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
591592
XSIMD_IF_CONSTEXPR(sizeof(T) == 4)
592593
{
593594
return _mm512_rol_epi32(self, count);
@@ -631,9 +632,10 @@ namespace xsimd
631632
return rotr(self, batch<T, A>(other), A {});
632633
}
633634

634-
template <int count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
635+
template <size_t count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
635636
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, requires_arch<avx512f>) noexcept
636637
{
638+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
637639
XSIMD_IF_CONSTEXPR(sizeof(T) < 4)
638640
{
639641
return detail::fwd_to_avx([](__m256i s) noexcept

include/xsimd/arch/xsimd_avx512vbmi2.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ namespace xsimd
8282
}
8383
}
8484

85-
template <int count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
85+
template <size_t count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
8686
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, requires_arch<avx512vbmi2>) noexcept
8787
{
88+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
8889
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
8990
{
9091
return _mm512_shldi_epi16(self, self, count);
@@ -109,9 +110,10 @@ namespace xsimd
109110
}
110111
}
111112

112-
template <int count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
113+
template <size_t count, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
113114
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, requires_arch<avx512vbmi2>) noexcept
114115
{
116+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
115117
XSIMD_IF_CONSTEXPR(sizeof(T) == 2)
116118
{
117119
return _mm512_shrdi_epi16(self, self, count);

include/xsimd/arch/xsimd_common_fwd.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ namespace xsimd
2626
XSIMD_INLINE batch<T, A> abs(batch<T, A> const& self, requires_arch<common>) noexcept;
2727
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
2828
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept;
29-
template <int shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
29+
template <size_t shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
3030
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& self, requires_arch<common>) noexcept;
3131
template <class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
3232
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept;
33-
template <int shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
33+
template <size_t shift, class A, class T, class = typename std::enable_if<std::is_integral<T>::value, void>::type>
3434
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& self, requires_arch<common>) noexcept;
3535
template <class A, class T>
3636
XSIMD_INLINE batch_bool<T, A> gt(batch<T, A> const& self, batch<T, A> const& other, requires_arch<common>) noexcept;
@@ -44,11 +44,11 @@ namespace xsimd
4444
XSIMD_INLINE T hadd(batch<T, A> const& self, requires_arch<common>) noexcept;
4545
template <class A, class T, class STy>
4646
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, STy other, requires_arch<common>) noexcept;
47-
template <int count, class A, class T>
47+
template <size_t count, class A, class T>
4848
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& self, requires_arch<common>) noexcept;
4949
template <class A, class T, class STy>
5050
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, STy other, requires_arch<common>) noexcept;
51-
template <int count, class A, class T>
51+
template <size_t count, class A, class T>
5252
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& self, requires_arch<common>) noexcept;
5353
// Forward declarations for pack-level helpers
5454
namespace detail

include/xsimd/arch/xsimd_scalar.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,11 @@ namespace xsimd
300300
return x << shift;
301301
}
302302

303-
template <int shift, class T>
303+
template <size_t shift, class T>
304304
XSIMD_INLINE typename std::enable_if<std::is_integral<T>::value, T>::type
305305
bitwise_lshift(T x) noexcept
306306
{
307+
static_assert(shift < std::numeric_limits<T>::digits, "shift must be less than the number of bits in T");
307308
return x << shift;
308309
}
309310

@@ -313,10 +314,11 @@ namespace xsimd
313314
{
314315
return x >> shift;
315316
}
316-
template <int shift, class T>
317+
template <size_t shift, class T>
317318
XSIMD_INLINE typename std::enable_if<std::is_integral<T>::value, T>::type
318319
bitwise_rshift(T x) noexcept
319320
{
321+
static_assert(shift < std::numeric_limits<T>::digits, "shift must be less than the number of bits in T");
320322
return x >> shift;
321323
}
322324

@@ -463,10 +465,11 @@ namespace xsimd
463465
constexpr auto N = std::numeric_limits<T0>::digits;
464466
return (x << shift) | (x >> (N - shift));
465467
}
466-
template <int count, class T>
468+
template <size_t count, class T>
467469
XSIMD_INLINE typename std::enable_if<std::is_integral<T>::value, T>::type
468470
rotl(T x) noexcept
469471
{
472+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
470473
constexpr auto N = std::numeric_limits<T>::digits;
471474
return (x << count) | (x >> (N - count));
472475
}
@@ -478,10 +481,11 @@ namespace xsimd
478481
constexpr auto N = std::numeric_limits<T0>::digits;
479482
return (x >> shift) | (x << (N - shift));
480483
}
481-
template <int count, class T>
484+
template <size_t count, class T>
482485
XSIMD_INLINE typename std::enable_if<std::is_integral<T>::value, T>::type
483486
rotr(T x) noexcept
484487
{
488+
static_assert(count < std::numeric_limits<T>::digits, "count must be less than the number of bits in T");
485489
constexpr auto N = std::numeric_limits<T>::digits;
486490
return (x >> count) | (x << (N - count));
487491
}

include/xsimd/types/xsimd_api.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ namespace xsimd
373373
detail::static_check_supported_config<T, A>();
374374
return kernel::bitwise_lshift<A>(x, shift, A {});
375375
}
376-
template <int shift, class T, class A>
376+
template <size_t shift, class T, class A>
377377
XSIMD_INLINE batch<T, A> bitwise_lshift(batch<T, A> const& x) noexcept
378378
{
379379
detail::static_check_supported_config<T, A>();
@@ -458,7 +458,7 @@ namespace xsimd
458458
detail::static_check_supported_config<T, A>();
459459
return kernel::bitwise_rshift<A>(x, shift, A {});
460460
}
461-
template <int shift, class T, class A>
461+
template <size_t shift, class T, class A>
462462
XSIMD_INLINE batch<T, A> bitwise_rshift(batch<T, A> const& x) noexcept
463463
{
464464
detail::static_check_supported_config<T, A>();
@@ -1978,7 +1978,7 @@ namespace xsimd
19781978
detail::static_check_supported_config<T, A>();
19791979
return kernel::rotl<A>(x, shift, A {});
19801980
}
1981-
template <int count, class T, class A>
1981+
template <size_t count, class T, class A>
19821982
XSIMD_INLINE batch<T, A> rotl(batch<T, A> const& x) noexcept
19831983
{
19841984
detail::static_check_supported_config<T, A>();
@@ -2006,7 +2006,7 @@ namespace xsimd
20062006
detail::static_check_supported_config<T, A>();
20072007
return kernel::rotr<A>(x, shift, A {});
20082008
}
2009-
template <int count, class T, class A>
2009+
template <size_t count, class T, class A>
20102010
XSIMD_INLINE batch<T, A> rotr(batch<T, A> const& x) noexcept
20112011
{
20122012
detail::static_check_supported_config<T, A>();

0 commit comments

Comments
 (0)