This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3 RFC] PATCH to memory asm ops in atomicity.h


This patch is a followup to

  http://gcc.gnu.org/ml/gcc-patches/2003-01/msg00108.html

which has been sitting in my tree for months.  It makes memory I/O explicit
by adding input/output operands for *__mem to the patterns that don't have
them yet and removing the memory clobbers, which are thereby no longer
necessary.

Benjamin, do you think this should go in for 3.4 or should I keep holding
onto it for a while?

2003-12-16  Jason Merrill  <jason@redhat.com>

	* config/cpu/cris/atomicity.h: Remove memory clobbers.
	* config/cpu/i486/atomicity.h: Remove memory clobbers.
	* config/cpu/m68k/atomicity.h: Remove memory clobbers.
	* config/cpu/mips/atomicity.h: Remove memory clobbers.
	* config/cpu/powerpc/atomicity.h: Make memory I/O explicit.
	* config/cpu/s390/atomicity.h: Make memory I/O explicit.
	* config/cpu/sparc/atomicity.h: Make memory I/O explicit.

Index: libstdc++-v3/config/cpu/cris/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/cris/atomicity.h,v
retrieving revision 1.3
diff -c -p -r1.3 atomicity.h
*** libstdc++-v3/config/cpu/cris/atomicity.h	10 Dec 2003 04:52:34 -0000	1.3
--- libstdc++-v3/config/cpu/cris/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(_Atomic_word* __mem, 
*** 50,58 ****
  			" move.d %2,[%3]	\n"
  			" bwf 0b		\n"
  			" clearf		\n"
! 			:  "=&r" (__result), "=m" (*__mem), "=&r" (__tmp)
! 			: "r" (__mem), "g" (__val), "m" (*__mem)
! 			: "memory");
  #else
    __asm__ __volatile__ (" move $ccr,$r9		\n"
  			" di			\n"
--- 50,57 ----
  			" move.d %2,[%3]	\n"
  			" bwf 0b		\n"
  			" clearf		\n"
! 			: "=&r" (__result), "+m" (*__mem), "=&r" (__tmp)
! 			: "r" (__mem), "g" (__val));
  #else
    __asm__ __volatile__ (" move $ccr,$r9		\n"
  			" di			\n"
*************** __exchange_and_add(_Atomic_word* __mem, 
*** 61,69 ****
  			" add.d %0,%2		\n"
  			" move.d %2,[%3]	\n"
  			" move $r9,$ccr		\n"
! 			:  "=&r" (__result), "=m" (*__mem), "=&r" (__tmp)
! 			: "r" (__mem), "g" (__val), "m" (*__mem)
! 			: "memory", "r9");
  #endif
  
    return __result;
--- 60,68 ----
  			" add.d %0,%2		\n"
  			" move.d %2,[%3]	\n"
  			" move $r9,$ccr		\n"
! 			: "=&r" (__result), "+m" (*__mem), "=&r" (__tmp)
! 			: "r" (__mem), "g" (__val)
! 			: "r9");
  #endif
  
    return __result;
Index: libstdc++-v3/config/cpu/i486/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/i486/atomicity.h,v
retrieving revision 1.5
diff -c -p -r1.5 atomicity.h
*** libstdc++-v3/config/cpu/i486/atomicity.h	10 Dec 2003 04:52:35 -0000	1.5
--- libstdc++-v3/config/cpu/i486/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(volatile _Atomic_word
*** 39,46 ****
    register _Atomic_word __result;
    __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}"
  			: "=r" (__result), "+m" (*__mem) 
!                         : "0" (__val)
!                         : "memory");
    return __result;
  }
  
--- 39,45 ----
    register _Atomic_word __result;
    __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}"
  			: "=r" (__result), "+m" (*__mem) 
!                         : "0" (__val));
    return __result;
  }
  
*************** __attribute__ ((__unused__))
*** 49,55 ****
  __atomic_add(volatile _Atomic_word* __mem, int __val)
  {
    __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}"
! 			: "+m" (*__mem) : "ir" (__val) : "memory");
  }
  
  #endif /* atomicity.h */
--- 48,54 ----
  __atomic_add(volatile _Atomic_word* __mem, int __val)
  {
    __asm__ __volatile__ ("lock; add{l} {%1,%0|%0,%1}"
! 			: "+m" (*__mem) : "ir" (__val));
  }
  
  #endif /* atomicity.h */
