From 90f833894d7d732c2bf8f045a52d45a36ae34dda Mon Sep 17 00:00:00 2001 From: Michael Bradshaw Date: Tue, 10 Sep 2024 10:54:55 -0600 Subject: [PATCH] Use #if HAVE_* instead of #ifdef HAVE_* --- examples/dp_renderer.h | 22 ++++-- examples/dp_renderer_placebo.c | 22 +++--- examples/meson.build | 10 ++- meson.build | 123 ++++++++++++++++----------------- src/arm/cpu.c | 6 +- src/cpu.c | 8 +-- src/lib.c | 4 +- src/loongarch/cpu.c | 4 +- src/mem.h | 8 +-- src/ppc/cpu.c | 10 +-- src/riscv/cpu.c | 4 +- src/thread.h | 10 +-- tests/checkasm/checkasm.c | 8 +-- tests/checkasm/checkasm.h | 2 +- tests/seek_stress.c | 2 +- tools/dav1d.c | 6 +- tools/dav1d_cli_parse.c | 2 +- tools/input/section5.c | 2 +- 18 files changed, 131 insertions(+), 122 deletions(-) diff --git a/examples/dp_renderer.h b/examples/dp_renderer.h index a4373444..513e2ad6 100644 --- a/examples/dp_renderer.h +++ b/examples/dp_renderer.h @@ -30,22 +30,32 @@ #include "dav1d/dav1d.h" #include -#ifdef HAVE_PLACEBO +#if HAVE_PLACEBO # include #endif // Check libplacebo Vulkan rendering -#if defined(HAVE_VULKAN) && defined(SDL_VIDEO_VULKAN) +#if HAVE_VULKAN && defined(SDL_VIDEO_VULKAN) # if defined(PL_HAVE_VULKAN) && PL_HAVE_VULKAN -# define HAVE_RENDERER_PLACEBO -# define HAVE_PLACEBO_VULKAN +# define HAVE_RENDERER_PLACEBO 1 +# define HAVE_PLACEBO_VULKAN 1 # endif #endif // Check libplacebo OpenGL rendering #if defined(PL_HAVE_OPENGL) && PL_HAVE_OPENGL -# define HAVE_RENDERER_PLACEBO -# define HAVE_PLACEBO_OPENGL +# define HAVE_RENDERER_PLACEBO 1 +# define HAVE_PLACEBO_OPENGL 1 +#endif + +#ifndef HAVE_RENDERER_PLACEBO +#define HAVE_RENDERER_PLACEBO 0 +#endif +#ifndef HAVE_PLACEBO_VULKAN +#define HAVE_PLACEBO_VULKAN 0 +#endif +#ifndef HAVE_PLACEBO_OPENGL +#define HAVE_PLACEBO_OPENGL 0 #endif /** diff --git a/examples/dp_renderer_placebo.c b/examples/dp_renderer_placebo.c index 3506bdef..972cc576 100644 --- a/examples/dp_renderer_placebo.c +++ b/examples/dp_renderer_placebo.c @@ -26,17 +26,17 @@ #include "dp_renderer.h" -#ifdef HAVE_RENDERER_PLACEBO +#if HAVE_RENDERER_PLACEBO #include #include #include -#ifdef HAVE_PLACEBO_VULKAN +#if HAVE_PLACEBO_VULKAN # include # include #endif -#ifdef HAVE_PLACEBO_OPENGL +#if HAVE_PLACEBO_OPENGL # include # include #endif @@ -53,7 +53,7 @@ typedef struct renderer_priv_ctx pl_log log; // Placebo renderer pl_renderer renderer; -#ifdef HAVE_PLACEBO_VULKAN +#if HAVE_PLACEBO_VULKAN // Placebo Vulkan handle pl_vulkan vk; // Placebo Vulkan instance @@ -61,7 +61,7 @@ typedef struct renderer_priv_ctx // Vulkan surface VkSurfaceKHR surf; #endif -#ifdef HAVE_PLACEBO_OPENGL +#if HAVE_PLACEBO_OPENGL // Placebo OpenGL handle pl_opengl gl; // SDL OpenGL context @@ -125,7 +125,7 @@ static Dav1dPlayRendererPrivateContext* return rd_priv_ctx; } -#ifdef HAVE_PLACEBO_OPENGL +#if HAVE_PLACEBO_OPENGL static void *placebo_renderer_create_gl(const Dav1dPlaySettings *settings) { SDL_Window *sdlwin = NULL; @@ -181,7 +181,7 @@ static void *placebo_renderer_create_gl(const Dav1dPlaySettings *settings) } #endif -#ifdef HAVE_PLACEBO_VULKAN +#if HAVE_PLACEBO_VULKAN static void *placebo_renderer_create_vk(const Dav1dPlaySettings *settings) { SDL_Window *sdlwin = NULL; @@ -278,14 +278,14 @@ static void placebo_renderer_destroy(void *cookie) for (int i = 0; i < 3; i++) pl_tex_destroy(rd_priv_ctx->gpu, &(rd_priv_ctx->plane_tex[i])); -#ifdef HAVE_PLACEBO_VULKAN +#if HAVE_PLACEBO_VULKAN if (rd_priv_ctx->vk) { pl_vulkan_destroy(&(rd_priv_ctx->vk)); vkDestroySurfaceKHR(rd_priv_ctx->vk_inst->instance, rd_priv_ctx->surf, NULL); pl_vk_inst_destroy(&(rd_priv_ctx->vk_inst)); } #endif -#ifdef HAVE_PLACEBO_OPENGL +#if HAVE_PLACEBO_OPENGL if (rd_priv_ctx->gl) pl_opengl_destroy(&(rd_priv_ctx->gl)); if (rd_priv_ctx->gl_context) @@ -392,7 +392,7 @@ static void placebo_release_pic(Dav1dPicture *pic, void *cookie) SDL_UnlockMutex(rd_priv_ctx->lock); } -#ifdef HAVE_PLACEBO_VULKAN +#if HAVE_PLACEBO_VULKAN const Dav1dPlayRenderInfo rdr_placebo_vk = { .name = "placebo-vk", .create_renderer = placebo_renderer_create_vk, @@ -407,7 +407,7 @@ const Dav1dPlayRenderInfo rdr_placebo_vk = { const Dav1dPlayRenderInfo rdr_placebo_vk = { NULL }; #endif -#ifdef HAVE_PLACEBO_OPENGL +#if HAVE_PLACEBO_OPENGL const Dav1dPlayRenderInfo rdr_placebo_gl = { .name = "placebo-gl", .create_renderer = placebo_renderer_create_gl, diff --git a/examples/meson.build b/examples/meson.build index 2b2b8bd5..adbf85b7 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -48,19 +48,23 @@ if sdl2_dependency.found() placebo_dependency = dependency('libplacebo', version: '>= 4.160.0', required: false) - if placebo_dependency.found() + have_vulkan = false + have_placebo = placebo_dependency.found() + if have_placebo dav1dplay_deps += placebo_dependency - dav1dplay_cflags += '-DHAVE_PLACEBO' # If libplacebo is found, we might be able to use Vulkan # with it, in which case we need the Vulkan library too. vulkan_dependency = dependency('vulkan', required: false) if vulkan_dependency.found() dav1dplay_deps += vulkan_dependency - dav1dplay_cflags += '-DHAVE_VULKAN' + have_vulkan = true endif endif + dav1dplay_cflags += '-DHAVE_PLACEBO=' + (have_placebo ? '1' : '0') + dav1dplay_cflags += '-DHAVE_VULKAN=' + (have_vulkan ? '1' : '0') + dav1dplay = executable('dav1dplay', dav1dplay_sources, rev_target, diff --git a/meson.build b/meson.build index f18968c5..194f5bea 100644 --- a/meson.build +++ b/meson.build @@ -103,6 +103,10 @@ if host_machine.system() in ['linux', 'gnu', 'emscripten'] add_project_arguments('-D_GNU_SOURCE', language: 'c') endif +have_clock_gettime = false +have_posix_memalign = false +have_memalign = false +have_aligned_alloc = false if host_machine.system() == 'windows' cdata.set('_WIN32_WINNT', '0x0601') cdata.set('UNICODE', 1) # Define to 1 for Unicode (Wide Chars) APIs @@ -150,26 +154,25 @@ else rt_dependency = [] if cc.has_function('clock_gettime', prefix : '#include ', args : test_args) - cdata.set('HAVE_CLOCK_GETTIME', 1) + have_clock_gettime = true elif host_machine.system() not in ['darwin', 'ios', 'tvos'] rt_dependency = cc.find_library('rt', required: false) if not cc.has_function('clock_gettime', prefix : '#include ', args : test_args, dependencies : rt_dependency) error('clock_gettime not found') endif - cdata.set('HAVE_CLOCK_GETTIME', 1) + have_clock_gettime = true endif - if cc.has_function('posix_memalign', prefix : '#include ', args : test_args) - cdata.set('HAVE_POSIX_MEMALIGN', 1) - endif - if cc.has_function('memalign', prefix : '#include ', args : test_args) - cdata.set('HAVE_MEMALIGN', 1) - endif - if cc.has_function('aligned_alloc', prefix : '#include ', args : test_args) - cdata.set('HAVE_ALIGNED_ALLOC', 1) - endif + have_posix_memalign = cc.has_function('posix_memalign', prefix : '#include ', args : test_args) + have_memalign = cc.has_function('memalign', prefix : '#include ', args : test_args) + have_aligned_alloc = cc.has_function('aligned_alloc', prefix : '#include ', args : test_args) endif +cdata.set10('HAVE_CLOCK_GETTIME', have_clock_gettime) +cdata.set10('HAVE_POSIX_MEMALIGN', have_posix_memalign) +cdata.set10('HAVE_MEMALIGN', have_memalign) +cdata.set10('HAVE_ALIGNED_ALLOC', have_aligned_alloc) + # check for fseeko on android. It is not always available if _FILE_OFFSET_BITS is defined to 64 have_fseeko = true if host_machine.system() == 'android' @@ -186,12 +189,12 @@ if host_machine.system() == 'android' endif libdl_dependency = [] +have_dlsym = false if host_machine.system() == 'linux' libdl_dependency = cc.find_library('dl', required : false) - if cc.has_function('dlsym', prefix : '#include ', args : test_args, dependencies : libdl_dependency) - cdata.set('HAVE_DLSYM', 1) - endif + have_dlsym = cc.has_function('dlsym', prefix : '#include ', args : test_args, dependencies : libdl_dependency) endif +cdata.set10('HAVE_DLSYM', have_dlsym) libm_dependency = cc.find_library('m', required: false) @@ -220,23 +223,13 @@ if host_machine.cpu_family().startswith('wasm') stdatomic_dependencies += thread_dependency.partial_dependency(compile_args: true) endif -if cc.check_header('sys/types.h') - cdata.set('HAVE_SYS_TYPES_H', 1) -endif - -if cc.check_header('unistd.h') - cdata.set('HAVE_UNISTD_H', 1) -endif - -if cc.check_header('io.h') - cdata.set('HAVE_IO_H', 1) -endif - -if cc.check_header('pthread_np.h') - cdata.set('HAVE_PTHREAD_NP_H', 1) - test_args += '-DHAVE_PTHREAD_NP_H' -endif +cdata.set10('HAVE_SYS_TYPES_H', cc.check_header('sys/types.h')) +cdata.set10('HAVE_UNISTD_H', cc.check_header('unistd.h')) +cdata.set10('HAVE_IO_H', cc.check_header('io.h')) +have_pthread_np = cc.check_header('pthread_np.h') +cdata.set10('HAVE_PTHREAD_NP_H', have_pthread_np) +test_args += '-DHAVE_PTHREAD_NP_H=' + (have_pthread_np ? '1' : '0') # Function checks @@ -249,41 +242,32 @@ else getopt_dependency = [] endif +have_getauxval = false +have_elf_aux_info = false if (host_machine.cpu_family() == 'aarch64' or host_machine.cpu_family().startswith('arm') or host_machine.cpu_family().startswith('loongarch') or host_machine.cpu() == 'ppc64le' or host_machine.cpu_family().startswith('riscv')) - if cc.has_function('getauxval', prefix : '#include ', args : test_args) - cdata.set('HAVE_GETAUXVAL', 1) - endif - if cc.has_function('elf_aux_info', prefix : '#include ', args : test_args) - cdata.set('HAVE_ELF_AUX_INFO', 1) - endif + have_getauxval = cc.has_function('getauxval', prefix : '#include ', args : test_args) + have_elf_aux_info = cc.has_function('elf_aux_info', prefix : '#include ', args : test_args) endif +cdata.set10('HAVE_GETAUXVAL', have_getauxval) +cdata.set10('HAVE_ELF_AUX_INFO', have_elf_aux_info) + pthread_np_prefix = ''' #include -#ifdef HAVE_PTHREAD_NP_H +#if HAVE_PTHREAD_NP_H #include #endif ''' -if cc.has_function('pthread_getaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency) - cdata.set('HAVE_PTHREAD_GETAFFINITY_NP', 1) -endif -if cc.has_function('pthread_setaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency) - cdata.set('HAVE_PTHREAD_SETAFFINITY_NP', 1) -endif -if cc.has_function('pthread_setname_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency) - cdata.set('HAVE_PTHREAD_SETNAME_NP', 1) -endif -if cc.has_function('pthread_set_name_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency) - cdata.set('HAVE_PTHREAD_SET_NAME_NP', 1) -endif +cdata.set10('HAVE_PTHREAD_GETAFFINITY_NP', cc.has_function('pthread_getaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)) +cdata.set10('HAVE_PTHREAD_SETAFFINITY_NP', cc.has_function('pthread_setaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)) +cdata.set10('HAVE_PTHREAD_SETNAME_NP', cc.has_function('pthread_setname_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)) +cdata.set10('HAVE_PTHREAD_SET_NAME_NP', cc.has_function('pthread_set_name_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)) -if cc.compiles('int x = _Generic(0, default: 0);', name: '_Generic', args: test_args) - cdata.set('HAVE_C11_GENERIC', 1) -endif +cdata.set10('HAVE_C11_GENERIC', cc.compiles('int x = _Generic(0, default: 0);', name: '_Generic', args: test_args)) # Compiler flag tests @@ -364,6 +348,17 @@ endif cdata.set10('ARCH_AARCH64', host_machine.cpu_family() == 'aarch64' or host_machine.cpu() == 'arm64') cdata.set10('ARCH_ARM', host_machine.cpu_family().startswith('arm') and host_machine.cpu() != 'arm64') + +have_as_func = false +have_as_arch = false +aarch64_extensions = { + 'dotprod': 'udot v0.4s, v0.16b, v0.16b', + 'i8mm': 'usdot v0.4s, v0.16b, v0.16b', + 'sve': 'whilelt p0.s, x0, x1', + 'sve2': 'sqrdmulh z0.s, z0.s, z0.s', +} +supported_aarch64_archexts = [] +supported_aarch64_instructions = [] if (is_asm_enabled and (host_machine.cpu_family() == 'aarch64' or host_machine.cpu_family().startswith('arm'))) @@ -374,7 +369,6 @@ if (is_asm_enabled and ); ''' have_as_func = cc.compiles(as_func_code) - cdata.set10('HAVE_AS_FUNC', have_as_func) # fedora package build infrastructure uses a gcc specs file to enable # '-fPIE' by default. The chosen way only adds '-fPIE' to the C compiler @@ -395,7 +389,6 @@ if (is_asm_enabled and if host_machine.cpu_family() == 'aarch64' have_as_arch = cc.compiles('''__asm__ (".arch armv8-a");''') - cdata.set10('HAVE_AS_ARCH_DIRECTIVE', have_as_arch) as_arch_str = '' if have_as_arch as_arch_level = 'armv8-a' @@ -424,13 +417,7 @@ if (is_asm_enabled and cdata.set('AS_ARCH_LEVEL', as_arch_level) as_arch_str = '".arch ' + as_arch_level + '\\n"' endif - extensions = { - 'dotprod': 'udot v0.4s, v0.16b, v0.16b', - 'i8mm': 'usdot v0.4s, v0.16b, v0.16b', - 'sve': 'whilelt p0.s, x0, x1', - 'sve2': 'sqrdmulh z0.s, z0.s, z0.s', - } - foreach name, instr : extensions + foreach name, instr : aarch64_extensions # Test for support for the various extensions. First test if # the assembler supports the .arch_extension directive for # enabling/disabling the extension, then separately check whether @@ -441,19 +428,27 @@ if (is_asm_enabled and code += '".arch_extension ' + name + '\\n"' code += ');' supports_archext = cc.compiles(code) - cdata.set10('HAVE_AS_ARCHEXT_' + name.to_upper() + '_DIRECTIVE', supports_archext) code = '__asm__ (' + as_arch_str if supports_archext + supported_aarch64_archexts += name code += '".arch_extension ' + name + '\\n"' endif code += '"' + instr + '\\n"' code += ');' - supports_instr = cc.compiles(code, name: name.to_upper()) - cdata.set10('HAVE_' + name.to_upper(), supports_instr) + if cc.compiles(code, name: name.to_upper()) + supported_aarch64_instructions += name + endif endforeach endif endif +cdata.set10('HAVE_AS_FUNC', have_as_func) +cdata.set10('HAVE_AS_ARCH_DIRECTIVE', have_as_arch) +foreach name, _ : aarch64_extensions + cdata.set10('HAVE_AS_ARCHEXT_' + name.to_upper() + '_DIRECTIVE', name in supported_aarch64_archexts) + cdata.set10('HAVE_' + name.to_upper(), name in supported_aarch64_instructions) +endforeach + cdata.set10('ARCH_X86', host_machine.cpu_family().startswith('x86')) cdata.set10('ARCH_X86_64', host_machine.cpu_family() == 'x86_64') cdata.set10('ARCH_X86_32', host_machine.cpu_family() == 'x86') diff --git a/src/arm/cpu.c b/src/arm/cpu.c index d59b8da8..5275b740 100644 --- a/src/arm/cpu.c +++ b/src/arm/cpu.c @@ -32,7 +32,7 @@ #include "src/cpu.h" #include "src/arm/cpu.h" -#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO) +#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO #include #if ARCH_AARCH64 @@ -43,7 +43,7 @@ #define HWCAP2_AARCH64_I8MM (1 << 13) COLD unsigned dav1d_get_cpu_flags_arm(void) { -#ifdef HAVE_GETAUXVAL +#if HAVE_GETAUXVAL unsigned long hw_cap = getauxval(AT_HWCAP); unsigned long hw_cap2 = getauxval(AT_HWCAP2); #else @@ -69,7 +69,7 @@ COLD unsigned dav1d_get_cpu_flags_arm(void) { #define HWCAP_ARM_I8MM (1 << 27) COLD unsigned dav1d_get_cpu_flags_arm(void) { -#ifdef HAVE_GETAUXVAL +#if HAVE_GETAUXVAL unsigned long hw_cap = getauxval(AT_HWCAP); #else unsigned long hw_cap = 0; diff --git a/src/cpu.c b/src/cpu.c index dcdc66c9..41526671 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -38,13 +38,13 @@ #include #include #endif -#ifdef HAVE_UNISTD_H +#if HAVE_UNISTD_H #include #endif -#ifdef HAVE_PTHREAD_GETAFFINITY_NP +#if HAVE_PTHREAD_GETAFFINITY_NP #include -#ifdef HAVE_PTHREAD_NP_H +#if HAVE_PTHREAD_NP_H #include #endif #if defined(__FreeBSD__) @@ -91,7 +91,7 @@ COLD int dav1d_num_logical_processors(Dav1dContext *const c) { GetNativeSystemInfo(&system_info); return system_info.dwNumberOfProcessors; #endif -#elif defined(HAVE_PTHREAD_GETAFFINITY_NP) && defined(CPU_COUNT) +#elif HAVE_PTHREAD_GETAFFINITY_NP && defined(CPU_COUNT) cpu_set_t affinity; if (!pthread_getaffinity_np(pthread_self(), sizeof(affinity), &affinity)) return CPU_COUNT(&affinity); diff --git a/src/lib.c b/src/lib.c index 4d9a2d30..6d2d80dd 100644 --- a/src/lib.c +++ b/src/lib.c @@ -31,7 +31,7 @@ #include #include -#if defined(__linux__) && defined(HAVE_DLSYM) +#if defined(__linux__) && HAVE_DLSYM #include #endif @@ -90,7 +90,7 @@ static void close_internal(Dav1dContext **const c_out, int flush); NO_SANITIZE("cfi-icall") // CFI is broken with dlsym() static COLD size_t get_stack_size_internal(const pthread_attr_t *const thread_attr) { -#if defined(__linux__) && defined(HAVE_DLSYM) && defined(__GLIBC__) +#if defined(__linux__) && HAVE_DLSYM && defined(__GLIBC__) /* glibc has an issue where the size of the TLS is subtracted from the stack * size instead of allocated separately. As a result the specified stack * size may be insufficient when used in an application with large amounts diff --git a/src/loongarch/cpu.c b/src/loongarch/cpu.c index 0ed7216c..383aa01e 100644 --- a/src/loongarch/cpu.c +++ b/src/loongarch/cpu.c @@ -30,7 +30,7 @@ #include "src/cpu.h" #include "src/loongarch/cpu.h" -#if defined(HAVE_GETAUXVAL) +#if HAVE_GETAUXVAL #include #define LA_HWCAP_LSX ( 1 << 4 ) @@ -39,7 +39,7 @@ COLD unsigned dav1d_get_cpu_flags_loongarch(void) { unsigned flags = dav1d_get_default_cpu_flags(); -#if defined(HAVE_GETAUXVAL) +#if HAVE_GETAUXVAL unsigned long hw_cap = getauxval(AT_HWCAP); flags |= (hw_cap & LA_HWCAP_LSX) ? DAV1D_LOONGARCH_CPU_FLAG_LSX : 0; flags |= (hw_cap & LA_HWCAP_LASX) ? DAV1D_LOONGARCH_CPU_FLAG_LASX : 0; diff --git a/src/mem.h b/src/mem.h index 25a44a79..c8c45d31 100644 --- a/src/mem.h +++ b/src/mem.h @@ -32,7 +32,7 @@ #include -#if defined(_WIN32) || defined(HAVE_MEMALIGN) +#if defined(_WIN32) || HAVE_MEMALIGN #include #endif @@ -90,13 +90,13 @@ static inline void *dav1d_alloc_aligned_internal(const size_t sz, const size_t a assert(!(align & (align - 1))); #ifdef _WIN32 return _aligned_malloc(sz, align); -#elif defined(HAVE_POSIX_MEMALIGN) +#elif HAVE_POSIX_MEMALIGN void *ptr; if (posix_memalign(&ptr, align, sz)) return NULL; return ptr; -#elif defined(HAVE_MEMALIGN) +#elif HAVE_MEMALIGN return memalign(align, sz); -#elif defined(HAVE_ALIGNED_ALLOC) +#elif HAVE_ALIGNED_ALLOC // The C11 standard specifies that the size parameter // must be an integral multiple of alignment. return aligned_alloc(align, ROUND_UP(sz, align)); diff --git a/src/ppc/cpu.c b/src/ppc/cpu.c index 6c55c0bb..f58e8fbf 100644 --- a/src/ppc/cpu.c +++ b/src/ppc/cpu.c @@ -32,23 +32,23 @@ #include "src/cpu.h" #include "src/ppc/cpu.h" -#if (defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)) && ARCH_PPC64LE +#define HAVE_AUX ((HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO) && ARCH_PPC64LE) +#if HAVE_AUX #include -#define HAVE_AUX #endif COLD unsigned dav1d_get_cpu_flags_ppc(void) { unsigned flags = dav1d_get_default_cpu_flags(); -#if defined(HAVE_GETAUXVAL) && ARCH_PPC64LE +#if HAVE_GETAUXVAL && ARCH_PPC64LE unsigned long hw_cap = getauxval(AT_HWCAP); unsigned long hw_cap2 = getauxval(AT_HWCAP2); -#elif defined(HAVE_ELF_AUX_INFO) && ARCH_PPC64LE +#elif HAVE_ELF_AUX_INFO && ARCH_PPC64LE unsigned long hw_cap = 0; unsigned long hw_cap2 = 0; elf_aux_info(AT_HWCAP, &hw_cap, sizeof(hw_cap)); elf_aux_info(AT_HWCAP2, &hw_cap2, sizeof(hw_cap2)); #endif -#ifdef HAVE_AUX +#if HAVE_AUX flags |= (hw_cap & PPC_FEATURE_HAS_VSX) ? DAV1D_PPC_CPU_FLAG_VSX : 0; flags |= (hw_cap2 & PPC_FEATURE2_ARCH_3_00) ? DAV1D_PPC_CPU_FLAG_PWR9 : 0; #endif diff --git a/src/riscv/cpu.c b/src/riscv/cpu.c index 98356ccc..345ff079 100644 --- a/src/riscv/cpu.c +++ b/src/riscv/cpu.c @@ -32,7 +32,7 @@ #include "src/cpu.h" #include "src/riscv/cpu.h" -#if defined(HAVE_GETAUXVAL) +#if HAVE_GETAUXVAL #include #define HWCAP_RVV (1 << ('v' - 'a')) @@ -43,7 +43,7 @@ int dav1d_has_compliant_rvv(void); COLD unsigned dav1d_get_cpu_flags_riscv(void) { unsigned flags = dav1d_get_default_cpu_flags(); -#if defined(HAVE_GETAUXVAL) +#if HAVE_GETAUXVAL unsigned long hw_cap = getauxval(AT_HWCAP); flags |= (hw_cap & HWCAP_RVV) && dav1d_has_compliant_rvv() ? DAV1D_RISCV_CPU_FLAG_V : 0; #endif diff --git a/src/thread.h b/src/thread.h index dfdb45ea..459aaced 100644 --- a/src/thread.h +++ b/src/thread.h @@ -137,7 +137,7 @@ static inline int pthread_cond_broadcast(pthread_cond_t *const cond) { #define _SYS_PARAM_H_ #include #endif -#ifdef HAVE_PTHREAD_NP_H +#if HAVE_PTHREAD_NP_H #include #endif @@ -153,25 +153,25 @@ static inline void dav1d_set_thread_name(const char *const name) { prctl(PR_SET_NAME, name); } -#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(__APPLE__) +#elif HAVE_PTHREAD_SETNAME_NP && defined(__APPLE__) static inline void dav1d_set_thread_name(const char *const name) { pthread_setname_np(name); } -#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(__NetBSD__) +#elif HAVE_PTHREAD_SETNAME_NP && defined(__NetBSD__) static inline void dav1d_set_thread_name(const char *const name) { pthread_setname_np(pthread_self(), "%s", (void*)name); } -#elif defined(HAVE_PTHREAD_SETNAME_NP) +#elif HAVE_PTHREAD_SETNAME_NP static inline void dav1d_set_thread_name(const char *const name) { pthread_setname_np(pthread_self(), name); } -#elif defined(HAVE_PTHREAD_SET_NAME_NP) +#elif HAVE_PTHREAD_SET_NAME_NP static inline void dav1d_set_thread_name(const char *const name) { pthread_set_name_np(pthread_self(), name); diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 4804f95b..f890ae12 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -45,12 +45,12 @@ #endif #else #include -#ifdef HAVE_UNISTD_H +#if HAVE_UNISTD_H #include #endif -#ifdef HAVE_PTHREAD_SETAFFINITY_NP +#if HAVE_PTHREAD_SETAFFINITY_NP #include -#ifdef HAVE_PTHREAD_NP_H +#if HAVE_PTHREAD_NP_H #include #endif #endif @@ -736,7 +736,7 @@ int main(int argc, char *argv[]) { } else { fprintf(stderr, "checkasm: running on cpu %lu\n", affinity); } -#elif defined(HAVE_PTHREAD_SETAFFINITY_NP) && defined(CPU_SET) +#elif HAVE_PTHREAD_SETAFFINITY_NP && defined(CPU_SET) cpu_set_t set; CPU_ZERO(&set); CPU_SET(affinity, &set); diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 29de9b64..762caf6b 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -254,7 +254,7 @@ void checkasm_simd_warmup(void); * handled orthogonally from integer parameters passed in GPR registers. */ #define IGNORED_FP_ARGS 8 #endif -#ifdef HAVE_C11_GENERIC +#if HAVE_C11_GENERIC #define clobber_type(arg) _Generic((void (*)(void*, arg))NULL,\ void (*)(void*, int32_t ): clobber_mask |= 1 << mpos++,\ void (*)(void*, uint32_t): clobber_mask |= 1 << mpos++,\ diff --git a/tests/seek_stress.c b/tests/seek_stress.c index a85ec868..7f75ea86 100644 --- a/tests/seek_stress.c +++ b/tests/seek_stress.c @@ -60,7 +60,7 @@ static unsigned get_seed(void) { static unsigned get_seed(void) { #ifdef __APPLE__ return (unsigned) mach_absolute_time(); -#elif defined(HAVE_CLOCK_GETTIME) +#elif HAVE_CLOCK_GETTIME struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (unsigned) (1000000000ULL * ts.tv_sec + ts.tv_nsec); diff --git a/tools/dav1d.c b/tools/dav1d.c index 4d8d072d..eb19a80b 100644 --- a/tools/dav1d.c +++ b/tools/dav1d.c @@ -38,10 +38,10 @@ #include #include #include -#ifdef HAVE_UNISTD_H +#if HAVE_UNISTD_H # include #endif -#ifdef HAVE_IO_H +#if HAVE_IO_H # include #endif #ifdef _WIN32 @@ -68,7 +68,7 @@ static uint64_t get_time_nanos(void) { uint64_t seconds = t.QuadPart / frequency.QuadPart; uint64_t fractions = t.QuadPart % frequency.QuadPart; return 1000000000 * seconds + 1000000000 * fractions / frequency.QuadPart; -#elif defined(HAVE_CLOCK_GETTIME) +#elif HAVE_CLOCK_GETTIME struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return 1000000000ULL * ts.tv_sec + ts.tv_nsec; diff --git a/tools/dav1d_cli_parse.c b/tools/dav1d_cli_parse.c index f4259643..134be46b 100644 --- a/tools/dav1d_cli_parse.c +++ b/tools/dav1d_cli_parse.c @@ -35,7 +35,7 @@ #include #include #include -#ifdef HAVE_UNISTD_H +#if HAVE_UNISTD_H # include #endif diff --git a/tools/input/section5.c b/tools/input/section5.c index 9c850902..99cb7615 100644 --- a/tools/input/section5.c +++ b/tools/input/section5.c @@ -32,7 +32,7 @@ #include #include #include -#ifdef HAVE_SYS_TYPES_H +#if HAVE_SYS_TYPES_H #include #endif