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 #include <cpu-features.h>
     17 #include <stdio.h>
     18 
     19 int main(void)
     20 {
     21     AndroidCpuFamily family = android_getCpuFamily();
     22     switch (family) {
     23     case ANDROID_CPU_FAMILY_ARM:
     24         printf("CPU family is ARM\n");
     25         break;
     26     case ANDROID_CPU_FAMILY_X86:
     27         printf("CPU family is x86\n");
     28         break;
     29     case ANDROID_CPU_FAMILY_MIPS:
     30         printf("CPU family is MIPS\n");
     31         break;
     32     default:
     33         fprintf(stderr, "Unsupported CPU family: %d\n", family);
     34         return 1;
     35     }
     36 
     37     if (family == ANDROID_CPU_FAMILY_ARM) {
     38         uint64_t features = android_getCpuFeatures();
     39         printf( "Supported ARM features:\n");
     40 #define CHECK(name) \
     41         if ((features & ANDROID_CPU_ARM_FEATURE_## name) != 0) { \
     42             printf( "  "#name"\n" ); \
     43         }
     44         CHECK(LDREX_STREX)
     45         CHECK(VFPv2)
     46         CHECK(ARMv7)
     47         CHECK(VFPv3)
     48         CHECK(VFP_D32)
     49         CHECK(VFP_FP16)
     50         CHECK(VFP_FMA)
     51         CHECK(NEON)
     52         CHECK(NEON_FMA)
     53         CHECK(IDIV_ARM)
     54         CHECK(IDIV_THUMB2)
     55         CHECK(iWMMXt)
     56 #undef CHECK
     57     }
     58 
     59 #ifdef __arm__
     60     uint32_t cpu_id = android_getCpuIdArm();
     61     printf( "ARM CpuID: %08x\n", cpu_id);
     62     printf( "   implementer: %02x\n", (cpu_id >> 24) & 0xff);
     63     printf( "   variant    : %02x\n", (cpu_id >> 20) & 0x0f);
     64     printf( "   part       : %03x\n", (cpu_id >> 4) & 0xfff);
     65     printf( "   revision   : %x\n",    cpu_id & 0x0f);
     66 #endif
     67 
     68     if (family == ANDROID_CPU_FAMILY_X86) {
     69         uint64_t features = android_getCpuFeatures();
     70         printf( "Supported x86 features:\n");
     71 #define CHECK(name) \
     72         if ((features & ANDROID_CPU_X86_FEATURE_## name) != 0) { \
     73             printf( "  "#name"\n" ); \
     74         }
     75         CHECK(SSSE3)
     76         CHECK(POPCNT)
     77         CHECK(MOVBE)
     78 #undef CHECK
     79     }
     80 
     81     int count = android_getCpuCount();
     82     printf( "Number of CPU cores: %d\n", count);
     83     return 0;
     84 }
     85