The MASM Forum

General => The Workshop => Topic started by: Gunther on January 28, 2013, 10:07:46 PM

Title: CPU and instruction detection
Post by: Gunther on January 28, 2013, 10:07:46 PM
Here's a quote from the IntelĀ® 64 and IA-32 Architectures Optimization Reference Manual, Order Number: 248966-026, p. 4-6:

Quote
Prior to using AVX, the application must identify that the operating system supports the XGETBV instruction, the YMM register state, in addition to processor's support for YMM state management using XSAVE/XRSTOR and AVX instructions. The following simplified sequence accomplishes both and is strongly recommended.
1) Detect CPUID.1:ECX.OSXSAVE[bit 27] = 1 (XGETBV enabled for application use1)
2) Issue XGETBV and verify that XFEATURE_ENABLED_MASK[2:1] = '11b' (XMM state and YMM state are enabled by OS).
3) detect CPUID.1:ECX.AVX[bit 28] = 1 (AVX instructions supported).
(Step 3 can be done in any order relative to 1 and 2)

Has anybody done these steps for the CPU and instruction set detection? Any source code available?

Gunther
Title: Re: CPU and instruction detection
Post by: dedndave on January 29, 2013, 12:14:50 AM
the problem is that intel and amd don't write operating systems - lol
come to think of it, it would be nice if they did   :P

steps 1 and 3 are easy to do
i have never tried step 2

http://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled (http://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled)
i would read the user comments also
Title: Re: CPU and instruction detection
Post by: Gunther on January 29, 2013, 12:48:17 AM
Hi Dave,

Quote from: dedndave on January 29, 2013, 12:14:50 AM
http://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled (http://software.intel.com/en-us/blogs/2011/04/14/is-avx-enabled)
i would read the user comments also

I know that link and it's a slightly modified code variant which Intel provides in the manual.

Gunther
Title: Re: CPU and instruction detection
Post by: dedndave on January 29, 2013, 12:54:29 AM
it doesn't appear that you have to access the control registers

that is when feature identification becomes a little more painful
i guess you need a kernel mode driver to access those registers
and - on newer OS's, MS has this WHQL thing that falls in the "piss-me-off" catagory - lol
i am an XP fan, forever - even if i can't do 64-bit or AVX
Title: Re: CPU and instruction detection
Post by: Gunther on January 29, 2013, 03:23:15 AM
Hi Dave,

Quote from: dedndave on January 29, 2013, 12:54:29 AM
i am an XP fan, forever - even if i can't do 64-bit or AVX

there's a 64 bit XP, too.  :lol: But of course, AVX isn't supported by that OS.

Gunther
Title: Re: CPU and instruction detection
Post by: dedndave on January 29, 2013, 04:55:34 AM
yah - my understanding of xp-64 is that it has a lot of problems
i may have a 64-bit machine some time in the future, but my 32-bit XP's will always be my fave
Title: Re: CPU and instruction detection
Post by: Gunther on January 29, 2013, 05:39:36 AM
Hi Dave,

Quote from: dedndave on January 29, 2013, 04:55:34 AM
i may have a 64-bit machine some time in the future, but my 32-bit XP's will always be my fave

so far as I know, the oldest Sempron or Celeron can handle 64 bit operating systems. Why not give it a try? You could run both systems in parallel with a good boot manager. But for 64 bit I would recommend Windows 7, not XP.

Gunther
Title: Re: CPU and instruction detection
Post by: dedndave on January 29, 2013, 10:11:16 AM
i have a prescott that supports "em64"
kind of a lame duck, i think
it would probably run xp64

at some point, i will probably acquire a laptop with windows 7-64
i don't have a laptop, so i can kill 2 birds with one stone

wifee has a laptop that came with vista on it
she cried until i managed to get xp on it for her   :P
Title: Re: CPU and instruction detection
Post by: Gunther on January 30, 2013, 04:22:19 AM
Hi Dave,

Quote from: dedndave on January 29, 2013, 10:11:16 AM
i have a prescott that supports "em64"
kind of a lame duck, i think
it would probably run xp64

it would run without any doubt a 64 bit Linux.

Quote from: dedndave on January 29, 2013, 10:11:16 AM
at some point, i will probably acquire a laptop with windows 7-64
i don't have a laptop, so i can kill 2 birds with one stone

that's a good idea. Go forward.

Gunther
Title: Re: CPU and instruction detection
Post by: Magnum on January 30, 2013, 05:33:06 AM
Quote from: dedndave on January 29, 2013, 12:14:50 AM
the problem is that intel and amd don't write operating systems - lol
come to think of it, it would be nice if they did   :P


That would be nice if they did.

I think they could make a killer o.s. and would do it without having a 'tude.

I remember when they sent me some programming and chip manuals for free.

Andy
Title: Re: CPU and instruction detection
Post by: dedndave on January 30, 2013, 05:43:47 AM
probably something in the monopoly laws prevents them from doing so
otherwise - they certainly have the resources to do it - especially intel
if not by law - maybe by agreement with ms   :P
Title: Re: CPU and instruction detection
Post by: Magnum on January 30, 2013, 06:14:44 AM
Do you think Intel would make chips that only ran their o.s. ?

