so imagine that I have a function add
template<class type>
type* add(type*,type* x, int len)
{
type *result = new type[len];
for(int i = 0; i < len; i += simd_reg_size)
{
// do addition here
}
return result;
}
I Thought of using template specializations such that I write a specialized add function for each datatype I'd like to support however it seems the syntax I have thought of is invalid.
template<>
__m256 SIMD_add<float>(__m256 x, __m256 y){
return _mm256_add_ps(x, y);
}
Am not an expert in c++ but from what I have understood I must use the templete type in the arguments or parameters. I also thought of writing a macro with something similar to
#define simd_add(x, y, type)
if type == int
simd_add_integer(x, y)
However looking around, it seems that there is no way to actually perform the conditional statements in macros. What should I do ? its important for me that the syntax is flexible enough to allow me to abstract architectures such as arm in addition to x86.