Skip to content

Commit 3a29f7c

Browse files
committedJun 6, 2019
[X86] Add ENQCMD instructions
For more details about these instructions, please refer to the latest ISE document: https://software.intel.com/en-us/download/intel-architecture-instruction-set-extensions-programming-reference. Patch by Tianqing Wang (tianqing) Differential Revision: https://reviews.llvm.org/D62282 llvm-svn: 362685
1 parent 3c82c57 commit 3a29f7c

File tree

12 files changed

+116
-0
lines changed

12 files changed

+116
-0
lines changed
 

‎clang/docs/ClangCommandLineReference.rst

+2
Original file line numberDiff line numberDiff line change
@@ -2657,6 +2657,8 @@ X86
26572657

26582658
.. option:: -mcx16, -mno-cx16
26592659

2660+
.. option:: -menqcmd, -mno-enqcmd
2661+
26602662
.. option:: -mf16c, -mno-f16c
26612663

26622664
.. option:: -mfma, -mno-fma

‎clang/include/clang/Basic/BuiltinsX86.def

+4
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,10 @@ TARGET_BUILTIN(__builtin_ia32_ptwrite32, "vUi", "n", "ptwrite")
18941894
// INVPCID
18951895
TARGET_BUILTIN(__builtin_ia32_invpcid, "vUiv*", "nc", "invpcid")
18961896

1897+
// ENQCMD
1898+
TARGET_BUILTIN(__builtin_ia32_enqcmd, "Ucv*vC*", "n", "enqcmd")
1899+
TARGET_BUILTIN(__builtin_ia32_enqcmds, "Ucv*vC*", "n", "enqcmd")
1900+
18971901
// MSVC
18981902
TARGET_HEADER_BUILTIN(_BitScanForward, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
18991903
TARGET_HEADER_BUILTIN(_BitScanReverse, "UcUNi*UNi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")

‎clang/include/clang/Driver/Options.td

+2
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,8 @@ def mclzero : Flag<["-"], "mclzero">, Group<m_x86_Features_Group>;
29162916
def mno_clzero : Flag<["-"], "mno-clzero">, Group<m_x86_Features_Group>;
29172917
def mcx16 : Flag<["-"], "mcx16">, Group<m_x86_Features_Group>;
29182918
def mno_cx16 : Flag<["-"], "mno-cx16">, Group<m_x86_Features_Group>;
2919+
def menqcmd : Flag<["-"], "menqcmd">, Group<m_x86_Features_Group>;
2920+
def mno_enqcmd : Flag<["-"], "mno-enqcmd">, Group<m_x86_Features_Group>;
29192921
def mf16c : Flag<["-"], "mf16c">, Group<m_x86_Features_Group>;
29202922
def mno_f16c : Flag<["-"], "mno-f16c">, Group<m_x86_Features_Group>;
29212923
def mfma : Flag<["-"], "mfma">, Group<m_x86_Features_Group>;

‎clang/lib/Basic/Targets/X86.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
835835
HasPTWRITE = true;
836836
} else if (Feature == "+invpcid") {
837837
HasINVPCID = true;
838+
} else if (Feature == "+enqcmd") {
839+
HasENQCMD = true;
838840
}
839841

840842
X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
@@ -1218,6 +1220,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
12181220
Builder.defineMacro("__PTWRITE__");
12191221
if (HasINVPCID)
12201222
Builder.defineMacro("__INVPCID__");
1223+
if (HasENQCMD)
1224+
Builder.defineMacro("__ENQCMD__");
12211225

