projg2 / cpuid2cpuflags

Tool to generate CPU_FLAGS_* for your CPU
GNU General Public License v2.0
104 stars 20 forks source link

Inconsistent flags shown under QEMU with `-cpu Westmere` #27

Closed lucatrv closed 2 months ago

lucatrv commented 3 months ago

I'm running Gentoo Linux as a QEMU 9.0 guest on a Windows 10 host, with -cpu Westmere.

cpuid2cpuflags shows the following output:

CPU_FLAGS_X86: aes avx2 mmx mmxext pclmul popcnt sha sse sse2 sse3 sse4_1 sse4_2 ssse3 vpclmulqdq

but avx2, sha, and vpclmulqdq look wrong to me.

I do not have a real Westmere system to compare.

mgorny commented 3 months ago

What does /proc/cpuinfo list?

mgorny commented 3 months ago

Also please try if it works at runtime, e.g.:

$ git clone -q https://github.com/noloader/SHA-Intrinsics
$ cd SHA-Intrinsics
$ gcc sha1-x86.c -DTEST_MAIN -march=westmere -msha
$ ./a.out 
SHA1 hash of empty message: DA39A3EE5E6B4B0D...
Success!
lucatrv commented 3 months ago

What does /proc/cpuinfo list?

/proc/cpuinfo shows 13th Gen Intel(R) Core(TM) i7-1370P, which is my host CPU. However I'm running QEMU with -cpu Westmere, so my guest CPU is Westmere instead.

If I run:

gcc -v -E -x c /dev/null -o /dev/null -march=native 2>&1 | grep /cc1 | grep mtune

as suggested here I get -mtune=westmere, so GCC detects my guest CPU correctly.

lucatrv commented 3 months ago

Also please try if it works at runtime, e.g.:

$ git clone -q https://github.com/noloader/SHA-Intrinsics
$ cd SHA-Intrinsics
$ gcc sha1-x86.c -DTEST_MAIN -march=westmere -msha
$ ./a.out 
SHA1 hash of empty message: DA39A3EE5E6B4B0D...
Success!

It works. Now I'm confused...

mgorny commented 3 months ago

What does /proc/cpuinfo list?

/proc/cpuinfo shows 13th Gen Intel(R) Core(TM) i7-1370P, which is my host CPU. However I'm running QEMU with -cpu Westmere, so my guest CPU is Westmere instead.

I'm asking which feature flags it reports.

You could also try if -cpu Westmere,-sha-ni changes anything.

lucatrv commented 3 months ago

I now tried to run QEM without -cpu flag, the above gcc -v -E ... command correctly reports -mtune=nocona, /proc/cpuinfo still shows 13th Gen Intel(R) Core(TM) i7-1370P, while cpuid2cpuflags shows CPU_FLAGS_X86: avx2 mmx mmxext sha sse sse2 sse3 vpclmulqdq (again avx2, sha, and vpclmulqdq look wrong to me).

Now sha1-x86.c does not compile.

mgorny commented 3 months ago

Please provide the requested information and error logs for "does not compile".

lucatrv commented 2 months ago

Sorry I cannot answer anymore because I uninstalled QEMU and moved back to VMware, please feel free to close this issue.