google / highway

Performance-portable, length-agnostic SIMD with runtime dispatch
Apache License 2.0
4.13k stars 315 forks source link

Made fixes to C++11/C++14 HWY_EXPORT_T #2177

Closed johnplatts closed 4 months ago

johnplatts commented 4 months ago

Reimplemented HWY_EXPORT_T for C++11/C++14 to remove dependency on std::map.

The following lines of code in the updated HWY_EXPORT_T macro for C++11/C++14 declares a const object of an unnamed struct that has a different type from any other object:

  static const struct {                                                       \
  } HWY_CONCAT(TABLE_NAME, HighwayDispatchExportsKey) = {};                   \

decltype(HWY_CONCAT(TABLE_NAME, HighwayDispatchExportsKey)) then can then be used as a template argument to FunctionCache::ChooseAndCall as decltype(HWY_CONCAT(TABLE_NAME, HighwayDispatchExportsKey)) is unique for each table that is declared by HWY_EXPORT_T.

The reimplementation of C++11/C++14 HWY_EXPORT_T in this pull request fixes compilation errors that are there with GCC 8 or earlier in C++11 or C++14 mode.

Also updated HWY_EXPORT for C++11/C++14 to use the table-based dispatch approach that was used prior to applying commit c90768a38ff2fd7c79e6d0f92e2bb875aa7615af if compiling with MSVC 19.16 or later, GCC, or Clang.

johnplatts commented 4 months ago

I ran some builds of Google Highway that integrated the changes in pull request #2177, pull request #2176, and pull request #2178, and I am able to get Google Highway to successfully compile on x86_64 with GCC 5 through 14, Clang 5 through 15, and MSVC 19.29 after applying the changes in pull requests #2176, #2177, and #2178.

Here is a result of running the build/test workflow with pull requests #2176, #2177, and #2178 applied: https://github.com/johnplatts/jep_google_highway/actions/runs/9103630808