include/SSEPlus_CPUID.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2006-2008 Advanced Micro Devices, Inc. All Rights Reserved.
00003 // This software is subject to the Apache v2.0 License.
00004 //
00005 
00006 // This file should contain all platform specific code. 
00007 
00008 #ifndef __SSEPLUS_CPUID_H__
00009 #define __SSEPLUS_CPUID_H__
00010 
00011 #include "SSEPlus_base.h"
00012 
00018 typedef enum 
00019 {
00020     SSP_REF,
00021     SSP_SSE,
00022     SSP_SSE2,
00023     SSP_SSE3,
00024     SSP_SSSE3,
00025     SSP_SSE4a,
00026     SSP_SSE4_1,
00027     SSP_SSE4_2,
00028     SSP_SSE5,
00029     SSP_SSE_COUNT
00030 }ssp_cpu_feature;
00031 
00032 typedef struct 
00033 {
00034     int feature[SSP_SSE_COUNT]; 
00035 }ssp_cpuid;
00036 
00037 
00038 ssp_cpuid ssp_get_cpuid()
00039 {
00040     unsigned maxInfoType;
00041     ssp_cpuid cpu;
00042     int data[4], i;
00043 
00044     for( i=0; i<SSP_SSE_COUNT; ++i )
00045     {
00046         cpu.feature[i] = 0;
00047     }
00048 
00049     __cpuid( data, 0 );  
00050     maxInfoType = data[0] + 0x80000000;
00051 
00052     __cpuid( data, 1 );      
00053 
00054     cpu.feature[SSP_SSE   ] = (data[3] & 0x1000000) || 0;  // EDX: bit 25
00055     cpu.feature[SSP_SSE2  ] = (data[3] & 0x2000000) || 0;  // EDX: bit 26
00056     cpu.feature[SSP_SSE3  ] = (data[2] & 0x1      ) || 0;  // ECX: bit 0
00057     cpu.feature[SSP_SSSE3 ] = (data[2] & 0x100    ) || 0;  // ECX: bit 9
00058     cpu.feature[SSP_SSE4_1] = (data[2] & 0x40000  ) || 0;  // ECX: bit 19
00059     cpu.feature[SSP_SSE4_2] = (data[2] & 0x80000  ) || 0;  // ECX: bit 20     
00060 
00061     if( maxInfoType >= 0x80000001 )
00062     {
00063         __cpuid( data, 0x80000001 );        
00064         
00065         cpu.feature[ SSP_SSE4a ] = (data[2] & 0x40  ) || 0;  // ECX: bit 6
00066         cpu.feature[ SSP_SSE5  ] = (data[2] & 0x800 ) || 0;  // ECX: bit 11    
00067     }
00068    
00069     return cpu;    
00070 }
00071 
00072 int ssp_is_supported( ssp_cpu_feature index )
00073 {
00074     ssp_cpuid cpu = ssp_get_cpuid();
00075     return cpu.feature[ index ];
00076 }
00077 
00083 #endif //__SSEPLUS_CPUID_H__

Generated on Wed May 21 13:44:11 2008 for "SSEPlus" by  doxygen 1.5.4