Skip to content

Commit 3ea4dd3

Browse files
committed
Move and rename SizedInt to type_traits
1 parent 754f3ab commit 3ea4dd3

2 files changed

Lines changed: 36 additions & 31 deletions

File tree

cpp/src/arrow/util/byte_stream_split_internal.h

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "arrow/util/endian.h"
2121
#include "arrow/util/simd.h"
2222
#include "arrow/util/small_vector.h"
23+
#include "arrow/util/type_traits.h"
2324
#include "arrow/util/ubsan.h"
2425

2526
#include <algorithm>
@@ -112,56 +113,33 @@ void ByteStreamSplitDecodeSimd128(const uint8_t* data, int width, int64_t num_va
112113
}
113114
}
114115

115-
template <int kNumBytes>
116-
struct grouped_bytes_impl;
117-
118-
template <>
119-
struct grouped_bytes_impl<1> {
120-
using type = int8_t;
121-
};
122-
123-
template <>
124-
struct grouped_bytes_impl<2> {
125-
using type = int16_t;
126-
};
127-
128-
template <>
129-
struct grouped_bytes_impl<4> {
130-
using type = int32_t;
131-
};
132-
133-
template <>
134-
struct grouped_bytes_impl<8> {
135-
using type = int64_t;
136-
};
137-
138-
// Map a number of bytes to a type
139-
template <int kNumBytes>
140-
using grouped_bytes_t = typename grouped_bytes_impl<kNumBytes>::type;
141-
142116
// Like xsimd::zip_lo, but zip groups of kNumBytes at once.
143117
template <int kNumBytes, int kBatchSize = 16,
144118
typename Batch = xsimd::make_sized_batch_t<int8_t, kBatchSize>>
145119
auto zip_lo_n(Batch const& a, Batch const& b) -> Batch {
120+
using arrow::internal::SizedInt;
121+
146122
if constexpr (kNumBytes == kBatchSize) {
147123
return a;
148124
} else {
149125
return xsimd::bitwise_cast<int8_t>(
150-
xsimd::zip_lo(xsimd::bitwise_cast<grouped_bytes_t<kNumBytes>>(a),
151-
xsimd::bitwise_cast<grouped_bytes_t<kNumBytes>>(b)));
126+
xsimd::zip_lo(xsimd::bitwise_cast<SizedInt<kNumBytes>>(a),
127+
xsimd::bitwise_cast<SizedInt<kNumBytes>>(b)));
152128
}
153129
}
154130

155131
// Like xsimd::zip_hi, but zip groups of kNumBytes at once.
156132
template <int kNumBytes, int kBatchSize = 16,
157133
typename Batch = xsimd::make_sized_batch_t<int8_t, kBatchSize>>
158134
auto zip_hi_n(Batch const& a, Batch const& b) -> Batch {
135+
using arrow::internal::SizedInt;
136+
159137
if constexpr (kNumBytes == kBatchSize) {
160138
return b;
161139
} else {
162140
return xsimd::bitwise_cast<int8_t>(
163-
xsimd::zip_hi(xsimd::bitwise_cast<grouped_bytes_t<kNumBytes>>(a),
164-
xsimd::bitwise_cast<grouped_bytes_t<kNumBytes>>(b)));
141+
xsimd::zip_hi(xsimd::bitwise_cast<SizedInt<kNumBytes>>(a),
142+
xsimd::bitwise_cast<SizedInt<kNumBytes>>(b)));
165143
}
166144
}
167145

cpp/src/arrow/util/type_traits.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,32 @@ template <typename T>
4242
struct is_null_pointer : std::is_same<std::nullptr_t, typename std::remove_cv<T>::type> {
4343
};
4444

45+
template <int kNumBytes>
46+
struct SizedIntImpl;
47+
48+
template <>
49+
struct SizedIntImpl<1> {
50+
using type = int8_t;
51+
};
52+
53+
template <>
54+
struct SizedIntImpl<2> {
55+
using type = int16_t;
56+
};
57+
58+
template <>
59+
struct SizedIntImpl<4> {
60+
using type = int32_t;
61+
};
62+
63+
template <>
64+
struct SizedIntImpl<8> {
65+
using type = int64_t;
66+
};
67+
68+
// Map a number of bytes to a type
69+
template <int kNumBytes>
70+
using SizedInt = typename SizedIntImpl<kNumBytes>::type;
71+
4572
} // namespace internal
4673
} // namespace arrow

0 commit comments

Comments
 (0)