如何重载其参数仅由gcc矢量扩展vector_size属性不同的函数
How to overload functions whose arguments only differ by gcc vector extension vector_size attribute?
我正在尝试编写一些常用的实用函数,例如在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];
}
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];
}
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 在某些循环内使用vector.push_back时出现分段错误
- 当vector是tje全局变量时,c++中vector的内存管理
- 是否可以通过C++扩展强制多个python进程共享同一内存
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- std::vector的包装器,使数组的结构看起来像结构的数组
- 从函数为 std::vector 创建自定义扩展
- 如何将 Python 对象转换为 Cython 扩展类型的 std::vector 并返回?
- 扩展 std::vector 是个好主意吗?
- 使用范围检查和带符号的size_type扩展std::vector
- 是否可以计算出 std::vector 扩展其数组大小的频率
- 获取 std::vector 的大小(通过扩展专门使用参数类型的可变参数模板函数来处理参数)
- 将 JavaScript Array.slice + 隐式扩展转换为 C++ vector
- 在C++中扩展容器(如std::vector)功能的正确方法,而不从中继承
- 扩展std::vector以从其他vector类型移动元素
- CUDA扩展std::vector来管理主机和设备数据