Skip to content

Commit e0a63bc

Browse files
committed
WIP: move cx impl into non-member functions in simd_complex.h
include/ChangeLog: * bits/simd_complex.h: * bits/simd_vec.h:
1 parent 31699d5 commit e0a63bc

2 files changed

Lines changed: 68 additions & 33 deletions

File tree

include/bits/simd_complex.h

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,42 @@ namespace simd
188188
return __builtin_bit_cast(__tree_of_ulong_t<__div_ceil(_Np, size_t(__CHAR_BIT__))>, __b);
189189
}
190190

191+
namespace __cx
192+
{
193+
template <typename _Tp, typename _Ap>
194+
[[__gnu__::__always_inline__]]
195+
constexpr void
196+
__set_real(basic_vec<_Tp, _Ap>& __x,
197+
const __similar_vec<_Tp, _Ap::_S_size / 2, _Ap>& __re) noexcept
198+
{
199+
static_assert(is_floating_point_v<_Tp>);
200+
static_assert((_Ap::_S_size & 1) == 0);
201+
if constexpr (_Ap::_S_nreg == 1)
202+
{
203+
using _DataType = typename _Ap::template _DataType<_Tp>;
204+
_DataType& __xv = __x._M_get();
205+
const auto __rv = __re._M_get();
206+
if constexpr (_Ap::_S_size == 2)
207+
__vec_set(__xv, 0, __rv);
208+
else if (__is_const_known(__x, __re))
209+
{
210+
constexpr auto [...__is] = _IotaArray<_Ap::_S_size>;
211+
__xv = _DataType {((__is & 1) == 0 ? __rv[__is / 2] : __xv[__is])...};
212+
}
213+
else
214+
_VecOps<_DataType>::_S_overwrite_even_elements(__xv, __rv);
215+
}
216+
else
217+
{
218+
constexpr int __n0 = __x._M_get_low().size();
219+
const auto& [__lo, __hi] = __re.template _M_chunk<
220+
__similar_vec<_Tp, __n0 / 2, _Ap>>();
221+
__set_real(__x._M_get_low(), __lo);
222+
__set_real(__x._M_get_high(), __hi);
223+
}
224+
}
225+
}
226+
191227
// complex interleaved (_CxIleav) -------------------------------------------
192228

193229
template <size_t _Bytes, __abi_tag _Ap>
@@ -968,7 +1004,7 @@ namespace simd
9681004
constexpr
9691005
basic_vec(const _RealSimd& __re, const _RealSimd& __im = {}) noexcept
9701006
{
971-
_M_data._M_complex_set_real(__re);
1007+
__cx::__set_real(_M_data, __re);
9721008
_M_data._M_complex_set_imag(__im);
9731009
}
9741010

@@ -1191,7 +1227,7 @@ namespace simd
11911227
[[__gnu__::__always_inline__]]
11921228
constexpr void
11931229
real(const _RealSimd& __x) noexcept
1194-
{ _M_data._M_complex_set_real(__x); }
1230+
{ __cx::__set_real(_M_data, __x); }
11951231

11961232
[[__gnu__::__always_inline__]]
11971233
constexpr void
@@ -1683,14 +1719,24 @@ namespace simd
16831719
using mask_type = _VecBase<_Tp, _Ap>::mask_type;
16841720

16851721
// internal but public API ----------------------------------------------
1722+
[[__gnu__::__always_inline__]]
1723+
constexpr _RealSimd&
1724+
_M_get_real() noexcept
1725+
{ return _M_real; }
1726+
16861727
[[__gnu__::__always_inline__]]
16871728
constexpr const _RealSimd&
1688-
_M_get_real() const
1729+
_M_get_real() const noexcept
16891730
{ return _M_real; }
16901731

1732+
[[__gnu__::__always_inline__]]
1733+
constexpr _RealSimd&
1734+
_M_get_imag() noexcept
1735+
{ return _M_imag; }
1736+
16911737
[[__gnu__::__always_inline__]]
16921738
constexpr const _RealSimd&
1693-
_M_get_imag() const
1739+
_M_get_imag() const noexcept
16941740
{ return _M_imag; }
16951741

16961742
[[__gnu__::__always_inline__]]

include/bits/simd_vec.h

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,14 @@ namespace simd
341341
return __r;
342342
}
343343

344+
[[__gnu__::__always_inline__]]
345+
constexpr _DataType&
346+
_M_get() noexcept
347+
{ return _M_data; }
348+
344349
[[__gnu__::__always_inline__]]
345350
constexpr const _DataType&
346-
_M_get() const
351+
_M_get() const noexcept
347352
{ return _M_data; }
348353
#if VIR_PATCH_PERMUTE_DYNAMIC
349354

@@ -452,22 +457,6 @@ namespace simd
452457

453458
static constexpr bool _SupportCxApi = (_S_size & 1) == 0 && is_floating_point_v<value_type>;
454459

455-
[[__gnu__::__always_inline__]]
456-
constexpr void
457-
_M_complex_set_real(const _HalfVec& __x) requires _SupportCxApi
458-
{
459-
if (__is_const_known(*this, __x))
460-
{
461-
constexpr auto [...__is] = _IotaArray<_S_size>;
462-
_M_data = _DataType { ((__is & 1) == 0 ? __canon_value_type(__x[__is / 2])
463-
: _M_data[__is])...};
464-
}
465-
else if constexpr (_S_size == 2)
466-
_M_data[0] = __x[0];
467-
else
468-
_VecOps<_DataType>::_S_overwrite_even_elements(_M_data, __x);
469-
}
470-
471460
[[__gnu__::__always_inline__]]
472461
constexpr void
473462
_M_complex_set_imag(const _HalfVec& __x) requires _SupportCxApi
@@ -2214,14 +2203,24 @@ namespace simd
22142203
return __r;
22152204
}
22162205

2206+
[[__gnu__::__always_inline__]]
2207+
constexpr _DataType0&
2208+
_M_get_low() noexcept
2209+
{ return _M_data0; }
2210+
22172211
[[__gnu__::__always_inline__]]
22182212
constexpr const _DataType0&
2219-
_M_get_low() const
2213+
_M_get_low() const noexcept
22202214
{ return _M_data0; }
22212215

2216+
[[__gnu__::__always_inline__]]
2217+
constexpr _DataType1&
2218+
_M_get_high() noexcept
2219+
{ return _M_data1; }
2220+
22222221
[[__gnu__::__always_inline__]]
22232222
constexpr const _DataType1&
2224-
_M_get_high() const
2223+
_M_get_high() const noexcept
22252224
{ return _M_data1; }
22262225
#if VIR_PATCH_PERMUTE_DYNAMIC
22272226

@@ -2272,16 +2271,6 @@ namespace simd
22722271

22732272
static constexpr bool _SupportCxApi = (_S_size & 1) == 0 && is_floating_point_v<value_type>;
22742273

2275-
[[__gnu__::__always_inline__]]
2276-
constexpr void
2277-
_M_complex_set_real(const _HalfVec& __x) requires _SupportCxApi
2278-
{
2279-
const auto& [__lo, __hi]
2280-
= __x.template _M_chunk<__similar_resized_vec<value_type, _N0 / 2, _Ap>>();
2281-
_M_data0._M_complex_set_real(__lo);
2282-
_M_data1._M_complex_set_real(__hi);
2283-
}
2284-
22852274
[[__gnu__::__always_inline__]]
22862275
constexpr void
22872276
_M_complex_set_imag(const _HalfVec& __x) requires _SupportCxApi

0 commit comments

Comments
 (0)