Skip to content

Commit b30d148

Browse files
committed
Add support for operators on vector_ref
1 parent 933c1b9 commit b30d148

File tree

5 files changed

+56
-62
lines changed

5 files changed

+56
-62
lines changed

include/kernel_float/base.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,13 @@ struct preferred_vector_size {
240240
};
241241

242242
template<typename V>
243-
struct vector_traits;
243+
struct is_vector_impl {
244+
static constexpr bool value = false;
245+
};
244246

245247
template<typename T, typename E, typename S>
246-
struct vector_traits<vector<T, E, S>> {
247-
using value_type = T;
248-
using extent_type = E;
249-
using storage_type = S;
250-
using vector_type = vector<T, E, S>;
248+
struct is_vector_impl<vector<T, E, S>> {
249+
static constexpr bool value = true;
251250
};
252251

253252
template<typename V>
@@ -259,6 +258,9 @@ using vector_extent_type = typename into_vector_impl<V>::extent_type;
259258
template<typename V>
260259
static constexpr size_t vector_size = extent_size<vector_extent_type<V>>;
261260

261+
template<typename V>
262+
static constexpr bool is_vector = is_vector_impl<V>::value;
263+
262264
template<typename V>
263265
using into_vector_type = vector<vector_value_type<V>, vector_extent_type<V>>;
264266

include/kernel_float/binops.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,12 @@ KERNEL_FLOAT_INLINE zip_common_type<F, L, R> zip_common(F fun, const L& left, co
109109
#define KERNEL_FLOAT_DEFINE_BINARY_OP_FALLBACK(NAME, OP, EXPR_F64, EXPR_F32) \
110110
KERNEL_FLOAT_DEFINE_BINARY(NAME, left OP right, EXPR_F64, EXPR_F32) \
111111
\
112-
template<typename L, typename R, typename C = promote_t<L, R>, typename E1, typename E2> \
113-
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, vector<L, E1>, vector<R, E2>> operator OP( \
114-
const vector<L, E1>& left, \
115-
const vector<R, E2>& right) { \
116-
return zip_common(ops::NAME<C> {}, left, right); \
117-
} \
118-
template<typename L, typename R, typename C = promote_t<L, vector_value_type<R>>, typename E> \
119-
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, vector<L, E>, R> operator OP( \
120-
const vector<L, E>& left, \
121-
const R \
122-
& right) { \
123-
return zip_common(ops::NAME<C> {}, left, right); \
124-
} \
125-
template<typename L, typename R, typename C = promote_t<vector_value_type<L>, R>, typename E> \
126-
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, L, vector<R, E>> operator OP( \
127-
const L \
128-
& left, \
129-
const vector<R, E>& right) { \
112+
template< \
113+
typename L, \
114+
typename R, \
115+
typename C = enable_if_t<is_vector<L> || is_vector<R>, promoted_vector_value_type<L, R>>> \
116+
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, L, R> \
117+
operator OP(const L & left, const R & right) { \
130118
return zip_common(ops::NAME<C> {}, left, right); \
131119
}
132120

include/kernel_float/memory.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ struct into_vector_impl<vector_ref<T, N, U, Alignment>> {
436436
}
437437
};
438438

439+
template<typename T, size_t N, typename U, size_t Alignment>
440+
struct is_vector_impl<vector_ref<T, N, U, Alignment>> {
441+
static constexpr bool value = true;
442+
};
443+
439444
/**
440445
* A wrapper for a pointer that enables vectorized access and supports type conversions..
441446
*
@@ -461,6 +466,7 @@ struct vector_ptr {
461466
* Default constructor sets the pointer to `NULL`.
462467
*/
463468
vector_ptr() = default;
469+
vector_ptr(decltype(nullptr)) {}
464470

465471
/**
466472
* Constructor from a given pointer. It is up to the user to assert that the pointer is aligned to `Alignment`.
@@ -556,6 +562,7 @@ struct vector_ptr<T, N, const U, Alignment> {
556562
using value_type = decay_t<T>;
557563

558564
vector_ptr() = default;
565+
vector_ptr(decltype(nullptr)) {}
559566

560567
template<typename V = U, enable_if_t<Alignment != alignof(V), int> = 0>
561568
KERNEL_FLOAT_INLINE explicit vector_ptr(pointer_type p) : data_(p) {}

include/kernel_float/unops.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ KERNEL_FLOAT_INLINE vector<R, vector_extent_type<V>> cast(const V& input) {
109109
\
110110
KERNEL_FLOAT_DEFINE_UNARY_FUN(NAME)
111111

112-
#define KERNEL_FLOAT_DEFINE_UNARY_OP(NAME, OP, EXPR) \
113-
KERNEL_FLOAT_DEFINE_UNARY(NAME, EXPR) \
114-
\
115-
template<typename T, typename E, typename S> \
116-
KERNEL_FLOAT_INLINE vector<T, E> operator OP(const vector<T, E, S>& vec) { \
117-
return NAME(vec); \
112+
#define KERNEL_FLOAT_DEFINE_UNARY_OP(NAME, OP, EXPR) \
113+
KERNEL_FLOAT_DEFINE_UNARY(NAME, EXPR) \
114+
\
115+
template<typename V, typename T = enable_if_t<is_vector<V>, vector_value_type<V>>> \
116+
KERNEL_FLOAT_INLINE map_type<ops::NAME<T>, V> operator OP(const V & vec) { \
117+
return NAME(vec); \
118118
}
119119

120120
KERNEL_FLOAT_DEFINE_UNARY_OP(negate, -, -input)

single_include/kernel_float.h

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
//================================================================================
1818
// this file has been auto-generated, do not modify its contents!
19-
// date: 2025-10-31 19:02:16.510739
20-
// git hash: f01c913003692e3270c174964ddafb02a016e9b8
19+
// date: 2025-11-20 10:30:52.307303
20+
// git hash: 933c1b91a0c1bca3ea28576dbff8a3d91d815ff9
2121
//================================================================================
2222

2323
#ifndef KERNEL_FLOAT_MACROS_H
@@ -642,14 +642,13 @@ struct preferred_vector_size {
642642
};
643643

644644
template<typename V>
645-
struct vector_traits;
645+
struct is_vector_impl {
646+
static constexpr bool value = false;
647+
};
646648

647649
template<typename T, typename E, typename S>
648-
struct vector_traits<vector<T, E, S>> {
649-
using value_type = T;
650-
using extent_type = E;
651-
using storage_type = S;
652-
using vector_type = vector<T, E, S>;
650+
struct is_vector_impl<vector<T, E, S>> {
651+
static constexpr bool value = true;
653652
};
654653

655654
template<typename V>
@@ -661,6 +660,9 @@ using vector_extent_type = typename into_vector_impl<V>::extent_type;
661660
template<typename V>
662661
static constexpr size_t vector_size = extent_size<vector_extent_type<V>>;
663662

663+
template<typename V>
664+
static constexpr bool is_vector = is_vector_impl<V>::value;
665+
664666
template<typename V>
665667
using into_vector_type = vector<vector_value_type<V>, vector_extent_type<V>>;
666668

@@ -1322,12 +1324,12 @@ KERNEL_FLOAT_INLINE vector<R, vector_extent_type<V>> cast(const V& input) {
13221324
\
13231325
KERNEL_FLOAT_DEFINE_UNARY_FUN(NAME)
13241326

1325-
#define KERNEL_FLOAT_DEFINE_UNARY_OP(NAME, OP, EXPR) \
1326-
KERNEL_FLOAT_DEFINE_UNARY(NAME, EXPR) \
1327-
\
1328-
template<typename T, typename E, typename S> \
1329-
KERNEL_FLOAT_INLINE vector<T, E> operator OP(const vector<T, E, S>& vec) { \
1330-
return NAME(vec); \
1327+
#define KERNEL_FLOAT_DEFINE_UNARY_OP(NAME, OP, EXPR) \
1328+
KERNEL_FLOAT_DEFINE_UNARY(NAME, EXPR) \
1329+
\
1330+
template<typename V, typename T = enable_if_t<is_vector<V>, vector_value_type<V>>> \
1331+
KERNEL_FLOAT_INLINE map_type<ops::NAME<T>, V> operator OP(const V & vec) { \
1332+
return NAME(vec); \
13311333
}
13321334

13331335
KERNEL_FLOAT_DEFINE_UNARY_OP(negate, -, -input)
@@ -1834,24 +1836,12 @@ KERNEL_FLOAT_INLINE zip_common_type<F, L, R> zip_common(F fun, const L& left, co
18341836
#define KERNEL_FLOAT_DEFINE_BINARY_OP_FALLBACK(NAME, OP, EXPR_F64, EXPR_F32) \
18351837
KERNEL_FLOAT_DEFINE_BINARY(NAME, left OP right, EXPR_F64, EXPR_F32) \
18361838
\
1837-
template<typename L, typename R, typename C = promote_t<L, R>, typename E1, typename E2> \
1838-
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, vector<L, E1>, vector<R, E2>> operator OP( \
1839-
const vector<L, E1>& left, \
1840-
const vector<R, E2>& right) { \
1841-
return zip_common(ops::NAME<C> {}, left, right); \
1842-
} \
1843-
template<typename L, typename R, typename C = promote_t<L, vector_value_type<R>>, typename E> \
1844-
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, vector<L, E>, R> operator OP( \
1845-
const vector<L, E>& left, \
1846-
const R \
1847-
& right) { \
1848-
return zip_common(ops::NAME<C> {}, left, right); \
1849-
} \
1850-
template<typename L, typename R, typename C = promote_t<vector_value_type<L>, R>, typename E> \
1851-
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, L, vector<R, E>> operator OP( \
1852-
const L \
1853-
& left, \
1854-
const vector<R, E>& right) { \
1839+
template< \
1840+
typename L, \
1841+
typename R, \
1842+
typename C = enable_if_t<is_vector<L> || is_vector<R>, promoted_vector_value_type<L, R>>> \
1843+
KERNEL_FLOAT_INLINE zip_common_type<ops::NAME<C>, L, R> \
1844+
operator OP(const L & left, const R & right) { \
18551845
return zip_common(ops::NAME<C> {}, left, right); \
18561846
}
18571847

@@ -3019,6 +3009,11 @@ struct into_vector_impl<vector_ref<T, N, U, Alignment>> {
30193009
}
30203010
};
30213011

3012+
template<typename T, size_t N, typename U, size_t Alignment>
3013+
struct is_vector_impl<vector_ref<T, N, U, Alignment>> {
3014+
static constexpr bool value = true;
3015+
};
3016+
30223017
/**
30233018
* A wrapper for a pointer that enables vectorized access and supports type conversions..
30243019
*
@@ -3044,6 +3039,7 @@ struct vector_ptr {
30443039
* Default constructor sets the pointer to `NULL`.
30453040
*/
30463041
vector_ptr() = default;
3042+
vector_ptr(decltype(nullptr)) {}
30473043

30483044
/**
30493045
* Constructor from a given pointer. It is up to the user to assert that the pointer is aligned to `Alignment`.
@@ -3139,6 +3135,7 @@ struct vector_ptr<T, N, const U, Alignment> {
31393135
using value_type = decay_t<T>;
31403136

31413137
vector_ptr() = default;
3138+
vector_ptr(decltype(nullptr)) {}
31423139

31433140
template<typename V = U, enable_if_t<Alignment != alignof(V), int> = 0>
31443141
KERNEL_FLOAT_INLINE explicit vector_ptr(pointer_type p) : data_(p) {}

0 commit comments

Comments
 (0)