]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use new CNT_MASK in lfstack
authorIan Lance Taylor <iant@golang.org>
Sun, 27 Jan 2013 02:16:43 +0000 (18:16 -0800)
committerIan Lance Taylor <iant@golang.org>
Sun, 27 Jan 2013 02:16:43 +0000 (18:16 -0800)
This is for SPARC64, a 64-bit processor that uses all 64-bits
of virtual addresses.  The idea is to use the low order 3 bits
to at least get a small ABA counter.  That should work since
pointers are aligned.  The idea is for SPARC64 to set CNT_MASK
== 7, PTR_BITS == 0, PTR_MASK == 0xffffffffffffff8.

Also add uintptr casts to avoid GCC warnings.  The gccgo
runtime code is compiled with GCC, and GCC warns when casting
between a pointer and a type of a different size.

R=dvyukov
CC=golang-dev
https://golang.org/cl/7225043

src/pkg/runtime/lfstack.c

index e4ea6e83da4bc1f2d25328d36fc31be14e007fe2..1d48491aac782df124c70050b687f85552db9dce 100644 (file)
 # define PTR_BITS 32
 #endif
 #define PTR_MASK ((1ull<<PTR_BITS)-1)
+#define CNT_MASK (0ull-1)
 
 void
 runtime·lfstackpush(uint64 *head, LFNode *node)
 {
        uint64 old, new;
 
-       if((uint64)node != ((uint64)node&PTR_MASK)) {
+       if((uintptr)node != ((uintptr)node&PTR_MASK)) {
                runtime·printf("p=%p\n", node);
                runtime·throw("runtime·lfstackpush: invalid pointer");
        }
 
        node->pushcnt++;
-       new = (uint64)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*)(old&PTR_MASK);
+               node->next = (LFNode*)(uintptr)(old&PTR_MASK);
                if(runtime·cas64(head, &old, new))
                        break;
        }
@@ -46,11 +47,11 @@ runtime·lfstackpop(uint64 *head)
        for(;;) {
                if(old == 0)
                        return nil;
-               node = (LFNode*)(old&PTR_MASK);
+               node = (LFNode*)(uintptr)(old&PTR_MASK);
                node2 = runtime·atomicloadp(&node->next);
                new = 0;
                if(node2 != nil)
-                       new = (uint64)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;
        }