1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-12-06 12:01:08 +03:00
Files
glibc/sysdeps/riscv/atomic-machine.h
Adhemerval Zanella 7fec8a5de6 Revert __HAVE_64B_ATOMICS configure check
The 53807741fb added a configure check
for 64-bit atomic operations that were not previously enabled on some
32-bit ABIs.

However, the NPTL semaphore code casts a sem_t to a new_sem and issues
a 64-bit atomic operation for __HAVE_64B_ATOMICS.  Since sem_t has
32-bit alignment on 32-bit architectures, this prevents the use of
64-bit atomics even if the ABI supports them.

Assume 64-bit atomic support from __WORDSIZE, which maps to how glibc
defines it before the broken change.  Also rename __HAVE_64B_ATOMICS
to USE_64B_ATOMICS to define better the flag meaning.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Reviewed-by: Wilco Dijkstra  <Wilco.Dijkstra@arm.com>
2025-11-14 14:05:20 -03:00

54 lines
1.9 KiB
C

/* Low-level functions for atomic operations. RISC-V version.
Copyright (C) 2014-2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */
#ifndef _LINUX_RISCV_BITS_ATOMIC_H
#define _LINUX_RISCV_BITS_ATOMIC_H 1
#ifdef __riscv_atomic
#include_next <atomic-machine.h>
/* Miscellaneous. */
# define asm_amo(which, ordering, mem, value) ({ \
__atomic_check_size (mem); \
typeof (*mem) __tmp; \
if (sizeof (__tmp) == 4) \
asm volatile (which ".w" ordering "\t%0, %z2, %1" \
: "=r" (__tmp), "+A" (* (mem)) \
: "rJ" (value)); \
else if (sizeof (__tmp) == 8) \
asm volatile (which ".d" ordering "\t%0, %z2, %1" \
: "=r" (__tmp), "+A" (* (mem)) \
: "rJ" (value)); \
else \
abort (); \
__tmp; })
# define atomic_max(mem, value) asm_amo ("amomaxu", ".aq", mem, value)
# define atomic_min(mem, value) asm_amo ("amominu", ".aq", mem, value)
#else /* __riscv_atomic */
# error "ISAs that do not subsume the A extension are not supported"
#endif /* !__riscv_atomic */
/* Execute a PAUSE hint when spinning. */
#define atomic_spin_nop() __asm(".insn i 0x0f, 0, x0, x0, 0x010")
#endif /* bits/atomic.h */