Skip to content

Commit

Permalink
Updated atomic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sadko4u committed Jun 20, 2024
1 parent 06fcc15 commit bdfe42a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 43 deletions.
33 changes: 22 additions & 11 deletions include/lsp-plug.in/common/arch/aarch64/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
\
Expand All @@ -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
Expand Down
27 changes: 18 additions & 9 deletions include/lsp-plug.in/common/arch/arm/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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( \
Expand All @@ -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
Expand Down
33 changes: 22 additions & 11 deletions include/lsp-plug.in/common/arch/generic/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
35 changes: 23 additions & 12 deletions include/lsp-plug.in/common/arch/x86/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,44 @@
#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 \
( \
__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 */
Expand Down

0 comments on commit bdfe42a

Please sign in to comment.