Skip to content

Commit

Permalink
Support architectures other than x86
Browse files Browse the repository at this point in the history
Theoretically, at least.
  • Loading branch information
cantabile committed Feb 22, 2015
1 parent 957236a commit 686b8ee
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 135 deletions.
23 changes: 15 additions & 8 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
AM_CFLAGS = -O2 -msse2 -mfpmath=sse -Wall -Wextra -Wno-unused-parameter
warning_flags = -Wall -Wextra -Wno-unused-parameter -Wshadow
common_cflags = -O2 $(MFLAGS) $(warning_flags)
AM_CFLAGS = $(common_cflags)
AM_CXXFLAGS = -std=c++11 $(common_cflags)

AM_CPPFLAGS = $(VapourSynth_CFLAGS)
AM_CPPFLAGS = $(VapourSynth_CFLAGS) -DNNEDI3_DATADIR='"$(pkgdatadir)"'

dist_pkgdata_DATA = src/nnedi3\ weights.bin

lib_LTLIBRARIES = libnnedi3.la

Expand All @@ -11,11 +16,13 @@ yasm_verbose_0 = @echo " YASM " $@;
.asm.lo:
$(yasm_verbose)$(LIBTOOL) $(AM_V_lt) --mode=compile --tag=CC $(AS) $(ASFLAGS) -o $@ $< -prefer-non-pic

libnnedi3_la_SOURCES = src/cpufeatures.c \
src/cpufeatures.h \
src/nnedi3.c \
src/asm/binary1.asm \
src/asm/cpu-a.asm \
src/asm/nnedi3.asm
libnnedi3_la_SOURCES = src/nnedi3.cpp \
src/cpufeatures.cpp \
src/cpufeatures.h

if NNEDI3_X86
libnnedi3_la_SOURCES += src/asm/cpu-a.asm \
src/asm/nnedi3.asm
endif

libnnedi3_la_LDFLAGS = -no-undefined -avoid-version $(PLUGINLDFLAGS)
100 changes: 65 additions & 35 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AC_INIT([nnedi3], [1], [https://github.com/dubhater/vapoursynth-nnedi3/issues], [nnedi3], [https://github.com/dubhater/vapoursynth-nnedi3/])
AC_INIT([nnedi3], [3], [https://github.com/dubhater/vapoursynth-nnedi3/issues], [nnedi3], [https://github.com/dubhater/vapoursynth-nnedi3/])

: ${CFLAGS=""}
: ${CXXFLAGS=""}

AM_INIT_AUTOMAKE([foreign no-dist-gzip dist-xz subdir-objects no-define])
AM_SILENT_RULES([yes])
Expand All @@ -9,53 +9,83 @@ LT_INIT([disable-static win32-dll])

AC_CANONICAL_HOST

AC_PROG_CC_C99
AC_PROG_CXX

AC_SEARCH_LIBS([sqrt], [m], [], [
AC_MSG_ERROR([unable to find the sqrt() function])
])

AC_CHECK_PROGS([YASM], [yasm])
AS_IF(
[test "x$YASM" = "x"],
[AC_MSG_ERROR([yasm required but not found])],
[AS="$YASM"]

X86="false"
PPC="false"
ARM="false"

AS_CASE(
[$host_cpu],
[i?86], [BITS="32" ASFLAGS="$ASFLAGS -DARCH_X86_64=0" X86="true"],
[x86_64], [BITS="64" ASFLAGS="$ASFLAGS -DARCH_X86_64=1 -DPIC -m amd64" X86="true"],
[powerpc*], [PPC="true"],
[arm*], [ARM="true"] # Maybe doesn't work for all arm systems?
)

AS_CASE(
[$host_cpu],
[i?86], [BITS="32" ASFLAGS="$ASFLAGS -DARCH_X86_64=0"],
[x86_64], [BITS="64" ASFLAGS="$ASFLAGS -DARCH_X86_64=1 -DPIC -m amd64"],
[AC_MSG_ERROR([Currently nnedi3 can only be compiled for Intel CPUs.])]
[$host_os],
[darwin*],
[
ASFLAGS="$ASFLAGS -f macho$BITS -DPREFIX"
],
[*linux*|gnu*|dragonfly*|*bsd*], # The BSDs are close enough, right?
[
ASFLAGS="$ASFLAGS -f elf"
],
[cygwin*|mingw*],
[
ASFLAGS="$ASFLAGS -f win32"
AS_IF(
[test "x$BITS" = "x32"],
[
ASFLAGS="$ASFLAGS -DPREFIX"
AC_SUBST([PLUGINLDFLAGS], ["-Wl,--kill-at"])
]
)
],
[AC_MSG_ERROR(["Unknown host OS: $host_os"])]
)

ASFLAGS="$ASFLAGS -Dprivate_prefix=nnedi3"
AS_IF(
[test "x$X86" = "xtrue"],
[
AC_DEFINE([NNEDI3_X86])
AS_CASE(
[$host_os],
[darwin*],
[
ASFLAGS="$ASFLAGS -f macho$BITS -DPREFIX"
],
[*linux*|gnu*|dragonfly*|*bsd*],
[
ASFLAGS="$ASFLAGS -f elf"
],
[cygwin*|mingw*],
[
ASFLAGS="$ASFLAGS -f win32"
AS_IF(
[test "x$BITS" = "x32"],
[
ASFLAGS="$ASFLAGS -DPREFIX"
AC_SUBST([PLUGINLDFLAGS], ["-Wl,--kill-at"])
]
)
],
[AC_MSG_ERROR([Unknown host OS])]
ASFLAGS="$ASFLAGS -Dprivate_prefix=nnedi3"
AC_SUBST([MFLAGS], ["-mfpmath=sse -msse2"])
AC_CHECK_PROGS([YASM], [yasm])
AS_IF(
[test "x$YASM" = "x"],
[AC_MSG_ERROR([yasm required but not found])],
[AS="$YASM"]
)
]
)

AS_IF(
[test "x$PPC" = "xtrue"],
[AC_DEFINE([NNEDI3_POWERPC])]
)

AS_IF(
[test "x$ARM" = "xtrue"],
[AC_DEFINE([NNEDI3_ARM])]
)

AC_SUBST([ASFLAGS])


AM_CONDITIONAL([NNEDI3_X86], [test "x$X86" = "xtrue"])


PKG_CHECK_MODULES([VapourSynth], [vapoursynth])

AC_CONFIG_FILES([Makefile])
Expand Down
4 changes: 3 additions & 1 deletion readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This is a port of tritical's nnedi3 filter.
Usage
=====

The file ``nnedi3 weights.bin`` is required. In Windows, it must be located in the same folder as ``libnnedi3.dll``. Everywhere else it can be located either in the same folder as ``libnnedi3.so``/``libnnedi3.dylib``, or in ``$prefix/share/nnedi3/``. The build system installs it at the latter location automatically.

::

nnedi3.nnedi3(clip clip, int field[, bint dh=False, bint Y=True, bint U=True, bint V=True, int nsize=6, int nns=1, int qual=1, int etype=0, int pscrn=2, bint opt=True, int fapprox=15])
Expand Down Expand Up @@ -63,7 +65,7 @@ Compilation
./configure
make

yasm is currently not optional.
On x86, yasm is currently not optional.

DLLs can be found in the "releases" section.

Expand Down
7 changes: 0 additions & 7 deletions src/asm/binary1.asm

This file was deleted.

16 changes: 8 additions & 8 deletions src/cpufeatures.c → src/cpufeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@

#include "cpufeatures.h"

#ifdef VS_TARGET_CPU_X86
#ifdef NNEDI3_X86
extern "C" {
extern void nnedi3_cpu_cpuid(uint32_t index, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
extern void nnedi3_cpu_xgetbv(uint32_t op, uint32_t *eax, uint32_t *edx);
extern void nnedi3_cpu_cpuid_test(void);
}

void getCPUFeatures(CPUFeatures *cpuFeatures) {
memset(cpuFeatures, 0, sizeof(CPUFeatures));
Expand Down Expand Up @@ -62,32 +64,30 @@ void getCPUFeatures(CPUFeatures *cpuFeatures) {
}

}
#elif defined(VS_TARGET_OS_LINUX)
#else
#include <sys/auxv.h>

void getCPUFeatures(CPUFeatures *cpuFeatures) {
memset(cpuFeatures, 0, sizeof(CPUFeatures));

unsigned long long hwcap = getauxval(AT_HWCAP);

cpuFeatures->can_run_vs = 1;

#ifdef VS_TARGET_CPU_ARM
#ifdef NNEDI3_ARM
cpuFeatures->half_fp = !!(hwcap & HWCAP_ARM_HALF);
cpuFeatures->edsp = !!(hwcap & HWCAP_ARM_EDSP);
cpuFeatures->iwmmxt = !!(hwcap & HWCAP_ARM_IWMMXT);
cpuFeatures->neon = !!(hwcap & HWCAP_ARM_NEON);
cpuFeatures->fast_mult = !!(hwcap & HWCAP_ARM_FAST_MULT);
cpuFeatures->idiv_a = !!(hwcap & HWCAP_ARM_IDIVA);
#elif defined(VS_TARGET_CPU_POWERPC)
#elif defined(NNEDI3_POWERPC)
cpuFeatures->altivec = !!(hwcap & PPC_FEATURE_HAS_ALTIVEC);
cpuFeatures->spe = !!(hwcap & PPC_FEATURE_HAS_SPE);
cpuFeatures->efp_single = !!(hwcap & PPC_FEATURE_HAS_EFP_SINGLE);
cpuFeatures->efp_double = !!(hwcap & PPC_FEATURE_HAS_EFP_DOUBLE);
cpuFeatures->dfp = !!(hwcap & PPC_FEATURE_HAS_DFP);
cpuFeatures->vsx = !!(hwcap & PPC_FEATURE_HAS_VSX);
#else
#error Do not know how to get CPU features on Linux.
#endif
}
#else
#error Do not know how to get CPU features.
#endif
16 changes: 4 additions & 12 deletions src/cpufeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#define VS_TARGET_CPU_X86

typedef struct CPUFeatures {
// This is to determine if the cpu is up to the minimum requirements in terms of supported instructions
// that the VapourSynth core uses.
char can_run_vs;
#ifdef VS_TARGET_CPU_X86
#ifdef NNEDI3_X86
// On x86, all features up to sse2 are required.
char sse3;
char ssse3;
Expand All @@ -34,31 +33,24 @@ typedef struct CPUFeatures {
char fma4;
char avx;
char avx2;
#elif defined(VS_TARGET_CPU_ARM)
#elif defined(NNEDI3_ARM)
// On ARM, VFP-D16+ (16 double registers or more) is required.
char half_fp;
char edsp;
char iwmmxt;
char neon;
char fast_mult;
char idiv_a;
#elif defined(VS_TARGET_CPU_POWERPC)
#elif defined(NNEDI3_POWERPC)
// On PowerPC, FPU and MMU are required.
char altivec;
char spe;
char efp_single;
char efp_double;
char dfp;
char vsx;
#else
#error No VS_TARGET_CPU_* defined/handled!
#endif
} CPUFeatures;

#ifdef __cplusplus
#define CPU_FEATURES_EXTERN_C extern "C"
#else
#define CPU_FEATURES_EXTERN_C
#endif

CPU_FEATURES_EXTERN_C void getCPUFeatures(CPUFeatures *cpuFeatures);
void getCPUFeatures(CPUFeatures *cpuFeatures);
File renamed without changes.
Loading

0 comments on commit 686b8ee

Please sign in to comment.