[PATCH] x86: Properly match CPU feature [BZ #27222]
H.J. Lu
hjl.tools@gmail.com
Fri Jan 22 15:01:07 GMT 2021
On Thu, Jan 21, 2021 at 11:47 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> /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
>
I am checking it in.
--
H.J.
More information about the Libc-alpha
mailing list