Channels ▼


Boost Performance for Your Android Native Code

The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications. The Android NDK Revision 6, launched in July 2011, added the possibility of generating machine code that runs on compatible x86-based Android devices (IA-32). Thus, since that version, you can optimize the performance-critical portions of your apps to take advantage of most of the advanced SIMD instruction sets found in Intel Atom CPUs that run Android.

If you have some experience writing Android native code for the ARMv7 architecture, you are probably aware of the ARM Advanced SIMD instruction set extension, known as NEON. Intel Atom CPUs provide support for SSSE3 (short for Supplemental Streaming SIMD Extensions 3) and its predecessors, such as SSE3, SSE2, SSE, and MMX. You can easily take advantage of the powerful SIMD instructions up to SSE3 in order to optimize your algorithms for the x86 architecture with the Android NDK. The latest version of Android NDK is Revision 7, launched in November 2011, and it provides a specific ABI (short for Application Binary Interface) that defines exactly how the application's machine code is expected to interact with an x86 (IA-32) system at runtime.

The x86 ABI provided by Android NDK Revision 7 details the CPU instruction set that the machine code should use up to SSE3 for Intel Atom, and therefore, it excludes SSSE3. It is still possible to use SSSE3 but you have to use both runtime features probing to enable them and fallbacks for devices that don't support the extended instruction set.

The SSE3 instruction set is different than NEON but you can easily port NEON to SSE3 and its predecessor x86 SIMD extensions. In addition, you can write native code that targets x86 from scratch and take advantage of all the SIMD extensions provided by modern Intel Atom CPUs.

One of the main differences with ARM is that you don't need to check for any specific CPU feature in x86 in order to use the SIMD instructions. If the value returned from android_getCpuFamily() is ANDROID_CPU_FAMILY_X86, you will have the SSE3 instruction set extensions and its predecessors available, because you have an Intel Atom. With ARM CPUs, it is necessary to check for the specific availability of NEON. It isn't necessary to check a specific value returned in android_getCpuFeatures for Intel Atom and you don't need to call that function at all.

If you want to have the best performance for your native code but you target multiple platforms, you can create the most efficient code based on the value retrieved from android_getCpuFamily and then you'll have to check android_getCpuFeatures for ARM. However, for Intel Atom CPUs, you can use most of the SIMD instructions you already master and boost performance of Android native code portions of applications. In addition, you can use all the tools provided by Intel to optimize your algorithms, test them in your Intel Atom netbooks in order to solve potential bottlenecks, and finally build them with the x86 ABI provided by the Android NDK. The computing continuum makes it easy for experienced x86 developers to take advantage of their existing knowledge of the x86 platform on different devices and operating systems without having to learn new instruction sets. Android runs on Intel Atom, and the chips that run Android have the same instruction sets you already use in either a netbook or a tablet.

Developers that have experience in optimizing pieces of code to execute instructions in multiple data with SIMD during the last years have a great opportunity to boost performance and extend battery life for Android applications that require native code optimizations. You can read more information about Android on Intel Architecture in the Android Developers portal @ Intel Software Network.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.