C++ 如何重载参数仅因gcc向量扩展向量大小属性不同的函数?
我正在尝试编写一些常用的实用函数,例如在gcc向量中添加所有元素C++ 如何重载参数仅因gcc向量扩展向量大小属性不同的函数?,c++,gcc,simd,C++,Gcc,Simd,我正在尝试编写一些常用的实用函数,例如在gcc向量中添加所有元素 inline float add_all(float const in __attribute__((vector_size(8)))) { return in[0] + in[1]; } inline float add_all(float const in __attribute__((vector_size(16)))) { return in[0] + in[1] + in[2] + in[3]; } inli
inline float add_all(float const in __attribute__((vector_size(8))))
{
return in[0] + in[1];
}
inline float add_all(float const in __attribute__((vector_size(16))))
{
return in[0] + in[1] + in[2] + in[3];
}
inline double add_all(double const in __attribute__((vector_size(16))))
{
return in[0] + in[1];
}
inline double add_all(double const in __attribute__((vector_size(32))))
{
return in[0] + in[1] + in[2] + in[3];
}
但是,在编译时,gcc对象:
In file included from matrix.hpp:5:0,
from matrix.cpp:3:
vector.hpp:22:1: error: 'float vxl::add_all(__vector(4) float)' conflicts with a previous declaration
}
^
vector.hpp:14:14: note: previous declaration 'float vxl::add_all(__vector(2) float)'
inline float add_all(float const in __attribute__((vector_size(8))))
^
vector.hpp:19:14: note: -fabi-version=6 (or =0) avoids this error with a change in mangling
inline float add_all(float const in __attribute__((vector_size(16))))
^
vector.hpp:32:1: error: 'double vxl::add_all(__vector(4) double)' conflicts with a previous declaration
}
^
vector.hpp:24:15: note: previous declaration 'double vxl::add_all(__vector(2) double)'
inline double add_all(double const in __attribute__((vector_size(16))))
^
vector.hpp:29:15: note: -fabi-version=6 (or =0) avoids this error with a change in mangling
inline double add_all(double const in __attribute__((vector_size(32))))
除了gcc建议的解决方法外,是否存在其他解决方法?提供一个额外的默认参数,该参数为函数提供一个不同的损坏名称:
typedef float __attribute__((vector_size(8))) vector_f8;
typedef float __attribute__((vector_size(16))) vector_f16;
typedef double __attribute__((vector_size(16))) vector_d16;
typedef double __attribute__((vector_size(32))) vector_d32;
template <int _len>
struct vector_len {
static int const len = _len;
};
float
add_all(vector_f8 in, vector_len<8> *_p = NULL) {
return in[0] + in[1];
}
float
add_all(vector_f16 in, vector_len<16> *_p = NULL) {
return in[0] + in[1] + in[2] + in[3];
}
float
add_all(vector_d16 in, vector_len<16> *_p = NULL) {
return in[0] + in[1];
}
float
add_all(vector_d32 in, vector_len<32> *_p = NULL) {
return in[0] + in[1] + in[2] + in[3];
}
typedef float uuu属性uuu((向量大小(8)))向量f8;
typedef float uuu属性uuu((向量大小(16)))向量f16;
typedef double属性(向量大小(16))向量d16;
typedef double uuu属性uuu((向量大小(32)))向量d32;
模板
结构向量{
静态int const len=_len;
};
浮动
添加所有(向量为f8英寸,向量为len*\u p=NULL){
[0]中返回+在[1]中返回;
}
浮动
添加所有(向量f16英寸,向量长度*\p=NULL){
[0]+在[1]+在[2]+在[3]中返回;
}
浮动
全部相加(向量d16英寸,向量长度*\p=NULL){
[0]中返回+在[1]中返回;
}
浮动
全部相加(向量d32英寸,向量长度*\p=NULL){
[0]+在[1]+在[2]+在[3]中返回;
}
您可以链接到gcc建议的解决方法吗?这是编译器错误消息中给出的建议:注意:-fabi版本=6(或=0)通过更改损坏来避免此错误