Log in

View Full Version : CPU Detection


LoRd_MuldeR
27th May 2008, 23:49
Okay, I'm currently implementing automated CPU detection for my MPlayer installer.

I have the following builds to choose from:
* AMD Athlon (MMX, 3DNow!)
* Intel Pentium III (MMX, SSE)
* Intel Pentium 4 (MMX, SSE, SSE2)
* Runtime CPU Detection (Generic)


At the moment I choose the build with those rules:
* No MMX -> Runtime CPU Detection
* MMX only -> Runtime CPU Detection
* MMX and SSE -> Intel Pentium III
* MMX and 3DNow! -> AMD Athlon
* MMX, SSE and 3DNow! -> AMD Athlon
* MMX, SSE and SSE2 -> Intel Pentium 4
* MMX, SSE, SSE2 and 3DNow! -> Intel Pentium 4

Possible alternatives I currently do not use:
* MMX, SSE and 3DNow! -> Intel Pentium III (Could use SSE instead of 3DNow!)
* MMX, SSE, SSE2 and 3DNow! -> AMD Athlon (Could use 3DNow! instead of SSE and SSE2)


I need some advice from the experts: Is that a good choice? :confused:

Note: It will only be a suggestion, the user can still choose what he/she thinks is the best :)

JohnnyMalaria
28th May 2008, 01:04
Given your choice of builds, the selection logic makes good sense.

The only thing that needs clarification is Athlon == SSE2. Prior to the Athlon 64, SSE2 was not implemented, so the possible alternative that you list for MMX, SSE, SSE2 and 3DNow! won't work for the eariler Athlons.

Out of curiosity, when you say "Intel Pentium 4 (MMX, SSE, SSE2)" build, do you mean that the code includes those instruction sets in a generic way or has the code been explicity optimized for the P4 architecture? This *could* hurt performance on post-P4 Intel CPUs that more closely resemble the PIII.

LoRd_MuldeR
28th May 2008, 01:31
Given your choice of builds, the selection logic makes good sense.

:thanks:

The only thing that needs clarification is Athlon == SSE2. Prior to the Athlon 64, SSE2 was not implemented, so the possible alternative that you list for MMX, SSE, SSE2 and 3DNow! won't work for the eariler Athlons.

I think the "Athlon" build was built with MMX and 3DNow! enabled only, so it's targeting for the "original" Athlon K7 CPU's.
That's why I use that build when only the MMX and 3DNow! extensions are present.

When you have MMX, SSE and 3DNow! available, I still use the "Athlon" build, because that would indicate an AthlonXP CPU.
The "Pentium III" build should run on that kind of CPU too, yes! But I think it's less optimized for AMD's CPUs...

As soon as we have MMX, SSE, SSE2 and 3DNow! available, this would indicate an Athlon64 or AthlonX2 CPU.
In that I case I will select the "Pentium 4" build. This won't use the 3DNow! capabilities, but SSE and especially SSE2 can be used.

Out of curiosity, when you say "Intel Pentium 4 (MMX, SSE, SSE2)" build, do you mean that the code includes those instruction sets in a generic way or has the code been explicity optimized for the P4 architecture? This *could* hurt performance on post-P4 Intel CPUs that more closely resemble the PIII.

I'm not sure, because I don't make those builds. But I think they are optimized especially for a specific arch (like -march=pentium4)
On the one hand, this is sub-optimal for later Intel CPU's like Core and Core2, but on the other hand you can use SSE and especially SSE2.
As far as I know, Celtic Druid made some "Core2" optimized builds a while back, but stopped to do so...

That said, the "Pentium 4" builds seems to run pretty well on my Q6600. I can watch 1080p H.264 Trailers with MPlayer now :cool:

krosswindz
28th May 2008, 05:28
http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options

This would be my interpretation of the gcc manual


