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.
You can check neon support using this doc. To get core count read this thread and take a look at this page.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With