Already some companies strong arm all kinds of sweet heart deals.

Monster O.S.'s need monster hard drives, etc.

You can infer a lot of the "back room activities" it by going deep and reading the specifics on some of the patches and updates.

On another funny side.

In my limited user, I had configured to use the oldest i.e.

Even though I had +R on i.e., it changed mysteriously to sp3 version.

But when I am using my admin account, it uses the sp2 version.  :t

Just for shi*s and grins, I added +S to iexplore.exe.

Laterz.





Title: Re: CPU and instruction detection
Post by: dedndave on January 30, 2013, 06:23:17 AM
QuoteDo you think Intel would make chips that only ran their o.s. ?

yah - i am pretty sure that would be a violation of laws
microsoft got sued for bundling IE with windows
how do you think the fed would react to an os that only ran on the same companies chips - lol

back in the day, i remember intel's x86 assembler
it was a bit clumsy, really - very basic
but, it was good enough for ibm to use for writing pc/xt bios code
in fact, it handled rom-able code better than masm, in some ways
well - masm is not intended for use, other than code to be run under ms operating systems
i have played some tricks and used it for my own rom-able code, though (personal use)
Title: Re: CPU and instruction detection
Post by: Magnum on January 30, 2013, 07:53:19 AM
They got sued but it's still bundled with the o.s. except for Europe.  :icon13:

Title: Re: CPU and instruction detection
Post by: dedndave on January 30, 2013, 11:09:43 AM
yah - i really didn't understand that one   :redface:
if i buy an operating system, i want one that comes with a browser
what do they think ? - i am going to buy one ? - or, maybe they think i can write one - lol
Title: Re: CPU and instruction detection
Post by: Magnum on January 30, 2013, 01:00:47 PM
Freeware
Title: Re: CPU and instruction detection
Post by: dedndave on January 30, 2013, 11:54:27 PM
of course - but the courts don't provide firefox - lol
Title: Re: CPU and instruction detection
Post by: Magnum on January 31, 2013, 02:02:34 AM
What I didn't say in the previous post is that even though m.s. was sued and lost,
only Europe had the browser separated from the o.s.

The rest of the world are their own in that respect.

I am using a H.I.D.S. program and that was why I accidentally terminated services.exe.

I have evaluated Malware Defender and am now trying out Comodo Personal  Firewall.

Andy

Do you many problems with squirrels in your area ?
Title: Re: CPU and instruction detection
Post by: dedndave on January 31, 2013, 02:23:00 AM
squirrels ?

we don't have many in the Phoenix area - it's too hot - we have a few
in the northern and south-eastern part of the state, there are many

last time i was in Michigan, it wasn't the squirrels that were a problem
it was the oak trees
i thought it was raining acorns - lol
Title: Re: CPU and instruction detection
Post by: Gunther on February 01, 2013, 06:01:43 AM
Andy and Dave,

only to finish the white noise, here is one for you. I've written an assembly language procedure, which detects the available instruction sets (supported by processor and operating system) up to the upcoming AVX2. For the 64 bit operating systems it's very easy, because at least SSE2 must be supported; otherwise the OS installation would fail. So, one has only to check the instruction enhancements above SSE2.

A bit mor tricky is the situation for the 32 bit world. The only thing what's safe is at least the presence of an 80386. The other features must be figured out. Very complicated is the detection in the 16 bit world, because nothing is safe there.

I've done the easy part first: 64 bit. You may check the following new thread: http://masm32.com/board/index.php?topic=1405.0 (http://masm32.com/board/index.php?topic=1405.0). There you can find the commented sources for Windows and Linux.

Gunther 
Title: Re: CPU and instruction detection
Post by: Magnum on February 01, 2013, 06:25:59 AM
White noise can be good at times.

Thanks for the links.

I would like to test it on a Thinkpad Edge E530  62724GU Win7 Pro 64 that
my daughter will receive next week.

Andy
Title: Re: CPU and instruction detection
Post by: Gunther on February 01, 2013, 05:55:20 PM
Hi Andy,

Quote from: Magnum on February 01, 2013, 06:25:59 AM
I would like to test it on a Thinkpad Edge E530  62724GU Win7 Pro 64 that
my daughter will receive next week.

Andy

that would be nice; I think it'll work properly.

Gunther
Title: Re: CPU and instruction detection
Post by: Magnum on February 02, 2013, 02:42:08 AM
Quote from: dedndave on January 31, 2013, 02:23:00 AM
squirrels ?

we don't have many in the Phoenix area - it's too hot - we have a few
in the northern and south-eastern part of the state, there are many

last time i was in Michigan, it wasn't the squirrels that were a problem
it was the oak trees
i thought it was raining acorns - lol

My neighborhood has a "No chop down tree unless it's a chinese tallow tree." policy.

One clever neighbor strung up a bird feeder and put LP records on both sides.

I wish I had been there when the first squirrel tried to get to the bird food at about 20 feet above ground.