google / google/highway

HWY_EXPORT_AND_DYNAMIC_DISPATCH_T for multiple template parameters function with Clang/GCC

Open
#2,260 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.8k
Forks
471
Avg merge
1d 6h
Merged PRs (30d)
81

Description

Hi,

I'm facing difficulties to compile or execute properly with dynamic dispatch multi template parameter functions. The code compile and seems to work fine on MSVC but no luck with Clang and GCC. I tried to expand partially the HWY_EXPORT_AND_DYNAMIC_DISPATCH_T macro and managed to compile with clang, however at run time dynamic dispatch mechanism may call wrong functions (not always). See below a small reproduction for this issue.
``

#undef HWY_TARGET_INCLUDE
#define HWY_TARGET_INCLUDE "example.cpp"
#include
#include

HWY_BEFORE_NAMESPACE();

namespace Test {
namespace HWY_NAMESPACE {
namespace hn = hwy::HWY_NAMESPACE;
template
void func1() {}

template
void func2(){}
}// namespace HWY_NAMESPACE
} // namespace SLHDR

HWY_AFTER_NAMESPACE();

#define SINGLE_ARG(...) __VA_ARGS__

#if HWY_ONCE
namespace Test {

template
void callerFunc1()
{
HWY_EXPORT_AND_DYNAMIC_DISPATCH_T(func1)(); //this works
}

template
void callerFunc2()
{
HWY_EXPORT_AND_DYNAMIC_DISPATCH_T(SINGLE_ARG(func2))(); //this doesn't compile with clang nor gcc
//lines below compiles, but doesn't work properly dynamic dispatch may use wrong function pointers
//HWY_MAYBE_UNUSED static decltype(&HWY_STATIC_DISPATCH(SINGLE_ARG(func2< i,j>))) const
//HWY_DISPATCH_TABLE(HWY_DISPATCH_TABLE_T())[1] = {&HWY_STATIC_DISPATCH(SINGLE_ARG(func2< i,j>))};HWY_DYNAMIC_DISPATCH_T(HWY_DISPATCH_TABLE_T())();
}

template void callerFunc2<0,0>();
}

#endif // HWY_ONCE

``

Thanks,

Anarchitectus

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.