Skip to content

Commit 5412849

Browse files
guyuqiserge-sans-paille
authored andcommitted
Implement uint8 casting functions
Casting simd data source: (uint8 * N_u8) to (uint16 * N_u16), (uint32 * N_u32) and (uint64 * N_u64). Change-Id: Iaea18face98fc9490fa24c205c4c265fd784e4d4 Signed-off-by: Yuqi Gu <guyuqi@apache.org>
1 parent efa5c3e commit 5412849

5 files changed

Lines changed: 202 additions & 0 deletions

File tree

include/xsimd/types/xsimd_avx512_conversion.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ namespace xsimd
3131
batch<float, 16> to_float(const batch<int32_t, 16>& x);
3232
batch<double, 8> to_float(const batch<int64_t, 8>& x);
3333

34+
batch<uint16_t, 32> u8_to_u16(const batch<uint8_t, 64>& x);
35+
batch<uint8_t, 64> u16_to_u8(const batch<uint16_t, 32>& x);
36+
batch<uint32_t, 16> u8_to_u32(const batch<uint8_t, 64>& x);
37+
batch<uint8_t, 64> u32_to_u8(const batch<uint32_t, 16>& x);
38+
batch<uint64_t, 8> u8_to_u64(const batch<uint8_t, 64>& x);
39+
batch<uint8_t, 64> u64_to_u8(const batch<uint64_t, 8>& x);
40+
3441
/**************************
3542
* boolean cast functions *
3643
**************************/
@@ -179,6 +186,34 @@ namespace xsimd
179186
XSIMD_BATCH_CAST_INTRINSIC(double, uint64_t, 8, _mm512_cvttpd_epu64)
180187
#endif
181188

189+
inline batch<uint16_t, 32> u8_to_u16(const batch<uint8_t, 64>& x)
190+
{
191+
return static_cast<batch<uint16_t, 32>>(x);
192+
}
193+
inline batch<uint8_t, 64> u16_to_u8(const batch<uint16_t, 32>& x)
194+
{
195+
return static_cast<batch<uint8_t, 64>>(x);
196+
}
197+
198+
inline batch<uint32_t, 16> u8_to_u32(const batch<uint8_t, 64>& x)
199+
{
200+
return static_cast<batch<uint32_t, 16>>(x);
201+
}
202+
inline batch<uint8_t, 64> u32_to_u8(const batch<uint32_t, 16>& x)
203+
{
204+
return static_cast<batch<uint8_t, 64>>(x);
205+
}
206+
207+
inline batch<uint64_t, 8> u8_to_u64(const batch<uint8_t, 64>& x)
208+
{
209+
return static_cast<batch<uint64_t, 8>>(x);
210+
}
211+
212+
inline batch<uint8_t, 64> u64_to_u8(const batch<uint64_t, 8>& x)
213+
{
214+
return static_cast<batch<uint8_t, 64>>(x);
215+
}
216+
182217
/**************************
183218
* boolean cast functions *
184219
**************************/

include/xsimd/types/xsimd_avx_conversion.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ namespace xsimd
3131
batch<float, 8> to_float(const batch<int32_t, 8>& x);
3232
batch<double, 4> to_float(const batch<int64_t, 4>& x);
3333

34+
batch<uint16_t, 16> u8_to_u16(const batch<uint8_t, 32>& x);
35+
batch<uint8_t, 32> u16_to_u8(const batch<uint16_t, 16>& x);
36+
batch<uint32_t, 8> u8_to_u32(const batch<uint8_t, 32>& x);
37+
batch<uint8_t, 32> u32_to_u8(const batch<uint32_t, 8>& x);
38+
batch<uint64_t, 4> u8_to_u64(const batch<uint8_t, 32>& x);
39+
batch<uint8_t, 32> u64_to_u8(const batch<uint64_t, 4>& x);
40+
3441
/**************************
3542
* boolean cast functions *
3643
**************************/
@@ -78,6 +85,34 @@ namespace xsimd
7885
#endif
7986
}
8087

88+
inline batch<uint16_t, 16> u8_to_u16(const batch<uint8_t, 32>& x)
89+
{
90+
return static_cast<batch<uint16_t, 16>>(x);
91+
}
92+
inline batch<uint8_t, 32> u16_to_u8(const batch<uint16_t, 16>& x)
93+
{
94+
return static_cast<batch<uint8_t, 32>>(x);
95+
}
96+
97+
inline batch<uint32_t, 8> u8_to_u32(const batch<uint8_t, 32>& x)
98+
{
99+
return static_cast<batch<uint32_t, 8>>(x);
100+
}
101+
inline batch<uint8_t, 32> u32_to_u8(const batch<uint32_t, 8>& x)
102+
{
103+
return static_cast<batch<uint8_t, 32>>(x);
104+
}
105+
106+
inline batch<uint64_t, 4> u8_to_u64(const batch<uint8_t, 32>& x)
107+
{
108+
return static_cast<batch<uint64_t, 4>>(x);
109+
}
110+
111+
inline batch<uint8_t, 32> u64_to_u8(const batch<uint64_t, 4>& x)
112+
{
113+
return static_cast<batch<uint8_t, 32>>(x);
114+
}
115+
81116
/*****************************************
82117
* batch cast functions implementation *
83118
*****************************************/