No MMX = Runtime CPU detection
MMX = Runtime CPU detection
MMX/SSE = Pentium 3
MMX/SSE/SSE2 = Pentium 4
MMX/3dNOW! = Athlon
MMX/3dNOW!/SSE = AthlonXP
MMX/3dNOW!/SSE/SSE2 = Athlon64/K8/Opteron


To the best of my knowledge Intel never supported 3dNOW

krosswindz
28th May 2008, 05:32
On a side note have you tried building mplayer using ICC, I have some times found some codes to run better when compiled with ICC than GCC especially for newer processors. I havent been messing around for quite sometime now.

LoRd_MuldeR
28th May 2008, 11:26
I think Selecting the arch (like -march=pentium4) does not only define which extensions (MMX, SSE, 3DNow!, etc) are enabled/disabled.
AFAIK it also tunes the build especially for that CPU type, because speed for certain instructions differ from CPU type to CPU type significantly.
If I remember correctly, it was said that for example SSE instructions run pretty slow on some AMD CPUs...

Also I'm 100% sure that Intel never ever did release a CPU with 3DNow! support ;)

But back to the topic of this thread:
Are my rules to select the "optimal" build good (regarding the gives builds) or do you recommend a different mapping?

krosswindz
28th May 2008, 23:46
I think Selecting the arch (like -march=pentium4) does not only define which extensions (MMX, SSE, 3DNow!, etc) are enabled/disabled.
AFAIK it also tunes the build especially for that CPU type, because speed for certain instructions differ from CPU type to CPU type significantly.
If I remember correctly, it was said that for example SSE instructions run pretty slow on some AMD CPUs...

Also I'm 100% sure that Intel never ever did release a CPU with 3DNow! support ;)

But back to the topic of this thread:
Are my rules to select the "optimal" build good (regarding the gives builds) or do you recommend a different mapping?

IMO the rules are good I would stick with them unless something new comes up :p

As for enabling and disabling SSE/SSE2/MMX you would have to specifically add them depending on the compiler. IIRC on i386 you would have to specify -march=cpu-type -msse -msse2 -mmmx to enable them. By default they are not, but on a x86_64 based compiler by default i think it enables SSE.

mousemurder
12th June 2008, 19:51
also does /proc/cpuinfo help ?
or
uname -a -m -p

LoRd_MuldeR
12th June 2008, 20:26
I currently use a small tool called "cpuinfo.exe" from here:
http://oss.netfarm.it/

Then I parse the console output with my NSIS script in order to get the CPU flags...

mousemurder
13th June 2008, 00:36
oh when you mentioned mplayer installer i assumed linux.

with windows i am at a loss.

good luck.

LoRd_MuldeR
13th June 2008, 00:58
oh when you mentioned mplayer installer i assumed linux.

Have a look here:
http://forum.doom9.org/showthread.php?t=129909

MPlayer does a great job on Windows, but people prefer an "all-in-one" installer :D

krosswindz
17th June 2008, 16:02
on-topic: I am not sure if you can use this for cpu detection: http://www.cpuid.com/cpuz.php

off-topic: I love mplayer, have been using it for a while but on linux. Now that debian has it in their own repos I dont have to worry about getting other builds. For windows off late i like this new player KMPlayer. Does a very good job.

LoRd_MuldeR
17th June 2008, 16:18
on-topic: I am not sure if you can use this for cpu detection: http://www.cpuid.com/cpuz.php

off-topic: I love mplayer, have been using it for a while but on linux. Now that debian has it in their own repos I dont have to worry about getting other builds. For windows off late i like this new player KMPlayer. Does a very good job.

I know about CPU-Z, but I already have a more lightweight commandline utility (cpuinfo.exe) to get a list of supported CPU extensions.
The main problem is: Once you have the list of supported extensions, how to decide which MPlayer build to install ???

But I think the problem is solved for now, because nobody seems to complain about a wrong build being suggested :p

clsid
17th June 2008, 16:45
The CPU detection code of ffdshow might be interesting for you. It uses InnoSetup instead of NSIS, but it is a good example. The actual detection routines are in a DLL file.
http://ffdshow-tryout.svn.sourceforge.net/viewvc/ffdshow-tryout/trunk/bin/distrib/InnoSetup/

