Skip to content

Adding 'sb' instruction to spin_delay() for ARM v8.5 onward #18

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: master
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion src/include/aerospike/as_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,39 @@

#elif defined __aarch64__

#define as_arch_pause() asm volatile("isb" : : : "memory")
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
#include <sys/auxv.h>

#ifndef HWCAP_SB
#define HWCAP_SB (1 << 29)
#endif // HWCAP_SB

static inline void as_arch_pause(void)
{
static int use_spin_delay_sb = -1;

if (__builtin_expect(use_spin_delay_sb == 1, 1)) {
asm volatile(".inst 0xd50330ff" : : : "memory"); // SB instruction encoding
}
else if (use_spin_delay_sb == 0) {
asm volatile("isb" : : : "memory");
}
else {
// Initialize variable and check if SB is supported
if (getauxval(AT_HWCAP) & HWCAP_SB)
use_spin_delay_sb = 1;
else
use_spin_delay_sb = 0;
}
}
#else
static inline void as_arch_pause(void)
{
asm volatile("isb" : : : "memory");
}
#endif // __linux__ __GNUC__ __clang__

#define as_arch_pause() as_arch_pause()

#endif

Expand Down