[llvm] af658d9 - [llvm-exegesis][X86] Save and restore eflags.
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 4 01:44:33 PST 2020
Author: Clement Courbet
Date: 2020-11-04T10:44:15+01:00
New Revision: af658d920e2b677117d52fdb83a871f2ca5a98a0
URL: https://github.com/llvm/llvm-project/commit/af658d920e2b677117d52fdb83a871f2ca5a98a0
DIFF: https://github.com/llvm/llvm-project/commit/af658d920e2b677117d52fdb83a871f2ca5a98a0.diff
LOG: [llvm-exegesis][X86] Save and restore eflags.
This is needed to benchmark instruction that touch EFLAGS (e.g. STD: set direction flag).
Differential Revision: https://reviews.llvm.org/D90742
Added:
llvm/test/tools/llvm-exegesis/X86/uops-STD.s
Modified:
llvm/tools/llvm-exegesis/lib/X86/Target.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-exegesis/X86/uops-STD.s b/llvm/test/tools/llvm-exegesis/X86/uops-STD.s
new file mode 100644
index 000000000000..c67beed97022
--- /dev/null
+++ b/llvm/test/tools/llvm-exegesis/X86/uops-STD.s
@@ -0,0 +1,7 @@
+# RUN: llvm-exegesis -mode=uops -opcode-name=STD -repetition-mode=duplicate | FileCheck %s
+# RUN: llvm-exegesis -mode=uops -opcode-name=STD -repetition-mode=loop | FileCheck %s
+
+CHECK: mode: uops
+CHECK-NEXT: key:
+CHECK-NEXT: instructions:
+CHECK-NEXT: STD
diff --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index db30c1f1837d..005ee4e9a129 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -603,8 +603,10 @@ class X86SavedState : public ExegesisTarget::SavedState {
#ifdef __x86_64__
# if defined(_MSC_VER)
_fxsave64(FPState);
+ Eflags = __readeflags();
# elif defined(__GNUC__)
__builtin_ia32_fxsave64(FPState);
+ Eflags = __builtin_ia32_readeflags_u64();
# endif
#else
llvm_unreachable("X86 exegesis running on non-X86 target");
@@ -618,9 +620,11 @@ class X86SavedState : public ExegesisTarget::SavedState {
# if defined(_MSC_VER)
_clearfp();
_fxrstor64(FPState);
+ __writeeflags(Eflags);
# elif defined(__GNUC__)
asm volatile("fwait");
__builtin_ia32_fxrstor64(FPState);
+ __builtin_ia32_writeeflags_u64(Eflags);
# endif
#else
llvm_unreachable("X86 exegesis running on non-X86 target");
@@ -630,6 +634,7 @@ class X86SavedState : public ExegesisTarget::SavedState {
private:
#ifdef __x86_64__
alignas(16) char FPState[512];
+ uint64_t Eflags;
#endif
};
More information about the llvm-commits
mailing list