~angelsl/ubuntu/wily/gcc-5/mips-cross

« back to all changes in this revision

Viewing changes to debian/patches/pr67508.diff

  • Committer: angelsl
  • Date: 2015-10-30 03:30:35 UTC
  • Revision ID: angelsl-20151030033035-rmug41zm8hyjgisg
Original import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# DP: libgo: Fix PR go/67508, rewrite lfstack packing/unpacking
 
2
# DP: to look more like that in Go
 
3
 
 
4
From 95eb3733500feffc2eeeec5bcfac7e34583514e2 Mon Sep 17 00:00:00 2001
 
5
From: Michael Hudson-Doyle <michael.hudson@canonical.com>
 
6
Date: Fri, 31 Jul 2015 11:45:45 +1200
 
7
Subject: [PATCH] runtime: rewrite lfstack packing/unpacking to look more like that in Go
 
8
 
 
9
Change-Id: I4ca61240c3f69c6dce1fde8d859f8507dfab80fc
 
10
---
 
11
 
 
12
diff --git a/libgo/runtime/lfstack.goc b/libgo/runtime/lfstack.goc
 
13
index 060a0cc..9eb80d9 100644
 
14
--- a/src/libgo/runtime/lfstack.goc
 
15
+++ b/src/libgo/runtime/lfstack.goc
 
16
@@ -9,25 +9,41 @@
 
17
 #include "arch.h"
 
18
 
 
19
 #if __SIZEOF_POINTER__ == 8
 
20
-// Amd64 uses 48-bit virtual addresses, 47-th bit is used as kernel/user flag.
 
21
-// So we use 17msb of pointers as ABA counter.
 
22
-# define PTR_BITS 47
 
23
-#else
 
24
-# define PTR_BITS 32
 
25
-#endif
 
26
-#define PTR_MASK ((1ull<<PTR_BITS)-1)
 
27
-#define CNT_MASK (0ull-1)
 
28
-
 
29
-#if __SIZEOF_POINTER__ == 8 && (defined(__sparc__) || (defined(__sun__) && defined(__amd64__)))
 
30
 // SPARC64 and Solaris on AMD64 uses all 64 bits of virtual addresses.
 
31
 // Use low-order three bits as ABA counter.
 
32
 // http://docs.oracle.com/cd/E19120-01/open.solaris/816-5138/6mba6ua5p/index.html
 
33
-#undef PTR_BITS
 
34
-#undef CNT_MASK
 
35
-#undef PTR_MASK
 
36
-#define PTR_BITS 0
 
37
-#define CNT_MASK 7
 
38
-#define PTR_MASK ((0ull-1)<<3)
 
39
+# if defined(__sparc__) || (defined(__sun__) && defined(__amd64__))
 
40
+static inline uint64 lfPack(LFNode *node, uintptr cnt) {
 
41
+       return ((uint64)(node)) | ((cnt)&7);
 
42
+}
 
43
+static inline LFNode* lfUnpack(uint64 val) {
 
44
+       return (LFNode*)(val&~7);
 
45
+}
 
46
+# else
 
47
+#  if defined(__aarch64__)
 
48
+// Depending on the kernel options, pointers on arm64 can have up to 48 significant
 
49
+// bits (see https://www.kernel.org/doc/Documentation/arm64/memory.txt).
 
50
+#   define PTR_BITS 48
 
51
+#  else
 
52
+// Amd64 uses 48-bit virtual addresses, 47-th bit is used as kernel/user flag.
 
53
+// So we use 17msb of pointers as ABA counter.
 
54
+#   define PTR_BITS 47
 
55
+#  endif
 
56
+# endif
 
57
+# define CNT_BITS (64 - PTR_BITS + 3)
 
58
+static inline uint64 lfPack(LFNode *node, uintptr cnt) {
 
59
+       return ((uint64)(node)<<(64-PTR_BITS)) | (cnt&(((1<<CNT_BITS)-1)));
 
60
+}
 
61
+static inline LFNode* lfUnpack(uint64 val) {
 
62
+       return (LFNode*)((val >> CNT_BITS) << 3);
 
63
+}
 
64
+#else
 
65
+static inline uint64 lfPack(LFNode *node, uintptr cnt) {
 
66
+       return ((uint64)(uintptr)(node)<<32) | cnt;
 
67
+}
 
68
+static inline LFNode* lfUnpack(uint64 val) {
 
69
+       return (LFNode*)(uintptr)(val >> 32);
 
70
+}
 
71
 #endif
 
72
 
 
73
 void
 
74
@@ -35,16 +51,16 @@
 
75
 {
 
76
        uint64 old, new;
 
77
 
 
78
-       if((uintptr)node != ((uintptr)node&PTR_MASK)) {
 
79
+       if(node != lfUnpack(lfPack(node, 0))) {
 
80
                runtime_printf("p=%p\n", node);
 
81
                runtime_throw("runtime_lfstackpush: invalid pointer");
 
82
        }
 
83
 
 
84
        node->pushcnt++;
 
85
-       new = (uint64)(uintptr)node|(((uint64)node->pushcnt&CNT_MASK)<<PTR_BITS);
 
86
+       new = lfPack(node, node->pushcnt);
 
87
        for(;;) {
 
88
                old = runtime_atomicload64(head);
 
89
-               node->next = (LFNode*)(uintptr)(old&PTR_MASK);
 
90
+               node->next = lfUnpack(old);
 
91
                if(runtime_cas64(head, old, new))
 
92
                        break;
 
93
        }
 
94
@@ -60,11 +76,11 @@
 
95
                old = runtime_atomicload64(head);
 
96
                if(old == 0)
 
97
                        return nil;
 
98
-               node = (LFNode*)(uintptr)(old&PTR_MASK);
 
99
+               node = lfUnpack(old);
 
100
                node2 = runtime_atomicloadp(&node->next);
 
101
                new = 0;
 
102
                if(node2 != nil)
 
103
-                       new = (uint64)(uintptr)node2|(((uint64)node2->pushcnt&CNT_MASK)<<PTR_BITS);
 
104
+                       new = lfPack(node2, node2->pushcnt);
 
105
                if(runtime_cas64(head, old, new))
 
106
                        return node;
 
107
        }