This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Added _InterlockedCompareExchangePointer to Intrin.h
ClosedPublic

Authored by kumquats.a.pair on Jan 22 2014, 10:56 PM.

Details

Summary

This patch adds _InterlockedCompareExchangePointer to Intrin.h. It has only been made available when x86_64 similar to MSVC Intrin.h. Please review.

Diff Detail

Event Timeline

kumquats.a.pair updated this revision to Unknown Object (????).Jan 23 2014, 3:47 AM

Updated patch to include an implementation of __faststorefence based on cl assembly output.

Adding people that might want to review this change and commit it for me if it's acceptable. :)

Adding one more potential reviewer.

rnk added a comment.Jan 27 2014, 10:27 AM

Thanks, looks good, I'll commit it.

Looks like we were missing some of the declaration stubs for intrin.h, so
Eric went ahead and added the rest in r199992 and r200061. Feel free to
send more implementations.

rnk added inline comments.Jan 27 2014, 10:35 AM
lib/Headers/Intrin.h
783

I think this needs to have a memory constraint to avoid reordering non-volatile loads and stores across it.

echristo resigned from this revision.Feb 25 2014, 2:47 PM

Don't know if this was closed or not...

kumquats.a.pair accepted this revision.Jun 8 2014, 7:21 AM
kumquats.a.pair added a reviewer: kumquats.a.pair.
kumquats.a.pair added inline comments.
lib/Headers/Intrin.h
783

This instruction reads a memory address, or's it with the constant 0, and writes it back to the same location with the lock prefix. That's read-modify-write with lock prefix, and I believe the AMD and Intel manuals state that this should be enough. I can provide references if you like. It's also the same instruction emitted by MSVC.

783

Alternatively, we could use sfence here. Are you a also looking to prevent the compiler from re-ordering this instruction? Will it do that?

This revision is now accepted and ready to land.Jun 8 2014, 7:21 AM
rnk added inline comments.Jun 9 2014, 11:13 AM
lib/Headers/Intrin.h
783

I meant it needs to have a gcc inline asm style "memory" constraint, like so:

__asm__ volatile("lock orq $0, (%%rsp)" : : : "memory");

GCC doesn't parse inline assembly, so it needs the user to carefully spell out the constraints on scheduling. Clang follows that model for gcc-style inline asm.

You are correct, and I think the change was already committed with that fix
applied. Thank you. I was just trying to mark the review as "finished" or
"accepted". Please excuse my unfamiliarity with Confabulator's workflow.

Eugene.Zelenko closed this revision.Oct 3 2016, 6:51 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in rL200239.