diff mbox

libgo patch committed: rewrite lfstack to look more like gc code

Message ID CAOyqgcX9TQYkLg9vfTJM7OLAPkbu3U-Gon0GJg7K4a5+i7TS7Q@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Sept. 23, 2015, 5:07 p.m. UTC
This patch by Michael Hudson-Doyle rewrites the lfstack code in libgo
to look more like that in the gc library.  It also fixes it for arm64.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Comments

Rainer Orth Sept. 24, 2015, 1:25 p.m. UTC | #1
Ian Lance Taylor <iant@golang.org> writes:

> This patch by Michael Hudson-Doyle rewrites the lfstack code in libgo
> to look more like that in the gc library.  It also fixes it for arm64.
> Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
> Committed to mainline.

This patch broke Solaris/x86 bootstrap: the amd64 lfstack.goc fails to
compile:

$ /bin/ksh ./libtool --tag=CC   --mode=compile /var/gcc/gcc-6.0.0-20150924/12-gcc/./gcc/xgcc -B/var/gcc/gcc-6.0.0-20150924/12-gcc/./gcc/ -B/usr/local/i386-pc-solaris2.12/bin/ -B/usr/local/i386-pc-solaris2.12/lib/ -isystem /usr/local/i386-pc-solaris2.12/include -isystem /usr/local/i386-pc-solaris2.12/sys-include  -m64 -DHAVE_CONFIG_H -I. -I/vol/gcc/src/hg/trunk/solaris/libgo  -I /vol/gcc/src/hg/trunk/solaris/libgo/runtime -I/vol/gcc/src/hg/trunk/solaris/libgo/../libffi/include -I../libffi/include -pthread  -fexceptions -fnon-call-exceptions -fplan9-extensions  -Wall -Wextra -Wwrite-strings -Wcast-qual -Werror -minline-all-stringops -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I /vol/gcc/src/hg/trunk/solaris/libgo/../libgcc -I /vol/gcc/src/hg/trunk/solaris/libgo/../libbacktrace -I ../../../gcc/include -g -O2 -MT lfstack.lo -MD -MP -MF .deps/lfstack.Tpo -c -o lfstack.lo lfstack.c
libtool: compile:  /var/gcc/gcc-6.0.0-20150924/12-gcc/./gcc/xgcc -B/var/gcc/gcc-6.0.0-20150924/12-gcc/./gcc/ -B/usr/local/i386-pc-solaris2.12/bin/ -B/usr/local/i386-pc-solaris2.12/lib/ -isystem /usr/local/i386-pc-solaris2.12/include -isystem /usr/local/i386-pc-solaris2.12/sys-include -m64 -DHAVE_CONFIG_H -I. -I/vol/gcc/src/hg/trunk/solaris/libgo -I /vol/gcc/src/hg/trunk/solaris/libgo/runtime -I/vol/gcc/src/hg/trunk/solaris/libgo/../libffi/include -I../libffi/include -pthread -fexceptions -fnon-call-exceptions -fplan9-extensions -Wall -Wextra -Wwrite-strings -Wcast-qual -Werror -minline-all-stringops -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I /vol/gcc/src/hg/trunk/solaris/libgo/../libgcc -I /vol/gcc/src/hg/trunk/solaris/libgo/../libbacktrace -I ../../../gcc/include -g -O2 -MT lfstack.lo -MD -MP -MF .deps/lfstack.Tpo -c lfstack.c  -fPIC -DPIC -o .libs/lfstack.o
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:32:22: error: redefinition of 'lfPack'
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:16:22: note: previous definition of 'lfPack' was here
 static inline uint64 lfPack(LFNode *node, uintptr cnt) {
                      ^
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc: In function 'lfPack':
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:33:38: error: 'PTR_BITS' undeclared (first use in this function)
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:33:38: note: each undeclared identifier is reported only once for each function it appears in
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc: At top level:
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:35:23: error: redefinition of 'lfUnpack'
  return ((uint64)(node)<<(64-PTR_BITS)) | (cnt&(((1<<CNT_BITS)-1)));
                       ^
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:19:23: note: previous definition of 'lfUnpack' was here
 static inline LFNode* lfUnpack(uint64 val) {
                       ^
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc: In function 'lfUnpack':
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:31:26: error: 'PTR_BITS' undeclared (first use in this function)
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:36:31: note: in expansion of macro 'CNT_BITS'
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc: In function 'lfPack':
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:34:1: error: control reaches end of non-void function [-Werror=return-type]
 static inline uint64 lfPack(LFNode *node, uintptr cnt) {
 ^
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc: In function 'lfUnpack':
/vol/gcc/src/hg/trunk/solaris/libgo/runtime/lfstack.goc:37:1: error: control reaches end of non-void function [-Werror=return-type]
 static inline LFNode* lfUnpack(uint64 val) {
 ^
cc1: all warnings being treated as errors
make: *** [lfstack.lo] Error 1

      Rainer
diff mbox

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 227863)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-e069d4417a692c1261df99fe3323277e1a0193d2
+2087b95180caea3477647c449772b7fecc01a71c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/runtime/lfstack.goc
===================================================================
--- libgo/runtime/lfstack.goc	(revision 227696)
+++ libgo/runtime/lfstack.goc	(working copy)
@@ -9,25 +9,41 @@  package runtime
 #include "arch.h"
 
 #if __SIZEOF_POINTER__ == 8
-// Amd64 uses 48-bit virtual addresses, 47-th bit is used as kernel/user flag.
-// So we use 17msb of pointers as ABA counter.
-# define PTR_BITS 47
-#else
-# define PTR_BITS 32
-#endif
-#define PTR_MASK ((1ull<<PTR_BITS)-1)
-#define CNT_MASK (0ull-1)
-
-#if __SIZEOF_POINTER__ == 8 && (defined(__sparc__) || (defined(__sun__) && defined(__amd64__)))
 // SPARC64 and Solaris on AMD64 uses all 64 bits of virtual addresses.
 // Use low-order three bits as ABA counter.
 // http://docs.oracle.com/cd/E19120-01/open.solaris/816-5138/6mba6ua5p/index.html
-#undef PTR_BITS
-#undef CNT_MASK
-#undef PTR_MASK
-#define PTR_BITS 0
-#define CNT_MASK 7
-#define PTR_MASK ((0ull-1)<<3)
+# if defined(__sparc__) || (defined(__sun__) && defined(__amd64__))
+static inline uint64 lfPack(LFNode *node, uintptr cnt) {
+	return ((uint64)(node)) | ((cnt)&7);
+}
+static inline LFNode* lfUnpack(uint64 val) {
+	return (LFNode*)(val&~7);
+}
+# else
+#  if defined(__aarch64__)
+// Depending on the kernel options, pointers on arm64 can have up to 48 significant
+// bits (see https://www.kernel.org/doc/Documentation/arm64/memory.txt).
+#   define PTR_BITS 48
+#  else
+// Amd64 uses 48-bit virtual addresses, 47-th bit is used as kernel/user flag.
+// So we use 17msb of pointers as ABA counter.
+#   define PTR_BITS 47
+#  endif
+# endif
+# define CNT_BITS (64 - PTR_BITS + 3)
+static inline uint64 lfPack(LFNode *node, uintptr cnt) {
+	return ((uint64)(node)<<(64-PTR_BITS)) | (cnt&(((1<<CNT_BITS)-1)));
+}
+static inline LFNode* lfUnpack(uint64 val) {
+	return (LFNode*)((val >> CNT_BITS) << 3);
+}
+#else
+static inline uint64 lfPack(LFNode *node, uintptr cnt) {
+	return ((uint64)(uintptr)(node)<<32) | cnt;
+}
+static inline LFNode* lfUnpack(uint64 val) {
+	return (LFNode*)(uintptr)(val >> 32);
+}
 #endif
 
 void
@@ -35,16 +51,16 @@  runtime_lfstackpush(uint64 *head, LFNode
 {
 	uint64 old, new;
 
-	if((uintptr)node != ((uintptr)node&PTR_MASK)) {
+	if(node != lfUnpack(lfPack(node, 0))) {
 		runtime_printf("p=%p\n", node);
 		runtime_throw("runtime_lfstackpush: invalid pointer");
 	}
 
 	node->pushcnt++;
-	new = (uint64)(uintptr)node|(((uint64)node->pushcnt&CNT_MASK)<<PTR_BITS);
+	new = lfPack(node, node->pushcnt);
 	for(;;) {
 		old = runtime_atomicload64(head);
-		node->next = (LFNode*)(uintptr)(old&PTR_MASK);
+		node->next = lfUnpack(old);
 		if(runtime_cas64(head, old, new))
 			break;
 	}
@@ -60,11 +76,11 @@  runtime_lfstackpop(uint64 *head)
 		old = runtime_atomicload64(head);
 		if(old == 0)
 			return nil;
-		node = (LFNode*)(uintptr)(old&PTR_MASK);
+		node = lfUnpack(old);
 		node2 = runtime_atomicloadp(&node->next);
 		new = 0;
 		if(node2 != nil)
-			new = (uint64)(uintptr)node2|(((uint64)node2->pushcnt&CNT_MASK)<<PTR_BITS);
+			new = lfPack(node2, node2->pushcnt);
 		if(runtime_cas64(head, old, new))
 			return node;
 	}