View Post - post55889
Re: Compiler Error due to using Neon Pipeline on OMAP3530
On 10-05-21 06:29 AM, Philipp Lutz wrote:
> Hi Ryan,
>
> yes, I've tried to follow this guide: http://www.qnx.com/developers/docs/6.4.1/neutrino/technotes/
vector_floating_point.html#id5 in order to replace the libm.so by the libm-vfp.so. however ALL my programs I'm liking 
against libm-vfp are finally liked against libm (after checking with ldd).
> What did I wrong? Is there an existing issue?

> Wow, these header files gave me an increase to around 5200 MIPS, but thats rather close to ridiculous than to 
realistic. It seems that these header files activate the fastmath ability of QNX in the first place. What are these 
compiler builtin functions? Is this only a pointer to the compiler to implement the math function in a predefined way 
which is optimized by execution speed?

Yes, in my patch when you compile with -ffast-math there is a compiler 
define __FAST_MATH__ set which redefines the calls to sin, cos, etc with 
explicit calls to __builtin_sin, __builtin_cos, etc. The builtins are 
optimized routines provided by GCC. For more information, see 
http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Other-Builtins.html. Often 
these compiler builtins can replace a expensive function call with only 
a handful of inline instructions.  Under Linux when you compile with -O1 
or greater the gcc will automatically replace the call to sin/cos/atan 
with their corresponding builtin. When compiling with >=O1 will use 
builtins for cos, sin and atan and by adding fast-math gcc will use 
builtins for log, exp, and sqrt. You'll notice that when you specify -O3 
-ffast-math you no longer have to link against libm. Under QNX our libm 
headers redefine sin, cos to be _Sin which prevents gcc from 
automatically using the compiler builtins. The headers I gave you do the 
redefinition so the optimized builtins are used.

> Another point: Can you explain why I get twice the speed (without fast-math) under linux compared to QNX?

The difference can be mainly attributed to the use of the builtin 
functions. For example, under Linux whetstone compiled with  -O3 
-mtune=cortex-a8 -march=armv7-a -Wa,-march=armv7-a -ftree-vectorize 
-mfpu=neon -Wa,-mfpu=neon -mfloat-abi=softfp -fno-builtin -lm yields 
approximately the same performance under QNX.  The previous patch I 
attached had all the builtins enabled by __FAST_MATH__. I've tweaked the 
patch to use builtins for sin and cos when O1 or greater is used, not 
just -ffast-math is specified.  I also attached a version of whetsone 
for Neutrino that uses Clockcycles for better precision.

Here are my results:

Linux (mainline gcc 4.3.2):

arm-unknown-linux-gnueabi-gcc ~/whetstone.c  -O3 -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp -fno-builtin -lm

Loops: 10000, Iterations: 1, Duration: 8 sec. 

C Converted Double Precision Whetstones: 125.0 MIPS

arm-unknown-linux-gnueabi-gcc ~/whetstone.c  -O3 -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp  -lm

Loops: 10000, Iterations: 1, Duration: 4 sec. 

C Converted Double Precision Whetstones: 250.0 MIPS

arm-unknown-linux-gnueabi-gcc ~/whetstone.c  -O3 -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp  -ffast-math -funroll-loops 
-fomit-frame-pointer

Loops: 100000, Iterations: 1, Duration: 4 sec. 

C Converted Double Precision Whetstones: 2500.0 MIPS

QNX (with attached header changes)

qcc -V4.3.3,gcc_ntoarmle whetstone-qnx.c -O3 -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp -fno-builtin -lm

Loops: 1000, Iterations: 1, Duration: 0.767395 sec. 

C Converted Double Precision Whetstones: 130.3 MIPS

qcc -V4.3.3,gcc_ntoarmle whetstone-qnx.c -O3 -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp -lm (libm-vfp)
 

Loops: 1000, Iterations: 1, Duration: 0.264155 sec. 

C Converted Double Precision Whetstones: 378.6 MIPS

qcc -V4.3.3,gcc_ntoarmle whetstone-qnx.c -O3  -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp -ffast-math

Loops: 1000, Iterations: 1, Duration: 0.048495 sec. 

C Converted Double Precision Whetstones: 2062.1 MIPS

  qcc -V4.3.3,gcc_ntoarmle whetstone-qnx.c -O3 -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp -ffast-math -funroll-loops

Loops: 1000, Iterations: 1, Duration: 0.031042 sec. 

C Converted Double Precision Whetstones: 3221.4 MIPS

qcc -V4.3.3,gcc_ntoarmle whetstone-qnx.c -O3  -mtune=cortex-a8 
-march=armv7-a -Wa,-march=armv7-a -ftree-vectorize -mfpu=neon 
-Wa,-mfpu=neon -mfloat-abi=softfp -ffast-math -funroll-loops 
-fomit-frame-pointer

Loops: 1000, Iterations: 1, Duration: 0.030462 sec. 

C Converted Double Precision Whetstones: 3282.8 MIPS

Regards,

Ryan Mansfield

>> Hi Phil,
>>
>> Are you using the soft-float libm.so or the libm-vfp.so? If you're using
>> the soft-float libm.so, can you replace the libm.so.2 on your target
>> with the libm-vfp.so and let me know if you see any performance improvement.
>>
>>> When i'm using even the "dangerous" compiler flags: -ffast-math -fomit-frame
>> -pointer -funroll-loops
>>>
>>> Results after two minutes testing:
>>> Linux: 1700 MIPS
>>> QNX:    134 MIPS
>>>
>>
>> In the fast math case it looks math.h is redefining sin, cos and a few
>> others so the compiler builtins are not being used. Can you extract the
>> attached tarball into $QNX_TARGET and recompile/rerun the benchmark?
>>
>> Regards,
>>
>> Ryan Mansfield
>>
>
>
>
>
>
>
> _______________________________________________
>
> QNX Momentics Community Support
> http://community.qnx.com/sf/go/post55348
>