|
Packit Service |
82fcde |
/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library. If not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <stdint.h>
|
|
Packit Service |
82fcde |
#include <sysdep.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef int8_t atomic8_t;
|
|
Packit Service |
82fcde |
typedef uint8_t uatomic8_t;
|
|
Packit Service |
82fcde |
typedef int_fast8_t atomic_fast8_t;
|
|
Packit Service |
82fcde |
typedef uint_fast8_t uatomic_fast8_t;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef int32_t atomic32_t;
|
|
Packit Service |
82fcde |
typedef uint32_t uatomic32_t;
|
|
Packit Service |
82fcde |
typedef int_fast32_t atomic_fast32_t;
|
|
Packit Service |
82fcde |
typedef uint_fast32_t uatomic_fast32_t;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
typedef intptr_t atomicptr_t;
|
|
Packit Service |
82fcde |
typedef uintptr_t uatomicptr_t;
|
|
Packit Service |
82fcde |
typedef intmax_t atomic_max_t;
|
|
Packit Service |
82fcde |
typedef uintmax_t uatomic_max_t;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __HAVE_64B_ATOMICS 0
|
|
Packit Service |
82fcde |
#define USE_ATOMIC_COMPILER_BUILTINS 0
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* XXX Is this actually correct? */
|
|
Packit Service |
82fcde |
#define ATOMIC_EXCHANGE_USES_CAS 1
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Microblaze does not have byte and halfword forms of load and reserve and
|
|
Packit Service |
82fcde |
store conditional. So for microblaze we stub out the 8- and 16-bit forms. */
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_bool_8_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_bool_16_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_val_32_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __tmp; \
|
|
Packit Service |
82fcde |
__typeof (mem) __memp = (mem); \
|
|
Packit Service |
82fcde |
int test; \
|
|
Packit Service |
82fcde |
__asm __volatile ( \
|
|
Packit Service |
82fcde |
" addc r0, r0, r0;" \
|
|
Packit Service |
82fcde |
"1: lwx %0, %3, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
" cmp %1, %0, %4;" \
|
|
Packit Service |
82fcde |
" bnei %1, 2f;" \
|
|
Packit Service |
82fcde |
" swx %5, %3, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
"2:" \
|
|
Packit Service |
82fcde |
: "=&r" (__tmp), \
|
|
Packit Service |
82fcde |
"=&r" (test), \
|
|
Packit Service |
82fcde |
"=m" (*__memp) \
|
|
Packit Service |
82fcde |
: "r" (__memp), \
|
|
Packit Service |
82fcde |
"r" (oldval), \
|
|
Packit Service |
82fcde |
"r" (newval) \
|
|
Packit Service |
82fcde |
: "cc", "memory"); \
|
|
Packit Service |
82fcde |
__tmp; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_compare_and_exchange_val_64_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*mem) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_compare_and_exchange_val_32_acq (mem, newval, oldval); \
|
|
Packit Service |
82fcde |
else if (sizeof (*mem) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_compare_and_exchange_val_64_acq (mem, newval, oldval); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_compare_and_exchange_val_rel(mem, newval, oldval) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*mem) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_compare_and_exchange_val_32_acq (mem, newval, oldval); \
|
|
Packit Service |
82fcde |
else if (sizeof (*mem) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_compare_and_exchange_val_64_acq (mem, newval, oldval); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_exchange_32_acq(mem, value) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __tmp; \
|
|
Packit Service |
82fcde |
__typeof (mem) __memp = (mem); \
|
|
Packit Service |
82fcde |
int test; \
|
|
Packit Service |
82fcde |
__asm __volatile ( \
|
|
Packit Service |
82fcde |
" addc r0, r0, r0;" \
|
|
Packit Service |
82fcde |
"1: lwx %0, %4, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
" swx %3, %4, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
: "=&r" (__tmp), \
|
|
Packit Service |
82fcde |
"=&r" (test), \
|
|
Packit Service |
82fcde |
"=m" (*__memp) \
|
|
Packit Service |
82fcde |
: "r" (value), \
|
|
Packit Service |
82fcde |
"r" (__memp) \
|
|
Packit Service |
82fcde |
: "cc", "memory"); \
|
|
Packit Service |
82fcde |
__tmp; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_exchange_64_acq(mem, newval) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_exchange_acq(mem, value) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*mem) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_exchange_32_acq (mem, value); \
|
|
Packit Service |
82fcde |
else if (sizeof (*mem) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_exchange_64_acq (mem, value); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_exchange_rel(mem, value) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*mem) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_exchange_32_acq (mem, value); \
|
|
Packit Service |
82fcde |
else if (sizeof (*mem) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_exchange_64_acq (mem, value); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_exchange_and_add_32(mem, value) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __tmp; \
|
|
Packit Service |
82fcde |
__typeof (mem) __memp = (mem); \
|
|
Packit Service |
82fcde |
int test; \
|
|
Packit Service |
82fcde |
__asm __volatile ( \
|
|
Packit Service |
82fcde |
" addc r0, r0, r0;" \
|
|
Packit Service |
82fcde |
"1: lwx %0, %4, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
" add %1, %3, %0;" \
|
|
Packit Service |
82fcde |
" swx %1, %4, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
: "=&r" (__tmp), \
|
|
Packit Service |
82fcde |
"=&r" (test), \
|
|
Packit Service |
82fcde |
"=m" (*__memp) \
|
|
Packit Service |
82fcde |
: "r" (value), \
|
|
Packit Service |
82fcde |
"r" (__memp) \
|
|
Packit Service |
82fcde |
: "cc", "memory"); \
|
|
Packit Service |
82fcde |
__tmp; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_exchange_and_add_64(mem, value) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_exchange_and_add(mem, value) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*mem) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_exchange_and_add_32 (mem, value); \
|
|
Packit Service |
82fcde |
else if (sizeof (*mem) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_exchange_and_add_64 (mem, value); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_increment_val_32(mem) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __val; \
|
|
Packit Service |
82fcde |
int test; \
|
|
Packit Service |
82fcde |
__asm __volatile ( \
|
|
Packit Service |
82fcde |
" addc r0, r0, r0;" \
|
|
Packit Service |
82fcde |
"1: lwx %0, %3, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
" addi %0, %0, 1;" \
|
|
Packit Service |
82fcde |
" swx %0, %3, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
: "=&r" (__val), \
|
|
Packit Service |
82fcde |
"=&r" (test), \
|
|
Packit Service |
82fcde |
"=m" (*mem) \
|
|
Packit Service |
82fcde |
: "r" (mem), \
|
|
Packit Service |
82fcde |
"m" (*mem) \
|
|
Packit Service |
82fcde |
: "cc", "memory"); \
|
|
Packit Service |
82fcde |
__val; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_increment_val_64(mem) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_increment_val(mem) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*(mem)) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_increment_val_32 (mem); \
|
|
Packit Service |
82fcde |
else if (sizeof (*(mem)) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_increment_val_64 (mem); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_increment(mem) ({ atomic_increment_val (mem); (void) 0; })
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_decrement_val_32(mem) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __val; \
|
|
Packit Service |
82fcde |
int test; \
|
|
Packit Service |
82fcde |
__asm __volatile ( \
|
|
Packit Service |
82fcde |
" addc r0, r0, r0;" \
|
|
Packit Service |
82fcde |
"1: lwx %0, %3, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
" rsubi %0, %0, 1;" \
|
|
Packit Service |
82fcde |
" swx %0, %3, r0;" \
|
|
Packit Service |
82fcde |
" addic %1, r0, 0;" \
|
|
Packit Service |
82fcde |
" bnei %1, 1b;" \
|
|
Packit Service |
82fcde |
: "=&r" (__val), \
|
|
Packit Service |
82fcde |
"=&r" (test), \
|
|
Packit Service |
82fcde |
"=m" (*mem) \
|
|
Packit Service |
82fcde |
: "r" (mem), \
|
|
Packit Service |
82fcde |
"m" (*mem) \
|
|
Packit Service |
82fcde |
: "cc", "memory"); \
|
|
Packit Service |
82fcde |
__val; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define __arch_atomic_decrement_val_64(mem) \
|
|
Packit Service |
82fcde |
(abort (), (__typeof (*mem)) 0)
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_decrement_val(mem) \
|
|
Packit Service |
82fcde |
({ \
|
|
Packit Service |
82fcde |
__typeof (*(mem)) __result; \
|
|
Packit Service |
82fcde |
if (sizeof (*(mem)) == 4) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_decrement_val_32 (mem); \
|
|
Packit Service |
82fcde |
else if (sizeof (*(mem)) == 8) \
|
|
Packit Service |
82fcde |
__result = __arch_atomic_decrement_val_64 (mem); \
|
|
Packit Service |
82fcde |
else \
|
|
Packit Service |
82fcde |
abort (); \
|
|
Packit Service |
82fcde |
__result; \
|
|
Packit Service |
82fcde |
})
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define atomic_decrement(mem) ({ atomic_decrement_val (mem); (void) 0; })
|