Commit 7af588f6 authored by Stiopa Koltsov's avatar Stiopa Koltsov Committed by Facebook Github Bot

Do not define __SSE4_2__ unconditionally in clang

Summary:
Clang defines `_MSC_VER` on Windows, but it is not MSC.

```
% ./third-party/toolchains/llvm/8.0.0/bin/windows/clang.exe -march=corei7 -dM -E -x c empty | grep MSC
#define _MSC_BUILD 1
#define _MSC_EXTENSIONS 1
#define _MSC_FULL_VER 191225835
#define _MSC_VER 1912
```

We are not allowed to define `__SSE4_2__` in clang when clang assumes older arch, because in that case it refuses to compile SSE intrinsics, there is a couple of places in folly where we assume defined `__SSE4_2__` to use SSE4.2 intrinsics.

On the other hand clang defines `__SSE4_2__` itself when it is available:

```
% ./third-party/toolchains/llvm/8.0.0/bin/windows/clang.exe -march=corei7 -dM -E -x c empty | grep SSE
#define __SSE2_MATH__ 1
#define __SSE2__ 1
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSE_MATH__ 1
#define __SSE__ 1
#define __SSSE3__ 1
```

This is an example clang error on Windows:

```
folly/container/detail/F14Table.h:1098:23: error: always_inline function '_mm_crc32_u64' requires target feature 'sse4.2', but would be inlined into function 'splitHash' that is compiled without support for 'sse4.2'
      std::size_t c = _mm_crc32_u64(0, hash);
```

Reviewed By: vener91

Differential Revision: D16038436

fbshipit-source-id: 8728a8d91cadb936c9e244795c9270943fe005ad
parent e22d96d6
......@@ -263,7 +263,13 @@ constexpr bool kIsSanitize = false;
// We have compiler support for the newest of the new, but
// MSVC doesn't tell us that.
//
// Clang pretends to be MSVC on Windows, but it refuses to compile
// SSE4.2 intrinsics unless -march argument is specified.
// So cannot unconditionally define __SSE4_2__ in clang.
#ifndef __clang__
#define __SSE4_2__ 1
#endif
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment