From 46efdbbc0113427e165b0d3635d5a26fb83d1448 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 23 Sep 2015 17:07:15 +0000 Subject: [PATCH] runtime: rewrite lfstack packing/unpacking to look more like that in Go Reviewed-on: https://go-review.googlesource.com/13037 From-SVN: r228057 --- gcc/go/gofrontend/MERGE | 2 +- libgo/runtime/lfstack.goc | 58 +++++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index f21c43a8c6d..1ea55554fba 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -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. diff --git a/libgo/runtime/lfstack.goc b/libgo/runtime/lfstack.goc index 060a0cc5941..9eb80d900f9 100644 --- a/libgo/runtime/lfstack.goc +++ b/libgo/runtime/lfstack.goc @@ -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<> 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 *node) { 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)<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)<pushcnt); if(runtime_cas64(head, old, new)) return node; } -- 2.30.2