Skip to content

Add Arm RTCD for OpenBSD #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ endif()
target_compile_definitions(opus
PRIVATE
$<$<BOOL:${HAVE_LRINT}>:HAVE_LRINT>
$<$<BOOL:${HAVE_LRINTF}>:HAVE_LRINTF>)
$<$<BOOL:${HAVE_LRINTF}>:HAVE_LRINTF>
$<$<BOOL:${HAVE_ELF_AUX_INFO}>:HAVE_ELF_AUX_INFO>)

if(OPUS_BUILD_FRAMEWORK)
set_target_properties(opus PROPERTIES
Expand Down
34 changes: 33 additions & 1 deletion celt/arm/armcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static opus_uint32 opus_cpu_capabilities(void)
return flags;
}

#elif defined(__FreeBSD__)
#elif defined(HAVE_ELF_AUX_INFO)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why you need to change the FreeBSD case to add OpenBSD. Not against your OpenBSD patch but would like to make sure we don't break FreeBSD. More specifically, your HAVE_ELF_AUX_INFO is added to only two out of the four build systems we support.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not every release of FreeBSD nor OpenBSD has the elf_aux_info() API. This is how I've done things with pretty much every other project I've added OpenBSD or FreeBSD/OpenBSD support. I have now added and fixed the CMake support.

#include <sys/auxv.h>

static opus_uint32 opus_cpu_capabilities(void)
Expand Down Expand Up @@ -239,6 +239,38 @@ static opus_uint32 opus_cpu_capabilities(void)
return (flags);
}

#elif defined(__OpenBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#include <machine/armreg.h>
#include <machine/cpu.h>

static opus_uint32 opus_cpu_capabilities(void)
{
opus_uint32 flags = 0;

#if defined(OPUS_ARM_MAY_HAVE_DOTPROD) && defined(CPU_ID_AA64ISAR0)
const int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 };
uint64_t isar0;
size_t len = sizeof(isar0);

if (sysctl(isar0_mib, 2, &isar0, &len, NULL, 0) != -1)
{
if (ID_AA64ISAR0_DP(isar0) >= ID_AA64ISAR0_DP_IMPL)
flags |= OPUS_CPU_ARM_DOTPROD_FLAG;
}
#endif

#if defined(OPUS_ARM_PRESUME_NEON_INTR) \
|| defined(OPUS_ARM_PRESUME_AARCH64_NEON_INTR)
flags |= OPUS_CPU_ARM_EDSP_FLAG | OPUS_CPU_ARM_MEDIA_FLAG | OPUS_CPU_ARM_NEON_FLAG;
# if defined(OPUS_ARM_PRESUME_DOTPROD)
flags |= OPUS_CPU_ARM_DOTPROD_FLAG;
# endif
#endif
return flags;
}

#else
/* The feature registers which can tell us what the processor supports are
* accessible in priveleged modes only, so we can't have a general user-space
Expand Down
1 change: 1 addition & 0 deletions cmake/OpusConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ endif()

check_symbol_exists(lrintf "math.h" HAVE_LRINTF)
check_symbol_exists(lrint "math.h" HAVE_LRINT)
check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO)
cmake_pop_check_state()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "(i[0-9]86|x86|X86|amd64|AMD64|x86_64)")
Expand Down
6 changes: 3 additions & 3 deletions cmake/OpusFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ function(opus_supports_cpu_detection RUNTIME_CPU_CAPABILITY_DETECTION)
endif()
endif()
elseif(OPUS_CPU_ARM)
# ARM cpu detection is implemented for Windows and anything
# using a Linux kernel (such as Android).
if (CMAKE_SYSTEM_NAME MATCHES "(Windows|Linux|Android)")
# ARM cpu detection is implemented for Windows, Linux, Android, FreeBSD
# and OpenBSD.
if (CMAKE_SYSTEM_NAME MATCHES "(Windows|Linux|Android|FreeBSD|OpenBSD)")
set(RUNTIME_CPU_CAPABILITY_DETECTION 1 PARENT_SCOPE)
endif ()
else()
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ AC_CHECK_FUNCS([lrintf])
AC_CHECK_FUNCS([lrint])
LIBS="$saved_LIBS"

AC_CHECK_FUNCS([__malloc_hook])
AC_CHECK_FUNCS([__malloc_hook elf_aux_info])

AC_SUBST([PC_BUILD])

Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ libm = cc.find_library('m', required : false)
opus_conf.set('HAVE_LRINTF', cc.has_function('lrintf', prefix: '#include <math.h>', dependencies: libm))
opus_conf.set('HAVE_LRINT', cc.has_function('lrint', prefix: '#include <math.h>', dependencies: libm))
opus_conf.set('HAVE___MALLOC_HOOK', cc.has_function('__malloc_hook', prefix: '#include <malloc.h>'))
opus_conf.set('HAVE_ELF_AUX_INFO', cc.has_function('elf_aux_info', prefix: '#include <sys/auxv.h>'))
opus_conf.set('HAVE_STDINT_H', cc.check_header('stdint.h'))

# Check for restrict keyword
Expand Down