629 char* cpuinfo = NULL;
639 if (cpuinfo_len < 0) {
640 D(
"cpuinfo_len cannot be computed!");
643 cpuinfo = (
char *) malloc(cpuinfo_len);
644 if (cpuinfo == NULL) {
645 D(
"cpuinfo buffer could not be allocated");
648 cpuinfo_len =
read_file(
"/proc/cpuinfo", cpuinfo, cpuinfo_len);
649 D(
"cpuinfo_len is (%d):\n%.*s\n", cpuinfo_len,
650 cpuinfo_len >= 0 ? cpuinfo_len : 0, cpuinfo);
652 if (cpuinfo_len < 0) {
677 if (cpuArch != NULL) {
682 D(
"found cpuArch = '%s'\n", cpuArch);
685 archNumber = strtol(cpuArch, &end, 10);
688 if (end > cpuArch && archNumber >= 7) {
705 if (cpuProc != NULL) {
706 D(
"found cpuProc = '%s'\n", cpuProc);
708 D(
"CPU processor and architecture mismatch!!\n");
720 if (archNumber >= 6) {
731 D(
"Parsing /proc/self/auxv to extract ELF hwcaps!\n");
738 D(
"Parsing /proc/cpuinfo to extract ELF hwcaps!\n");
743 int has_vfp = (hwcaps & HWCAP_VFP);
744 int has_vfpv3 = (hwcaps & HWCAP_VFPv3);
745 int has_vfpv3d16 = (hwcaps & HWCAP_VFPv3D16);
746 int has_vfpv4 = (hwcaps & HWCAP_VFPv4);
747 int has_neon = (hwcaps & HWCAP_NEON);
748 int has_idiva = (hwcaps & HWCAP_IDIVA);
749 int has_idivt = (hwcaps & HWCAP_IDIVT);
750 int has_iwmmxt = (hwcaps & HWCAP_IWMMXT);
766 if (has_vfpv3 || has_vfpv3d16)
804 static const struct CpuIdEntry {
809 } cpu_id_entries[] = {
810 {
"CPU implementer",
'x', 24, 8 },
811 {
"CPU variant",
'x', 20, 4 },
812 {
"CPU part",
'x', 4, 12 },
813 {
"CPU revision",
'd', 0, 4 },
816 D(
"Parsing /proc/cpuinfo to recover CPUID\n");
818 i <
sizeof(cpu_id_entries)/
sizeof(cpu_id_entries[0]);
820 const struct CpuIdEntry* entry = &cpu_id_entries[i];
827 D(
"field=%s value='%s'\n", entry->field, value);
828 char* value_end = value + strlen(value);
830 const char* start = value;
832 if (value[0] ==
'0' && (value[1] ==
'x' || value[1] ==
'X')) {
835 }
else if (entry->format ==
'x')
840 if (p > (
const char*)start) {
841 val &= ((1 << entry->bit_length)-1);
842 val <<= entry->bit_lshift;
851 static const struct CpuFix {
863 for (n = 0; n <
sizeof(cpu_fixes)/
sizeof(cpu_fixes[0]); ++n) {
864 const struct CpuFix* entry = &cpu_fixes[n];
879 if (!strcmp(hardware,
"Goldfish") &&
893 #define VENDOR_INTEL_b 0x756e6547
894 #define VENDOR_INTEL_c 0x6c65746e
895 #define VENDOR_INTEL_d 0x49656e69
898 int vendorIsIntel = (regs[1] == VENDOR_INTEL_b &&
899 regs[2] == VENDOR_INTEL_c &&
900 regs[3] == VENDOR_INTEL_d);
903 if ((regs[2] & (1 << 9)) != 0) {
906 if ((regs[2] & (1 << 23)) != 0) {
909 if (vendorIsIntel && (regs[2] & (1 << 22)) != 0) {
static char * extract_cpuinfo_field(const char *buffer, int buflen, const char *field)
static uint64_t g_cpuFeatures
static AndroidCpuFamily g_cpuFamily
static uint32_t get_elf_hwcap_from_getauxval(void)
static int get_file_size(const char *pathname)
static uint32_t get_elf_hwcap_from_proc_self_auxv(void)
static uint32_t get_elf_hwcap_from_proc_cpuinfo(const char *cpuinfo, int cpuinfo_len)
static void android_cpuInitFamily(void)
static __inline__ void x86_cpuid(int func, int values[4])
static const char * parse_hexadecimal(const char *input, const char *limit, int *result)
static int read_file(const char *pathname, char *buffer, size_t buffsize)
static int has_list_item(const char *list, const char *item)
static const char * parse_decimal(const char *input, const char *limit, int *result)
static int get_cpu_count(void)
static uint32_t g_cpuIdArm