[syslinux:master] cpu_has_eflag(): eliminate if the answer is already known
syslinux-bot for H. Peter Anvin
hpa at zytor.com
Wed Feb 20 18:48:07 PST 2019
Commit-ID: 87a6dff094a32ff477404bfea42d9e8b02ad8176
Gitweb: https://www.syslinux.org/commit/87a6dff094a32ff477404bfea42d9e8b02ad8176
Author: H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 20 Feb 2019 18:46:34 -0800
Committer: H. Peter Anvin <hpa at zytor.com>
CommitDate: Wed, 20 Feb 2019 18:46:34 -0800
cpu_has_eflag(): eliminate if the answer is already known
There is no need to test for a flag if the answer can be given at
compile time.
Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
com32/include/x86/cpu.h | 8 +++++++-
com32/include/x86/regs.h | 13 +++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/com32/include/x86/cpu.h b/com32/include/x86/cpu.h
index 5bdc74de..5537da66 100644
--- a/com32/include/x86/cpu.h
+++ b/com32/include/x86/cpu.h
@@ -4,11 +4,17 @@
#include <klibc/compiler.h>
#include <inttypes.h>
#include <stdbool.h>
+#include <x86/regs.h>
-static inline bool cpu_has_eflag(unsigned long flag)
+static inline __constfunc bool cpu_has_eflag(unsigned long flag)
{
unsigned long f1, f2;
+ if (__builtin_constant_p(flag)) {
+ if (!(flag & ~(unsigned long)KNOWN_EFLAGS))
+ return true;
+ }
+
asm("pushf ; "
"pushf ; "
"pop %0 ; "
diff --git a/com32/include/x86/regs.h b/com32/include/x86/regs.h
index 62f3a53d..d774c724 100644
--- a/com32/include/x86/regs.h
+++ b/com32/include/x86/regs.h
@@ -24,6 +24,19 @@
#define EFLAGS_VIP 0x00100000
#define EFLAGS_ID 0x00200000
+/* Flags known to be present */
+#define I386_KNOWN_EFLAGS \
+ (EFLAGS_CF|EFLAGS_PF|EFLAGS_AF|EFLAGS_ZF|EFLAGS_SF|EFLAGS_TF|\
+ EFLAGS_IF|EFLAGS_DF|EFLAGS_OF|EFLAGS_IOPL|EFLAGS_NT|EFLAGS_RF)
+#define X86_64_KNOWN_EFLAGS \
+ (I386_KNOWN_EFLAGS|EFLAGS_AC|EFLAGS_ID)
+
+#ifdef __x86_64__
+# define KNOWN_EFLAGS X86_64_KNOWN_EFLAGS
+#else
+# define KNOWN_EFLAGS I386_KNOWN_EFLAGS
+#endif
+
/* CR0 definitions */
#define CR0_PE 0x00000001
#define CR0_MP 0x00000002
More information about the Syslinux-commits
mailing list