Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 #define __STDC_FORMAT_MACROS 1
     17 
     18 #include <cpu-features.h>
     19 #include <inttypes.h>
     20 #include <stdio.h>
     21 
     22 int main(void)
     23 {
     24     AndroidCpuFamily family = android_getCpuFamily();
     25     switch (family) {
     26     case ANDROID_CPU_FAMILY_ARM:
     27         printf("CPU family is ARM\n");
     28         break;
     29     case ANDROID_CPU_FAMILY_X86:
     30         printf("CPU family is x86\n");
     31         break;
     32     case ANDROID_CPU_FAMILY_MIPS:
     33         printf("CPU family is MIPS\n");
     34         break;
     35     case ANDROID_CPU_FAMILY_ARM64:
     36         printf("CPU family is ARM64\n");
     37         break;
     38     case ANDROID_CPU_FAMILY_X86_64:
     39         printf("CPU family is x86_64\n");
     40         break;
     41     case ANDROID_CPU_FAMILY_MIPS64:
     42         printf("CPU family is MIPS64\n");
     43         break;
     44     default:
     45         fprintf(stderr, "Unsupported CPU family: %d\n", family);
     46         return 1;
     47     }
     48 
     49 #define CHECK(arch, name) \
     50     if ((features & ANDROID_CPU_## arch ##_FEATURE_## name) != 0) { \
     51         printf( "  "#name"\n" ); \
     52     }
     53 
     54     uint64_t features = android_getCpuFeatures();
     55     int result = 0;
     56     switch(family) {
     57     case ANDROID_CPU_FAMILY_ARM:
     58         printf( "Supported ARM features:\n");
     59         CHECK(ARM, ARMv7)
     60         CHECK(ARM, VFPv3)
     61         CHECK(ARM, NEON)
     62         CHECK(ARM, LDREX_STREX)
     63         CHECK(ARM, VFPv2)
     64         CHECK(ARM, VFP_D32)
     65         CHECK(ARM, VFP_FP16)
     66         CHECK(ARM, VFP_FMA)
     67         CHECK(ARM, NEON_FMA)
     68         CHECK(ARM, IDIV_ARM)
     69         CHECK(ARM, IDIV_THUMB2)
     70         CHECK(ARM, iWMMXt)
     71         CHECK(ARM, AES)
     72         CHECK(ARM, PMULL)
     73         CHECK(ARM, SHA1)
     74         CHECK(ARM, SHA2)
     75         CHECK(ARM, CRC32)
     76         break;
     77     case ANDROID_CPU_FAMILY_ARM64:
     78         CHECK(ARM64, FP)
     79         CHECK(ARM64, ASIMD)
     80         CHECK(ARM64, AES)
     81         CHECK(ARM64, PMULL)
     82         CHECK(ARM64, SHA1)
     83         CHECK(ARM64, SHA2)
     84         CHECK(ARM64, CRC32)
     85         break;
     86     case ANDROID_CPU_FAMILY_X86:
     87     case ANDROID_CPU_FAMILY_X86_64:
     88         printf( "Supported x86 features:\n");
     89         CHECK(X86, SSSE3)
     90         CHECK(X86, POPCNT)
     91         CHECK(X86, MOVBE)
     92         CHECK(X86, SSE4_1)
     93         CHECK(X86, SSE4_2)
     94         break;
     95     case ANDROID_CPU_FAMILY_MIPS:
     96     case ANDROID_CPU_FAMILY_MIPS64:
     97         printf( "Supported MIPS features:\n");
     98         CHECK(MIPS, R6)
     99         CHECK(MIPS, MSA)
    100         break;
    101     default:
    102         if (features != 0) {
    103             printf("ERROR: Unexpected CPU features mask: %016" PRIX64 "\n",
    104                    features);
    105             result = 1;
    106         }
    107     }
    108 
    109 #ifdef __arm__
    110     uint32_t cpu_id = android_getCpuIdArm();
    111     printf( "ARM CpuID: %08x\n", cpu_id);
    112     printf( "   implementer: %02x\n", (cpu_id >> 24) & 0xff);
    113     printf( "   variant    : %02x\n", (cpu_id >> 20) & 0x0f);
    114     printf( "   part       : %03x\n", (cpu_id >> 4) & 0xfff);
    115     printf( "   revision   : %x\n",    cpu_id & 0x0f);
    116 #endif
    117 
    118     int count = android_getCpuCount();
    119     printf( "Number of CPU cores: %d\n", count);
    120     return result;
    121 }
    122