cpu.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. This unit contains some routines to get informations about the
  5. processor
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. unit cpu;
  14. interface
  15. uses
  16. sysutils;
  17. function InterlockedCompareExchange128Support : boolean;inline;
  18. function InterlockedCompareExchange128(var Target: Int128Rec; NewValue: Int128Rec; Comperand: Int128Rec): Int128Rec;
  19. implementation
  20. var
  21. _InterlockedCompareExchange128Support : boolean;
  22. function InterlockedCompareExchange128Support : boolean;inline;
  23. begin
  24. result:=_InterlockedCompareExchange128Support;
  25. end;
  26. function InterlockedCompareExchange128(var Target: Int128Rec; NewValue: Int128Rec; Comperand: Int128Rec): Int128Rec; assembler;
  27. {
  28. win64:
  29. rcx ... pointer to result
  30. rdx ... target
  31. r8 ... NewValue
  32. r9 ... Comperand
  33. }
  34. asm
  35. pushq %rbx
  36. { store result pointer for later use }
  37. pushq %rcx
  38. { load new value }
  39. movq (%r8),%rbx
  40. movq 8(%r8),%rcx
  41. { save target pointer for later use }
  42. movq %rdx,%r8
  43. { load comperand }
  44. movq (%r9),%rax
  45. movq 8(%r9),%rdx
  46. lock cmpxchg16b (%r8)
  47. { restore result pointer }
  48. popq %rcx
  49. { store result }
  50. movq %rax,(%rcx)
  51. movq %rdx,8(%rcx)
  52. popq %rbx
  53. end;
  54. procedure SetupSupport;
  55. var
  56. _ecx : longint;
  57. begin
  58. asm
  59. pushq %rbx
  60. movl $0x00000001,%eax
  61. cpuid
  62. movl %ecx,_ecx
  63. popq %rbx
  64. end;
  65. _InterlockedCompareExchange128Support:=(_ecx and $2000)<>0;
  66. end;
  67. begin
  68. SetupSupport;
  69. end.