Index: libstdc++-v3/config/cpu/m68k/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/m68k/atomicity.h,v
retrieving revision 1.7
diff -c -p -r1.7 atomicity.h
*** libstdc++-v3/config/cpu/m68k/atomicity.h	10 Dec 2003 04:52:36 -0000	1.7
--- libstdc++-v3/config/cpu/m68k/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(volatile _Atomic_word
*** 48,55 ****
  			"cas%.l %0,%1,%2\n\t"
  			"jne 1b"
  			: "=d" (__result), "=&d" (__temp), "+m" (*__mem)
! 			: "d" (__val), "0" (__result)
! 			: "memory");
    return __result;
  }
  
--- 48,54 ----
  			"cas%.l %0,%1,%2\n\t"
  			"jne 1b"
  			: "=d" (__result), "=&d" (__temp), "+m" (*__mem)
! 			: "d" (__val), "0" (__result));
    return __result;
  }
  
Index: libstdc++-v3/config/cpu/mips/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/mips/atomicity.h,v
retrieving revision 1.7
diff -c -p -r1.7 atomicity.h
*** libstdc++-v3/config/cpu/mips/atomicity.h	10 Dec 2003 04:52:36 -0000	1.7
--- libstdc++-v3/config/cpu/mips/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(volatile _Atomic_word
*** 52,59 ****
       "beqz	%1,1b\n\t"
       "/* End exchange & add */"
       : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem)
!      : "m" (*__mem), "r"(__val)
!      : "memory");
  
    return __result;
  }
--- 52,58 ----
       "beqz	%1,1b\n\t"
       "/* End exchange & add */"
       : "=&r"(__result), "=&r"(__tmp), "=m"(*__mem)
!      : "m" (*__mem), "r"(__val));
  
    return __result;
  }
*************** __atomic_add(volatile _Atomic_word* __me
*** 78,85 ****
       "beqz	%0,1b\n\t"
       "/* End atomic add */"
       : "=&r"(__result), "=m"(*__mem)
!      : "m" (*__mem), "r"(__val)
!      : "memory");
  }
  
  #endif /* atomicity.h */
--- 77,83 ----
       "beqz	%0,1b\n\t"
       "/* End atomic add */"
       : "=&r"(__result), "=m"(*__mem)
!      : "m" (*__mem), "r"(__val));
  }
  
  #endif /* atomicity.h */
Index: libstdc++-v3/config/cpu/powerpc/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/powerpc/atomicity.h,v
retrieving revision 1.6
diff -c -p -r1.6 atomicity.h
*** libstdc++-v3/config/cpu/powerpc/atomicity.h	10 Dec 2003 04:52:37 -0000	1.6
--- libstdc++-v3/config/cpu/powerpc/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(volatile _Atomic_word
*** 46,59 ****
    __asm__ __volatile__ (
  	"/* Inline exchange & add */\n"
  	"0:\t"
! 	"lwarx    %0,0,%2 \n\t"
! 	"add%I3   %1,%0,%3 \n\t"
! 	_STWCX "  %1,0,%2 \n\t"
  	"bne-     0b \n\t"
  	"/* End exchange & add */"
! 	: "=&b"(__res), "=&r"(__tmp)
  	: "r" (__mem), "Ir"(__val)
! 	: "cr0", "memory");
    return __res;
  }
  
--- 46,59 ----
    __asm__ __volatile__ (
  	"/* Inline exchange & add */\n"
  	"0:\t"
! 	"lwarx    %0,0,%3 \n\t"
! 	"add%I3   %1,%0,%4 \n\t"
! 	_STWCX "  %1,0,%3 \n\t"
  	"bne-     0b \n\t"
  	"/* End exchange & add */"
! 	: "=&b"(__res), "=&r"(__tmp), "+m" (*__mem)
  	: "r" (__mem), "Ir"(__val)
! 	: "cr0");
    return __res;
  }
  
*************** __atomic_add(volatile _Atomic_word* __me
*** 65,78 ****
    __asm__ __volatile__ (
  	"/* Inline atomic add */\n"
  	"0:\t"
! 	"lwarx    %0,0,%1 \n\t"
! 	"add%I2   %0,%0,%2 \n\t"
! 	_STWCX "  %0,0,%1 \n\t"
  	"bne-     0b \n\t"
  	"/* End atomic add */"
! 	: "=&b"(__tmp)
  	: "r" (__mem), "Ir"(__val)
! 	: "cr0", "memory");
  }
  
  #endif /* atomicity.h */
--- 65,78 ----
    __asm__ __volatile__ (
  	"/* Inline atomic add */\n"
  	"0:\t"
! 	"lwarx    %0,0,%2 \n\t"
! 	"add%I2   %0,%0,%3 \n\t"
! 	_STWCX "  %0,0,%2 \n\t"
  	"bne-     0b \n\t"
  	"/* End atomic add */"
! 	: "=&b"(__tmp), "+m" (*__mem)
  	: "r" (__mem), "Ir"(__val)
! 	: "cr0");
  }
  
  #endif /* atomicity.h */
