From bdfe42a984b0017d280081e6391ae4c82c6c27e7 Mon Sep 17 00:00:00 2001 From: Vladimir Sadovnikov Date: Fri, 21 Jun 2024 00:18:49 +0300 Subject: [PATCH] Updated atomic functions --- .../lsp-plug.in/common/arch/aarch64/atomic.h | 33 +++++++++++------ include/lsp-plug.in/common/arch/arm/atomic.h | 27 +++++++++----- .../lsp-plug.in/common/arch/generic/atomic.h | 33 +++++++++++------ include/lsp-plug.in/common/arch/x86/atomic.h | 35 ++++++++++++------- 4 files changed, 85 insertions(+), 43 deletions(-) diff --git a/include/lsp-plug.in/common/arch/aarch64/atomic.h b/include/lsp-plug.in/common/arch/aarch64/atomic.h index 48a12e0..4b14c1b 100644 --- a/include/lsp-plug.in/common/arch/aarch64/atomic.h +++ b/include/lsp-plug.in/common/arch/aarch64/atomic.h @@ -26,8 +26,8 @@ #error "This file should not be included directly" #endif /* LSP_PLUG_IN_COMMON_ATOMIC_IMPL */ -#define ATOMIC_LOAD_DEF(type, qsz, mod) \ - inline type atomic_load(type *ptr) \ +#define ATOMIC_LOAD_DEF(type, ptrtype, qsz, mod) \ + inline type atomic_load(ptrtype, ptr) \ { \ type tmp; \ \ @@ -43,15 +43,26 @@ namespace lsp { - ATOMIC_LOAD_DEF(int8_t, "sb", "w") - ATOMIC_LOAD_DEF(uint8_t, "b", "w") - ATOMIC_LOAD_DEF(int16_t, "sh", "w") - ATOMIC_LOAD_DEF(uint16_t, "h", "w") - ATOMIC_LOAD_DEF(int32_t, "", "w") - ATOMIC_LOAD_DEF(uint32_t, "", "w") - ATOMIC_LOAD_DEF(int64_t, "", "x") - ATOMIC_LOAD_DEF(uint64_t, "", "x") - ATOMIC_LOAD_DEF(void *, "", "x") + ATOMIC_LOAD_DEF(int8_t, int8_t *, "sb", "w") + ATOMIC_LOAD_DEF(int8_t, const int8_t *, "sb", "w") + ATOMIC_LOAD_DEF(uint8_t, uint8_t *, "b", "w") + ATOMIC_LOAD_DEF(uint8_t, const uint8_t *, "b", "w") + ATOMIC_LOAD_DEF(int16_t, int16_t *, "sh", "w") + ATOMIC_LOAD_DEF(int16_t, const int16_t *, "sh", "w") + ATOMIC_LOAD_DEF(uint16_t, uint16_t *, "h", "w") + ATOMIC_LOAD_DEF(uint16_t, const uint16_t *, "h", "w") + ATOMIC_LOAD_DEF(int32_t, int32_t *, "", "w") + ATOMIC_LOAD_DEF(int32_t, const int32_t *, "", "w") + ATOMIC_LOAD_DEF(uint32_t, uint32_t *, "", "w") + ATOMIC_LOAD_DEF(uint32_t, const uint32_t *, "", "w") + ATOMIC_LOAD_DEF(int64_t, int64_t *, "", "x") + ATOMIC_LOAD_DEF(int64_t, const int64_t *, "", "x") + ATOMIC_LOAD_DEF(uint64_t, uint64_t *, "", "x") + ATOMIC_LOAD_DEF(uint64_t, const uint64_t *, "", "x") + ATOMIC_LOAD_DEF(void *, void **, "", "x") + ATOMIC_LOAD_DEF(void *, void * const *, "", "x") + ATOMIC_LOAD_DEF(const void *, const void **, "", "x") + ATOMIC_LOAD_DEF(const void *, const void * const *, "", "x") } /* namespace lsp */ #undef ATOMIC_LOAD_DEF diff --git a/include/lsp-plug.in/common/arch/arm/atomic.h b/include/lsp-plug.in/common/arch/arm/atomic.h index 2f6abfa..da702eb 100644 --- a/include/lsp-plug.in/common/arch/arm/atomic.h +++ b/include/lsp-plug.in/common/arch/arm/atomic.h @@ -26,8 +26,8 @@ #error "This file should not be included directly" #endif /* LSP_PLUG_IN_COMMON_ATOMIC_IMPL */ -#define ATOMIC_LOAD_DEF(type, cmd) \ - inline type atomic_load(type *ptr) \ +#define ATOMIC_LOAD_DEF(type, ptrtype, cmd) \ + inline type atomic_load(ptrtype ptr) \ { \ type retval; \ ARCH_ARM_ASM( \ @@ -43,13 +43,22 @@ namespace lsp { - ATOMIC_LOAD_DEF(int8_t, "ldrb") - ATOMIC_LOAD_DEF(uint8_t, "ldrb") - ATOMIC_LOAD_DEF(int16_t, "ldrh") - ATOMIC_LOAD_DEF(uint16_t, "ldrh") - ATOMIC_LOAD_DEF(int32_t, "ldr") - ATOMIC_LOAD_DEF(uint32_t, "ldr") - ATOMIC_LOAD_DEF(void *, "ldr") + ATOMIC_LOAD_DEF(int8_t, int8_t *, "ldrb") + ATOMIC_LOAD_DEF(int8_t, const int8_t *, "ldrb") + ATOMIC_LOAD_DEF(uint8_t, uint8_t *, "ldrb") + ATOMIC_LOAD_DEF(uint8_t, const uint8_t *, "ldrb") + ATOMIC_LOAD_DEF(int16_t, int16_t *, "ldrh") + ATOMIC_LOAD_DEF(int16_t, const int16_t *, "ldrh") + ATOMIC_LOAD_DEF(uint16_t, uint16_t *, "ldrh") + ATOMIC_LOAD_DEF(uint16_t, const uint16_t *, "ldrh") + ATOMIC_LOAD_DEF(int32_t, int32_t *, "ldr") + ATOMIC_LOAD_DEF(int32_t, const int32_t *, "ldr") + ATOMIC_LOAD_DEF(uint32_t, uint32_t *, "ldr") + ATOMIC_LOAD_DEF(uint32_t, const uint32_t *, "ldr") + ATOMIC_LOAD_DEF(void *, void **, "ldr") + ATOMIC_LOAD_DEF(void *, void * const *, "ldr") + ATOMIC_LOAD_DEF(const void *, const void **, "ldr") + ATOMIC_LOAD_DEF(const void *, const void * const *, "ldr") } /* namespace lsp */ #undef ATOMIC_LOAD_DEF diff --git a/include/lsp-plug.in/common/arch/generic/atomic.h b/include/lsp-plug.in/common/arch/generic/atomic.h index b373bff..fbf216a 100644 --- a/include/lsp-plug.in/common/arch/generic/atomic.h +++ b/include/lsp-plug.in/common/arch/generic/atomic.h @@ -49,24 +49,35 @@ namespace lsp #undef ATOMIC_STORE_DEF -#define ATOMIC_LOAD_DEF(type) \ - inline type atomic_load(type *ptr) { \ +#define ATOMIC_LOAD_DEF(type, ptrtype) \ + inline type atomic_load(ptrtype ptr) { \ return __atomic_load_n(ptr, __ATOMIC_SEQ_CST); \ } namespace lsp { - ATOMIC_LOAD_DEF(int8_t) - ATOMIC_LOAD_DEF(uint8_t) - ATOMIC_LOAD_DEF(int16_t) - ATOMIC_LOAD_DEF(uint16_t) - ATOMIC_LOAD_DEF(int32_t) - ATOMIC_LOAD_DEF(uint32_t) - ATOMIC_LOAD_DEF(void *) + ATOMIC_LOAD_DEF(int8_t, int8_t *) + ATOMIC_LOAD_DEF(int8_t, const int8_t *) + ATOMIC_LOAD_DEF(uint8_t, uint8_t *) + ATOMIC_LOAD_DEF(uint8_t, const uint8_t *) + ATOMIC_LOAD_DEF(int16_t, int16_t *) + ATOMIC_LOAD_DEF(int16_t, const int16_t *) + ATOMIC_LOAD_DEF(uint16_t, uint16_t *) + ATOMIC_LOAD_DEF(uint16_t, const uint16_t *) + ATOMIC_LOAD_DEF(int32_t, int32_t *) + ATOMIC_LOAD_DEF(int32_t, const int32_t *) + ATOMIC_LOAD_DEF(uint32_t, uint32_t *) + ATOMIC_LOAD_DEF(uint32_t, const uint32_t *) + ATOMIC_LOAD_DEF(void *, void **) + ATOMIC_LOAD_DEF(void *, void * const *) + ATOMIC_LOAD_DEF(const void *, const void **) + ATOMIC_LOAD_DEF(const void *, const void * const *) #ifdef ARCH_64BIT - ATOMIC_LOAD_DEF(int64_t) - ATOMIC_LOAD_DEF(uint64_t) + ATOMIC_LOAD_DEF(int64_t, int64_t *) + ATOMIC_LOAD_DEF(int64_t, const int64_t *) + ATOMIC_LOAD_DEF(uint64_t, uint64_t *) + ATOMIC_LOAD_DEF(uint64_t, const uint64_t *) #endif /* ARCH_64BIT */ } /* namespace lsp */ diff --git a/include/lsp-plug.in/common/arch/x86/atomic.h b/include/lsp-plug.in/common/arch/x86/atomic.h index a1e0bbd..8f0ec84 100644 --- a/include/lsp-plug.in/common/arch/x86/atomic.h +++ b/include/lsp-plug.in/common/arch/x86/atomic.h @@ -26,8 +26,8 @@ #error "This file should not be included directly" #endif /* LSP_PLUG_IN_COMMON_ATOMIC_IMPL */ -#define ATOMIC_LOAD_DEF(type) \ - inline type atomic_load(type *ptr) \ +#define ATOMIC_LOAD_DEF(type, ptrtype) \ + inline type atomic_load(ptrtype ptr) \ { \ type value; \ ARCH_X86_ASM \ @@ -35,24 +35,35 @@ __ASM_EMIT("mov (%[ptr]), %[value]") \ : [value] "=&r"(value) \ : [ptr] "r" (ptr) \ - : "memory" \ + : \ ); \ return value; \ } namespace lsp { - ATOMIC_LOAD_DEF(int8_t) - ATOMIC_LOAD_DEF(uint8_t) - ATOMIC_LOAD_DEF(int16_t) - ATOMIC_LOAD_DEF(uint16_t) - ATOMIC_LOAD_DEF(int32_t) - ATOMIC_LOAD_DEF(uint32_t) - ATOMIC_LOAD_DEF(void *) + ATOMIC_LOAD_DEF(int8_t, int8_t *) + ATOMIC_LOAD_DEF(int8_t, const int8_t *) + ATOMIC_LOAD_DEF(uint8_t, uint8_t *) + ATOMIC_LOAD_DEF(uint8_t, const uint8_t *) + ATOMIC_LOAD_DEF(int16_t, int16_t *) + ATOMIC_LOAD_DEF(int16_t, const int16_t *) + ATOMIC_LOAD_DEF(uint16_t, uint16_t *) + ATOMIC_LOAD_DEF(uint16_t, const uint16_t *) + ATOMIC_LOAD_DEF(int32_t, int32_t *) + ATOMIC_LOAD_DEF(int32_t, const int32_t *) + ATOMIC_LOAD_DEF(uint32_t, uint32_t *) + ATOMIC_LOAD_DEF(uint32_t, const uint32_t *) + ATOMIC_LOAD_DEF(void *, void **) + ATOMIC_LOAD_DEF(void *, void * const *) + ATOMIC_LOAD_DEF(const void *, const void **) + ATOMIC_LOAD_DEF(const void *, const void * const *) #ifdef ARCH_X86_64 - ATOMIC_LOAD_DEF(int64_t) - ATOMIC_LOAD_DEF(uint64_t) + ATOMIC_LOAD_DEF(int64_t, int64_t *) + ATOMIC_LOAD_DEF(int64_t, const int64_t *) + ATOMIC_LOAD_DEF(uint64_t, uint64_t *) + ATOMIC_LOAD_DEF(uint64_t, const uint64_t *) #endif /* ARCH_X86_64 */ } /* namespace lsp */