Using a P4 optimized build will probably hurt performance with newer CPU models. I think it is worthwhile to test if runtime detection gives better performance.

LoRd_MuldeR
17th June 2008, 17:03
Any idea how to measure performance with MPlayer? Something like Haali's TimeCodec would be needed...

clsid
17th June 2008, 18:15
You could use something like Sysinternals Process Explorer and compare the used CPU time.

LoRd_MuldeR
17th June 2008, 18:47
You could use something like Sysinternals Process Explorer and compare the used CPU time.

I wonder how comparable those results are, but I'll give it a try when I have some time.
One problem though: The MPlayer process will disappear from ProcExp as soon as playback has ended...

krosswindz
17th June 2008, 20:26
^ I dont know much about windows but does windows have an equivalent of time and measure the actual wall time. Not sure if this would be a good benchmark. IMO a better estimation would be actually running mencoder to see if that build really performs better than others.

LoRd_MuldeR
9th July 2008, 17:27
Okay, I got a CPU detection problem reported by a user, but I don't know how to solve it :confused:

My installer detects the following:
http://img363.imageshack.us/img363/6715/capture09072008180041kz0.jpg

Since the CPU has MMX + MMXEXT + 3DNOW + 3DNOWEXT (detected by cpuinfo.exe) it should be okay to recommend the "Athlon" Build.
And that's what my installer does!


But the user gets this for some reason with the "Athlon" Build:
http://img503.imageshack.us/img503/9353/capture09072008181741rl1.jpg


I also asked for a CPU-Z screenshot, but still I think "Athlon" is supposed to work:
http://img95.imageshack.us/img95/1533/capture09072008103258lo1.jpg


Any ideas on what could cause "Illegal Instruction" exception ???

BTW: The user also reported that re-installing with the "Generic" build fixed to problem :o

:thanks:

Dark Shikari
9th July 2008, 17:49
Are you sure that it supports MMX2?

LoRd_MuldeR
9th July 2008, 17:57
Are you sure that it supports MMX2?

Well, according to "cpuinfo.exe" it supports MMX. And if I'm not mistaken, MMX2 is simply a subset of MMX, so MMX should be sufficient.

Also checking for "MMX2" wouldn't work, because all the MPlayer builds say:
"Compiled for x86 CPU with extensions: MMX MMX2 [..]"

Even the P4 build says so, but "cpuinfo.exe" doesn't find "MMX2" on my Core2 Quad.
That means: Checking for "MMX2" would prevent the installer from suggesting the P4 build for my system.
But obviously the P4 build runs fine here...

:confused:

Dark Shikari
9th July 2008, 18:02
Well, according to "cpuinfo.exe" it supports MMX. And if I'm not mistaken, MMX2 is simply a subset of MMX, so MMX should be sufficient.Nope! MMX2 is the subset of SSE that acts on MMX registers.

LoRd_MuldeR
9th July 2008, 18:06
Nope! MMX2 is the subset of SSE that acts on MMX registers.

Thanks for the info. That makes sens now! :eek:

Any idea how to detect when the "Athlon" build (MMX, MMX2, 3DNOW, 3DNOWEX) is save to install from the "cpuinfo.exe" output?
I think it either requires MMX+MMX2+3DNOWEX or MMX+SSE+3DNOWEX. Can you agree on that?

Is 3DNOW a subset of 3DNOWEXT ???

Dark Shikari
9th July 2008, 18:14
Thanks for the info. That makes sens now! :eek:

Any idea how to detect when the "Athlon" build (MMX, MMX2, 3DNOW, 3DNOWEX) is save to install from the "cpuinfo.exe" output?
I think it either requires MMX+MMX2+3DNOWEX or MMX+SSE+3DNOWEX. Can you agree on that?

Is 3DNOW a subset of 3DNOWEXT ???Any computer with 3DNOWEX must have 3DNOW. Any computer with SSE must have MMX/MMX2. Any computer with MMX2 must have MMX.

