1

The following code builds just fine under cl, but fails under clang-cl:

#define NUDGE_FORCEINLINE __forceinline

NUDGE_FORCEINLINE __m128 operator-(__m128 a) {
  return _mm_xor_ps(a, _mm_set1_ps(-0.0f));
}

This is the error message:

..\nudge.cpp(65,26): error: overloaded 'operator-' must have at least one parameter of class or enumeration type
NUDGE_FORCEINLINE __m128 operator-(__m128 a) {
                         ^

The code is from rasmusbarr/nudge, an experiment which seems to be abandoned since 2017.

Setup (CMake/VSCode):

  • cl with VS Build Tools 2019 v16.8.2

  • clang-cl with C++ Clang Tools for Windows 10.0.0 (VS Build Tools 2019 v16.8.2)

cmake_minimum_required(VERSION 3.18.0)
project(nudge LANGUAGES C CXX)

add_executable(tests "nudge.cpp" "tests/main.cpp")
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR})

Research:

I came across these two sources (1, 2) that seem to point out that the reason might be clang-cl does not consider __m128 to be a struct type. They fixed it in (1), but it seems that they just disable SSE for some platforms.

Although it was a long shot, I tried compiling with the VS version of immintrin.h and intrin.h but that path led nowhere.

I also noticed that someone else who build this experiment used the c++11 standard so I tried that too by setting set(CMAKE_CXX_STANDARD 11) in cmake. No change.

Question:

How can I modify the code (or change compiler flags) in order to build rasmusbarr/nudge with clang-cl?

Thank you

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
ompadu
  • 71
  • 1
  • 5
  • Normal clang allows function overloads that only differ by `__m128i` vs. `__m128d` or a `long long` arg. https://godbolt.org/z/b7eYE8. Oh, but apparently operator overloads are different. https://godbolt.org/z/GPc6Po. You could use one of the other C++ wrapper libraries, like VCL, or maybe use a class wrapper for `__m128` instead of `__m128` directly, perhaps using a C preprocessor macro as a hack for existing code. – Peter Cordes Dec 06 '20 at 18:42
  • How would a wrapper class for `__m128` look like? – ompadu Dec 06 '20 at 19:00
  • Clang already provides `operator-(__m128)`, which does exactly what you want: https://godbolt.org/z/c75fWf – chtz Dec 06 '20 at 21:33
  • I've disabled all the operator overload code and it seems to build and run fine. I'll test the rest of the operators with godbolt. – ompadu Dec 06 '20 at 21:48

0 Answers0