Skip to content

Commit bbeeeb2

Browse files
committed
Move add to v15 on arm
1 parent 5491a13 commit bbeeeb2

11 files changed

Lines changed: 280 additions & 135 deletions

File tree

include/xsimd/arch/utils/sve.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/****************************************************************************
2+
* Copyright (c) xsimd contributors *
3+
* *
4+
* Distributed under the terms of the BSD 3-Clause License. *
5+
* *
6+
* The full license is in the file LICENSE, distributed with this software. *
7+
****************************************************************************/
8+
9+
#ifndef XSIMD_ARCH_UTILS_SVE_HPP
10+
#define XSIMD_ARCH_UTILS_SVE_HPP
11+
12+
#include "../../config/xsimd_macros.hpp"
13+
#include "../../types/xsimd_sve_register.hpp"
14+
15+
#include <type_traits>
16+
17+
// Define a inline namespace with the explicit SVE vector size to avoid ODR violation
18+
// When dynamically dispatching between different SVE sizes.
19+
// While most code is safe from ODR violation as the size is already encoded in the
20+
// register (and hence batch) types, utilities can quickly fall prone to this issue.
21+
#define XSIMD_SVE_NAMESPACE XSIMD_CONCAT(sve, XSIMD_SVE_BITS)
22+
23+
namespace xsimd::kernel::detail
24+
{
25+
inline namespace XSIMD_SVE_NAMESPACE
26+
{
27+
template <class T>
28+
XSIMD_INLINE auto svptrue() noexcept
29+
{
30+
#if XSIMD_WITH_SVE
31+
if constexpr (sizeof(T) == 1)
32+
{
33+
return svptrue_b8();
34+
}
35+
else if constexpr (sizeof(T) == 2)
36+
{
37+
return svptrue_b16();
38+
}
39+
else if constexpr (sizeof(T) == 4)
40+
{
41+
return svptrue_b32();
42+
}
43+
else if constexpr (sizeof(T) == 8)
44+
{
45+
return svptrue_b64();
46+
}
47+
#endif
48+
}
49+
}
50+
}
51+
#endif

include/xsimd/arch/xsimd_isa.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
#include "../config/xsimd_arch.hpp"
1717
#include "./xsimd_common_fwd.hpp"
1818

19+
// v15 API under migration
20+
#if XSIMD_WITH_NEON || XSIMD_WITH_SVE
21+
#include "../v15/arithmetic/arm.hpp"
22+
#endif
23+
1924
#if XSIMD_WITH_EMULATED
2025
#include "./xsimd_emulated.hpp"
2126
#endif

include/xsimd/arch/xsimd_neon.hpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -811,42 +811,6 @@ namespace xsimd
811811
return vnegq_f32(rhs);
812812
}
813813

814-
/*******
815-
* add *
816-
*******/
817-
818-
namespace wrap
819-
{
820-
// TODO(c++17): Make a single function with if constexpr switch
821-
// Templating on the scalar type `T` is required because in some compilers (e.g. MSVC)
822-
// the vector types are all aliases of the same type.
823-
template <class T, std::enable_if_t<std::is_same_v<T, uint8_t>, int> = 0>
824-
XSIMD_INLINE uint8x16_t x_vaddq(uint8x16_t a, uint8x16_t b) noexcept { return vaddq_u8(a, b); }
825-
template <class T, std::enable_if_t<std::is_same_v<T, int8_t>, int> = 0>
826-
XSIMD_INLINE int8x16_t x_vaddq(int8x16_t a, int8x16_t b) noexcept { return vaddq_s8(a, b); }
827-
template <class T, std::enable_if_t<std::is_same_v<T, uint16_t>, int> = 0>
828-
XSIMD_INLINE uint16x8_t x_vaddq(uint16x8_t a, uint16x8_t b) noexcept { return vaddq_u16(a, b); }
829-
template <class T, std::enable_if_t<std::is_same_v<T, int16_t>, int> = 0>
830-
XSIMD_INLINE int16x8_t x_vaddq(int16x8_t a, int16x8_t b) noexcept { return vaddq_s16(a, b); }
831-
template <class T, std::enable_if_t<std::is_same_v<T, uint32_t>, int> = 0>
832-
XSIMD_INLINE uint32x4_t x_vaddq(uint32x4_t a, uint32x4_t b) noexcept { return vaddq_u32(a, b); }
833-
template <class T, std::enable_if_t<std::is_same_v<T, int32_t>, int> = 0>
834-
XSIMD_INLINE int32x4_t x_vaddq(int32x4_t a, int32x4_t b) noexcept { return vaddq_s32(a, b); }
835-
template <class T, std::enable_if_t<std::is_same_v<T, uint64_t>, int> = 0>
836-
XSIMD_INLINE uint64x2_t x_vaddq(uint64x2_t a, uint64x2_t b) noexcept { return vaddq_u64(a, b); }
837-
template <class T, std::enable_if_t<std::is_same_v<T, int64_t>, int> = 0>
838-
XSIMD_INLINE int64x2_t x_vaddq(int64x2_t a, int64x2_t b) noexcept { return vaddq_s64(a, b); }
839-
template <class T, std::enable_if_t<std::is_same_v<T, float>, int> = 0>
840-
XSIMD_INLINE float32x4_t x_vaddq(float32x4_t a, float32x4_t b) noexcept { return vaddq_f32(a, b); }
841-
}
842-
843-
template <class A, class T, detail::enable_neon_type_t<T> = 0>
844-
XSIMD_INLINE batch<T, A> add(batch<T, A> const& lhs, batch<T, A> const& rhs, requires_arch<neon>) noexcept
845-
{
846-
using register_type = typename batch<T, A>::register_type;
847-
return wrap::x_vaddq<map_to_sized_type_t<T>>(register_type(lhs), register_type(rhs));
848-
}
849-
850814
/*******
851815
* avg *
852816
*******/

include/xsimd/arch/xsimd_neon64.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "../types/xsimd_neon64_register.hpp"
1616
#include "../types/xsimd_utils.hpp"
17+
#include "../v15/kernel_fwd.hpp"
1718
#include "./xsimd_neon.hpp"
1819

1920
#include <cassert>
@@ -352,24 +353,14 @@ namespace xsimd
352353
return vnegq_f64(rhs);
353354
}
354355

355-
/*******
356-
* add *
357-
*******/
358-
359-
template <class A>
360-
XSIMD_INLINE batch<double, A> add(batch<double, A> const& lhs, batch<double, A> const& rhs, requires_arch<neon64>) noexcept
361-
{
362-
return vaddq_f64(lhs, rhs);
363-
}
364-
365356
/********
366357
* sadd *
367358
********/
368359

369360
template <class A>
370361
XSIMD_INLINE batch<double, A> sadd(batch<double, A> const& lhs, batch<double, A> const& rhs, requires_arch<neon64>) noexcept
371362
{
372-
return add(lhs, rhs, neon64 {});
363+
return ::xsimd::kernel::add(lhs, rhs);
373364
}
374365

375366
/*******

0 commit comments

Comments
 (0)