12221226
// Each case falls through to the previous one here.
12231227
switch (SSELevel) {
@@ -1334,6 +1338,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
13341338
.Case("clwb", true)
13351339
.Case("clzero", true)
13361340
.Case("cx16", true)
1341+
.Case("enqcmd", true)
13371342
.Case("f16c", true)
13381343
.Case("fma", true)
13391344
.Case("fma4", true)
@@ -1415,6 +1420,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
14151420
.Case("clzero", HasCLZERO)
14161421
.Case("cx8", HasCX8)
14171422
.Case("cx16", HasCX16)
1423+
.Case("enqcmd", HasENQCMD)
14181424
.Case("f16c", HasF16C)
14191425
.Case("fma", HasFMA)
14201426
.Case("fma4", XOPLevel >= FMA4)

‎clang/lib/Basic/Targets/X86.h

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
108108
bool HasMOVDIR64B = false;
109109
bool HasPTWRITE = false;
110110
bool HasINVPCID = false;
111+
bool HasENQCMD = false;
111112

112113
protected:
113114
/// Enumeration of all of the X86 CPUs supported by Clang.

‎clang/lib/Headers/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(files
5050
clflushoptintrin.h
5151
clwbintrin.h
5252
emmintrin.h
53+
enqcmdintrin.h
5354
f16cintrin.h
5455
float.h
5556
fma4intrin.h

‎clang/lib/Headers/cpuid.h

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
#define bit_CLDEMOTE 0x02000000
178178
#define bit_MOVDIRI 0x08000000
179179
#define bit_MOVDIR64B 0x10000000
180+
#define bit_ENQCMD 0x20000000
180181

181182
/* Features in %edx for leaf 7 sub-leaf 0 */
182183
#define bit_AVX5124VNNIW 0x00000004

‎clang/lib/Headers/enqcmdintrin.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*===------------------ enqcmdintrin.h - enqcmd intrinsics -----------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __IMMINTRIN_H
11+
#error "Never use <enqcmdintrin.h> directly; include <immintrin.h> instead."
12+
#endif
13+
14+
#ifndef __ENQCMDINTRIN_H
15+
#define __ENQCMDINTRIN_H
16+
17+
/* Define the default attributes for the functions in this file */
18+
#define _DEFAULT_FN_ATTRS \
19+
__attribute__((__always_inline__, __nodebug__, __target__("enqcmd")))
20+
21+
/// Reads 64-byte command pointed by \a __src, formats 64-byte enqueue store
22+
/// data, and performs 64-byte enqueue store to memory pointed by \a __dst.
23+
/// This intrinsics may only be used in User mode.
24+
///
25+
/// \headerfile <x86intrin.h>
26+
///
27+
/// This intrinsics corresponds to the <c> ENQCMD </c> instruction.
28+
///
29+
/// \param __dst
30+
/// Pointer to the destination of the enqueue store.
31+
/// \param __src
32+
/// Pointer to 64-byte command data.
33+
/// \returns If the command data is successfully written to \a __dst then 0 is
34+
/// returned. Otherwise 1 is returned.
35+
static __inline__ int _DEFAULT_FN_ATTRS
36+
_enqcmd (void *__dst, const void *__src)
37+
{
38+
return __builtin_ia32_enqcmd(__dst, __src);
39+
}
40+
41+
/// Reads 64-byte command pointed by \a __src, formats 64-byte enqueue store
42+
/// data, and performs 64-byte enqueue store to memory pointed by \a __dst
43+
/// This intrinsic may only be used in Privileged mode.
44+
///
45+
/// \headerfile <x86intrin.h>
46+
///
47+
/// This intrinsics corresponds to the <c> ENQCMDS </c> instruction.
48+
///
49+
/// \param __dst
50+
/// Pointer to the destination of the enqueue store.
51+
/// \param __src
52+
/// Pointer to 64-byte command data.
53+
/// \returns If the command data is successfully written to \a __dst then 0 is
54+
/// returned. Otherwise 1 is returned.
55+
static __inline__ int _DEFAULT_FN_ATTRS
56+
_enqcmds (void *__dst, const void *__src)
57+
{
58+
return __builtin_ia32_enqcmds(__dst, __src);
59+
}
60+
61+
#undef _DEFAULT_FN_ATTRS
62+
63+
#endif /* __ENQCMDINTRIN_H */

‎clang/lib/Headers/immintrin.h

+4
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ _storebe_i64(void * __P, long long __D) {
431431
#include <avx512vlvp2intersectintrin.h>
432432
#endif
433433

434+
#if !defined(_MSC_VER) || __has_feature(modules) || defined(__ENQCMD__)
435+
#include <enqcmdintrin.h>
436+
#endif
437+
434438
#if defined(_MSC_VER) && __has_extension(gnu_asm)
435439
/* Define the default attributes for these intrinsics */
436440
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 %s -ffreestanding -triple i386-unknown-unknown -target-feature +enqcmd -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-unknown -target-feature +enqcmd -emit-llvm -o - | FileCheck %s
3+
4+
#include <immintrin.h>
5+
6+
int test_enqcmd(void *dst, const void *src) {
7+
// CHECK-LABEL: @test_enqcmd
8+
// CHECK: %[[TMP0:.+]] = call i8 @llvm.x86.enqcmd(i8* %{{.+}}, i8* %{{.+}})
9+
// CHECK: %[[RET:.+]] = zext i8 %[[TMP0]] to i32
10+
// CHECK: ret i32 %[[RET]]
11+
return _enqcmd(dst, src);
12+
}
13+
14+
int test_enqcmds(void *dst, const void *src) {
15+
// CHECK-LABEL: @test_enqcmds
16+
// CHECK: %[[TMP0:.+]] = call i8 @llvm.x86.enqcmds(i8* %{{.+}}, i8* %{{.+}})
17+
// CHECK: %[[RET:.+]] = zext i8 %[[TMP0]] to i32
18+
// CHECK: ret i32 %[[RET]]
19+
return _enqcmds(dst, src);
20+
}

‎clang/test/Driver/x86-target-features.c

+5
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,8 @@
188188
// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-avx512bf16 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-AVX512BF16 %s
189189
// AVX512BF16: "-target-feature" "+avx512bf16"
190190
// NO-AVX512BF16: "-target-feature" "-avx512bf16"
191+
192+
// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -menqcmd %s -### -o %t.o 2>&1 | FileCheck --check-prefix=ENQCMD %s
193+
// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-enqcmd %s -### -o %t.o 2>&1 | FileCheck --check-prefix=NO-ENQCMD %s
194+
// ENQCMD: "-target-feature" "+enqcmd"
195+
// NO-ENQCMD: "-target-feature" "-enqcmd"

‎clang/test/Preprocessor/x86_target_features.c

+7
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,10 @@
468468

469469
// NOVP2INTERSECT-NOT: #define __AVX512VP2INTERSECT__ 1
470470

471+
// RUN: %clang -target i386-unknown-unknown -march=atom -menqcmd -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=ENQCMD %s
472+
473+
// ENQCMD: #define __ENQCMD__ 1
474+
475+
// RUN: %clang -target i386-unknown-unknown -march=atom -mno-enqcmd -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=NOENQCMD %s
476+
477+
// NOENQCMD-NOT: #define __ENQCMD__ 1

0 commit comments

Comments
 (0)