News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Instruction Set detection for 32 bit Operating Systems

Started by Gunther, February 03, 2013, 08:24:36 AM

Previous topic - Next topic

Gunther

I've attached the file instrset32.zip. It contains the sources and running applications for 32 bit Windows and Linux. An appropriate test program is included, too. The procedure detrects the instruction sets up to AVX2 properly. You may check the following threads, too: http://masm32.com/board/index.php?topic=1380.0 and http://masm32.com/board/index.php?topic=1405.0.

The assembly language part is written for jWasm, but it should work for masm, too. The C-source is compiled with gcc, but it should work with any other C compiler. Here is the output under Windows XP, SP3 as VM (Windows XP Mode).

Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3, SSE4.1,
     POPCNT, SSE4.2

     featurenumber = 13

XP doesn't support AVX; I'm not sure about the behaviour under Windows 7 (32 bit). Could anyone test that, please?

The 16 bit version is much more tricky and will be published probably as stand alone assembly language application inside the 16 bit forum.

Gunther
You have to know the facts before you can distort them.

Magnum

Output when run on Win 7 Pro 32 bit version

Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3

     featurenumber = 10
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

P4 prescott w/htt
     MMX, CMOV and FCOMI, SSE, SSE2, SSE3

     featurenumber = 9

it looks correct, although i don't know how to interpret the featurenumber

hutch--

Hi Gunther,

Works fine on my dev Core2 Quad.


Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3, SSE4.1

     featurenumber = 11

Gunther

Thank you Steve and Andy for testing. Dave, the featurenumber is only for information. Please have a look into the C-source cpufeatures.c; that should give you enough explanation (a simple select case statement).

Gunther
You have to know the facts before you can distort them.

dedndave

good work   :t

it's nice to know how to test for AVX when i don't have a machine to test it   :biggrin:

Magnum

Quote from: Gunther on February 03, 2013, 10:40:39 AM
Thank you Steve and Andy for testing.

Gunther

Glad to help. I like your thorough notes about what each step does.

Have you thought about seeing if Microsoft would buy a license for it ?  :t

They really need help with identifying important things, o.s.'s in particular.  :biggrin:

Andy



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

identifying the os version is WAY easier than identifying the CPU   :P

http://www.masmforum.com/board/index.php?topic=11963.0

i can upload the attachment if you like

these registry values....

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion]
"Version"="Windows 95"
"VersionNumber"="4.00.1111"
"ProductName"="Microsoft Windows 95"
"CurrentVersion"=(Value not found)
"CurrentBuildNumber"=(Value not found)
"SubVersionNumber"=" B"
"CSDVersion"=(Value not found)
"BuildLab"=(Value not found)
"ProductId"="24264-XXX-XXXXXXX-XXXXX"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center]
"Ident"=(Key not found)

OSVERSIONINFOEX Structure:

       Version.Build: 4.0.67109975
         Platform ID: Win32 on Windows 95
         CSD Version:  B


and the stuff at the end is from GetVersionEx

frktons

Quote
Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3

     featurenumber = 10

Windows 7/64 bit ultimate - Core Duo INTEL
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

Gunther

Hi Dave,

Quote from: dedndave on February 03, 2013, 12:54:00 PM
identifying the os version is WAY easier than identifying the CPU   :P

http://www.masmforum.com/board/index.php?topic=11963.0

i can upload the attachment if you like

why not. But it's not the question of detecting the underlying operating system. We have to check if the operating system is at least SSE aware, because the xmm registers must be saved during task switches. Unfortunately, the information that can be obtained from the CPUID instruction is not sufficient for determining whether it is possible to use XMM registers. The CPU can disable the use of the XMM registers in order to prevent their use under old operating systems that do not save these registers. Operating systems that support the use of XMM registers must set bit 9 of the control register CR4 to enable the use of XMM registers and indicate its ability to save and restore these registers during task switches.

Unfortunately, the CR4 register can only be read in privileged mode. Application programs therefore have a serious problem determining whether they are allowed to use the XMM registers or not. According to official Intel documents, the only way for an application program to determine whether the operating system supports the use of XMM registers is to try to execute an XMM instruction and see if you get an invalid opcode exception. But not all operating systems, compilers and programming languages provide facilities for application programs to catch invalid opcode exceptions. A Windows application, for example, using Intel's detection method would therefore have to be tested in all compatible operating systems, including various Windows emulators running under a number of other operating systems.

The demonstrated detection method in the procedure doesn't have this drawback. That is the point.

Gunther
You have to know the facts before you can distort them.

Gunther

Hi Andy,

Quote from: Magnum on February 03, 2013, 12:09:07 PM
Have you thought about seeing if Microsoft would buy a license for it ?  :t

no, not really. But we should help other code writers which are relatively new to assembly language. Therefore the comments and remarks.

Gunther
You have to know the facts before you can distort them.

dedndave

QuoteUnfortunately, the CR4 register can only be read in privileged mode. Application programs therefore have a serious problem determining whether they are allowed to use the XMM registers or not. According to official Intel documents, the only way for an application program to determine whether the operating system supports the use of XMM registers is to try to execute an XMM instruction and see if you get an invalid opcode exception. But not all operating systems, compilers and programming languages provide facilities for application programs to catch invalid opcode exceptions. A Windows application, for example, using Intel's detection method would therefore have to be tested in all compatible operating systems, including various Windows emulators running under a number of other operating systems.

The demonstrated detection method in the procedure doesn't have this drawback. That is the point.

i see - very interesting   :t

however, i think if you tested XP, Vista, Windows 7, you'd have enough info to determine support level

Gunther

Hi Dave,

Quote from: dedndave on February 03, 2013, 10:57:31 PM
i see - very interesting   :t

however, i think if you tested XP, Vista, Windows 7, you'd have enough info to determine support level

that might be. I'll tell you the following story. My son (20 years old) has a Linux (64 bit) installed and he experimented with Wine (the Windows emulator). He needs a special Wine version for some older software to run. What about that? That's the next serious problem.

Gunther
You have to know the facts before you can distort them.

dedndave

well - that could be a number of things

but - i hadn't considered os's other than windows, really
at my age, i have more than i can handle learning xp, vista, and win7 - lol

Magnum

Quote from: Gunther on February 03, 2013, 09:45:17 PM
Hi Andy,

Quote from: Magnum on February 03, 2013, 12:09:07 PM
Have you thought about seeing if Microsoft would buy a license for it ?  :t

no, not really. But we should help other code writers which are relatively new to assembly language. Therefore the comments and remarks.

Gunther

The comment was meant as humor.

I should have labeled the comment at the end.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org