[CodeGen][X86] Implement _InterlockedCompareExchange128 intrinsic
authorReid Kleckner <rnk@google.com>
Thu, 14 Dec 2017 19:00:21 +0000 (19:00 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 14 Dec 2017 19:00:21 +0000 (19:00 +0000)
commit627f45fe5289193854329a75f46bd3d2197f8fa8
tree0df598d34bd5269981a7497f3b6a63685bfee32b
parentf19d3cd43b1f175b9c60e20d45c4c84161e15322
[CodeGen][X86] Implement _InterlockedCompareExchange128 intrinsic

Summary:
InterlockedCompareExchange128 is a bit more complicated than the other
InterlockedCompareExchange functions, so it requires a bit more work. It
doesn't directly refer to 128bit ints, instead it takes pointers to
64bit ints for Destination and ComparandResult, and exchange is taken as
two 64bit ints (high & low). The previous value is written to
ComparandResult, and success is returned. This implementation does the
following in order to produce a cmpxchg instruction:

  1. Cast everything to 128bit ints or int pointers, and glues together
     the Exchange values
  2. Reads from CompareandResult to get the comparand
  3. Calls cmpxchg volatile (on X86 this will produce a lock cmpxchg16b
     instruction)
    1. Result 0 (previous value) is written back to ComparandResult
    2. Result 1 (success bool) is zext'ed to a uchar and returned

Resolves bug https://llvm.org/PR35251

Patch by Colden Cullen!

Reviewers: rnk, agutowski

Reviewed By: rnk

Subscribers: majnemer, cfe-commits

Differential Revision: https://reviews.llvm.org/D41032

llvm-svn: 320730
clang/include/clang/Basic/BuiltinsX86_64.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/ms-intrinsics.c