diff mbox

libgo patch committed: Support sparc64 in lfstack.c

Message ID mcrsj5o96ch.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 25, 2013, 11:43 p.m. UTC
Looks like sparc64 broke for libgo when parallel garbage collection was
introduced.  This patch is an attempt to get it working again.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu, not that
that proves much.  Committed to mainline.

Ian
diff mbox

Patch

diff -r b8ae4def7c14 libgo/runtime/lfstack.c
--- a/libgo/runtime/lfstack.c	Thu Jan 24 11:43:43 2013 -0800
+++ b/libgo/runtime/lfstack.c	Fri Jan 25 15:41:18 2013 -0800
@@ -15,6 +15,15 @@ 
 # define PTR_BITS 32
 #endif
 #define PTR_MASK ((1ull<<PTR_BITS)-1)
+#define CNT_MASK (0ull-1)
+
+#if __SIZEOF_POINTER__ == 8 && defined(__sparc__)
+// SPARC64 uses all 64 bits of virtual addresses.  Use low-order three
+bits as ABA counter.
+#define PTR_BITS 0
+#define CNT_MASK 7
+#define PTR_MASK ((0ull-1)<<3)
+#endif
 
 void
 runtime_lfstackpush(uint64 *head, LFNode *node)
@@ -27,7 +36,7 @@ 
 	}
 
 	node->pushcnt++;
-	new = (uint64)(uintptr)node|(((uint64)node->pushcnt)<<PTR_BITS);
+	new = (uint64)(uintptr)node|(((uint64)node->pushcnt&CNT_MASK)<<PTR_BITS);
 	old = runtime_atomicload64(head);
 	for(;;) {
 		node->next = (LFNode*)(uintptr)(old&PTR_MASK);
@@ -50,7 +59,7 @@ 
 		node2 = runtime_atomicloadp(&node->next);
 		new = 0;
 		if(node2 != nil)
-			new = (uint64)(uintptr)node2|(((uint64)node2->pushcnt)<<PTR_BITS);
+			new = (uint64)(uintptr)node2|(((uint64)node2->pushcnt&CNT_MASK)<<PTR_BITS);
 		if(runtime_cas64(head, &old, new))
 			return node;
 	}