aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/lfstack_amd64.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-11-14 12:55:23 -0500
committerRuss Cox <rsc@golang.org>2014-11-14 12:55:23 -0500
commit5fce15a2a3cd94427bb9979d73acf14013ec7f31 (patch)
treea49b9ffa5eac49d991e820b27da919aadd9e010b /src/runtime/lfstack_amd64.go
parenta87e4a2d01097c7f2430df0427aaae9c0b6f2031 (diff)
downloadgo-5fce15a2a3cd94427bb9979d73acf14013ec7f31.tar.xz
[dev.cc] runtime: fix lfstack for amd64 addresses in top half of addr space
While we are here, add the linux/power64 version. LGTM=austin R=austin CC=aram, dvyukov, golang-codereviews https://golang.org/cl/177750043
Diffstat (limited to 'src/runtime/lfstack_amd64.go')
-rw-r--r--src/runtime/lfstack_amd64.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/runtime/lfstack_amd64.go b/src/runtime/lfstack_amd64.go
index 1245557819..84e28519f6 100644
--- a/src/runtime/lfstack_amd64.go
+++ b/src/runtime/lfstack_amd64.go
@@ -4,9 +4,21 @@
package runtime
-// Amd64 uses 48-bit virtual addresses, 47-th bit is used as kernel/user flag.
-// So we use 17msb of pointers as ABA counter.
-const (
- lfPtrBits = 47
- lfCountMask = 1<<17 - 1
-)
+import "unsafe"
+
+// On AMD64, virtual addresses are 48-bit numbers sign extended to 64.
+// We shift the address left 16 to eliminate the sign extended part and make
+// room in the bottom for the count.
+// In addition to the 16 bits taken from the top, we can take 3 from the
+// bottom, because node must be pointer-aligned, giving a total of 19 bits
+// of count.
+
+func lfstackPack(node *lfnode, cnt uintptr) uint64 {
+ return uint64(uintptr(unsafe.Pointer(node)))<<16 | uint64(cnt&(1<<19-1))
+}
+
+func lfstackUnpack(val uint64) (node *lfnode, cnt uintptr) {
+ node = (*lfnode)(unsafe.Pointer(uintptr(int64(val) >> 19 << 3)))
+ cnt = uintptr(val & (1<<19 - 1))
+ return
+}