Skip to content

Commit 6830b4b

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

2 files changed

Lines changed: 38 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ struct batch_test
100100
CHECK_EQ(res_dump.str(), b_dump.str());
101101
}
102102

103+
void test_register_conversion() const
104+
{
105+
batch_type b1 = batch_type::load_unaligned(lhs.data());
106+
107+
auto b_native = b1.raw();
108+
CHECK(std::is_same<decltype(b_native), typename batch_type::register_type>::value);
109+
110+
batch_type b2 = b_native; // Converting ctor
111+
CHECK_BATCH_EQ(b1, b2);
112+
}
113+
103114
void test_load_store() const
104115
{
105116
array_type res;
@@ -1161,6 +1172,11 @@ TEST_CASE_TEMPLATE("[batch]", B, BATCH_TYPES)
11611172
Test.test_stream_dump();
11621173
}
11631174

1175+
SUBCASE("register_conversion")
1176+
{
1177+
Test.test_register_conversion();
1178+
}
1179+
11641180
SUBCASE("load_store")
11651181
{
11661182
Test.test_load_store();

0 commit comments

Comments
 (0)