src/cpuinfo/SDL_cpuinfo.c
changeset 1426 ef9a9064bff2
parent 1402 d910939febfa
child 1442 e3242177fe4a
equal deleted inserted replaced
1425:aea151eb97b8 1426:ef9a9064bff2
    53 {
    53 {
    54 	longjmp(jmpbuf, 1);
    54 	longjmp(jmpbuf, 1);
    55 }
    55 }
    56 #endif /* HAVE_SETJMP */
    56 #endif /* HAVE_SETJMP */
    57 
    57 
    58 static __inline__ int CPU_haveCPUID()
    58 static __inline__ int CPU_haveCPUID(void)
    59 {
    59 {
    60 	int has_CPUID = 0;
    60 	int has_CPUID = 0;
    61 #if defined(__GNUC__) && defined(i386)
    61 #if defined(__GNUC__) && defined(i386)
    62 	__asm__ (
    62 	__asm__ (
    63 "        pushfl                      # Get original EFLAGS             \n"
    63 "        pushfl                      # Get original EFLAGS             \n"
   143 	);
   143 	);
   144 #endif
   144 #endif
   145 	return has_CPUID;
   145 	return has_CPUID;
   146 }
   146 }
   147 
   147 
   148 static __inline__ int CPU_getCPUIDFeatures()
   148 static __inline__ int CPU_getCPUIDFeatures(void)
   149 {
   149 {
   150 	int features = 0;
   150 	int features = 0;
   151 #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) )
   151 #if defined(__GNUC__) && ( defined(i386) || defined(__x86_64__) )
   152 	__asm__ (
   152 	__asm__ (
   153 "        movl    %%ebx,%%edi\n"
   153 "        movl    %%ebx,%%edi\n"
   196 "        movl    %edi,%ebx\n" );
   196 "        movl    %edi,%ebx\n" );
   197 #endif
   197 #endif
   198 	return features;
   198 	return features;
   199 }
   199 }
   200 
   200 
   201 static __inline__ int CPU_getCPUIDFeaturesExt()
   201 static __inline__ int CPU_getCPUIDFeaturesExt(void)
   202 {
   202 {
   203 	int features = 0;
   203 	int features = 0;
   204 #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) )
   204 #if defined(__GNUC__) && (defined(i386) || defined (__x86_64__) )
   205 	__asm__ (
   205 	__asm__ (
   206 "        movl    %%ebx,%%edi\n"
   206 "        movl    %%ebx,%%edi\n"
   247 	    );
   247 	    );
   248 #endif
   248 #endif
   249 	return features;
   249 	return features;
   250 }
   250 }
   251 
   251 
   252 static __inline__ int CPU_haveRDTSC()
   252 static __inline__ int CPU_haveRDTSC(void)
   253 {
   253 {
   254 	if ( CPU_haveCPUID() ) {
   254 	if ( CPU_haveCPUID() ) {
   255 		return (CPU_getCPUIDFeatures() & 0x00000010);
   255 		return (CPU_getCPUIDFeatures() & 0x00000010);
   256 	}
   256 	}
   257 	return 0;
   257 	return 0;
   258 }
   258 }
   259 
   259 
   260 static __inline__ int CPU_haveMMX()
   260 static __inline__ int CPU_haveMMX(void)
   261 {
   261 {
   262 	if ( CPU_haveCPUID() ) {
   262 	if ( CPU_haveCPUID() ) {
   263 		return (CPU_getCPUIDFeatures() & 0x00800000);
   263 		return (CPU_getCPUIDFeatures() & 0x00800000);
   264 	}
   264 	}
   265 	return 0;
   265 	return 0;
   266 }
   266 }
   267 
   267 
   268 static __inline__ int CPU_haveMMXExt()
   268 static __inline__ int CPU_haveMMXExt(void)
   269 {
   269 {
   270 	if ( CPU_haveCPUID() ) {
   270 	if ( CPU_haveCPUID() ) {
   271 		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
   271 		return (CPU_getCPUIDFeaturesExt() & 0x00400000);
   272 	}
   272 	}
   273 	return 0;
   273 	return 0;
   274 }
   274 }
   275 
   275 
   276 static __inline__ int CPU_have3DNow()
   276 static __inline__ int CPU_have3DNow(void)
   277 {
   277 {
   278 	if ( CPU_haveCPUID() ) {
   278 	if ( CPU_haveCPUID() ) {
   279 		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
   279 		return (CPU_getCPUIDFeaturesExt() & 0x80000000);
   280 	}
   280 	}
   281 	return 0;
   281 	return 0;
   282 }
   282 }
   283 
   283 
   284 static __inline__ int CPU_have3DNowExt()
   284 static __inline__ int CPU_have3DNowExt(void)
   285 {
   285 {
   286 	if ( CPU_haveCPUID() ) {
   286 	if ( CPU_haveCPUID() ) {
   287 		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
   287 		return (CPU_getCPUIDFeaturesExt() & 0x40000000);
   288 	}
   288 	}
   289 	return 0;
   289 	return 0;
   290 }
   290 }
   291 
   291 
   292 static __inline__ int CPU_haveSSE()
   292 static __inline__ int CPU_haveSSE(void)
   293 {
   293 {
   294 	if ( CPU_haveCPUID() ) {
   294 	if ( CPU_haveCPUID() ) {
   295 		return (CPU_getCPUIDFeatures() & 0x02000000);
   295 		return (CPU_getCPUIDFeatures() & 0x02000000);
   296 	}
   296 	}
   297 	return 0;
   297 	return 0;
   298 }
   298 }
   299 
   299 
   300 static __inline__ int CPU_haveSSE2()
   300 static __inline__ int CPU_haveSSE2(void)
   301 {
   301 {
   302 	if ( CPU_haveCPUID() ) {
   302 	if ( CPU_haveCPUID() ) {
   303 		return (CPU_getCPUIDFeatures() & 0x04000000);
   303 		return (CPU_getCPUIDFeatures() & 0x04000000);
   304 	}
   304 	}
   305 	return 0;
   305 	return 0;
   306 }
   306 }
   307 
   307 
   308 static __inline__ int CPU_haveAltiVec()
   308 static __inline__ int CPU_haveAltiVec(void)
   309 {
   309 {
   310 	volatile int altivec = 0;
   310 	volatile int altivec = 0;
   311 #ifdef __MACOSX__
   311 #ifdef __MACOSX__
   312 	int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 
   312 	int selectors[2] = { CTL_HW, HW_VECTORUNIT }; 
   313 	int hasVectorUnit = 0; 
   313 	int hasVectorUnit = 0; 
   330 	return altivec; 
   330 	return altivec; 
   331 }
   331 }
   332 
   332 
   333 static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
   333 static Uint32 SDL_CPUFeatures = 0xFFFFFFFF;
   334 
   334 
   335 static Uint32 SDL_GetCPUFeatures()
   335 static Uint32 SDL_GetCPUFeatures(void)
   336 {
   336 {
   337 	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
   337 	if ( SDL_CPUFeatures == 0xFFFFFFFF ) {
   338 		SDL_CPUFeatures = 0;
   338 		SDL_CPUFeatures = 0;
   339 		if ( CPU_haveRDTSC() ) {
   339 		if ( CPU_haveRDTSC() ) {
   340 			SDL_CPUFeatures |= CPU_HAS_RDTSC;
   340 			SDL_CPUFeatures |= CPU_HAS_RDTSC;
   362 		}
   362 		}
   363 	}
   363 	}
   364 	return SDL_CPUFeatures;
   364 	return SDL_CPUFeatures;
   365 }
   365 }
   366 
   366 
   367 SDL_bool SDL_HasRDTSC()
   367 SDL_bool SDL_HasRDTSC(void)
   368 {
   368 {
   369 	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
   369 	if ( SDL_GetCPUFeatures() & CPU_HAS_RDTSC ) {
   370 		return SDL_TRUE;
   370 		return SDL_TRUE;
   371 	}
   371 	}
   372 	return SDL_FALSE;
   372 	return SDL_FALSE;
   373 }
   373 }
   374 
   374 
   375 SDL_bool SDL_HasMMX()
   375 SDL_bool SDL_HasMMX(void)
   376 {
   376 {
   377 	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
   377 	if ( SDL_GetCPUFeatures() & CPU_HAS_MMX ) {
   378 		return SDL_TRUE;
   378 		return SDL_TRUE;
   379 	}
   379 	}
   380 	return SDL_FALSE;
   380 	return SDL_FALSE;
   381 }
   381 }
   382 
   382 
   383 SDL_bool SDL_HasMMXExt()
   383 SDL_bool SDL_HasMMXExt(void)
   384 {
   384 {
   385 	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
   385 	if ( SDL_GetCPUFeatures() & CPU_HAS_MMXEXT ) {
   386 		return SDL_TRUE;
   386 		return SDL_TRUE;
   387 	}
   387 	}
   388 	return SDL_FALSE;
   388 	return SDL_FALSE;
   389 }
   389 }
   390 
   390 
   391 SDL_bool SDL_Has3DNow()
   391 SDL_bool SDL_Has3DNow(void)
   392 {
   392 {
   393 	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
   393 	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOW ) {
   394 		return SDL_TRUE;
   394 		return SDL_TRUE;
   395 	}
   395 	}
   396 	return SDL_FALSE;
   396 	return SDL_FALSE;
   397 }
   397 }
   398 
   398 
   399 SDL_bool SDL_Has3DNowExt()
   399 SDL_bool SDL_Has3DNowExt(void)
   400 {
   400 {
   401 	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
   401 	if ( SDL_GetCPUFeatures() & CPU_HAS_3DNOWEXT ) {
   402 		return SDL_TRUE;
   402 		return SDL_TRUE;
   403 	}
   403 	}
   404 	return SDL_FALSE;
   404 	return SDL_FALSE;
   405 }
   405 }
   406 
   406 
   407 SDL_bool SDL_HasSSE()
   407 SDL_bool SDL_HasSSE(void)
   408 {
   408 {
   409 	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
   409 	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE ) {
   410 		return SDL_TRUE;
   410 		return SDL_TRUE;
   411 	}
   411 	}
   412 	return SDL_FALSE;
   412 	return SDL_FALSE;
   413 }
   413 }
   414 
   414 
   415 SDL_bool SDL_HasSSE2()
   415 SDL_bool SDL_HasSSE2(void)
   416 {
   416 {
   417 	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
   417 	if ( SDL_GetCPUFeatures() & CPU_HAS_SSE2 ) {
   418 		return SDL_TRUE;
   418 		return SDL_TRUE;
   419 	}
   419 	}
   420 	return SDL_FALSE;
   420 	return SDL_FALSE;
   421 }
   421 }
   422 
   422 
   423 SDL_bool SDL_HasAltiVec()
   423 SDL_bool SDL_HasAltiVec(void)
   424 {
   424 {
   425 	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
   425 	if ( SDL_GetCPUFeatures() & CPU_HAS_ALTIVEC ) {
   426 		return SDL_TRUE;
   426 		return SDL_TRUE;
   427 	}
   427 	}
   428 	return SDL_FALSE;
   428 	return SDL_FALSE;