flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
A$M 03 Feb 2014, 17:58
Hello!
How can I get the number of cores in a processor? I can't do that with CPUID I think. Last edited by A$M on 04 Feb 2014, 20:38; edited 1 time in total |
|||
![]() |
|
shutdownall 03 Feb 2014, 18:22
There is some code example but very long.
Maybe you can strip it down. ![]() In this CPUID documentation on page 74 (middle) there is a query of the cores. You can search for _dcp_cache_eax or ">= 2 cores?". found here: www.microbe.cz/docs/CPUID.pdf |
|||
![]() |
|
cod3b453 03 Feb 2014, 18:45
You can use GetSystemInfo from WinAPI to get the total number of cores; or do you really want to know for a particular core?
|
|||
![]() |
|
A$M 03 Feb 2014, 19:15
With a code like this:
Code: invoke GetSystemInfo, _systeminfo cinvoke printf, _cores, [_systeminfo+20] jmp $ _systeminfo rd 9 |
|||
![]() |
|
tthsqe 03 Feb 2014, 19:44
What I posted gives the logical processor count. If you want the physical processor count check out the function GetLogicalProcessorInformation.
|
|||
![]() |
|
HaHaAnonymous 03 Feb 2014, 21:18
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:19; edited 1 time in total |
|||
![]() |
|
tthsqe 03 Feb 2014, 23:14
Quote: My processor does not support popcnt instruction. My condolences. As you know, the popcnt instruction is the only way one can count the number of bits that are set. |
|||
![]() |
|
HaHaAnonymous 04 Feb 2014, 00:47
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:19; edited 1 time in total |
|||
![]() |
|
shutdownall 04 Feb 2014, 00:58
A$M wrote: I can get the logical cores count. How can I get the number of physical cores? Just use GetLogicalProcessorInformationEx Quote:
If it is a HT processor (HyperThreading) you have double logical cores than physical cores. If you have no HT then logical cores should be same like physical cores. So if you get this structure with RelationProcessorCore there should be found either "1" or "2" which means 1 physical core=1 logical core or 1 physical core=2 logical cores. Maybe there are more easy ways to find out if it is a Hyperthreading CPU or not. ![]() |
|||
![]() |
|
l_inc 04 Feb 2014, 08:51
HaHaAnonymous
Quote: The only way in a single instruction you mean... Right? I have a gift for you. Here it is. Use it wisely. _________________ Faith is a superposition of knowledge and fallacy |
|||
![]() |
|
sinsi 04 Feb 2014, 09:09
Maybe the Intel docs? It is low-level though, maybe an OS will prevent it.
8.9.5 Identifying Topological Relationships in a MP System |
|||
![]() |
|
HaHaAnonymous 04 Feb 2014, 13:47
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 18:18; edited 1 time in total |
|||
![]() |
|
typedef 04 Feb 2014, 16:38
HaHaAnonymous wrote:
Don't listen to him bro. Here's another way of counting bits 5 Different ways to count bits in x86/x64 Assembly |
|||
![]() |
|
A$M 04 Feb 2014, 18:37
Well...
![]() Code: invoke GetSystemInfo, _systeminfo mov eax, 1 cpuid mov eax, [_systeminfo+20] test edx, 1 shl 28 jz not_htt shr eax, 1 not_htt: cinvoke printf, _processor, eax,[_systeminfo+20] jmp $ _processor db "%i cores, %i threads.",0 _systeminfo rd 9 That is, if the hyperthreaded cores remain as 2 logical cores... ![]() Ps.: And this, for counting bits ![]() Code: xor edx, edx mov ecx, 32 mov ebx, 1 lp: test eax, ebx jz @f inc edx @@: shl ebx, 1 loop lp |
|||
![]() |
|
tthsqe 04 Feb 2014, 19:51
oops, obviously my statement as it is should be interpreted as sarcasm, but if you put a 'NOT' in the right place, then you get the literal meaning. I simple macro will get te number of set bits
Code: macro my_popcnt a,b { xor a,a repreat 32 shr b,1 adc a,0 end repeat } |
|||
![]() |
|
A$M 04 Feb 2014, 20:34
tthsqe wrote: oops, obviously my statement as it is should be interpreted as sarcasm, but if you put a 'NOT' in the right place, then you get the literal meaning. I simple macro will get te number of set bits ![]() Code: xor edx, edx mov ecx, 32 @@: shr eax, 1 adc edx, 0 loop @b ![]() |
|||
![]() |
|
l_inc 07 Feb 2014, 10:16
A$M wrote: I forgot of the carry existance. You guys need to learn optimizations. Even the following is much better, than the sum over cf: Code: ;input in eax xor edx,edx test eax,eax jz .omit @@: inc edx lea ecx,[eax-1] and eax,ecx jnz @B .omit: ;output in edx This way you need to iterate over the set bits only. Not over all of them. The following code performance is rather input independent: Code: ;input in eax mov edx,eax shr edx,1 and edx,$55555555 sub eax,edx mov ecx,$33333333 mov edx,eax and eax,ecx shr edx,2 and edx,ecx add eax,edx mov edx,eax shr eax,4 add eax,edx and eax,$0F0F0F0F imul eax,$01010101 shr eax,24 ;output in eax _________________ Faith is a superposition of knowledge and fallacy |
|||
![]() |
|
revolution 07 Feb 2014, 10:24
Hehe, what goes around comes around. There is an old thread here (that I am too lazy to search for now) discussing the population count problem with lots of code and optimisations.
|
|||
![]() |
|
revolution 07 Feb 2014, 11:08
Here it is:
http://board.flatassembler.net/topic.php?t=7936 Note: That thread also the <tab> conversion problem. |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.