Re: [libav-devel] [PATCH] Move avutil tables only used in libavcodec to libavcodec.

2012-10-11 Thread Martin Storsjö

On Thu, 11 Oct 2012, Diego Biurrun wrote:


---
Fixed placement of extern table declarations (for arm), they need to
come before the arch-specific headers, as they are referenced there.

libavcodec/Makefile|7 +
libavcodec/arm/mathops.h   |   24 
libavcodec/inverse.c   |1 -
libavcodec/mathops.h   |   29 +++
libavutil/inverse.c => libavcodec/mathtables.c |   14 +++--
libavcodec/motion_est.c|2 +-
libavcodec/mpegvideo.c |2 +-
libavcodec/mpegvideo_enc.c |1 +
libavcodec/ra144.c |2 +-
libavcodec/roqaudioenc.c   |2 +-
libavutil/Makefile |1 -
libavutil/arm/intmath.h|   24 
libavutil/intmath.h|   35 
libavutil/mathematics.c|   11 ---
14 files changed, 70 insertions(+), 85 deletions(-)
delete mode 100644 libavcodec/inverse.c
rename libavutil/inverse.c => libavcodec/mathtables.c (79%)


Looks ok.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Move avutil tables only used in libavcodec to libavcodec.

2012-10-10 Thread Diego Biurrun
---
Fixed placement of extern table declarations (for arm), they need to
come before the arch-specific headers, as they are referenced there.

 libavcodec/Makefile|7 +
 libavcodec/arm/mathops.h   |   24 
 libavcodec/inverse.c   |1 -
 libavcodec/mathops.h   |   29 +++
 libavutil/inverse.c => libavcodec/mathtables.c |   14 +++--
 libavcodec/motion_est.c|2 +-
 libavcodec/mpegvideo.c |2 +-
 libavcodec/mpegvideo_enc.c |1 +
 libavcodec/ra144.c |2 +-
 libavcodec/roqaudioenc.c   |2 +-
 libavutil/Makefile |1 -
 libavutil/arm/intmath.h|   24 
 libavutil/intmath.h|   35 
 libavutil/mathematics.c|   11 ---
 14 files changed, 70 insertions(+), 85 deletions(-)
 delete mode 100644 libavcodec/inverse.c
 rename libavutil/inverse.c => libavcodec/mathtables.c (79%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6aa13af..5dbd60e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -22,6 +22,7 @@ OBJS = allcodecs.o
  \
fmtconvert.o \
imgconvert.o \
jrevdct.o\
+   mathtables.o \
options.o\
parser.o \
raw.o\
@@ -655,12 +656,6 @@ OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
 OBJS-$(HAVE_PTHREADS)  += pthread.o
 OBJS-$(HAVE_W32THREADS)+= pthread.o
 
-# inverse.o contains the ff_inverse table definition, which is used by
-# the FASTDIV macro (from libavutil); since referencing the external
-# table has a negative effect on performance, copy it in libavcodec as
-# well.
-OBJS-$(!CONFIG_SMALL)  += inverse.o
-
 SKIPHEADERS+= %_tablegen.h  \
   %_tables.h\
   aac_tablegen_decl.h   \
diff --git a/libavcodec/arm/mathops.h b/libavcodec/arm/mathops.h
index 3803fcd..17a687d 100644
--- a/libavcodec/arm/mathops.h
+++ b/libavcodec/arm/mathops.h
@@ -36,6 +36,30 @@ static inline av_const int MULH(int a, int b)
 __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
 return r;
 }