Index: libstdc++-v3/config/cpu/s390/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/s390/atomicity.h,v
retrieving revision 1.3
diff -c -p -r1.3 atomicity.h
*** libstdc++-v3/config/cpu/s390/atomicity.h	10 Dec 2003 04:52:37 -0000	1.3
--- libstdc++-v3/config/cpu/s390/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(volatile _Atomic_word
*** 38,50 ****
  {
    register _Atomic_word __old_val, __new_val;
  
!   __asm__ __volatile__ ("   l     %0,0(%2)\n"
                          "0: lr    %1,%0\n"
!                         "   ar    %1,%3\n"
!                         "   cs    %0,%1,0(%2)\n"
                          "   jl    0b"
!                         : "=&d" (__old_val), "=&d" (__new_val)
!                         : "a" (__mem), "d" (__val) : "cc", "memory" );
    return __old_val;
  }
  
--- 38,50 ----
  {
    register _Atomic_word __old_val, __new_val;
  
!   __asm__ __volatile__ ("   l     %0,0(%3)\n"
                          "0: lr    %1,%0\n"
!                         "   ar    %1,%4\n"
!                         "   cs    %0,%1,0(%3)\n"
                          "   jl    0b"
!                         : "=&d" (__old_val), "=&d" (__new_val), "+m" (*__mem)
!                         : "a" (__mem), "d" (__val) : "cc");
    return __old_val;
  }
  
Index: libstdc++-v3/config/cpu/sparc/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/sparc/atomicity.h,v
retrieving revision 1.4
diff -c -p -r1.4 atomicity.h
*** libstdc++-v3/config/cpu/sparc/atomicity.h	10 Dec 2003 04:52:37 -0000	1.4
--- libstdc++-v3/config/cpu/sparc/atomicity.h	16 Dec 2003 22:38:12 -0000
*************** __exchange_and_add(volatile _Atomic_word
*** 41,55 ****
    _Atomic_word __tmp1, __tmp2;
    _Atomic_word __val_extended = __val;
  
!   __asm__ __volatile__("1:	ldx	[%2], %0\n\t"
! 		       "	add	%0, %3, %1\n\t"
! 		       "	casx	[%2], %0, %1\n\t"
  		       "	sub	%0, %1, %0\n\t"
  		       "	brnz,pn	%0, 1b\n\t"
  		       "	 nop"
! 		       : "=&r" (__tmp1), "=&r" (__tmp2)
! 		       : "r" (__mem), "r" (__val_extended)
! 		       : "memory");
    return __tmp2;
  }
  
--- 41,54 ----
    _Atomic_word __tmp1, __tmp2;
    _Atomic_word __val_extended = __val;
  
!   __asm__ __volatile__("1:	ldx	[%3], %0\n\t"
! 		       "	add	%0, %4, %1\n\t"
! 		       "	casx	[%3], %0, %1\n\t"
  		       "	sub	%0, %1, %0\n\t"
  		       "	brnz,pn	%0, 1b\n\t"
  		       "	 nop"
! 		       : "=&r" (__tmp1), "=&r" (__tmp2), "+m" (*__mem)
! 		       : "r" (__mem), "r" (__val_extended));
    return __tmp2;
  }
  
*************** __atomic_add(volatile _Atomic_word* __me
*** 60,74 ****
    _Atomic_word __tmp1, __tmp2;
    _Atomic_word __val_extended = __val;
  
!   __asm__ __volatile__("1:	ldx	[%2], %0\n\t"
! 		       "	add	%0, %3, %1\n\t"
! 		       "	casx	[%2], %0, %1\n\t"
  		       "	sub	%0, %1, %0\n\t"
  		       "	brnz,pn	%0, 1b\n\t"
  		       "	 nop"
! 		       : "=&r" (__tmp1), "=&r" (__tmp2)
! 		       : "r" (__mem), "r" (__val_extended)
! 		       : "memory");
  }
  
  #else /* __arch32__ */
--- 59,72 ----
    _Atomic_word __tmp1, __tmp2;
    _Atomic_word __val_extended = __val;
  
!   __asm__ __volatile__("1:	ldx	[%3], %0\n\t"
! 		       "	add	%0, %4, %1\n\t"
! 		       "	casx	[%3], %0, %1\n\t"
  		       "	sub	%0, %1, %0\n\t"
  		       "	brnz,pn	%0, 1b\n\t"
  		       "	 nop"
! 		       : "=&r" (__tmp1), "=&r" (__tmp2), "+m" (*__mem)
! 		       : "r" (__mem), "r" (__val_extended));
  }
  
  #else /* __arch32__ */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]