Skip to content

Commit b716501

Browse files
committed
mimalloc: fix mi_atomic_yield on 32-bit ARM
Previously, `mi_atomic_yield` for 32-bit ARM: * Used a non-standard __ARM_ARCH__ macro to determine if the compiler was targeting ARMv7+ in order to emit a `yield` instruction, however it was often not defined so fell through to an `__armel__` branch * Had a logic gap in the #ifdef where an `__arm__` target would be expected to emit `mi_atomic_yield` but there was no condition to define a function for big-endian targets Now, the standard ACLE __ARM_ARCH macro [1] [2] is used which GCC and Clang support. The branching logic for `__armel__` has been removed so if the target architecture supports v7+ instructions, a `yield` is emitted, otherwise a `nop` is emitted. This covers both big and little endian scenarios. [1]: https://arm-software.github.io/acle/main/acle.html#arm-architecture-level [2]: https://arm-software.github.io/acle/main/acle.html#mapping-of-object-build-attributes-to-predefines Signed-off-by: Vincent Fazio <[email protected]>
1 parent 151d1bf commit b716501

File tree

1 file changed

+8
-6
lines changed
  • Include/internal/mimalloc/mimalloc

1 file changed

+8
-6
lines changed

Include/internal/mimalloc/mimalloc/atomic.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static inline void mi_atomic_yield(void) {
338338
_mm_pause();
339339
}
340340
#elif (defined(__GNUC__) || defined(__clang__)) && \
341-
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__armel__) || defined(__ARMEL__) || \
341+
(defined(__x86_64__) || defined(__i386__) || defined(__arm__) || \
342342
defined(__aarch64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)) || defined(__POWERPC__)
343343
#if defined(__x86_64__) || defined(__i386__)
344344
static inline void mi_atomic_yield(void) {
@@ -348,10 +348,16 @@ static inline void mi_atomic_yield(void) {
348348
static inline void mi_atomic_yield(void) {
349349
__asm__ volatile("wfe");
350350
}
351-
#elif (defined(__arm__) && __ARM_ARCH__ >= 7)
351+
#elif defined(__arm__)
352+
#if __ARM_ARCH >= 7
352353
static inline void mi_atomic_yield(void) {
353354
__asm__ volatile("yield" ::: "memory");
354355
}
356+
#else
357+
static inline void mi_atomic_yield(void) {
358+
__asm__ volatile ("nop" ::: "memory");
359+
}
360+
#endif // __ARM_ARCH >= 7
355361
#elif defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__POWERPC__)
356362
#ifdef __APPLE__
357363
static inline void mi_atomic_yield(void) {
@@ -362,10 +368,6 @@ static inline void mi_atomic_yield(void) {
362368
__asm__ __volatile__ ("or 27,27,27" ::: "memory");
363369
}
364370
#endif
365-
#elif defined(__armel__) || defined(__ARMEL__)
366-
static inline void mi_atomic_yield(void) {
367-
__asm__ volatile ("nop" ::: "memory");
368-
}
369371
#endif
370372
#elif defined(__sun)
371373
// Fallback for other archs

0 commit comments

Comments
 (0)