LoRd_MuldeR
9th July 2008, 18:18
Any computer with 3DNOWEX must have 3DNOW. Any computer with SSE must have MMX/MMX2. Any computer with MMX2 must have MMX.

Allright. Thanks again :)

LoRd_MuldeR
9th July 2008, 18:38
I have now adjusted my CPU detection code:

1. If no MMX then stop.
2. If SSE2 then suggest "Pentium 4" build and stop.
3. If SSE, but no 3DNOWEXT then suggest "Pentium III" build and stop.
4. If SSE and 3DNOWEXT then suggest "Athlon" build and stop.
5. If MMX2 and 3DNOWEXT then suggest "Athlon" build and stop.
6. Suggest "Generic (RTM)" build.

LoRd_MuldeR
11th July 2008, 03:52
Sorry, there still is some confusion :confused:

What I know now:
MMX2 (sometimes called "Integer SSE") is an extension used on first-generation Athlon CPUs. It's a subset of SSE.
With AthlonXP the entire SSE set was implemented.

But what is MMXEXT ??? Where is the difference to MMX2 ???

Obviously MMX2 is *not* MMXEXT, because:
The "Athlon" MPlayer build requires MMX2, so it will run on CPU's with MMX2 and of course on CPU's with SSE.
But on the user's CPU (AMD Geode LX) it crashed, although cpuinfo.exe does detect the MMXEXT flag on his machine!
Conclusion: The MMXEXT flag does *not* say that MMX2 is available.

So if MMXEXT is not MMX2, what the heck is it?

I checked my Core2 Q6600 and even digged out my old AthlonXP machine:
* The Athlon XP shows the MMXEXT flag, but *not* the MMX2 flag. It shows the SSE flag, so it implicitly has MMX2. But it doesn't explicitly show the MMX2 flag!
* The Q6600 neither shows MMXEXT nor MMX2. Of course it implicitly supports MMX2 because of SSE. But again MMX2 is not shown explicitly as a flag!


I start to wonder whether there actually is any CPU that will show the MMX2 flag in cpuinfo.exe, because I'm yet to see one :o
So maybe checking cpuinfo.exe's output for the MMX2 flag is useless, because it will never be there. Only that strange MMXEXT, which doesn't help me...


Q6600:
http://img70.imageshack.us/img70/4820/cpuinfoq6600ni5.png

AthlonXP:
http://img224.imageshack.us/img224/5120/cpuinfoathlonxpxq2.png


Any help to clear this up would be appreciated :thanks:

squid_80
11th July 2008, 04:15
AFAIK MMXEXT is the same thing as MMX2.
Funny you should mention the geode, IIRC they implement some extra non-standard 3DNOW instructions. According to AMD documentation they do indeed support MMX, MMX extensions, 3DNOW and 3DNOW extensions (but not SSE or SSE2).

EDIT: Also, since MMX/3DNOW extensions are only present on AMD chips, you should never see them reported as being present on an intel chip. So it's no surprise your Q6600 doesn't show it.

LoRd_MuldeR
11th July 2008, 13:28
If you say MMX2 and MMXEXT are the same thing, how do you explain this :confused:

Obviously MMX2 is *not* MMXEXT, because:
The "Athlon" MPlayer build requires MMX2, so it will run on CPU's with MMX2 and of course on CPU's with SSE.
But on the user's CPU (AMD Geode LX) it crashed, although cpuinfo.exe does detect the MMXEXT flag on his machine!
Conclusion: The MMXEXT flag does *not* say that MMX2 is available.

