Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime CPU type detection for Android on ARM

What is the simplest method to determine CPU type from within a running C application? I am interested in determining how many cores current CPU has and whether it has a NEON unit. One simple solution could be to check cpuinfo flags in /proc but I am not sure if it's a fast and reliable method.

like image 813
psihodelia Avatar asked Dec 09 '25 00:12

psihodelia


2 Answers

You can check neon support using this doc. To get core count read this thread and take a look at this page.

like image 126
Leonidos Avatar answered Dec 11 '25 13:12

Leonidos


You could use Yeppp! library to get a lot of information about CPU. This information is also accessible via Java bindings, so you could define several native methods in your classes, e.g. processGeneric() and processNeon(), and call the NEON method only if the CPU supports it:

import info.yeppp.Library;
import info.yeppp.ArmCpuSimdFeature;
import info.yeppp.CpuMicroarchitecture;

if (Library.isSupported(ArmCpuSimdFeature.NEON)) {
    if (Library.getMicroarchitecture().equals(CpuMicroarchitecture.Krait)) {
        /* Special NEON implementation for recent Qualcomm processors */
        nativeClass.processKrait();
    } else {
        /* Generic NEON implementation */
        nativeClass.processNeon();
    }
} else {
    /* Generic implementation without NEON */
    nativeClass.processGeneric();
}
like image 22
Marat Dukhan Avatar answered Dec 11 '25 14:12

Marat Dukhan