aboutsummaryrefslogtreecommitdiffstats
path: root/com32/include
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-02-20 18:46:34 -0800
committerH. Peter Anvin <hpa@zytor.com>2019-02-20 18:46:34 -0800
commit87a6dff094a32ff477404bfea42d9e8b02ad8176 (patch)
treebe899718fe987d59330b36e17fcd804409066d49 /com32/include
parent458a54133ecdf1685c02294d812cb562fe7bf4c3 (diff)
downloadsyslinux-87a6dff094a32ff477404bfea42d9e8b02ad8176.tar.gz
syslinux-87a6dff094a32ff477404bfea42d9e8b02ad8176.tar.xz
syslinux-87a6dff094a32ff477404bfea42d9e8b02ad8176.zip
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@zytor.com>
Diffstat (limited to 'com32/include')
-rw-r--r--com32/include/x86/cpu.h8
-rw-r--r--com32/include/x86/regs.h13
2 files changed, 20 insertions, 1 deletions
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