
#include "scolPrerequisites.h"
#include "common/cpu_detect.h"

#ifdef		OPTI_P3
int infoP3 ;

///////////////////////////////////////////////
///		SSE1_Hard_Support					///
///////////////////////////////////////////////
///
/// Checking for Streaming SIMD 1 Extensions
///	--> P3
///
//$BB brand was not filled
int SSE1_Hard_Support()
{
	int HWSupport = 0;
	unsigned int brand[3];

#if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
	__try 
	{
		_asm
		{
      mov   edi, brand 
			mov		eax, 0			//First, check to make sure this is an Intel processor
			cpuid					//by getting the processor information string with CPUID
			mov	    brand, ebx		//  ebx contains "Genu"
			mov     brand+4, edx		//  edx contains "ineI"
			mov		brand+8, ecx		//  ecx contains "ntel"  -- "GenuineIntel"
		}
	}
    __except(EXCEPTION_EXECUTE_HANDLER) 
	{
		unsigned long code = _exception_code();
		return (0);
	}
	// Now make sure the processor is "GenuineIntel".
	if (strncmp((char *)brand, "GenuineIntel", 12) != 0) 
	{
		return (0);
	}

	// And finally, check the CPUID for Streaming SIMD Extensions support.
	_asm
	{
		push	ebx
		mov		eax, 1			// Put a "1" in eax to tell CPUID to get the feature bits
		cpuid					// Perform CPUID (puts processor feature info into EDX)
		test	edx, 02000000h	// Test bit 25, for Streaming SIMD Extensions existence.
		jz		NotFound		// If not set, jump over the next instruction (No Streaming
		mov		[HWSupport],1	// SIMD Extensions).  Set return value to 1 to indicate,
								// that the processor does support Streaming SIMD Extensions.
NotFound:				
		pop		ebx
	}
#elif SCOL_PLATFORM == SCOL_PLATFORM_LINUX
  // TODO LINUX
#endif
	
	return (HWSupport);
}	



///////////////////////////////////////////////
///		SSE1_OS_Support						///
///////////////////////////////////////////////
int SSE1_OS_Support()
{
#if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
	__try
	{
		_asm  xorps xmm0, xmm0  //Execute a Streaming SIMD Extensions
								//to see if support exists.
	}
	__except(EXCEPTION_EXECUTE_HANDLER) 
	{
		unsigned long code = _exception_code();
		return 0;
	}
#elif SCOL_PLATFORM == SCOL_PLATFORM_LINUX
  // TODO LINUX
#endif
	return 1;
}







int testP3()
{
	if(SSE1_Hard_Support())
	{
		if(SSE1_OS_Support()) return 1;
		else return 0;
	}
	else return 0;

	return 0;
}





#endif


#ifdef OPTI_P4
int infoP4 ;

///////////////////////////////////////////////
///		SSE2_Hard_Support					///
///////////////////////////////////////////////
///
/// Checking for Streaming SIMD 2 Extensions
///	--> P4
///
//$BB brand was not filled
int SSE2_Hard_Support()
{
	int HWSupport = 0;
	unsigned int brand[3];

#if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
  __try
	{
		_asm
		{
      mov   edi, brand
			mov		eax, 0			  //First, check to make sure this is an Intel processor
			cpuid					      //by getting the processor information string with CPUID
			mov	   brand, ebx		  //  ebx contains "Genu"
			mov    brand+4, edx	  //  edx contains "ineI"
			mov		 brand+8, ecx		//  ecx contains "ntel"  -- "GenuineIntel"
		}
	}
    __except(EXCEPTION_EXECUTE_HANDLER) 
	{
		unsigned long code = _exception_code();
		return (0);
	}

	// Now make sure the processor is "GenuineIntel".
	if (strncmp((char *)brand, "GenuineIntel", 12) != 0) 
	{
		return (0);
	}

	// And finally, check the CPUID for Streaming SIMD Extensions support.
	_asm
	{
		push	ebx
		mov		eax, 1			// Put a "1" in eax to tell CPUID to get the feature bits
		cpuid					// Perform CPUID (puts processor feature info into EDX)
		shr		edx, 26			// Test bit 26, for Streaming *SIMD 2* Extensions existence.
		and		edx, 0x1
		mov		[HWSupport],edx
		pop		ebx
	}
#elif SCOL_PLATFORM == SCOL_PLATFORM_LINUX
  // TODO LINUX
#endif
	
	return HWSupport;
}	





///////////////////////////////////////////////
///		SSE2_OS_Support						///
///////////////////////////////////////////////
int SSE2_OS_Support()
{
#if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
	__try
	{
		_asm  xorpd xmm0, xmm0		//Execute a Streaming *SIMD 2* Extensions
	}
	__except(EXCEPTION_EXECUTE_HANDLER) 
	{
		unsigned long code = _exception_code();
		return 0;
	}
#elif SCOL_PLATFORM == SCOL_PLATFORM_LINUX
  // TODO LINUX
#endif
	return 1;
}

 


int testP4()
{
	if(SSE2_Hard_Support())
	{
		if(SSE2_OS_Support()) return 1 ;
		else return 0 ;
	}
	else return 0 ;
}




#endif