+
+#define FASTDIV FASTDIV
+static av_always_inline av_const int FASTDIV(int a, int b)
+{
+int r;
+__asm__ ("cmp %2, #2   \n\t"
+ "ldr %0, [%3, %2, lsl #2] \n\t"
+ "ite le   \n\t"
+ "lsrle   %0, %1, #1   \n\t"
+ "smmulgt %0, %0, %1   \n\t"
+ : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc");
+return r;
+}
+
+#else /* HAVE_ARMV6 */
+
+#define FASTDIV FASTDIV
+static av_always_inline av_const int FASTDIV(int a, int b)
+{
+int r, t;
+__asm__ ("umull %1, %0, %2, %3"
+ : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
+return r;
+}
 #endif
 
 #define MLS64(d, a, b) MAC64(d, -(a), b)
diff --git a/libavcodec/inverse.c b/libavcodec/inverse.c
deleted file mode 100644
index 04681d2..000
--- a/libavcodec/inverse.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "libavutil/inverse.c"
diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index ab545ef..218c459 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -22,9 +22,14 @@
 #ifndef AVCODEC_MATHOPS_H
 #define AVCODEC_MATHOPS_H
 
+#include 
+
 #include "libavutil/common.h"
 #include "config.h"
 
+extern const uint32_t ff_inverse[257];
+extern const uint8_t ff_sqrt_tab[256];
+
 #if   ARCH_ARM
 #   include "arm/mathops.h"
 #elif ARCH_AVR32
@@ -185,4 +190,28 @@ if ((y) < (x)) {\
 #   define PACK_2S16(a,b)PACK_2U16((a)&0x, (b)&0x)
 #endif
 
+#ifndef FASTDIV
+#   define FASTDIV(a,b) ((uint32_t)uint64_t)a) * ff_inverse[b]) >> 32))
+#endif /* FASTDIV */
+
+static inline av_const unsigned int ff_sqrt(unsigned int a)
+{
+unsigned int b;
+
+if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
+else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
+#if !CONFIG_SMALL
+else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
+else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8]   ;
+#endif
+else {
+int s = av_log2_16bit(a >> 16) >> 1;
+unsigned int c = a >> (s + 2);
+b = ff_sqrt_tab[c

Re: [libav-devel] [PATCH] Move avutil tables only used in libavcodec to libavcodec.

2012-10-10 Thread Måns Rullgård
Diego Biurrun  writes:

> ---
> Renamed mathops.c --> mathtables.c.
>
>  libavcodec/Makefile|7 +
>  libavcodec/arm/mathops.h   |   24 
>  libavcodec/inverse.c   |1 -
>  libavcodec/mathops.h   |   29 +++
>  libavutil/inverse.c => libavcodec/mathtables.c |   14 +++--
>  libavcodec/motion_est.c|2 +-
>  libavcodec/mpegvideo.c |2 +-
>  libavcodec/mpegvideo_enc.c |1 +
>  libavcodec/ra144.c |2 +-
>  libavcodec/roqaudioenc.c   |2 +-
>  libavutil/Makefile |1 -
>  libavutil/arm/intmath.h|   24 
>  libavutil/intmath.h|   35 
> 
>  libavutil/mathematics.c|   11 ---
>  14 files changed, 70 insertions(+), 85 deletions(-)
>  delete mode 100644 libavcodec/inverse.c
>  rename libavutil/inverse.c => libavcodec/mathtables.c (79%)

Looks OK.

-- 
Måns Rullgård
m...@mansr.com
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


[libav-devel] [PATCH] Move avutil tables only used in libavcodec to libavcodec.

2012-10-10 Thread Diego Biurrun
---
Renamed mathops.c --> mathtables.c.

 libavcodec/Makefile|7 +
 libavcodec/arm/mathops.h   |   24 
 libavcodec/inverse.c   |1 -
 libavcodec/mathops.h   |   29 +++
 libavutil/inverse.c => libavcodec/mathtables.c |   14 +++--
 libavcodec/motion_est.c|2 +-
 libavcodec/mpegvideo.c |2 +-
 libavcodec/mpegvideo_enc.c |1 +
 libavcodec/ra144.c |2 +-
 libavcodec/roqaudioenc.c   |2 +-
 libavutil/Makefile |1 -
 libavutil/arm/intmath.h|   24 
 libavutil/intmath.h|   35 
 libavutil/mathematics.c|   11 ---
 14 files changed, 70 insertions(+), 85 deletions(-)
 delete mode 100644 libavcodec/inverse.c
 rename libavutil/inverse.c => libavcodec/mathtables.c (79%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6aa13af..5dbd60e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -22,6 +22,7 @@ OBJS = allcodecs.o
  \
fmtconvert.o \
imgconvert.o \
jrevdct.o\
+   mathtables.o \
options.o\
parser.o \
raw.o\
@@ -655,12 +656,6 @@ OBJS-$(CONFIG_TEXT2MOVSUB_BSF)+= movsub_bsf.o
 OBJS-$(HAVE_PTHREADS)  += pthread.o
 OBJS-$(HAVE_W32THREADS)+= pthread.o
 
-# inverse.o contains the ff_inverse table definition, which is used by
-# the FASTDIV macro (from libavutil); since referencing the external
-# table has a negative effect on performance, copy it in libavcodec as
-# well.
-OBJS-$(!CONFIG_SMALL)  += inverse.o
-
 SKIPHEADERS+= %_tablegen.h  \
   %_tables.h\
   aac_tablegen_decl.h   \
diff --git a/libavcodec/arm/mathops.h b/libavcodec/arm/mathops.h
index 3803fcd..17a687d 100644
--- a/libavcodec/arm/mathops.h
+++ b/libavcodec/arm/mathops.h
@@ -36,6 +36,30 @@ static inline av_const int MULH(int a, int b)
 __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
 return r;
 }
+
+#define FASTDIV FASTDIV
+static av_always_inline av_const int FASTDIV(int a, int b)
+{
+int r;
+__asm__ ("cmp %2, #2   \n\t"
+ "ldr %0, [%3, %2, lsl #2] \n\t"
+ "ite le   \n\t"
+ "lsrle   %0, %1, #1   \n\t"
+ "smmulgt %0, %0, %1   \n\t"
+ : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc");
+return r;
+}
+
+#else /* HAVE_ARMV6 */
+
+#define FASTDIV FASTDIV
+static av_always_inline av_const int FASTDIV(int a, int b)
+{
+int r, t;
+__asm__ ("umull %1, %0, %2, %3"
+ : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b]));
+return r;
+}
 #endif
 
 #define MLS64(d, a, b) MAC64(d, -(a), b)
diff --git a/libavcodec/inverse.c b/libavcodec/inverse.c
deleted file mode 100644
index 04681d2..000
--- a/libavcodec/inverse.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "libavutil/inverse.c"
diff --git a/libavcodec/mathops.h b/libavcodec/mathops.h
index ab545ef..4e9f27f 100644
--- a/libavcodec/mathops.h
+++ b/libavcodec/mathops.h
@@ -22,6 +22,8 @@
 #ifndef AVCODEC_MATHOPS_H
 #define AVCODEC_MATHOPS_H
 
+#include 
+
 #include "libavutil/common.h"
 #include "config.h"
 
@@ -185,4 +187,31 @@ if ((y) < (x)) {\
 #   define PACK_2S16(a,b)PACK_2U16((a)&0x, (b)&0x)
 #endif
 
+extern const uint32_t ff_inverse[257];
+extern const uint8_t ff_sqrt_tab[256];
+
+#ifndef FASTDIV
+#   define FASTDIV(a,b) ((uint32_t)uint64_t)a) * ff_inverse[b]) >> 32))
+#endif /* FASTDIV */
+
+static inline av_const unsigned int ff_sqrt(unsigned int a)
+{
+unsigned int b;
+
+if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4;
+else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2;
+#if !CONFIG_SMALL
+else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1;
+else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8]   ;
+#endif
+else {
+int s = av_log2_16bit(a >> 16) >> 1;
+unsigned int c = a >> (s + 2);
+b = ff_sqrt_tab[c >> (s + 8)];
+b = FASTDIV(c,b) + (b << s);
+}
+
+return b - (a < b * b);
+}
+
 #endif /* AVCODEC_MATHOPS_H */
diff --git a/libavutil/inverse.c b/liba