October 24, 2006
Tomas Lindquist Olsen wrote:
> Hi all,
> I've written a simple class that encapsulates the cpuid instruction. It could probably be improved and polished, but I'm fairly happy with it.
> 
> One thing I'm considering is if a static only class would be better, it's not like the info can change dynamically...
> 
> Get it here: http://famolsen.dk/d/cpuid.zip
> 
> The zip contains the cpuid module and a simple test app. Running the test app I get personally get this:
> 
> Vendor string:    AuthenticAMD
> Processor string: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
> Features:         MMX SSE SSE2 SSE3 3DNow! 3DNow!+ MMX+ AMD64 HTT
> Multithreading:   2 threads / 2 cores
> 
> The threading info should work on both Intel and AMD cpus, but I have no way to test the Intel path. Any feedback would be much appreciated.
> 
> Also, I'm considering creating a library with sse/2/3 optimised batch operations for vector operations normalisation etc. Would such a library be of interest to the D community?

I got...

Vendor string:    GenuineIntel
Processor string: Genuine Intel(R) CPU           T2300  @ 1.66GHz
Features:         MMX SSE SSE2 SSE3 HTT
Multithreading:   2 threads / 2 cores

Seems to work.

~ Clay
October 24, 2006
Tomas Lindquist Olsen wrote:

> One thing I'm considering is if a static only class would be better, it's not like the info can change dynamically...

Who knows... Maybe one day D will be used in a multi-processor system with Hot-Swapped CPUs.

But anyway your code makes a nice contribution to D codebase.

-- 
'non-optimal' is a politically correct term for s*it
October 24, 2006
Tomas Lindquist Olsen wrote:

> Hi all,
> I've written a simple class that encapsulates the cpuid instruction. It
> could probably be improved and polished, but I'm fairly happy with it.
> 
> One thing I'm considering is if a static only class would be better, it's not like the info can change dynamically...
> 
> Get it here: http://famolsen.dk/d/cpuid.zip
> 
> The zip contains the cpuid module and a simple test app. Running the test app I get personally get this:
> 
> Vendor string:    AuthenticAMD
> Processor string: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
> Features:         MMX SSE SSE2 SSE3 3DNow! 3DNow!+ MMX+ AMD64 HTT
> Multithreading:   2 threads / 2 cores
> 
> The threading info should work on both Intel and AMD cpus, but I have no way to test the Intel path. Any feedback would be much appreciated.
> 
> Also, I'm considering creating a library with sse/2/3 optimised batch operations for vector operations normalisation etc. Would such a library be of interest to the D community?

larsivi@larsivi-laptop:~/code/d/cpuid$ ./test
Vendor string:    GenuineIntel
Processor string:         Intel(R) Pentium(R) M processor 1.86GHz
Features:         MMX SSE SSE2
Multithreading:   1 threads / 1 cores

Looks correct to me, the naming of the processor is Pentium-M 750 in the computer spec.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi
October 24, 2006
Tomas Lindquist Olsen wrote:
> Hi all,
> I've written a simple class that encapsulates the cpuid instruction. It could probably be improved and polished, but I'm fairly happy with it.
> 
> One thing I'm considering is if a static only class would be better, it's not like the info can change dynamically...

Maybe even just a module with some functions? (with recommendation to use static import)

> Get it here: http://famolsen.dk/d/cpuid.zip
> 
> The zip contains the cpuid module and a simple test app. Running the test app I get personally get this:
> 
> Vendor string:    AuthenticAMD
> Processor string: AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
> Features:         MMX SSE SSE2 SSE3 3DNow! 3DNow!+ MMX+ AMD64 HTT
> Multithreading:   2 threads / 2 cores
> 
> The threading info should work on both Intel and AMD cpus, but I have no way to test the Intel path. Any feedback would be much appreciated.

After a small patch:
	char[12] vendorStr = ' ';
	char[48] processorStr = ' ';
(Otherwise it crashes with an "invalid UTF string" exception)

it returned this:
  Vendor string:    GenuineIntel
  Processor string:
  Features:         MMX SSE
  Multithreading:   1 threads / 1 cores
on my laptop, which looks about right. Guess my laptop is so old it doesn't have a processor string.
Well, either that or your code's buggy :P. (It's a Celeron according to the sticker, and about 750 MHz IIRC)

Other computer:
  Vendor string:    AuthenticAMD
  Processor string: AMD Sempron(tm) 2600+
  Features:         MMX SSE 3DNow! 3DNow!+ MMX+
  Multithreading:   1 threads / 1 cores
also looks right.

> Also, I'm considering creating a library with sse/2/3 optimised batch
> operations for vector operations normalisation etc. Would such a library
> be of interest to the D community?

Not useful to me personally but the more D code is out there, the better :).
October 25, 2006
Walter Bright wrote:
> I'd like to put this into Phobos. Can you explicitly make it public domain?

Cool :) I have updated the zip and CPUID is now public domain. There is one more thing (at least) that should be implemented though before this is really worthy of being in std (IMHO).

The threading info is only probing the hardware. The OS might not allow the app to use those resources so processor affinity stuff should be added. I can add this, just have to read up on it. Or if someone knows it already feel free to patch, in which case I will do nothing :P
October 25, 2006
The zip has been updated:
* Added public domain header
* Fixed bug with manufacturer not being set if HTT was not supported
* Fixed invalid processor string bugs

It seems that there is actually some interest in this module so I will accept feature requests.
October 25, 2006
Tomas Lindquist Olsen escribió:
> The zip has been updated:
> * Added public domain header
> * Fixed bug with manufacturer not being set if HTT was not supported
> * Fixed invalid processor string bugs
> 
> It seems that there is actually some interest in this module so I will accept feature requests.

I have one: support other processors ;)

-- 
Carlos Santander Bernal
October 25, 2006
Tomas Lindquist Olsen wrote:
> Hi all,
> I've written a simple class that encapsulates the cpuid instruction. It could probably be improved and polished, but I'm fairly happy with it.

Doesn't quite work for me, says '0 threads / 0 cores'.  I have an Athlon thunderbird model C, 1.4 GHz.  The rest of the info looks correct.

Vendor string:    AuthenticAMD
Processor string: AMD Athlon(tm) processor
Features:         MMX 3DNow! 3DNow!+ MMX+
Multithreading:   0 threads / 0 cores
October 25, 2006
Vendor string:    AuthenticAMD
Processor string: AMD Sempron(tm)
Features:         MMX SSE 3DNow! 3DNow!+ MMX+
Multithreading:   0 threads / 0 cores

0 threads sounds weird, I am on Linux though.
October 25, 2006
notknown wrote:
> 
> Vendor string:    AuthenticAMD
> Processor string: AMD Sempron(tm)
> Features:         MMX SSE 3DNow! 3DNow!+ MMX+
> Multithreading:   0 threads / 0 cores
> 
> 0 threads sounds weird, I am on Linux though.

Weird indeed. The thread and core fields are initialised to one, and only if HTT is available is the code that set them invoked. As you dont have HTT on the list this really does not make sense. Can you try printing the value of those fields before the 'if (hyperThreading)' in CPUID.this ?