Click here to Skip to main content
15,897,704 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to find Number of processor or Cores ? Pin
«_Superman_»28-Jun-09 23:44
professional«_Superman_»28-Jun-09 23:44 
GeneralRe: How to find Number of processor or Cores ? Pin
ERLN29-Jun-09 0:00
ERLN29-Jun-09 0:00 
GeneralRe: How to find Number of processor or Cores ? Pin
Stuart Dootson29-Jun-09 0:05
professionalStuart Dootson29-Jun-09 0:05 
GeneralRe: How to find Number of processor or Cores ? Pin
«_Superman_»29-Jun-09 0:06
professional«_Superman_»29-Jun-09 0:06 
AnswerRe: How to find Number of processor or Cores ? Pin
Stuart Dootson29-Jun-09 0:01
professionalStuart Dootson29-Jun-09 0:01 
GeneralRe: How to find Number of processor or Cores ? Pin
ERLN29-Jun-09 0:35
ERLN29-Jun-09 0:35 
GeneralRe: How to find Number of processor or Cores ? Pin
Stuart Dootson29-Jun-09 0:42
professionalStuart Dootson29-Jun-09 0:42 
AnswerRe: How to find Number of processor or Cores ? Pin
Randor 29-Jun-09 4:11
professional Randor 29-Jun-09 4:11 
You can use the cpuid assembly instruction to get this information, it will require some assembly knowledge. I wrote the following functions a few years ago, you may want to check that they return the correct values.

__inline BOOL IsHyperThreaded()
{
	BOOL bHyperthread = 0;
	__asm
	{
		xor	eax, eax
		cpuid
		cmp	eax, 1
		jb end
		xor eax, eax
		inc eax
		cpuid
		test edx, 0x10000000
		jz end
		mov	dword ptr [bHyperthread], 1
	end:
	}
	return bHyperthread;
}

__inline unsigned int PhysicalCores()
{
unsigned int cores = 1;

__asm
{
	xor	eax, eax
	cpuid
	cmp	eax, 4
	jb	end
	mov	eax, 4
	xor	ecx, ecx
	cpuid
	shr	eax, 26
	and	eax, 0x1F
	add	eax, 1
	mov	dword ptr [cores], eax
end:
}
return cores;
}

__inline unsigned int CpuCores()
{
unsigned int cores = 0;
__asm
{
	xor eax, eax
	cpuid
	cmp eax, 4
	jl single
	mov eax, 4
	xor ecx, ecx
	cpuid
	mov cores, eax
	jmp multi
single:
	xor eax, eax
multi:
}
return (unsigned int)((cores & 0xFC000000) >> 26)+1;
}

__inline unsigned int LogicalCores()
{
unsigned int cores = 1;
__asm
{
	xor	eax, eax
	cpuid
	cmp	eax, 1
	jb	end
	xor eax, eax
	inc eax
	cpuid
	test edx, 0x10000000
	jz end
	mov eax, ebx
	and eax, 0x00FF0000
	shr eax, 16
	mov cores, eax
end:
}
return cores;
}


My code will not work on the MSVC 64 bit compiler, if you are creating a 64 bit application then you will need to use the CPUID intrinsics[^]

Best Wishes,
-David Delaune
Questionneed help of c code of imresize matlab function Pin
ashish_2418828-Jun-09 19:42
ashish_2418828-Jun-09 19:42 
AnswerRe: need help of c code of imresize matlab function Pin
chandu00428-Jun-09 20:38
chandu00428-Jun-09 20:38 
AnswerRe: need help of c code of imresize matlab function Pin
Stuart Dootson29-Jun-09 0:12
professionalStuart Dootson29-Jun-09 0:12 
QuestionWhy eVC4.0 can't start up? Pin
Le@rner28-Jun-09 19:31
Le@rner28-Jun-09 19:31 
AnswerRe: Why eVC4.0 can't start up? Pin
Rajesh R Subramanian28-Jun-09 22:31
professionalRajesh R Subramanian28-Jun-09 22:31 
AnswerRe: Why eVC4.0 can't start up? Pin
Randor 29-Jun-09 5:17
professional Randor 29-Jun-09 5:17 
QuestionList all databases Pin
Davitor28-Jun-09 19:23
Davitor28-Jun-09 19:23 
AnswerRe: List all databases Pin
Davitor29-Jun-09 0:21
Davitor29-Jun-09 0:21 
Questionneed c code of imrotate matlab function Pin
ashish_2418828-Jun-09 18:32
ashish_2418828-Jun-09 18:32 
AnswerRe: need c code of imrotate matlab function Pin
Rajesh R Subramanian28-Jun-09 19:06
professionalRajesh R Subramanian28-Jun-09 19:06 
Questionneed help Pin
ashish_2418828-Jun-09 18:25
ashish_2418828-Jun-09 18:25 
Questionhow to do user interface(UI) design? Pin
favorxx28-Jun-09 17:29
favorxx28-Jun-09 17:29 
AnswerRe: how to do user interface(UI) design? Pin
Taran928-Jun-09 19:02
Taran928-Jun-09 19:02 
GeneralRe: how to do user interface(UI) design? Pin
favorxx28-Jun-09 20:11
favorxx28-Jun-09 20:11 
GeneralRe: how to do user interface(UI) design? Pin
favorxx1-Jul-09 3:34
favorxx1-Jul-09 3:34 
Questionhow to prevent HDD format with source. Pin
ShinHyun28-Jun-09 14:21
ShinHyun28-Jun-09 14:21 
GeneralRe: how to prevent HDD format with source. Pin
Michael Dunn28-Jun-09 15:18
sitebuilderMichael Dunn28-Jun-09 15:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.