src/cpuinfo/SDL_cpuinfo.c
branchSDL-1.2
changeset 13219 4f88e197acad
parent 13212 3d6dc20a0974
child 13396 f765d8961a16
equal deleted inserted replaced
13218:8a6c0f0319d4 13219:4f88e197acad
    44 #define CPU_HAS_3DNOWEXT 0x00000020
    44 #define CPU_HAS_3DNOWEXT 0x00000020
    45 #define CPU_HAS_SSE	0x00000040
    45 #define CPU_HAS_SSE	0x00000040
    46 #define CPU_HAS_SSE2	0x00000080
    46 #define CPU_HAS_SSE2	0x00000080
    47 #define CPU_HAS_ALTIVEC	0x00000100
    47 #define CPU_HAS_ALTIVEC	0x00000100
    48 #define CPU_HAS_ARM_SIMD 0x00000200
    48 #define CPU_HAS_ARM_SIMD 0x00000200
       
    49 #define CPU_HAS_ARM_NEON 0x00000400
    49 
    50 
    50 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
    51 #if SDL_ALTIVEC_BLITTERS && HAVE_SETJMP && !__MACOSX__ && !__OpenBSD__
    51 /* This is the brute force way of detecting instruction sets...
    52 /* This is the brute force way of detecting instruction sets...
    52    the idea is borrowed from the libmpeg2 library - thanks!
    53    the idea is borrowed from the libmpeg2 library - thanks!
    53  */
    54  */
   420 		close(fd);
   421 		close(fd);
   421 	}
   422 	}
   422 	return arm_simd;
   423 	return arm_simd;
   423 }
   424 }
   424 
   425 
       
   426 static __inline__ int CPU_haveARMNEON(void)
       
   427 {
       
   428 	int arm_neon = 0;
       
   429 	int fd;
       
   430 
       
   431 	fd = open("/proc/self/auxv", O_RDONLY);
       
   432 	if (fd >= 0)
       
   433 	{
       
   434 		Elf32_auxv_t aux;
       
   435 		while (read(fd, &aux, sizeof aux) == sizeof aux)
       
   436 		{
       
   437 			if (aux.a_type == AT_HWCAP)
       
   438 				arm_neon = (aux.a_un.a_val & 4096) != 0;
       
   439 		}
       
   440 		close(fd);
       
   441 	}
       
   442 	return arm_neon;
       
   443 }
       
   444 
   425 #else
   445 #else
   426 
   446 
   427 static __inline__ int CPU_haveARMSIMD(void)
   447 static __inline__ int CPU_haveARMSIMD(void)
       
   448 {
       
   449 	return 0;
       
   450 }
       
   451 
       
   452 static __inline__ int CPU_haveARMNEON(void)
   428 {
   453 {
   429 	return 0;
   454 	return 0;
   430 }
   455 }
   431 
   456 
   432 #endif
   457 #endif
   462 			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
   487 			SDL_CPUFeatures |= CPU_HAS_ALTIVEC;
   463 		}
   488 		}
   464 		if ( CPU_haveARMSIMD() ) {
   489 		if ( CPU_haveARMSIMD() ) {
   465 			SDL_CPUFeatures |= CPU_HAS_ARM_SIMD;
   490 			SDL_CPUFeatures |= CPU_HAS_ARM_SIMD;
   466 		}
   491 		}
       
   492 		if ( CPU_haveARMNEON() ) {
       
   493 			SDL_CPUFeatures |= CPU_HAS_ARM_NEON;
       
   494 		}
   467 	}
   495 	}
   468 	return SDL_CPUFeatures;
   496 	return SDL_CPUFeatures;
   469 }
   497 }
   470 
   498 
   471 SDL_bool SDL_HasRDTSC(void)
   499 SDL_bool SDL_HasRDTSC(void)
   533 }
   561 }
   534 
   562 
   535 SDL_bool SDL_HasARMSIMD(void)
   563 SDL_bool SDL_HasARMSIMD(void)
   536 {
   564 {
   537 	if ( SDL_GetCPUFeatures() & CPU_HAS_ARM_SIMD ) {
   565 	if ( SDL_GetCPUFeatures() & CPU_HAS_ARM_SIMD ) {
       
   566 		return SDL_TRUE;
       
   567 	}
       
   568 	return SDL_FALSE;
       
   569 }
       
   570 
       
   571 SDL_bool SDL_HasARMNEON(void)
       
   572 {
       
   573 	if ( SDL_GetCPUFeatures() & CPU_HAS_ARM_NEON ) {
   538 		return SDL_TRUE;
   574 		return SDL_TRUE;
   539 	}
   575 	}
   540 	return SDL_FALSE;
   576 	return SDL_FALSE;
   541 }
   577 }
   542 
   578 
   553 	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
   589 	printf("3DNowExt: %d\n", SDL_Has3DNowExt());
   554 	printf("SSE: %d\n", SDL_HasSSE());
   590 	printf("SSE: %d\n", SDL_HasSSE());
   555 	printf("SSE2: %d\n", SDL_HasSSE2());
   591 	printf("SSE2: %d\n", SDL_HasSSE2());
   556 	printf("AltiVec: %d\n", SDL_HasAltiVec());
   592 	printf("AltiVec: %d\n", SDL_HasAltiVec());
   557 	printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
   593 	printf("ARM SIMD: %d\n", SDL_HasARMSIMD());
       
   594 	printf("ARM NEON: %d\n", SDL_HasARMNEON());
   558 	return 0;
   595 	return 0;
   559 }
   596 }
   560 
   597 
   561 #endif /* TEST_MAIN */
   598 #endif /* TEST_MAIN */