简体   繁体   中英

Android convert/compile C++ as Neon

I am currently writing a simple Android program using C++ with the help of JNI and OpenCV. The input is a image stored as a Mat. Instead of using OpenCV's normalize function, I wish to write my own normalize function in C++. From what I know, there is support for NEON. However, looking at HelloNeon sample in the NDK folder, I realised that the code is written in NEON instrinsics.

Question: Is there a way to directly compile my C++ code into NEON code? ie I wish to avoid writing my function in NEON intrinsics.

Thank you.

Largely depends on the compiler. Both gcc and clang do support "automatic vectorizing" in recent versions, but the quality of the generated code is very variable - mostly depending on the actual source code. As always, the compiler is firstly responsible for generating correct code, secondly to generate fast/efficient code. If in doubt, go for "safe" option.

It should, however, work to use -mfpu=neon -ftree-vectorize .

I do expect that you need to "massage" the code to make it vectorize well, however - at least that's my experience on x86, where the compiler will attempt to build SSE instructions when vectorizing. It succeeds in fairly simple cases, but falls back to "regular code" when the code is more complex. Later compilers do work better than older versions, as a rule.

If you really need to get good vectorizing results, you will probably end up needing to use Neon intrinsics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM