Skip to content

Commit

Permalink
Linux Ports (All): Update Autotools and Meson scripts to add JIT supp…
Browse files Browse the repository at this point in the history
…ort for ARM targets.

- Also fixes build errors related to explicitly building SIMD files for colorspacehandler. Don't do it! The proper way is to simply include "colorspacehandler.cpp" alone and let the compiler's preprocessor macros determine which SIMD file to use.
  • Loading branch information
rogerman committed Aug 9, 2024
1 parent 2e01c0a commit c75c1ce
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 92 deletions.
26 changes: 11 additions & 15 deletions desmume/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,13 @@ libdesmume_a_SOURCES = \
libretro-common/rthreads/rsemaphore.c \
libretro-common/rthreads/rthreads.c

if SUPPORT_SSE2
libdesmume_a_SOURCES += \
utils/colorspacehandler/colorspacehandler_SSE2.cpp
endif

if SUPPORT_AVX2
libdesmume_a_SOURCES += \
utils/colorspacehandler/colorspacehandler_AVX2.cpp
endif

if SUPPORT_ALTIVEC
if HAVE_JIT
libdesmume_a_SOURCES += \
utils/colorspacehandler/colorspacehandler_AltiVec.cpp
endif
arm_jit.h instruction_attributes.h

if HAVE_JIT
if HOST_CPU_KIND_X86
libdesmume_a_SOURCES += \
arm_jit.cpp arm_jit.h instruction_attributes.h \
arm_jit.cpp \
utils/AsmJit/AsmJit.h \
utils/AsmJit/Config.h \
utils/AsmJit/core.h \
Expand Down Expand Up @@ -227,6 +216,13 @@ libdesmume_a_SOURCES += \
utils/AsmJit/x86/x86operand.h \
utils/AsmJit/x86/x86util.cpp \
utils/AsmJit/x86/x86util.h
else
if HOST_CPU_KIND_ARM
libdesmume_a_SOURCES += \
utils/arm_jit/arm_jit_arm.cpp
endif
endif

endif

if ENABLE_OPENGL_ES
Expand Down
26 changes: 11 additions & 15 deletions desmume/src/frontend/posix/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,13 @@ libdesmume_a_SOURCES = \
../../libretro-common/rthreads/rthreads.c \
../../libretro-common/encodings/encoding_utf.c

if SUPPORT_SSE2
libdesmume_a_SOURCES += \
../../utils/colorspacehandler/colorspacehandler_SSE2.cpp ../../utils/colorspacehandler/colorspacehandler_SSE2.h
endif

if SUPPORT_AVX2
libdesmume_a_SOURCES += \
../../utils/colorspacehandler/colorspacehandler_AVX2.cpp ../../utils/colorspacehandler/colorspacehandler_AVX2.h
endif

if SUPPORT_ALTIVEC
if HAVE_JIT
libdesmume_a_SOURCES += \
../../utils/colorspacehandler/colorspacehandler_AltiVec.cpp ../../utils/colorspacehandler/colorspacehandler_AltiVec.h
endif
../../arm_jit.h ../../instruction_attributes.h

if HAVE_JIT
if HOST_CPU_KIND_X86
libdesmume_a_SOURCES += \
../../arm_jit.cpp ../../arm_jit.h ../../instruction_attributes.h \
../../arm_jit.cpp \
../../utils/AsmJit/AsmJit.h \
../../utils/AsmJit/Config.h \
../../utils/AsmJit/core.h \
Expand Down Expand Up @@ -206,6 +195,13 @@ libdesmume_a_SOURCES += \
../../utils/AsmJit/x86/x86operand.h \
../../utils/AsmJit/x86/x86util.cpp \
../../utils/AsmJit/x86/x86util.h
else
if HOST_CPU_KIND_ARM
libdesmume_a_SOURCES += \
../../utils/arm_jit/arm_jit_arm.cpp
endif
endif

endif

libdesmume_a_SOURCES += shared/desmume_config.cpp shared/desmume_config.h
Expand Down
38 changes: 28 additions & 10 deletions desmume/src/frontend/posix/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fi

dnl - jit support
case $host_cpu in
x86|x86_64|i386|i486|i586|i686)
x86|x86_64|i386|i486|i586|i686|arm|arm64|aarch64)
HAVE_JIT=yes
AC_DEFINE(HAVE_JIT)
;;
Expand Down Expand Up @@ -382,19 +382,37 @@ AS_CASE([$host],
)

AS_CASE([$host_cpu],
[x86_64], [AC_DEFINE(HOST_64)],
[amd64], [AC_DEFINE(HOST_64)],
[x86_64], [AC_DEFINE(HOST_64)],
[amd64], [AC_DEFINE(HOST_64)],
[aarch64], [AC_DEFINE(HOST_64)],
[arm64], [AC_DEFINE(HOST_64)],
[ppc64], [AC_DEFINE(HOST_64)],
[AC_DEFINE(HOST_32)]
)

AC_CHECK_DECL([__SSE2__])
AM_CONDITIONAL([SUPPORT_SSE2], [test "x$ac_cv_have_decl___SSE2__" = xyes])

AC_CHECK_DECL([__AVX2__])
AM_CONDITIONAL([SUPPORT_AVX2], [test "x$ac_cv_have_decl___AVX2__" = xyes])
host_cpu_kind_x86=no
host_cpu_kind_arm=no
host_cpu_kind_powerpc=no
host_cpu_kind_unknown=no
AS_CASE([$host_cpu],
[x86_64], [host_cpu_kind_x86=yes],
[amd64], [host_cpu_kind_x86=yes],
[x86], [host_cpu_kind_x86=yes],
[i686], [host_cpu_kind_x86=yes],
[i586], [host_cpu_kind_x86=yes],
[i486], [host_cpu_kind_x86=yes],
[i386], [host_cpu_kind_x86=yes],
[aarch64], [host_cpu_kind_arm=yes],
[arm64], [host_cpu_kind_arm=yes],
[arm], [host_cpu_kind_arm=yes],
[ppc64], [host_cpu_kind_powerpc=yes],
[powerpc], [host_cpu_kind_powerpc=yes],
[host_cpu_kind_unknown=yes]
)

AC_CHECK_DECL([__ALTIVEC__])
AM_CONDITIONAL([SUPPORT_ALTIVEC], [test "x$ac_cv_have_decl___ALTIVEC__" = xyes])
AM_CONDITIONAL([HOST_CPU_KIND_X86], [test x$host_cpu_kind_x86 = xyes])
AM_CONDITIONAL([HOST_CPU_KIND_ARM], [test x$host_cpu_kind_arm = xyes])
AM_CONDITIONAL([HOST_CPU_KIND_PPC], [test x$host_cpu_kind_powerpc = xyes])

AC_SUBST(UI_DIR)
AC_SUBST(PO_DIR)
Expand Down
129 changes: 77 additions & 52 deletions desmume/src/frontend/posix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,48 @@ endif

dependencies = [dep_glib2, dep_sdl, dep_pcap, dep_zlib, dep_threads]

if target_machine.cpu() == 'x86_64'
add_global_arguments('-DHAVE_JIT', language: ['c', 'cpp'])
# Determine the CPU architecture of the target.
target_cpu_64bit = false
target_cpu_kind_x86 = false
target_cpu_kind_arm = false
target_cpu_kind_powerpc = false
target_cpu_kind_unknown = false

if target_machine.cpu() == 'x86_64' or \
target_machine.cpu() == 'amd64'
target_cpu_kind_x86 = true
target_cpu_64bit = true
elif target_machine.cpu() == 'x86' or \
target_machine.cpu() == 'i686' or \
target_machine.cpu() == 'i586' or \
target_machine.cpu() == 'i486' or \
target_machine.cpu() == 'i386'
target_cpu_kind_x86 = true
elif target_machine.cpu() == 'aarch64' or \
target_machine.cpu() == 'arm64'
target_cpu_kind_arm = true
target_cpu_64bit = true
elif target_machine.cpu() == 'arm'
target_cpu_kind_arm = true
elif target_machine.cpu() == 'ppc64'
target_cpu_kind_powerpc = true
target_cpu_64bit = true
elif target_machine.cpu() == 'powerpc'
target_cpu_kind_powerpc = true
else
target_cpu_kind_unknown = true
endif

if target_cpu_64bit
add_global_arguments('-DHOST_64', language: ['c', 'cpp'])
have_jit = true
elif target_machine.cpu() == 'i686'
add_global_arguments('-DHAVE_JIT', language: ['c', 'cpp'])
else
add_global_arguments('-DHOST_32', language: ['c', 'cpp'])
endif

# Enable JIT for supported architectures.
if target_cpu_kind_x86 or target_cpu_kind_arm
have_jit = true
add_global_arguments('-DHAVE_JIT', language: ['c', 'cpp'])
else
have_jit = false
endif
Expand Down Expand Up @@ -133,38 +167,44 @@ libdesmume_src = [
]

if have_jit
libdesmume_src += [
'../../arm_jit.cpp',
'../../utils/AsmJit/core/assembler.cpp',
'../../utils/AsmJit/core/assert.cpp',
'../../utils/AsmJit/core/buffer.cpp',
'../../utils/AsmJit/core/compiler.cpp',
'../../utils/AsmJit/core/compilercontext.cpp',
'../../utils/AsmJit/core/compilerfunc.cpp',
'../../utils/AsmJit/core/compileritem.cpp',
'../../utils/AsmJit/core/context.cpp',
'../../utils/AsmJit/core/cpuinfo.cpp',
'../../utils/AsmJit/core/defs.cpp',
'../../utils/AsmJit/core/func.cpp',
'../../utils/AsmJit/core/logger.cpp',
'../../utils/AsmJit/core/memorymanager.cpp',
'../../utils/AsmJit/core/memorymarker.cpp',
'../../utils/AsmJit/core/operand.cpp',
'../../utils/AsmJit/core/stringbuilder.cpp',
'../../utils/AsmJit/core/stringutil.cpp',
'../../utils/AsmJit/core/virtualmemory.cpp',
'../../utils/AsmJit/core/zonememory.cpp',
'../../utils/AsmJit/x86/x86assembler.cpp',
'../../utils/AsmJit/x86/x86compiler.cpp',
'../../utils/AsmJit/x86/x86compilercontext.cpp',
'../../utils/AsmJit/x86/x86compilerfunc.cpp',
'../../utils/AsmJit/x86/x86compileritem.cpp',
'../../utils/AsmJit/x86/x86cpuinfo.cpp',
'../../utils/AsmJit/x86/x86defs.cpp',
'../../utils/AsmJit/x86/x86func.cpp',
'../../utils/AsmJit/x86/x86operand.cpp',
'../../utils/AsmJit/x86/x86util.cpp',
]
if target_cpu_kind_x86
libdesmume_src += [
'../../arm_jit.cpp',
'../../utils/AsmJit/core/assembler.cpp',
'../../utils/AsmJit/core/assert.cpp',
'../../utils/AsmJit/core/buffer.cpp',
'../../utils/AsmJit/core/compiler.cpp',
'../../utils/AsmJit/core/compilercontext.cpp',
'../../utils/AsmJit/core/compilerfunc.cpp',
'../../utils/AsmJit/core/compileritem.cpp',
'../../utils/AsmJit/core/context.cpp',
'../../utils/AsmJit/core/cpuinfo.cpp',
'../../utils/AsmJit/core/defs.cpp',
'../../utils/AsmJit/core/func.cpp',
'../../utils/AsmJit/core/logger.cpp',
'../../utils/AsmJit/core/memorymanager.cpp',
'../../utils/AsmJit/core/memorymarker.cpp',
'../../utils/AsmJit/core/operand.cpp',
'../../utils/AsmJit/core/stringbuilder.cpp',
'../../utils/AsmJit/core/stringutil.cpp',
'../../utils/AsmJit/core/virtualmemory.cpp',
'../../utils/AsmJit/core/zonememory.cpp',
'../../utils/AsmJit/x86/x86assembler.cpp',
'../../utils/AsmJit/x86/x86compiler.cpp',
'../../utils/AsmJit/x86/x86compilercontext.cpp',
'../../utils/AsmJit/x86/x86compilerfunc.cpp',
'../../utils/AsmJit/x86/x86compileritem.cpp',
'../../utils/AsmJit/x86/x86cpuinfo.cpp',
'../../utils/AsmJit/x86/x86defs.cpp',
'../../utils/AsmJit/x86/x86func.cpp',
'../../utils/AsmJit/x86/x86operand.cpp',
'../../utils/AsmJit/x86/x86util.cpp',
]
elif target_cpu_kind_arm
libdesmume_src += [
'../../utils/arm_jit/arm_jit_arm.cpp',
]
endif
endif

libdesmume_src += [
Expand Down Expand Up @@ -285,25 +325,10 @@ if get_option('gdb-stub')
]
endif

simd = import('unstable-simd')
cxx = meson.get_compiler('cpp')
rval = simd.check('colorspacehandler',
sse2: '../../utils/colorspacehandler/colorspacehandler_SSE2.cpp',
# TODO: add these two even in generic builds.
#avx2: '../../utils/colorspacehandler/colorspacehandler_AVX2.cpp',
#avx512: '../../utils/colorspacehandler/colorspacehandler_AVX512.cpp',
# TODO: add support for this in meson.
#altivec: '../../utils/colorspacehandler/colorspacehandler_AltiVec.cpp',
compiler: cxx,
include_directories: includes,
)
colorspacehandler_simd = rval[0]

libdesmume = static_library('desmume',
libdesmume_src,
dependencies: dependencies,
include_directories: includes,
link_with: colorspacehandler_simd,
)

if get_option('frontend-cli')
Expand Down

0 comments on commit c75c1ce

Please sign in to comment.