[PATCH] Clean up av_get_cpu_flag()
Instead of defining functions in per-arch header files included by the main cpu.c, define them normally and call them from the generic one. --- libavutil/Makefile | 4 ++++ libavutil/arm/{cpu.h => cpu.c} | 8 ++------ libavutil/cpu.c | 11 +++-------- libavutil/cpu.h | 5 +++++ libavutil/ppc/{cpu.h => cpu.c} | 8 ++------ libavutil/x86/{cpu.h => cpu.c} | 7 +------ 6 files changed, 17 insertions(+), 26 deletions(-) rename libavutil/arm/{cpu.h => cpu.c} (88%) rename libavutil/ppc/{cpu.h => cpu.c} (95%) rename libavutil/x86/{cpu.h => cpu.c} (97%) diff --git a/libavutil/Makefile b/libavutil/Makefile index 545e1c2..22b5452 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -57,6 +57,10 @@ OBJS = adler32.o \ tree.o \ utils.o \ +OBJS-$(ARCH_ARM) += arm/cpu.o +OBJS-$(ARCH_PPC) += ppc/cpu.o +OBJS-$(ARCH_X86) += x86/cpu.o + TESTPROGS = adler32 aes base64 cpu crc des lls md5 pca sha softfloat tree TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo diff --git a/libavutil/arm/cpu.h b/libavutil/arm/cpu.c similarity index 88% rename from libavutil/arm/cpu.h rename to libavutil/arm/cpu.c index 45ab761..59b9b90 100644 --- a/libavutil/arm/cpu.h +++ b/libavutil/arm/cpu.c @@ -16,14 +16,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_ARM_CPU_H -#define AVUTIL_ARM_CPU_H - +#include "libavutil/cpu.h" #include "config.h" -int av_get_cpu_flags(void) +int av_get_cpu_flags_arm(void) { return HAVE_IWMMXT * AV_CPU_FLAG_IWMMXT; } - -#endif /* AVUTIL_ARM_CPU_H */ diff --git a/libavutil/cpu.c b/libavutil/cpu.c index fb37edb..e88b018 100644 --- a/libavutil/cpu.c +++ b/libavutil/cpu.c @@ -19,18 +19,13 @@ #include "cpu.h" #include "config.h" -#if ARCH_ARM -# include "arm/cpu.h" -#elif ARCH_PPC -# include "ppc/cpu.h" -#elif ARCH_X86 -# include "x86/cpu.h" -#else int av_get_cpu_flags(void) { + if (ARCH_ARM) return av_get_cpu_flags_arm(); + if (ARCH_PPC) return av_get_cpu_flags_ppc(); + if (ARCH_X86) return av_get_cpu_flags_x86(); return 0; } -#endif #ifdef TEST diff --git a/libavutil/cpu.h b/libavutil/cpu.h index 08e82f1..bf4d0e0 100644 --- a/libavutil/cpu.h +++ b/libavutil/cpu.h @@ -46,4 +46,9 @@ */ int av_get_cpu_flags(void); +/* The following CPU-specific functions shall not be called directly. */ +int av_get_cpu_flags_arm(void); +int av_get_cpu_flags_ppc(void); +int av_get_cpu_flags_x86(void); + #endif /* AVUTIL_CPU_H */ diff --git a/libavutil/ppc/cpu.h b/libavutil/ppc/cpu.c similarity index 95% rename from libavutil/ppc/cpu.h rename to libavutil/ppc/cpu.c index 684361c..e7e1778 100644 --- a/libavutil/ppc/cpu.h +++ b/libavutil/ppc/cpu.c @@ -16,9 +16,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_PPC_CPU_H -#define AVUTIL_PPC_CPU_H - #ifdef __APPLE__ #undef _POSIX_C_SOURCE #include <sys/sysctl.h> @@ -32,13 +29,14 @@ #include <proto/exec.h> #endif /* __APPLE__ */ +#include "libavutil/cpu.h" #include "config.h" /** * This function MAY rely on signal() or fork() in order to make sure AltiVec * is present. */ -int av_get_cpu_flags(void) +int av_get_cpu_flags_ppc(void) { #if HAVE_ALTIVEC #ifdef __AMIGAOS4__ @@ -84,5 +82,3 @@ int av_get_cpu_flags(void) #endif /* HAVE_ALTIVEC */ return 0; } - -#endif /* AVUTIL_PPC_CPU_H */ diff --git a/libavutil/x86/cpu.h b/libavutil/x86/cpu.c similarity index 97% rename from libavutil/x86/cpu.h rename to libavutil/x86/cpu.c index 052d2c5..8a0773a 100644 --- a/libavutil/x86/cpu.h +++ b/libavutil/x86/cpu.c @@ -20,9 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_X86_CPU_H2 -#define AVUTIL_X86_CPU_H2 - #include <stdlib.h> #include "libavutil/x86_cpu.h" #include "libavutil/cpu.h" @@ -38,7 +35,7 @@ : "0" (index)); /* Function to test if multimedia instructions are supported... */ -int av_get_cpu_flags(void) +int av_get_cpu_flags_x86(void) { int rval = 0; int eax, ebx, ecx, edx; @@ -124,5 +121,3 @@ int av_get_cpu_flags(void) return rval; } - -#endif /* AVUTIL_X86_CPU_H2 */ -- 1.7.2.2
Hi, On Wed, Sep 8, 2010 at 3:46 PM, Mans Rullgard <mans at mansr.com> wrote:
+/* The following CPU-specific functions shall not be called directly. */ +int av_get_cpu_flags_arm(void); +int av_get_cpu_flags_ppc(void); +int av_get_cpu_flags_x86(void);
So remove the av_ prefix? Looks nice otherwise. Ronald
"Ronald S. Bultje" <rsbultje at gmail.com> writes:
Hi,
On Wed, Sep 8, 2010 at 3:46 PM, Mans Rullgard <mans at mansr.com> wrote:
+/* The following CPU-specific functions shall not be called directly. */ +int av_get_cpu_flags_arm(void); +int av_get_cpu_flags_ppc(void); +int av_get_cpu_flags_x86(void);
So remove the av_ prefix? Looks nice otherwise.
ff_ prefix instead? -- M?ns Rullg?rd mans at mansr.com
Hi, 2010/9/8 M?ns Rullg?rd <mans at mansr.com>:
"Ronald S. Bultje" <rsbultje at gmail.com> writes:
On Wed, Sep 8, 2010 at 3:46 PM, Mans Rullgard <mans at mansr.com> wrote:
+/* The following CPU-specific functions shall not be called directly. */ +int av_get_cpu_flags_arm(void); +int av_get_cpu_flags_ppc(void); +int av_get_cpu_flags_x86(void);
So remove the av_ prefix? Looks nice otherwise.
ff_ prefix instead?
Probably yes, and then put them in a private header also if wanted (or since they're only used in a single place, no header needed). Ronald
"Ronald S. Bultje" <rsbultje at gmail.com> writes:
Hi,
2010/9/8 M?ns Rullg?rd <mans at mansr.com>:
"Ronald S. Bultje" <rsbultje at gmail.com> writes:
On Wed, Sep 8, 2010 at 3:46 PM, Mans Rullgard <mans at mansr.com> wrote:
+/* The following CPU-specific functions shall not be called directly. */ +int av_get_cpu_flags_arm(void); +int av_get_cpu_flags_ppc(void); +int av_get_cpu_flags_x86(void);
So remove the av_ prefix? Looks nice otherwise.
ff_ prefix instead?
Probably yes, and then put them in a private header also if wanted (or
I though a separate header for those functions seemed overkill.
since they're only used in a single place, no header needed).
All non-static functions must have a prototype in a header. We even enforce that if the compiler supports it. -- M?ns Rullg?rd mans at mansr.com
On Wed, Sep 08, 2010 at 09:58:57PM +0100, M?ns Rullg?rd wrote:
"Ronald S. Bultje" <rsbultje at gmail.com> writes:
Hi,
2010/9/8 M?ns Rullg?rd <mans at mansr.com>:
"Ronald S. Bultje" <rsbultje at gmail.com> writes:
On Wed, Sep 8, 2010 at 3:46 PM, Mans Rullgard <mans at mansr.com> wrote:
+/* The following CPU-specific functions shall not be called directly. */ +int av_get_cpu_flags_arm(void); +int av_get_cpu_flags_ppc(void); +int av_get_cpu_flags_x86(void);
So remove the av_ prefix? Looks nice otherwise.
ff_ prefix instead?
done
Probably yes, and then put them in a private header also if wanted (or
I though a separate header for those functions seemed overkill.
I moved the prototypes to libavutil/internal.h I've also added the caching of the flags as requested by Micheal in the other thread. Janne
On Thu, 9 Sep 2010 19:59:45 +0200 Janne Grunau wrote:
int av_get_cpu_flags(void) { - return 0; + static int cpu_flags; + + if (!cpu_flags) { + if (ARCH_ARM) cpu_flags = ff_get_cpu_flags_arm(); + if (ARCH_PPC) cpu_flags = ff_get_cpu_flags_ppc(); + if (ARCH_X86) cpu_flags = ff_get_cpu_flags_x86(); + + // use AV_CPU_FLAGS_FORCE as sentinel for empty cpu flags + if (!cpu_flags) + cpu_flags = AV_CPU_FLAG_FORCE; + } + return cpu_flags & ~AV_CPU_FLAG_FORCE; }
Am I missing something, or is the sentinel part useless? -- Ben
Benoit Fouet <benoit.fouet at free.fr> writes:
On Thu, 9 Sep 2010 19:59:45 +0200 Janne Grunau wrote:
int av_get_cpu_flags(void) { - return 0; + static int cpu_flags; + + if (!cpu_flags) { + if (ARCH_ARM) cpu_flags = ff_get_cpu_flags_arm(); + if (ARCH_PPC) cpu_flags = ff_get_cpu_flags_ppc(); + if (ARCH_X86) cpu_flags = ff_get_cpu_flags_x86(); + + // use AV_CPU_FLAGS_FORCE as sentinel for empty cpu flags + if (!cpu_flags) + cpu_flags = AV_CPU_FLAG_FORCE; + } + return cpu_flags & ~AV_CPU_FLAG_FORCE; }
Am I missing something, or is the sentinel part useless?
The detected flags could be 0. Anyhow, I've committed a simpler variant. -- M?ns Rullg?rd mans at mansr.com
participants (4)
-
benoit.fouet@free.fr -
janne-ffmpeg@jannau.net -
mans@mansr.com -
rsbultje@gmail.com