Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

  1. ; call cpuid with args in eax, ecx
  2. ; store eax, ebx, ecx, edx to p
  3. PUBLIC _InterlockedCompareExchange128
  4. .CODE
  5. _InterlockedCompareExchange128 PROC FRAME
  6. ; extern "C" unsigned char _InterlockedCompareExchange128( int64 volatile * Destination, int64 ExchangeHigh, int64 ExchangeLow, int64 * ComparandResult );
  7. .endprolog
  8. ; fastcall conventions:
  9. ; RCX = Destination
  10. ; RDX = Exchange High
  11. ; R8 = Exchange Lo
  12. ; R9 = ComparandResult
  13. ; CMPXCHG16B refernece:
  14. ; http://download.intel.com/design/processor/manuals/253666.pdf
  15. ; Stash RBX in R11
  16. mov r11, rbx
  17. ; Destination ptr to r10
  18. mov r10, rcx
  19. ; RCX:RBX Exchange
  20. mov rcx, rdx
  21. mov rbx, r8
  22. ; RDX:RAX Comparand
  23. mov rax, [r9]
  24. mov rdx, [r9+8]
  25. ; Do the atomic operation
  26. lock cmpxchg16b [r10]
  27. ; RDX:RAX now contains the value of the destination, before the atomic operation.
  28. ; (Either it already matched and was not changed, or it did not match, in which case
  29. ; the value has been loaded into RDX:RAX.) The _InterlockedCompareExchange128 intrinsic
  30. ; semantics specify that this is always written out to CompareResult, so give it
  31. ; back to the caller.
  32. mov [r9], rax
  33. mov [r9+8], rdx
  34. ; Return value is in AL, set it equal to the zero flag
  35. setz al
  36. ; Restore RBX and get out
  37. mov rbx, r11
  38. ret
  39. _InterlockedCompareExchange128 ENDP
  40. ; For reference, here's what VC2010 generated
  41. ;
  42. ; __declspec(noinline) unsigned char Test_InterlockedCompareExchange128( int64 volatile * Destination, int64 ExchangeHigh, int64 ExchangeLow, int64 * ComparandResult )
  43. ; {
  44. ; return _InterlockedCompareExchange128( Destination, ExchangeHigh, ExchangeLow, ComparandResult );
  45. ; }
  46. ;
  47. ;
  48. ;?Test_InterlockedCompareExchange128@GCSDK@@YAEPEC_J_J1PEA_J@Z (unsigned char __cdecl GCSDK::Test_InterlockedCompareExchange128(__int64 volatile *,__int64,__int64,__int64 *)):
  49. ; 0000000000000000: 48 89 5C 24 08 mov qword ptr [rsp+8],rbx
  50. ; 0000000000000005: 49 8B 01 mov rax,qword ptr [r9]
  51. ; 0000000000000008: 4C 8B D1 mov r10,rcx
  52. ; 000000000000000B: 48 8B CA mov rcx,rdx
  53. ; 000000000000000E: 49 8B 51 08 mov rdx,qword ptr [r9+8]
  54. ; 0000000000000012: 49 8B D8 mov rbx,r8
  55. ; 0000000000000015: F0 49 0F C7 0A lock cmpxchg16b oword ptr [r10]
  56. ; 000000000000001A: 48 8B 5C 24 08 mov rbx,qword ptr [rsp+8]
  57. ; 000000000000001F: 49 89 01 mov qword ptr [r9],rax
  58. ; 0000000000000022: 49 89 51 08 mov qword ptr [r9+8],rdx
  59. ; 0000000000000026: 0F 94 C0 sete al
  60. ; 0000000000000029: C3 ret
  61. _TEXT ENDS
  62. END