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     if (family == ANDROID_CPU_FAMILY_X86) {
     60         uint64_t features = android_getCpuFeatures();
     61         printf( "Supported x86 features:\n");
     62 #define CHECK(name) \
     63         if ((features & ANDROID_CPU_X86_FEATURE_## name) != 0) { \
     64             printf( "  "#name"\n" ); \
     65         }
     66         CHECK(SSSE3)
     67         CHECK(POPCNT)
     68         CHECK(MOVBE)
     69 #undef CHECK
     70     }
     71 
     72     int count = android_getCpuCount();
     73     printf( "Number of CPU cores: %d\n", count);
     74     return 0;
     75 }
     76