This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/78357] New: nios2 uses non-standard atomic functions
- From: "sebastian dot huber at embedded-brains dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 15 Nov 2016 06:33:54 +0000
- Subject: [Bug target/78357] New: nios2 uses non-standard atomic functions
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78357
Bug ID: 78357
Summary: nios2 uses non-standard atomic functions
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: sebastian.huber@embedded-brains.de
Target Milestone: ---
Some Nios II variants lack support for atomic operations in hardware. The GCC
Nios II support generates in this case non-standard __sync_* function calls,
e.g.
#include <stdatomic.h>
_Bool cas(atomic_uint *a, unsigned int *e, unsigned int d)
{
return atomic_compare_exchange_strong_explicit(a, e, d,
memory_order_relaxed, memory_order_relaxed);
}
unsigned int add(atomic_uint *a, unsigned int v)
{
return atomic_fetch_add_explicit(a, v, memory_order_relaxed);
}
.file "atomic.c"
.global __sync_val_compare_and_swap_4
.section .text
.align 2
.global cas
.type cas, @function
cas:
addi sp, sp, -12
stw r17, 4(sp)
stw ra, 8(sp)
stw r16, 0(sp)
ldw r16, 0(r5)
mov r17, r5
mov r5, r16
call __sync_val_compare_and_swap_4
cmpeq r16, r2, r16
bne r16, zero, .L2
stw r2, 0(r17)
.L2:
mov r2, r16
ldw ra, 8(sp)
ldw r17, 4(sp)
ldw r16, 0(sp)
addi sp, sp, 12
ret
.size cas, .-cas
.global __sync_fetch_and_add_4
.align 2
.global add
.type add, @function
add:
addi sp, sp, -4
stw ra, 0(sp)
call __sync_fetch_and_add_4
ldw ra, 0(sp)
addi sp, sp, 4
ret
.size add, .-add
Thus, this target is not covered by libatomic. There are at least two options
to fix this problem:
1. Change the Nios II support to emit standard __atomic_* function calls:
https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
2. Add the __sync_* functions to libatomic.