include/xsimd/types/xsimd_fallback.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,24 @@ namespace xsimd
11991199
/*****************************************
12001200
* bitwise cast functions implementation *
12011201
*****************************************/
1202+
template <std::size_t in_N, std::size_t out_N>
1203+
batch<uint16_t, out_N> u8_to_u16(const batch<uint8_t, in_N>& x);
1204+
1205+
template <std::size_t in_N, std::size_t out_N>
1206+
batch<uint8_t, out_N> u16_to_u8(const batch<uint16_t, in_N>& x);
1207+
1208+
template <std::size_t in_N, std::size_t out_N>
1209+
batch<uint32_t, out_N> u8_to_u32(const batch<uint8_t, in_N>& x);
1210+
1211+
template <std::size_t in_N, std::size_t out_N>
1212+
batch<uint8_t, out_N> u32_to_u8(const batch<uint32_t, in_N>& x);
1213+
1214+
template <std::size_t in_N, std::size_t out_N>
1215+
batch<uint64_t, out_N> u8_to_u64(const batch<uint8_t, in_N>& x);
1216+
1217+
template <std::size_t in_N, std::size_t out_N>
1218+
batch<uint8_t, out_N> u64_to_u8(const batch<uint64_t, in_N>& x);
1219+
12021220

12031221
template <class T_in, class T_out, std::size_t N_in>
12041222
struct bitwise_cast_impl<batch<T_in, N_in>,
@@ -1221,6 +1239,46 @@ namespace xsimd
12211239
return batch<T_out, N_out>(caster.out);
12221240
}
12231241
};
1242+
1243+
/***********************************************
1244+
* static_cast conversion by bitwise_cast_impl *
1245+
***********************************************/
1246+
template <std::size_t in_N, std::size_t out_N>
1247+
inline batch<uint16_t, out_N> u8_to_u16(const batch<uint8_t, in_N>& x)
1248+
{
1249+
return bitwise_cast_impl<batch<uint8_t, in_N>, batch<uint16_t, out_N>>::run(x);
1250+
}
1251+
1252+
template <std::size_t in_N, std::size_t out_N>
1253+
inline batch<uint8_t, out_N> u16_to_u8(const batch<uint16_t, in_N>& x)
1254+
{
1255+
return bitwise_cast_impl<batch<uint16_t, in_N>, batch<uint8_t, out_N>>::run(x);
1256+
}
1257+
1258+
template <std::size_t in_N, std::size_t out_N>
1259+
inline batch<uint32_t, out_N> u8_to_u32(const batch<uint8_t, in_N>& x)
1260+
{
1261+
return bitwise_cast_impl<batch<uint8_t, in_N>, batch<uint32_t, out_N>>::run(x);
1262+
}
1263+
1264+
template <std::size_t in_N, std::size_t out_N>
1265+
inline batch<uint8_t, out_N> u32_to_u8(const batch<uint32_t, in_N>& x)
1266+
{
1267+
return bitwise_cast_impl<batch<uint32_t, in_N>, batch<uint8_t, out_N>>::run(x);
1268+
}
1269+
1270+
template <std::size_t in_N, std::size_t out_N>
1271+
inline batch<uint64_t, out_N> u8_to_u64(const batch<uint8_t, in_N>& x)
1272+
{
1273+
return bitwise_cast_impl<batch<uint8_t, in_N>, batch<uint64_t, out_N>>::run(x);
1274+
}
1275+
1276+
template <std::size_t in_N, std::size_t out_N>
1277+
inline batch<uint8_t, out_N> u64_to_u8(const batch<uint64_t, in_N>& x)
1278+
{
1279+
return bitwise_cast_impl<batch<uint64_t, in_N>, batch<uint8_t, out_N>>::run(x);
1280+
}
1281+
12241282
}
12251283

12261284
#endif

include/xsimd/types/xsimd_neon_conversion.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ namespace xsimd
3535
batch<int32_t, 4> to_int(const batch<float, 4>& x);
3636
batch<float, 4> to_float(const batch<int32_t, 4>& x);
3737

