[syslinux:master] dmi: check both the AC and ID flags at the same time

syslinux-bot for H. Peter Anvin hpa at zytor.com
Wed Feb 20 19:51:24 PST 2019


Commit-ID:  05ac953c23f90b2328d393f7eecde96e41aed067
Gitweb:     https://www.syslinux.org/commit/05ac953c23f90b2328d393f7eecde96e41aed067
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Wed, 20 Feb 2019 19:49:12 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Wed, 20 Feb 2019 19:49:12 -0800

dmi: check both the AC and ID flags at the same time

There is no reason to do the fairly complex flag-test sequence twice,
when we might as well check for both flags at the same time.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>

---
 com32/include/x86/cpu.h | 17 +++++++++++------
 core/dmi.c              |  6 ++++--
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/com32/include/x86/cpu.h b/com32/include/x86/cpu.h
index 4bbcc802..f61e4389 100644
--- a/com32/include/x86/cpu.h
+++ b/com32/include/x86/cpu.h
@@ -6,13 +6,13 @@
 #include <stdbool.h>
 #include <x86/regs.h>
 
-static inline __constfunc bool cpu_has_eflag(unsigned long flag)
+static inline __constfunc unsigned long cpu_has_eflags(unsigned long flags)
 {
     unsigned long f1, f2;
 
-    if (__builtin_constant_p(flag)) {
-	if (!(flag & ~(unsigned long)KNOWN_EFLAGS))
-	    return true;
+    if (__builtin_constant_p(flags)) {
+	if (!(flags & ~(unsigned long)KNOWN_EFLAGS))
+	    return flags;	/* We know we have them all */
     }
 
     asm("pushf ; "
@@ -25,9 +25,14 @@ static inline __constfunc bool cpu_has_eflag(unsigned long flag)
 	"pushf ; "
 	"pop %1 ; "
 	"popf"
-	: "=&r" (f1), "=&r" (f2) : "ri" (flag));
+	: "=&r" (f1), "=&r" (f2) : "ri" (flags));
+
+    return (f1 ^ f2) & flags;
+}
 
-    return !!((f1 ^ f2) & flag);
+static inline __constfunc bool cpu_has_eflag(unsigned long flag)
+{
+    return cpu_has_eflags(flag) != 0;
 }
 
 static inline uint64_t rdtsc(void)
diff --git a/core/dmi.c b/core/dmi.c
index 550b63e2..9a108341 100644
--- a/core/dmi.c
+++ b/core/dmi.c
@@ -317,6 +317,7 @@ struct cpuflag {
 
 static void sysappend_set_cpu(void)
 {
+    unsigned long have_eflags;
     static char cpu_str[6+6] = "CPU=";
     char *p = cpu_str + 4;
     static const struct cpuflag cpuflags[] = {
@@ -331,10 +332,11 @@ static void sysappend_set_cpu(void)
     const struct cpuflag *cf;
 
     /* Not technically from DMI, but it fit here... */
+    have_eflags = cpu_has_eflags(EFLAGS_ID|EFLAGS_AC);
 
-    if (!cpu_has_eflag(EFLAGS_ID)) {
+    if (!(have_eflags & EFLAGS_ID)) {
 	/* No CPUID */
-	*p++ = cpu_has_eflag(EFLAGS_AC) ? '4' : '3';
+	*p++ = (have_eflags & EFLAGS_AC) ? '4' : '3';
     } else {
 	uint32_t flags[4], eax, ebx, family;
 	uint32_t ext_level;


More information about the Syslinux-commits mailing list