Skip to content

Commit ce4c360

Browse files
committed
feat: Add batch::raw
1 parent 1bbcdae commit ce4c360

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

include/xsimd/types/xsimd_batch.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ namespace xsimd
193193

194194
XSIMD_INLINE T first() const noexcept;
195195

196+
XSIMD_INLINE register_type raw() const noexcept;
197+
196198
// comparison operators. Defined as friend to enable automatic
197199
// conversion of parameters from scalar to batch, at the cost of using a
198200
// proxy implementation from details::.
@@ -355,6 +357,8 @@ namespace xsimd
355357

356358
XSIMD_INLINE bool first() const noexcept;
357359

360+
XSIMD_INLINE register_type raw() const noexcept;
361+
358362
// mask operations
359363
XSIMD_INLINE uint64_t mask() const noexcept;
360364
XSIMD_INLINE static batch_bool from_mask(uint64_t mask) noexcept;
@@ -836,6 +840,15 @@ namespace xsimd
836840
return kernel::first(*this, A {});
837841
}
838842

843+
/**
844+
* Cast to the underlying native intrinsic register type.
845+
*/
846+
template <class T, class A>
847+
XSIMD_INLINE auto batch<T, A>::raw() const noexcept -> register_type
848+
{
849+
return static_cast<register_type>(*this);
850+
}
851+
839852
/******************************
840853
* batch comparison operators *
841854
******************************/
@@ -1167,6 +1180,15 @@ namespace xsimd
11671180
return kernel::first(*this, A {});
11681181
}
11691182

1183+
/**
1184+
* Cast to the underlying native intrinsic register type.
1185+
*/
1186+
template <class T, class A>
1187+
XSIMD_INLINE auto batch_bool<T, A>::raw() const noexcept -> register_type
1188+
{
1189+
return static_cast<register_type>(*this);
1190+
}
1191+
11701192
/***********************************
11711193
* batch_bool comparison operators *
11721194
***********************************/

test/test_batch.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ struct batch_test
100100
CHECK_EQ(res_dump.str(), b_dump.str());
101101
}
102102

103+
void test_register_conversion() const {
104+
batch_type b1 = batch_type::load_unaligned(lhs.data());
105+
106+
auto b_native = b1.raw();
107+
CHECK(std::is_same<decltype(b_native), typename batch_type::register_type>::value);
108+
109+
batch_type b2 = b_native; // Converting ctor
110+
CHECK_EQ(b1, b2);
111+
}
112+
103113
void test_load_store() const
104114
{
105115
array_type res;

0 commit comments

Comments
 (0)