38+
batch<uint16_t, 8> u8_to_u16(const batch<uint8_t, 16>& x);
39+
batch<uint8_t, 16> u16_to_u8(const batch<uint16_t, 8>& x);
40+
batch<uint32_t, 4> u8_to_u32(const batch<uint8_t, 16>& x);
41+
batch<uint8_t, 16> u32_to_u8(const batch<uint32_t, 4>& x);
42+
batch<uint64_t, 2> u8_to_u64(const batch<uint8_t, 16>& x);
43+
batch<uint8_t, 16> u64_to_u8(const batch<uint64_t, 2>& x);
44+
3845
#if XSIMD_ARM_INSTR_SET >= XSIMD_ARM8_64_NEON_VERSION
3946
batch<int64_t, 2> to_int(const batch<double, 2>& x);
4047
batch<double, 2> to_float(const batch<int64_t, 2>& x);
@@ -83,6 +90,36 @@ namespace xsimd
8390
return vcvtq_f32_s32(x);
8491
}
8592

93+
inline batch<uint16_t, 8> u8_to_u16(const batch<uint8_t, 16>& x)
94+
{
95+
return vreinterpretq_u16_u8(x);
96+
}
97+
98+
inline batch<uint8_t, 16> u16_to_u8(const batch<uint16_t, 8>& x)
99+
{
100+
return vreinterpretq_u8_u16(x);
101+
}
102+
103+
inline batch<uint32_t, 4> u8_to_u32(const batch<uint8_t, 16>& x)
104+
{
105+
return vreinterpretq_u32_u8(x);
106+
}
107+
108+
inline batch<uint8_t, 16> u32_to_u8(const batch<uint32_t, 4>& x)
109+
{
110+
return vreinterpretq_u8_u32(x);
111+
}
112+
113+
inline batch<uint64_t, 2> u8_to_u64(const batch<uint8_t, 16>& x)
114+
{
115+
return vreinterpretq_u64_u8(x);
116+
}
117+
118+
inline batch<uint8_t, 16> u64_to_u8(const batch<uint64_t, 2>& x)
119+
{
120+
return vreinterpretq_u8_u64(x);
121+
}
122+
86123
#if XSIMD_ARM_INSTR_SET >= XSIMD_ARM8_64_NEON_VERSION
87124
inline batch<int64_t, 2> to_int(const batch<double, 2>& x)
88125
{

include/xsimd/types/xsimd_sse_conversion.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ namespace xsimd
3131
batch<float, 4> to_float(const batch<int32_t, 4>& x);
3232
batch<double, 2> to_float(const batch<int64_t, 2>& x);
3333

34+
batch<uint16_t, 8> u8_to_u16(const batch<uint8_t, 16>& x);
35+
batch<uint8_t, 16> u16_to_u8(const batch<uint16_t, 8>& x);
36+
batch<uint32_t, 4> u8_to_u32(const batch<uint8_t, 16>& x);
37+
batch<uint8_t, 16> u32_to_u8(const batch<uint32_t, 4>& x);
38+
batch<uint64_t, 2> u8_to_u64(const batch<uint8_t, 16>& x);
39+
batch<uint8_t, 16> u64_to_u8(const batch<uint64_t, 2>& x);
40+
3441
/**************************
3542
* boolean cast functions *
3643
**************************/
@@ -72,6 +79,36 @@ namespace xsimd
7279
#endif
7380
}
7481

82+
inline batch<uint16_t, 8> u8_to_u16(const batch<uint8_t, 16>& x)
83+
{
84+
return static_cast<batch<uint16_t, 8>>(x);
85+
}
86+
87+
inline batch<uint8_t, 16> u16_to_u8(const batch<uint16_t, 8>& x)
88+
{
89+
return static_cast<batch<uint8_t, 16>>(x);
90+
}
91+
92+
inline batch<uint32_t, 4> u8_to_u32(const batch<uint8_t, 16>& x)
93+
{
94+
return static_cast<batch<uint32_t, 4>>(x);
95+
}
96+
97+
inline batch<uint8_t, 16> u32_to_u8(const batch<uint32_t, 4>& x)
98+
{
99+
return static_cast<batch<uint8_t, 16>>(x);
100+
}
101+
102+
inline batch<uint64_t, 2> u8_to_u64(const batch<uint8_t, 16>& x)
103+
{
104+
return static_cast<batch<uint64_t, 2>>(x);
105+
}
106+
107+
inline batch<uint8_t, 16> u64_to_u8(const batch<uint64_t, 2>& x)
108+
{
109+
return static_cast<batch<uint8_t, 16>>(x);
110+
}
111+
75112
/*****************************************
76113
* batch cast functions implementation *
77114
*****************************************/

0 commit comments

Comments
 (0)