7

I want to get the most performance of my mobile application on Android. I would like to know if someone is aware of a trick to check if the phone possesses an FPU.

After some research it seems that using FloatMath class is slower on a unit that possesses an FPU, so I would like to have best of both worlds.

Most newer phones have an FPU, but I would like to get the most performance the device can offer.

makes
  • 6,438
  • 3
  • 40
  • 58
gimpycpu
  • 607
  • 6
  • 16
  • 2
    Has anybody made a processor without a FPU in the last 15 years? – Robert Nov 17 '11 at 02:00
  • 1
    Some android phone don't have one, thats the point. HTC Hero for instance – gimpycpu Nov 17 '11 at 02:04
  • 1
    @gimpycpu I'm calling shenanigans. I can't understand a CPU not having an FPU – Kurtis Nusbaum Nov 17 '11 at 02:24
  • 1
    Well if no one know I will just stick with FloatMath class unless I notice bad performance on more mainstream type of phones. – gimpycpu Nov 17 '11 at 02:30
  • 1
    For those calling shenanigans, please know that at least one popular early android phone (the G1) did not have an FPU. The fact is referenced in Google's floating point advice: http://developer.android.com/guide/practices/design/performance.html#avoidfloat – Steve Blackwell Nov 23 '11 at 18:23
  • @gimpycpu Didn't you mean "After some research it seems that using FloatMath class is slower on a unit that DOES NOT possess an FPU" instead? – Bitcoin Cash - ADA enthusiast Oct 04 '15 at 20:58
  • @Tiago Hey Tiago, that question is quite old now and not very applicable anymore. According to google nowaway Floatmath is faster because most(all) devices have FPU and it get optimized correctly. – gimpycpu Oct 05 '15 at 01:01

2 Answers2

10

It's a Linux kernel underneath, and at least the default Android configuration will mount procfs. That means you can look into /proc/cpuinfo, which on an ARM system looks something like:

# cat /proc/cpuinfo 
Processor       : ARMv7 Processor rev 3 (v7l)
BogoMIPS        : 249.96
Features        : swp half thumb fastmult vfp edsp neon vfpv3 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x1
CPU part        : 0xc08
CPU revision    : 3
[ ... ]

If the "Features" line lists at least vfp, then the ARM SoC has an FPU.

You should be able to read /proc/cpuinfo via Dalvik/Java interfaces, just like a normal file, no privileged access or anything required. I'm not a Java programmer, so leaving that as an exercise to the reader.

FrankH.
  • 17,675
  • 3
  • 44
  • 63
1

Even though it is a very old thread, for anyone like me landed here by google may find this useful. Here I am showing how we can do it using NDK (C++) as the Java-way is already given.

Using NDK, by including cpu-features.h, we can utilize a number of API and predefined macros to detect the availability of FPU.

For 32 bit processor, you should check one of ANDROID_CPU_ARM_FEATURE_VFPv3, ANDROID_CPU_ARM_FEATURE_VFPv2, ANDROID_CPU_ARM_FEATURE_VFP_D32, ANDROID_CPU_ARM_FEATURE_VFP_FP16 or ANDROID_CPU_ARM_FEATURE_VFP_FMA on the return value of android_getCpuFeatures() which will ensure that your processor is armed with an FPU.

For 64 bit, please check ANDROID_CPU_ARM64_FEATURE_FP flag.

Additionally, call android_getCpuFamily() to get CPU family/architecture (ARM/MIPS, 32/64 bit etc).

The cpufeatures library manual has everything to include and use it in your project.

Khaled
  • 670
  • 6
  • 18