Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Issue 342763004: Add atomic load/store, fetch_add, fence, and is-lock-free lowering. (Closed)

Created:
6 years, 6 months ago by jvoung (off chromium)
Modified:
6 years, 6 months ago
Reviewers:
Jim Stichnoth, JF
CC:
native-client-reviews_googlegroups.com
Base URL:
https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Visibility:
Public.

Description

Add atomic load/store, fetch_add, fence, and is-lock-free lowering. Loads/stores w/ type i8, i16, and i32 are converted to plain load/store instructions and lowered w/ the plain lowerLoad/lowerStore. Atomic stores are followed by an mfence for sequential consistency. For 64-bit types, use movq to do 64-bit memory loads/stores (vs the usual load/store being broken into separate 32-bit load/stores). This means bitcasting the i64 -> f64, first (which splits the load of the value to be stored into two 32-bit ops) then stores in a single op. For load, load into f64 then bitcast back to i64 (which splits after the atomic load). This follows what GCC does for c++11 std::atomic<uint64_t> load/store methods (uses movq when -mfpmath=sse). This introduces some redundancy between movq and movsd, but the convention seems to be to use movq when working with integer quantities. Otherwise, movsd could work too. The difference seems to be in whether or not the XMM register's upper 64-bits are filled with 0 or not. Zero-extending could help avoid partial register stalls. Handle up to i32 fetch_add. TODO: add i64 via a cmpxchg loop. TODO: add some runnable crosstests to make sure that this doesn't do funny things to integer bit patterns that happen to look like signaling NaNs and quiet NaNs. However, the system clang would not know how to handle "llvm.nacl.*" if we choose to target that level directly via .ll files. Or, (a) we use old-school __sync methods (sync_fetch_and_add w/ 0 to load) or (b) require buildbot's clang/gcc to support c++11... BUG= https://code.google.com/p/nativeclient/issues/detail?id=3882 R=stichnot@chromium.org Committed: https://gerrit.chromium.org/gerrit/gitweb?p=native_client/pnacl-subzero.git;a=commit;h=5cd240d

Patch Set 1 #

Patch Set 2 : Handle atomic rmw add up to i32 for now #

Patch Set 3 : use movq for cast #

Patch Set 4 : beef up test a bit #

Total comments: 1

Patch Set 5 : make sure atomic loads are n't optimized out #

Patch Set 6 : test atomic rmw is not elided also #

Total comments: 10

Patch Set 7 : review #

Patch Set 8 : add a comment about xadd #

Patch Set 9 : move _xadd fakedef to common _xadd code #

Total comments: 7

Patch Set 10 : review #

Patch Set 11 : cleanup more #

Patch Set 12 : couple more daring tests #

Patch Set 13 : fix test todo now that separate fix landed #

Patch Set 14 : test 64 errors more #

Total comments: 2

Patch Set 15 : check width #

Total comments: 3

Patch Set 16 : add LOCK prefix to the usage part of comment #

Patch Set 17 : change comment #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1257 lines, -42 lines) Patch
M src/IceInstX8632.h View 1 2 3 5 chunks +87 lines, -0 lines 0 comments Download
M src/IceInstX8632.cpp View 1 2 3 4 5 6 7 8 9 7 chunks +112 lines, -0 lines 0 comments Download
M src/IceIntrinsics.h View 1 1 chunk +33 lines, -0 lines 0 comments Download
M src/IceIntrinsics.cpp View 1 2 3 4 5 6 7 8 9 2 chunks +6 lines, -1 line 0 comments Download
M src/IceTargetLoweringX8632.h View 1 2 3 4 5 6 7 8 6 chunks +20 lines, -0 lines 0 comments Download
M src/IceTargetLoweringX8632.cpp View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 14 chunks +205 lines, -39 lines 0 comments Download
M src/llvm2ice.cpp View 1 chunk +0 lines, -2 lines 0 comments Download
A tests_lit/llvm2ice_tests/nacl-atomic-errors.ll View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +169 lines, -0 lines 0 comments Download
A tests_lit/llvm2ice_tests/nacl-atomic-fence-all.ll View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +216 lines, -0 lines 0 comments Download
A tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 chunk +409 lines, -0 lines 0 comments Download

Messages

