diff options
| author | Russ Cox <rsc@golang.org> | 2013-07-12 00:03:32 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-07-12 00:03:32 -0400 |
| commit | fb63e4fefbb1325a21f643febc97987c82fcae7a (patch) | |
| tree | f466ebd0309d253308fd2b55a0c3a14b41808f24 /src/pkg/runtime/runtime.c | |
| parent | 3a8845b5259e9b4fa80a43444643ea74f1078286 (diff) | |
| download | go-fb63e4fefbb1325a21f643febc97987c82fcae7a.tar.xz | |
runtime: make cas64 like cas32 and casp
The current cas64 definition hard-codes the x86 behavior
of updating *old with the new value when the cas fails.
This is inconsistent with cas32 and casp.
Make it consistent.
This means that the cas64 uses will be epsilon less efficient
than they might be, because they have to do an unnecessary
memory load on x86. But so be it. Code clarity and consistency
is more important.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10909045
Diffstat (limited to 'src/pkg/runtime/runtime.c')
| -rw-r--r-- | src/pkg/runtime/runtime.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index f59a3f4e80..f0571f1899 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -157,11 +157,12 @@ TestAtomic64(void) z64 = 42; x64 = 0; PREFETCH(&z64); - if(runtime·cas64(&z64, &x64, 1)) + if(runtime·cas64(&z64, x64, 1)) runtime·throw("cas64 failed"); - if(x64 != 42) + if(x64 != 0) runtime·throw("cas64 failed"); - if(!runtime·cas64(&z64, &x64, 1)) + x64 = 42; + if(!runtime·cas64(&z64, x64, 1)) runtime·throw("cas64 failed"); if(x64 != 42 || z64 != 1) runtime·throw("cas64 failed"); @@ -193,7 +194,7 @@ runtime·check(void) uint64 h; float32 i, i1; float64 j, j1; - void* k; + byte *k, *k1; uint16* l; struct x1 { byte x; @@ -232,6 +233,17 @@ runtime·check(void) if(z != 4) runtime·throw("cas4"); + k = (byte*)0xfedcb123; + if(sizeof(void*) == 8) + k = (byte*)((uintptr)k<<10); + if(runtime·casp((void**)&k, nil, nil)) + runtime·throw("casp1"); + k1 = k+1; + if(!runtime·casp((void**)&k, k, k1)) + runtime·throw("casp2"); + if(k != k1) + runtime·throw("casp3"); + *(uint64*)&j = ~0ULL; if(j == j) runtime·throw("float64nan"); |
