diff mbox

[4/5] sparc: Convert to atomic_exchange.

Message ID 1321562265-12743-5-git-send-email-rth@redhat.com
State New
Headers show

Commit Message

Richard Henderson Nov. 17, 2011, 8:37 p.m. UTC
---
 gcc/config/sparc/sync.md |   91 +++++++++++++++-------------------------------
 1 files changed, 30 insertions(+), 61 deletions(-)
diff mbox

Patch

diff --git a/gcc/config/sparc/sync.md b/gcc/config/sparc/sync.md
index d38a828..782aa60 100644
--- a/gcc/config/sparc/sync.md
+++ b/gcc/config/sparc/sync.md
@@ -19,6 +19,7 @@ 
 ;; <http://www.gnu.org/licenses/>.
 
 (define_mode_iterator I12MODE [QI HI])
+(define_mode_iterator I124MODE [QI HI SI])
 (define_mode_iterator I24MODE [HI SI])
 (define_mode_iterator I48MODE [SI (DI "TARGET_ARCH64 || TARGET_V8PLUS")])
 (define_mode_attr modesuffix [(SI "") (DI "x")])
@@ -32,14 +33,6 @@ 
   DONE;
 })
 
-(define_expand "memory_barrier"
-  [(const_int 0)]
-  "TARGET_V8 || TARGET_V9"
-{
-  sparc_emit_membar_for_model (MEMMODEL_SEQ_CST, 3, 3);
-  DONE;
-})
-
 (define_expand "membar"
   [(set (match_dup 1)
 	(unspec:BLK [(match_dup 1)
@@ -198,46 +191,22 @@ 
   [(set_attr "type" "multi")
    (set_attr "length" "8")])
 
-;;;;;;;;
-
-(define_expand "sync_lock_test_and_set<mode>"
-  [(match_operand:I12MODE 0 "register_operand" "")
-   (match_operand:I12MODE 1 "memory_operand" "")
-   (match_operand:I12MODE 2 "arith_operand" "")]
-  "!TARGET_V9"
+(define_expand "atomic_exchangesi"
+  [(match_operand:SI 0 "register_operand" "")
+   (match_operand:SI 1 "memory_operand" "")
+   (match_operand:SI 2 "register_operand" "")
+   (match_operand:SI 3 "const_int_operand" "")]
+  "TARGET_V8 || TARGET_V9"
 {
-  if (operands[2] != const1_rtx)
-    FAIL;
-  if (TARGET_V8)
-    emit_insn (gen_memory_barrier ());
-  if (<MODE>mode != QImode)
-    operands[1] = adjust_address (operands[1], QImode, 0);
-  emit_insn (gen_ldstub<mode> (operands[0], operands[1]));
-  DONE;
-})
+  enum memmodel model = (enum memmodel) INTVAL (operands[3]);
 
-(define_expand "sync_lock_test_and_setsi"
-  [(parallel
-     [(set (match_operand:SI 0 "register_operand" "")
-	   (unspec_volatile:SI [(match_operand:SI 1 "memory_operand" "")]
-			       UNSPECV_SWAP))
-      (set (match_dup 1)
-	   (match_operand:SI 2 "arith_operand" ""))])]
-  ""
-{
-  if (! TARGET_V8 && ! TARGET_V9)
-    {
-      if (operands[2] != const1_rtx)
-	FAIL;
-      operands[1] = adjust_address (operands[1], QImode, 0);
-      emit_insn (gen_ldstubsi (operands[0], operands[1]));
-      DONE;
-    }
-  emit_insn (gen_memory_barrier ());
-  operands[2] = force_reg (SImode, operands[2]);
+  sparc_emit_membar_for_model (model, 3, 1);
+  emit_insn (gen_swapsi (operands[0], operands[1], operands[2]));
+  sparc_emit_membar_for_model (model, 3, 2);
+  DONE;
 })
 
-(define_insn "*swapsi"
+(define_insn "swapsi"
   [(set (match_operand:SI 0 "register_operand" "=r")
 	(unspec_volatile:SI [(match_operand:SI 1 "memory_operand" "+m")]
 			    UNSPECV_SWAP))
@@ -247,24 +216,24 @@ 
   "swap\t%1, %0"
   [(set_attr "type" "multi")])
 
-(define_expand "ldstubqi"
-  [(parallel [(set (match_operand:QI 0 "register_operand" "")
-		   (unspec_volatile:QI [(match_operand:QI 1 "memory_operand" "")]
-				       UNSPECV_LDSTUB))
-	      (set (match_dup 1) (const_int -1))])]
-  ""
-  "")
-
-(define_expand "ldstub<mode>"
-  [(parallel [(set (match_operand:I24MODE 0 "register_operand" "")
-		   (zero_extend:I24MODE
-		      (unspec_volatile:QI [(match_operand:QI 1 "memory_operand" "")]
-					  UNSPECV_LDSTUB)))
-	      (set (match_dup 1) (const_int -1))])]
+;; The original V7 LDSTUB can only be implemented with sync_test_and_set.
+;; The expanders have already tried atomic_exchange for V8, so we do not
+;; need to fall back to using SWAP here.
+(define_expand "sync_lock_test_and_set<mode>"
+  [(match_operand:I124MODE 0 "register_operand" "")
+   (match_operand:I124MODE 1 "memory_operand" "")
+   (match_operand:I124MODE 2 "arith_operand" "")]
   ""
-  "")
+{
+  if (operands[2] != const1_rtx)
+    FAIL;
+  if (<MODE>mode != QImode)
+    operands[1] = adjust_address (operands[1], QImode, 0);
+  emit_insn (gen_ldstub<mode> (operands[0], operands[1]));
+  DONE;
+})
 
-(define_insn "*ldstubqi"
+(define_insn "ldstubqi"
   [(set (match_operand:QI 0 "register_operand" "=r")
 	(unspec_volatile:QI [(match_operand:QI 1 "memory_operand" "+m")]
 			    UNSPECV_LDSTUB))
@@ -273,7 +242,7 @@ 
   "ldstub\t%1, %0"
   [(set_attr "type" "multi")])
 
-(define_insn "*ldstub<mode>"
+(define_insn "ldstub<mode>"
   [(set (match_operand:I24MODE 0 "register_operand" "=r")
 	(zero_extend:I24MODE
 	  (unspec_volatile:QI [(match_operand:QI 1 "memory_operand" "+m")]