Total messages: 14 (0 generated)
jvoung (off chromium)
6 years, 6 months ago (2014-06-20 18:41:59 UTC) #1
jvoung (off chromium)
https://codereview.chromium.org/342763004/diff/100001/tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll File tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll (right): https://codereview.chromium.org/342763004/diff/100001/tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll#newcode142 tests_lit/llvm2ice_tests/nacl-atomic-intrinsics.ll:142: ; TODO(jvoung): the 64-bit constant materialization Started looking into ...
6 years, 6 months ago (2014-06-20 23:21:07 UTC) #2
Jim Stichnoth
https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (left): https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp#oldcode2009 src/IceTargetLoweringX8632.cpp:2009: Src0 = OperandX8632Mem::create(Func, Ty, Base, Offset); Do you think ...
6 years, 6 months ago (2014-06-23 18:13:02 UTC) #3
jvoung (off chromium)
https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (left): https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp#oldcode2009 src/IceTargetLoweringX8632.cpp:2009: Src0 = OperandX8632Mem::create(Func, Ty, Base, Offset); On 2014/06/23 18:13:01, ...
6 years, 6 months ago (2014-06-23 22:41:43 UTC) #4
Jim Stichnoth
LGTM https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp#newcode1974 src/IceTargetLoweringX8632.cpp:1974: Context.insert(InstFakeDef::create(Func, T)); On 2014/06/23 22:41:43, jvoung wrote: > ...
6 years, 6 months ago (2014-06-23 23:55:54 UTC) #5
jvoung (off chromium)
Thanks! https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/140001/src/IceTargetLoweringX8632.cpp#newcode1974 src/IceTargetLoweringX8632.cpp:1974: Context.insert(InstFakeDef::create(Func, T)); On 2014/06/23 23:55:54, stichnot wrote: > ...
6 years, 6 months ago (2014-06-24 00:35:57 UTC) #6
JF
Quick drive-by, I haven't read this thoroughly but a few things jumped out. I think ...
6 years, 6 months ago (2014-06-24 01:23:29 UTC) #7
jvoung (off chromium)
Thanks! Good points all around. Let me know if there are other issues. https://codereview.chromium.org/342763004/diff/150009/src/IceIntrinsics.cpp File ...
6 years, 6 months ago (2014-06-24 21:16:55 UTC) #8
JF
Looks good overall, one last comment. https://codereview.chromium.org/342763004/diff/280001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/280001/src/IceTargetLoweringX8632.cpp#newcode1839 src/IceTargetLoweringX8632.cpp:1839: Result = Ctx->getConstantZero(IceType_i32); ...
6 years, 6 months ago (2014-06-24 23:50:37 UTC) #9
jvoung (off chromium)
https://codereview.chromium.org/342763004/diff/280001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/280001/src/IceTargetLoweringX8632.cpp#newcode1839 src/IceTargetLoweringX8632.cpp:1839: Result = Ctx->getConstantZero(IceType_i32); On 2014/06/24 23:50:37, JF wrote: > ...
6 years, 6 months ago (2014-06-25 01:31:42 UTC) #10
JF
https://codereview.chromium.org/342763004/diff/300001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/300001/src/IceTargetLoweringX8632.cpp#newcode1843 src/IceTargetLoweringX8632.cpp:1843: // have cmpxchg16b, which can make 16-byte operations lock ...
6 years, 6 months ago (2014-06-25 01:44:03 UTC) #11
jvoung (off chromium)
https://codereview.chromium.org/342763004/diff/300001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/300001/src/IceTargetLoweringX8632.cpp#newcode1843 src/IceTargetLoweringX8632.cpp:1843: // have cmpxchg16b, which can make 16-byte operations lock ...
6 years, 6 months ago (2014-06-25 15:32:45 UTC) #12
JF
https://codereview.chromium.org/342763004/diff/300001/src/IceTargetLoweringX8632.cpp File src/IceTargetLoweringX8632.cpp (right): https://codereview.chromium.org/342763004/diff/300001/src/IceTargetLoweringX8632.cpp#newcode1843 src/IceTargetLoweringX8632.cpp:1843: // have cmpxchg16b, which can make 16-byte operations lock ...
6 years, 6 months ago (2014-06-25 15:41:25 UTC) #13
jvoung (off chromium)
6 years, 6 months ago (2014-06-25 17:37:01 UTC) #14
Message was sent while issue was closed.
Committed patchset #17 manually as r5cd240d (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698