BTW: One of the few sources on that topic I found is the 3DNow! (http://en.wikipedia.org/wiki/3DNow!#3DNow.21_extensions) article on Wikipedia. (See "3DNow! extensions" subsection).

But I really need some technical documentation that makes it clear, especially about what CPU flags are reported on what CPU type...

clsid
11th July 2008, 20:41
I have tested your Athlon optimized build on an actual AMD Athlon Thunderbird CPU and it works fine.

squid_80
11th July 2008, 21:58
But I really need some technical documentation that makes it clear, especially about what CPU flags are reported on what CPU type...

There's no such thing as a MMX2 flag. There's a MMX-EXT flag, on AMD cpus only.

foxyshadis
12th July 2008, 02:36
MMXEXT also goes by MMX2, ISSE, and SSEMMX! There's no official name for this instruction set, cpuinfo just lists it for intel as a convenience since SSE implies it. Geode LX (which is a very different CPU than NX, which is an Athlon XP) may not implement all of the same instructions as the original Athlon.

ARDA
12th July 2008, 10:53
Intel® Processor Identification
and the CPUID Instruction
Application Note 485
December 2007
Look for 24161832.pdf. Maybe there is a newer one; search.

in cpuaccel.cpp Shodan has updated code for instructions set detection
http://avisynth2.cvs.sourceforge.net/avisynth2/avisynth/src/sources/avi/cpuaccel.cpp?view=markup


I´ve found this one from amd
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf

I hope this can be usefull
ARDA

LoRd_MuldeR
12th July 2008, 14:57
MMXEXT also goes by MMX2, ISSE, and SSEMMX! There's no official name for this instruction set, cpuinfo just lists it for intel as a convenience since SSE implies it. Geode LX (which is a very different CPU than NX, which is an Athlon XP) may not implement all of the same instructions as the original Athlon.

So the MMXEXT flag usually does indicate MMX2 (aka I(nteger)SSE, aka SSEMMX) support, but sometimes (e.g. on the Geode LX processor) the MMXEXT flag reported, although there is no (Athlon-comaptible) MMX2 support available in fact :mad:

How do I detect an "Athlon build compatible" CPU from the CPU flags reported by cpuinfo.exe then? Is there a way at all? :confused:

Thanks for your help anyway :)

LoRd_MuldeR
12th July 2008, 15:08
I´ve found this one from amd
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf

I hope this can be usefull
ARDA

Yes, it seems helpful:

CPUID Fn8000_0001_EDX Feature Identifiers:
MmxExt: AMD extensions to MMX instructions. See Appendix D “Instruction Subsets and CPUID Feature Sets” in APM3 and “128-Bit Media and Scientific Programming” in APM1.

This at least confirms what was said about the MMXEXT flag :)

krosswindz
13th July 2008, 06:08
Sorry, havent been following this thread busy with real life I remember this thread from gentoo-dev. Hopefully this is useful http://www.mail-archive.com/gentoo-dev@gentoo.org/msg05285.html

LoRd_MuldeR
13th July 2008, 16:22
There seems to be more confusion than conclusion on that mailing list ;)

Here's what we got...:

mmx2 = sse
sse = mmx2

From all that I know, that information is wrong!
* MMX2 is not equal to SEE, it's only a subset of it.
* SSE is not equal to MMX2, but it covers MMX2.

so mmx2 is NOT a flag for mmx2 support.. it's a flag for integer portion of sse...

That also is wrong from what I understood:
* There is no "MMX2" flag on any CPU, only a "MMXEXT" flag on AMD CPU's (Athlon and later)
* The MMXEXT flag signals support for the "integer portion of sse", which is also known as MMX2
* Basically you could say: MMXEXT = MMX2 = I(nteger)SSE http://img292.imageshack.us/img292/1312/subset2ch6.gif SSE

krosswindz
20th July 2008, 22:14
^ you should probably clear confusion in the mailing list :p

afaik i have never seen a processor with mmx2 flag only mmxext and specific to amd athlon processors.

probably looking at AMDs programmer documentation could shed some more info into the mmext flag. Even the GCC documents or mailing list might be a good place to look for info on this.

clsid
20th July 2008, 23:27
The correct conclusion has already been made by LoRd_MuldeR. No need to read more docs. All different names, but they mean the same.
MMXEXT = MMX2 = I(nteger)SSE = subset of SSE.