unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] x86: Properly match CPU feature [BZ #27222]
@ 2021-01-21 19:47 H.J. Lu via Libc-alpha
  2021-01-22 15:01 ` H.J. Lu via Libc-alpha
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu via Libc-alpha @ 2021-01-21 19:47 UTC (permalink / raw)
  To: libc-alpha

/proc/cpuinfo has

flags		: fpu vme de pse ... ssse3 ...

SSE3 in /proc/cpuinfo is displaced as "pni".  Search "pni" instead of
"sse3" for SSE3.  After finding a match for a string, verify the previous
character is space and the next character is space or null byte to avoid
matching "XXXYYYXXX" with "YYY".
---
 sysdeps/x86/tst-cpu-features-cpuinfo.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sysdeps/x86/tst-cpu-features-cpuinfo.c b/sysdeps/x86/tst-cpu-features-cpuinfo.c
index 771771c959..9308349869 100644
--- a/sysdeps/x86/tst-cpu-features-cpuinfo.c
+++ b/sysdeps/x86/tst-cpu-features-cpuinfo.c
@@ -64,7 +64,12 @@ check_proc (const char *proc_name, int flag, int usable, const char *name)
       return 0;
     }
   printf ("  %s: %d\n", name, flag);
-  if (strstr (cpu_flags, proc_name) != NULL)
+  char *str = strstr (cpu_flags, proc_name);
+  size_t len = strlen (proc_name);
+  /* Don't match "ssse3" with "sse3".  */
+  if (str != NULL
+      && str[-1] == ' '
+      && (str[len] == ' ' || str[len] == '\0'))
     found = 1;
   printf ("  cpuinfo (%s): %d\n", proc_name, found);
 
@@ -206,7 +211,7 @@ do_test (int argc, char **argv)
   fails += CHECK_PROC (ssbd, SSBD);
   fails += CHECK_PROC (sse, SSE);
   fails += CHECK_PROC (sse2, SSE2);
-  fails += CHECK_PROC (sse3, SSE3);
+  fails += CHECK_PROC (pni, SSE3);
   fails += CHECK_PROC (sse4_1, SSE4_1);
   fails += CHECK_PROC (sse4_2, SSE4_2);
   fails += CHECK_PROC (sse4a, SSE4A);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-17  0:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 19:47 [PATCH] x86: Properly match CPU feature [BZ #27222] H.J. Lu via Libc-alpha
2021-01-22 15:01 ` H.J. Lu via Libc-alpha
2021-01-22 16:56   ` Adhemerval Zanella via Libc-alpha
2021-01-22 18:11     ` H.J. Lu via Libc-alpha
2021-02-02 11:07       ` Andreas Schwab
2021-02-02 15:01         ` [PATCH] <bits/platform/x86.h>: Correct x86_cpu_TBM H.J. Lu via Libc-alpha
2021-02-22  9:49           ` Florian Weimer via Libc-alpha
2022-02-17  0:10             ` H.J. Lu via Libc-alpha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).