Skip to content

Commit b87d54c

Browse files
committed
Require the cx16 feature on Intel CPUs
This makes 128-bit atomics work on Intel. Without this feature, LLVM does not always know how to generate the respective code. The CPU feature `cx16` describes whether the CPU supports the `cmpxchg16b` instruction. All modern Intel CPUs support this feature; see the discussion in #14818. When Julia generates code for a `native` 64-bit CPU, this flag is already set correctly. However, when Julia generates code for either a 32-bit or a `generic` Intel CPU, then LLVM assumes pessimistically that this feature is not present. According to Wikipedia <https://en.wikipedia.org/wiki/X86-64>, this is only relevant for "early AMD64 processors", and "the 64-bit version of Windows 8.1 requires the instruction". I thus suggest to require this instruction as well when threading is enabled. The alternative is to disable support for 128-bit atomics. The generic CPU target is apparently specified at many occasions, including for 32-bit Intel CPUs and in Travis. Closes #14818.
1 parent 28cbd54 commit b87d54c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/codegen.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5794,7 +5794,7 @@ static void init_julia_llvm_env(Module *m)
57945794
}
57955795

57965796
// Helper to figure out what features to set for the LLVM target
5797-
// If the user specifies native ( or does not specify ) we default
5797+
// If the user specifies native (or does not specify) we default
57985798
// using the API provided by LLVM
57995799
static inline SmallVector<std::string,10> getTargetFeatures() {
58005800
StringMap<bool> HostFeatures;
@@ -5807,13 +5807,19 @@ static inline SmallVector<std::string,10> getTargetFeatures() {
58075807
// Platform specific overides follow
58085808
#if defined(_CPU_X86_64_) || defined(_CPU_X86_)
58095809
#ifndef USE_MCJIT
5810-
// Temporarily disable Haswell BMI2 features due to LLVM bug.
5810+
// Temporarily disable Haswell BMI2 features due to LLVM bug.
58115811
HostFeatures["bmi2"] = false;
58125812
HostFeatures["avx2"] = false;
58135813
#endif
58145814
#ifdef V128_BUG
58155815
HostFeatures["avx"] = false;
58165816
#endif
5817+
// Require cx16 (cmpxchg16b)
5818+
// We need this for 128-bit atomic operations. We only need this
5819+
// when threading is enabled; however, to test whether this excludes
5820+
// important systems, we require this even when threading is
5821+
// disabled.
5822+
HostFeatures["cx16"] = true;
58175823
#endif
58185824

58195825
// Figure out if we know the cpu_target

0 commit comments

Comments
 (0)