Compil assembly code for ARM and X86

2,158 views
Skip to first unread message

WebShaker

unread,
Jun 15, 2012, 5:32:55 AM6/15/12
to android-ndk
Sorry, I've ever post this message into "Android Developers" group
before finding this prefered group !

I've just bought an Intel Android smartphone !
I've change My Application.mk to add a plateforme

APP_ABI := armeabi armeabi-v7a x86

And that works for Java a C code source.

But I have a assembly file too.
For ARM I used to compile it whit some options

Here is my current Android.mk

LOCAL_MODULE := engine
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS := -mfpu=neon -march=armv6t2 -O9
LOCAL_SRC_FILES := engine-arm.s
LOCAL_LDLIBS := -lm -llog -ljnigraphics
LOCAL_STATIC_LIBRARIES := cpufeatures

Well now My problem is that I have another assembly file for the x86
called "engine-x68.s" containing the same functions but for x86
processor

What I'd like to do is compiling it with some gcc options
-msse2 -m32 -masm=intel

So My Android.mk file should be something like

LOCAL_MODULE := engine
LOCAL_CFLAGS := -msse2 -m32 -masm=intel
LOCAL_SRC_FILES := engine-x86.s
LOCAL_LDLIBS := -lm -llog -ljnigraphics
LOCAL_STATIC_LIBRARIES := cpufeatures

Finally my question is.

How Can I compile engine-arm.s with the first Android.mk param and
compile engine-x68.s with the second one ?

My goal is to have at the end only one module called engine and let
Android loading the correct processor code when I call
System.loadLibrary("engine");

Mārtiņš Možeiko

unread,
Jun 18, 2012, 2:17:05 AM6/18/12
to andro...@googlegroups.com
You can do this in Android.mk file:

ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS := -mfpu=neon -march=armv6t2 -O9
LOCAL_SRC_FILES := engine-arm.s
endif
ifeq ($(TARGET_ARCH),x86)
LOCAL_CFLAGS := -msse2 -m32 -masm=intel
LOCAL_SRC_FILES := engine-x86.s
endif

For more information I would recommend reading docs/ANDROID-MK.html
file in NDK distribution.

Btw, to use NEON in ARM assembly file you just need to add .neon
extension (engine-arm.s.neon) to file in Android.mk (not on the disk),
no need to mess with CFLAGS.
And for x86 target ndk-build by default uses "-march=i686 -msse3
-mstackrealign -mfpmath=sse". So no need to put "-msse2" for CFLAGS.

--
Martins Mozeiko
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>



--
Mārtiņš Možeiko

David Turner

unread,
Jun 19, 2012, 3:59:19 AM6/19/12
to andro...@googlegroups.com


On Mon, Jun 18, 2012 at 5:45 PM, Alexander Weggerle <alexa...@googlemail.com> wrote:
Hi,


Am Montag, 18. Juni 2012 08:17:05 UTC+2 schrieb Mārtiņš Možeiko:
And for x86 target ndk-build by default uses "-march=i686 -msse3
-mstackrealign -mfpmath=sse". So no need to put "-msse2" for CFLAGS.


The Atom processor is capable of SSE3. So there is no need to change the flags to produce valid code for x86 based Android phones. You might want to test the following options: "-march=atom -mssse3 -funroll-loops -mfpmath=sse" and see if you can get better performance with them.


Don't build with -march=atom, this will generate machine instructions that are not supported by all compatible x86 Android devices (e.g. emulator x86 system images that run under KVM/HAXM on your desktop, but there are other ones).

The x86 NDK ABI definition specifically excludes Atom-specific instruction for this very reason (see $NDK/docs/CPU-ARCH-ABIS.html).

You should use -march=i686 -mtune=atom if you want to generate application machine code that runs best on an Atom though.
 
Thanks,
Alex

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/DU7zMmzu7YcJ.

David Turner

unread,
Jun 19, 2012, 4:00:11 AM6/19/12
to andro...@googlegroups.com
On Tue, Jun 19, 2012 at 9:59 AM, David Turner <di...@android.com> wrote:


On Mon, Jun 18, 2012 at 5:45 PM, Alexander Weggerle <alexa...@googlemail.com> wrote:
Hi,

Am Montag, 18. Juni 2012 08:17:05 UTC+2 schrieb Mārtiņš Možeiko:
And for x86 target ndk-build by default uses "-march=i686 -msse3
-mstackrealign -mfpmath=sse". So no need to put "-msse2" for CFLAGS.


The Atom processor is capable of SSE3. So there is no need to change the flags to produce valid code for x86 based Android phones. You might want to test the following options: "-march=atom -mssse3 -funroll-loops -mfpmath=sse" and see if you can get better performance with them.


Don't build with -march=atom, this will generate machine instructions that are not supported by all compatible x86 Android devices (e.g. emulator x86 system images that run under KVM/HAXM on your desktop, but there are other ones).

The x86 NDK ABI definition specifically excludes Atom-specific instruction for this very reason (see $NDK/docs/CPU-ARCH-ABIS.html).

You should use -march=i686 -mtune=atom if you want to generate application machine code that runs best on an Atom though.
 

Similarly, SSSE3 is not part of the ABI, if you want to use these instructions, you'll have to first use CPUID (or cpu-features) at runtime before being able to call such code, or it will crash on other devices.

WebShaker

unread,
Jun 22, 2012, 6:08:47 AM6/22/12
to android-ndk
On 18 juin, 08:17, Mārtiņš Možeiko <martins.moze...@gmail.com> wrote:
> Btw, to use NEON in ARM assembly file you just need to add .neon
> extension (engine-arm.s.neon) to file in Android.mk (not on the disk),
> no need to mess with CFLAGS.
> --
> Mārtiņš Možeiko

Thank you.

Do you know if it possible to have a specific compiled lib for NEON
device and another one for device that do not have NEON ?

The main idea is to not have to test NEON flag in the source code !
Thank's
Reply all
Reply to author
Forward
0 new messages