Using YASM Compiler on Android* ndkbuild

In the traditional PC games and multimedia applications, lots of SIMD code has been used for performance improvement. SIMDSingle Instruction Multiple Datacan copy multiple data, in a synchronous manner, execute the same instructions at the same time. It particularly suitable for data intensive computing such as multimedia applicationsSIMD has implement by AMD and INTEL such as 3DNow!SSE

But if porting these SIMD improvement codes to android x86 platform, most code we have to give upthe reason isNDK has no NASM compiler(it only supports AT&T)

1.       What is YASM compiler

 

Yasm is a complete rewrite of the NASM assembler under the “new” BSD License (some portions are under other licenses, see COPYING for details).

Yasm currently supports the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes, outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32, and Win64 object formats, and generates source debugging information in STABS, DWARF 2, and CodeView 8 formats.

The official Yasm address is http://yasm.tortall.net

Yasm also provides some commonly used mathematical functions, such as FFT transformation, developer only needs to directly call these functions in order to obtain the best performance. The well-known open source projects which use yasm compiler areFFMPEGX264MPC-HC.

2.       Using yasm compiler on Android NDK ( x86 )

 

In the case of FFMPEG porting, generally it needs to add -disable-yasm option, if compiling arm versionit’s right and mustarm using neon. But if compiling x86 version, disable-yasm will discard a large number of optimized code which will significantly reduce performance. We are need adding ASM assembly support on android ndk in urgent.

We use the windows version of ndk-r8 as an example, the mainly modification part is “android-ndk-r8\build\core”.

1. build-binary.mk:

all_source_extensions := .c .s .S $(LOCAL_CPP_EXTENSION)  =>

all_source_extensions := .c .s .asm .S $(LOCAL_CPP_EXTENSION)

add compile-asm-source after # Build the sources to object files

 

2. definitions.mk

New compile-asm-source (can reference compile-c-source)

Add .asm in “get-object-name”

 

3. import-locals.mk

Add LOCAL_YASMFLAGSit the same with LOCAL_C_FLAGS, but for .asm file while not .c file

 

4. default-build-commands.mk

Add  TARGET_ASM       = $(TOOLCHAIN_PREFIX)yasm

 

5. toolchains\x86-4.4.3\prebuilt\windows

Download yasm compiler in http://yasm.tortall.netif you use windows ndkbuildyou can download win32 yasm compiler. Otherwise, you can download linux version yasm compiler.

If using win32 yasm compiler, rename it to yasm.exe and copy it to  android-ndk-r8\toolchains\x86-4.4.3\prebuilt\windows\i686-android-linux\bin,and also rename it to i686-android-linux-yasm.exe , copy it to android-ndk-r8\toolchains\x86-4.4.3\prebuilt\ windows\bin

3.       recompile ffmpeg using yasm compiler

do not add –disbale-yasm, reconfigure ffmpeg. You can see in config.h, #define HAVE_YASM 1; in config.mk contains HAVE_YASM=yes.

Define LOCAL_YASMFLAGS = -DANDROID -DPIC -DHAVE_AV_CONFIG_H  -DARCH_X86_32 and then do ndk-build. You can get full optimization lib the same as PC x86 version.