]> granicus.if.org Git - clang/commit
[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)
commit512570d77f25ef18315a665a625ff2d8f502dc3b
tree1ac1d103bdf999600f0ceb090119dcebf379b053
parenta66f080af76f4d928571c4a61ce5ce88c0f41b49
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320730 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/BuiltinsX86_64.def
lib/CodeGen/CGBuiltin.cpp
test/CodeGen/ms-intrinsics.c