
#include	"ZooMalloc.h"






#ifdef		__OPTI_P3__




///////////////////////////////////////////////
///		SSE1_Hard_Support					///
///////////////////////////////////////////////
///
/// Checking for Streaming SIMD 1 Extensions
///	--> P3
///
int SSE1_Hard_Support()
{
	int HWSupport = 0;
	char brand[12];
	unsigned *str = (unsigned *) brand;

	__try 
	{
		_asm
		{
			mov		eax, 0			//First, check to make sure this is an Intel processor
			cpuid					//by getting the processor information string with CPUID
			mov	    str, ebx		//  ebx contains "Genu"
			mov     str+4, edx		//  edx contains "ineI"
			mov		str+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(brand, "GenuineIntel", 12)) 
	{
		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
	}
	
	return (HWSupport);
}	



///////////////////////////////////////////////
///		SSE2_Hard_Support					///
///////////////////////////////////////////////
///
/// Checking for Streaming SIMD 2 Extensions
///	--> P4
///
int SSE2_Hard_Support()
{
	int HWSupport = 0;
	char brand[12];
	unsigned *str = (unsigned *) brand;

	__try 
	{
		_asm
		{
			mov		eax, 0			//First, check to make sure this is an Intel processor
			cpuid					//by getting the processor information string with CPUID
			mov	    str, ebx		//  ebx contains "Genu"
			mov     str+4, edx		//  edx contains "ineI"
			mov		str+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(brand, "GenuineIntel", 12)) 
	{
		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
	}
	
	return HWSupport;
}	




///////////////////////////////////////////////
///		SSE1_OS_Support						///
///////////////////////////////////////////////
int SSE1_OS_Support()
{
	__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;
	}
	return 1;
}



///////////////////////////////////////////////
///		SSE2_OS_Support						///
///////////////////////////////////////////////
int SSE2_OS_Support()
{
	__try
	{
		_asm  xorpd xmm0, xmm0		//Execute a Streaming *SIMD 2* Extensions
	}
	__except(EXCEPTION_EXECUTE_HANDLER) 
	{
		unsigned long code = _exception_code();
		return 0;
	}
	return 1;
}




bool testP3()
{
	if(SSE1_Hard_Support())
	{
		if(SSE1_OS_Support())		return true;
		else						return false;
	}
	else						return false;

	return 0;
}


bool testP4()
{
	if(SSE2_Hard_Support())
	{
		if(SSE2_OS_Support())		return true;
		else						return false;
	}
	else						return false;

	return 0;
}








#endif







