Skip to content

Commit 73c0712

Browse files
committed
Add shifts
1 parent 58e1b0c commit 73c0712

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

include/xsimd/types/xsimd_batch_constant.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ namespace xsimd
194194
{
195195
constexpr T operator()(T x, T y) const { return x ^ y; }
196196
};
197+
struct binary_rshift
198+
{
199+
constexpr T operator()(T x, T y) const { return x >> y; }
200+
};
201+
struct binary_lshift
202+
{
203+
constexpr T operator()(T x, T y) const { return x << y; }
204+
};
197205

198206
template <class F, class SelfPack, class OtherPack, std::size_t... Indices>
199207
static constexpr batch_constant<T, A, F()(std::tuple_element<Indices, SelfPack>::type::value, std::tuple_element<Indices, OtherPack>::type::value)...>
@@ -227,6 +235,8 @@ namespace xsimd
227235
MAKE_BINARY_OP(&, binary_and)
228236
MAKE_BINARY_OP(|, binary_or)
229237
MAKE_BINARY_OP(^, binary_xor)
238+
MAKE_BINARY_OP(<<, binary_lshift)
239+
MAKE_BINARY_OP(>>, binary_rshift)
230240

231241
#undef MAKE_BINARY_OP
232242

test/test_batch_constant.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ struct constant_batch_test
136136
constexpr auto n12_lxor_n3 = n12 ^ n3;
137137
static_assert(std::is_same<decltype(n12_lxor_n3), decltype(n15)>::value, "n12 ^ n3 == n15");
138138

139+
constexpr auto n96 = xsimd::make_batch_constant<value_type, constant<96>, arch_type>();
140+
constexpr auto n12_lshift_n3 = n12 << n3;
141+
static_assert(std::is_same<decltype(n12_lshift_n3), decltype(n96)>::value, "n12 << n3 == n96");
142+
143+
constexpr auto n1 = xsimd::make_batch_constant<value_type, constant<1>, arch_type>();
144+
constexpr auto n12_rshift_n3 = n12 >> n3;
145+
static_assert(std::is_same<decltype(n12_rshift_n3), decltype(n1)>::value, "n12 >> n3 == n1");
146+
139147
constexpr auto n12_uadd = +n12;
140148
static_assert(std::is_same<decltype(n12_uadd), decltype(n12)>::value, "+n12 == n12");
141149

0 commit comments

Comments
 (0)