[02/10] arm: Add VFP-accelerated version of int32_to_float_fmul_scalar

Message ID 1373980994-30628-2-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö July 16, 2013, 1:23 p.m.
From: Ben Avison <bavison@riscosopen.org>

               Before           After
               Mean    StdDev   Mean    StdDev  Change
This function   1175.0   4.4      366.2  18.3   +220.8%
Overall        19285.5 292.0    18420.5 489.1     +4.7%
---
 libavcodec/arm/fmtconvert_init_arm.c |   13 ++++++++++--
 libavcodec/arm/fmtconvert_vfp.S      |   38 ++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

Comments

Diego Biurrun July 16, 2013, 4:30 p.m. | #1
On 2013-07-16 15:23, Martin Storsjö wrote:
> --- a/libavcodec/arm/fmtconvert_init_arm.c
> +++ b/libavcodec/arm/fmtconvert_init_arm.c
> @@ -31,14 +31,23 @@ void ff_int32_to_float_fmul_scalar_neon(float *dst, const int *src,
>   void ff_float_to_int16_neon(int16_t *dst, const float *src, long len);
>   void ff_float_to_int16_interleave_neon(int16_t *, const float **, long, int);
>
> +void ff_int32_to_float_fmul_scalar_vfp(float *dst, const int *src,
> +                                       float mul, int len);
> +
>   void ff_float_to_int16_vfp(int16_t *dst, const float *src, long len);

Let's keep the ff_float_* prototypes together, move int32_to_float below.

Diego
Martin Storsjö July 16, 2013, 4:36 p.m. | #2
On Tue, 16 Jul 2013, Diego Biurrun wrote:

> On 2013-07-16 15:23, Martin Storsjö wrote:
>> --- a/libavcodec/arm/fmtconvert_init_arm.c
>> +++ b/libavcodec/arm/fmtconvert_init_arm.c
>> @@ -31,14 +31,23 @@ void ff_int32_to_float_fmul_scalar_neon(float *dst, 
>> const int *src,
>>   void ff_float_to_int16_neon(int16_t *dst, const float *src, long len);
>>   void ff_float_to_int16_interleave_neon(int16_t *, const float **, long, 
>> int);
>> 
>> +void ff_int32_to_float_fmul_scalar_vfp(float *dst, const int *src,
>> +                                       float mul, int len);
>> +
>>   void ff_float_to_int16_vfp(int16_t *dst, const float *src, long len);
>
> Let's keep the ff_float_* prototypes together, move int32_to_float below.

Instead I'll move it up next to the existing int32_to_float*_neon.

// Martin

Patch

diff --git a/libavcodec/arm/fmtconvert_init_arm.c b/libavcodec/arm/fmtconvert_init_arm.c
index c5f8fbf..98dc152 100644
--- a/libavcodec/arm/fmtconvert_init_arm.c
+++ b/libavcodec/arm/fmtconvert_init_arm.c
@@ -31,14 +31,23 @@  void ff_int32_to_float_fmul_scalar_neon(float *dst, const int *src,
 void ff_float_to_int16_neon(int16_t *dst, const float *src, long len);
 void ff_float_to_int16_interleave_neon(int16_t *, const float **, long, int);
 
+void ff_int32_to_float_fmul_scalar_vfp(float *dst, const int *src,
+                                       float mul, int len);
+
 void ff_float_to_int16_vfp(int16_t *dst, const float *src, long len);
 
 av_cold void ff_fmt_convert_init_arm(FmtConvertContext *c, AVCodecContext *avctx)
 {
     int cpu_flags = av_get_cpu_flags();
 
-    if (have_vfp(cpu_flags) && have_armv6(cpu_flags)) {
-        c->float_to_int16 = ff_float_to_int16_vfp;
+    if (have_vfp(cpu_flags)) {
+        if (!have_vfpv3(cpu_flags)) {
+            c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_vfp;
+        }
+
+        if (have_armv6(cpu_flags)) {
+            c->float_to_int16 = ff_float_to_int16_vfp;
+        }
     }
 
     if (have_neon(cpu_flags)) {
diff --git a/libavcodec/arm/fmtconvert_vfp.S b/libavcodec/arm/fmtconvert_vfp.S
index fb12de1..813a083 100644
--- a/libavcodec/arm/fmtconvert_vfp.S
+++ b/libavcodec/arm/fmtconvert_vfp.S
@@ -1,5 +1,6 @@ 
 /*
  * Copyright (c) 2008 Siarhei Siamashka <ssvb@users.sourceforge.net>
+ * Copyright (c) 2013 RISC OS Open Ltd <bavison@riscosopen.org>
  *
  * This file is part of Libav.
  *
@@ -76,3 +77,40 @@  function ff_float_to_int16_vfp, export=1
         vpop            {d8-d11}
         pop             {r4-r8,pc}
 endfunc
+
+/**
+ * ARM VFP optimised int32 to float conversion.
+ * Assume len is a multiple of 8, destination buffer is at least 4 bytes aligned
+ * (16 bytes alignment is best for BCM2835), little-endian.
+ */
+@ void ff_int32_to_float_fmul_scalar_vfp(float *dst, const int *src, float mul, int len)
+function ff_int32_to_float_fmul_scalar_vfp, export=1
+VFP     tmp     .req    a4
+VFP     len     .req    a3
+NOVFP   tmp     .req    a3
+NOVFP   len     .req    a4
+NOVFP   vmov    s0, a3
+        ldr     tmp, =0x03070000           @ RunFast mode, short vectors of length 8, stride 1
+        vmrs    ip, FPSCR
+        vmsr    FPSCR, tmp
+1:
+        vldmia          a2!, {s8-s15}
+        vcvt.f32.s32    s8, s8
+        vcvt.f32.s32    s9, s9
+        vcvt.f32.s32    s10, s10
+        vcvt.f32.s32    s11, s11
+        vcvt.f32.s32    s12, s12
+        vcvt.f32.s32    s13, s13
+        vcvt.f32.s32    s14, s14
+        vcvt.f32.s32    s15, s15
+        vmul.f32        s8, s8, s0
+        subs            len, len, #8
+        vstmia          a1!, {s8-s11}
+        vstmia          a1!, {s12-s15}
+        bne             1b
+
+        vmsr    FPSCR, ip
+        bx      lr
+endfunc
+        .unreq  tmp
+        .unreq  len