Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ARM processors have 2 general instruction sets that they support: "ARM" and "Thumb". Though there are different flavors of both, ARM instructions are 32 bits each and Thumb instructions are 16 bits. The main difference between the two is that ARM instructions have the possibility to do more in a single instruction than Thumb can. For example a single ARM instruction can add one register to another register, while performing a left shift on the second register. In Thumb one instruction would have to do the shift, then a second instruction would do the addition.</p> <p>ARM instructions are not twice as good, but in certain cases they can be faster. This is especially true in hand-rolled ARM assembly, which can be tuned in novel ways to make the best use of "shifts for free". Thumb instructions have their own advantage as well as size: they drain the battery less.</p> <p>Anyway, this is what LOCAL_ARM_MODE does - it means you compile your code as ARM instructions instead of Thumb instructions. Compiling to Thumb is the default in the NDK as it tends to create a smaller binary and the speed difference is not that noticeable for most code. The compiler can't always take advantage of the extra "oomph" that ARM can provide, so you end up needing more or less the same number of instructions anyway.</p> <p>The result of what you see from C/C++ code compiled to ARM or Thumb will be identical (barring <a href="https://stackoverflow.com/questions/4369265">compiler bugs</a>).</p> <p>This by itself is compatible between new and old ARM processors for all Android phones available today. This is because by default the NDK compiles to an "Application Binary Interface" for ARM-based CPUs that support the ARMv5TE instruction set. This ABI is known as "armeabi" and can be explicitly set in the Application.mk by putting <code>APP_ABI := armeabi</code>.</p> <p>Newer processors also support the Android-specific ABI known as <code>armeabi-v7a</code>, which extends armeabi to add the <a href="http://www.arm.com/products/processors/technologies/instruction-set-architectures.php?tab=Thumb-2+" rel="nofollow noreferrer">Thumb-2 instruction set</a> and a hardware floating point instruction set called VFPv3-D16. armeabi-v7a compatible CPUs can also optionally support the NEON instruction set, which you have to check for at run time and provide code paths for when it is available and when it is not. There's an example in the NDK/samples directory that does this (hello-neon). Under the hood, Thumb-2 is more "ARM-like" in that its instructions can do more in a single instruction, while having the advantage of still taking up less space.</p> <p>In order to compile a "fat binary" that contains both armeabi and armeabi-v7a libraries you would add the following to Application.mk:</p> <pre><code>APP_ABI := armeabi armeabi-v7a </code></pre> <p>When the .apk file is installed, the Android package manager installs the best library for the device. So on older platforms it would install the armeabi library, and on newer devices the armeabi-v7a one.</p> <p>If you want to test for CPU features at run time then you can use the NDK function <code>uint64_t android_getCpuFeatures()</code> to get the features supported by the processor. This returns a bit-flag of <code>ANDROID_CPU_ARM_FEATURE_ARMv7</code> on v7a processors, <code>ANDROID_CPU_ARM_FEATURE_VFPv3</code> if hardware floating points are supported and <code>ANDROID_CPU_ARM_FEATURE_NEON</code> if advanced SIMD instructions are supported. ARM can't have NEON without VFPv3.</p> <p>In summary: by default, your programs are the most compatible. Using LOCAL_ARM_MODE may make things slightly faster at the expense of battery life due to the use of ARM instructions - and it is as compatible as the default set-up. By adding the <code>APP_ABI := armeabi armeabi-v7a</code> line you will have improved performance on newer devices, remain compatible with older ones, but your .apk file will be larger (due to having 2 libraries). In order to use NEON instructions, you will need to write special code that detects the capabilities of the CPU at run time, and this only applies to newer devices that can run armeabi-v7a.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload