This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
S/390: Add __exchange_and_add "memory" clobber
- From: Ulrich Weigand <uweigand at de dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Cc: pcarlini at suse dot de
- Date: Wed, 6 Apr 2005 18:57:08 +0200 (CEST)
- Subject: S/390: Add __exchange_and_add "memory" clobber
Hello,
this fixes a potential problem in the s390 implementation of
__exchange_and_add in libstdc++: the inline assembly statement
does not have a "memory" clobber, which means that __exchange_and_add
may not reliably work as scheduling barrier for memory accesses.
This is a problem e.g. if the intended use of the primitive is
to implement reference counts guarding object lifetimes.
This patch fixes this by adding the "memory" clobber. Note that the
COMPARE AND SWAP instruction used already provides all required
memory ordering guarantees as far as the hardware is concerned.
Bootstrapped/regtested on s390-ibm-linux and s390x-ibm-linux on
4.0 branch and mainline; committed to both.
Thanks to Paolo Carlini for making me aware of that issue.
Bye,
Ulrich
ChangeLog:
* config/cpu/s390/atomicity.h (__exchange_and_add): Add "memory"
clobber to inline assembly statement.
Index: libstdc++-v3/config/cpu/s390/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/s390/atomicity.h,v
retrieving revision 1.5
diff -c -p -r1.5 atomicity.h
*** libstdc++-v3/config/cpu/s390/atomicity.h 27 Feb 2004 00:49:48 -0000 1.5
--- libstdc++-v3/config/cpu/s390/atomicity.h 4 Apr 2005 16:44:15 -0000
*************** namespace __gnu_cxx
*** 43,49 ****
" cs %0,%1,0(%3)\n"
" jl 0b"
: "=&d" (__old_val), "=&d" (__new_val), "=m" (*__mem)
! : "a" (__mem), "d" (__val), "m" (*__mem) : "cc");
return __old_val;
}
--- 43,50 ----
" cs %0,%1,0(%3)\n"
" jl 0b"
: "=&d" (__old_val), "=&d" (__new_val), "=m" (*__mem)
! : "a" (__mem), "d" (__val), "m" (*__mem)
! : "cc", "memory");
return __old_val;
}
--
Dr. Ulrich Weigand
Linux on zSeries Development
Ulrich.Weigand@de.ibm.com