mmx.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998 by Florian Klaempfl
  5. member of the Free Pascal development team
  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. { This unit contains some helpful stuff to deal with the mmx extensions }
  13. unit mmx;
  14. interface
  15. type
  16. tmmxshortint = array[0..7] of shortint;
  17. tmmxbyte = array[0..7] of byte;
  18. tmmxword = array[0..3] of word;
  19. tmmxinteger = array[0..3] of integer;
  20. tmmxfixed = array[0..3] of fixed16;
  21. tmmxlongint = array[0..1] of longint;
  22. tmmxcardinal = array[0..1] of cardinal;
  23. { for the AMD 3D }
  24. tmmxsingle = array[0..1] of single;
  25. pmmxshortint = ^tmmxshortint;
  26. pmmxbyte = ^tmmxbyte;
  27. pmmxword = ^tmmxword;
  28. pmmxinteger = ^tmmxinteger;
  29. pmmxfixed = ^tmmxfixed;
  30. pmmxlongint = ^tmmxlongint;
  31. pmmxcardinal = ^tmmxcardinal;
  32. { for the AMD 3D }
  33. pmmxsingle = ^tmmxsingle;
  34. const
  35. is_mmx_cpu : boolean = false;
  36. is_amd_3d_cpu : boolean = false;
  37. { sets all floating point registers to empty
  38. (use this after mmx usage)
  39. }
  40. procedure emms;
  41. implementation
  42. uses
  43. cpu;
  44. {$ifndef CPUIDSUP}
  45. {$ASMMODE DIRECT}
  46. {$else}
  47. {$ASMMODE ATT}
  48. {$endif}
  49. { returns true, if the processor supports the mmx instructions }
  50. function mmx_support : boolean;
  51. var
  52. _edx : longint;
  53. begin
  54. if cpuid_support then
  55. begin
  56. asm
  57. movl $1,%eax
  58. cpuid
  59. movl %edx,_edx
  60. end;
  61. mmx_support:=(_edx and $800000)<>0;
  62. end
  63. else
  64. { a cpu with without cpuid instruction supports never mmx }
  65. mmx_support:=false;
  66. end;
  67. function amd_3d_support : boolean;
  68. var
  69. _edx : longint;
  70. begin
  71. if cpuid_support then
  72. begin
  73. asm
  74. movl $0x80000001,%eax
  75. cpuid
  76. movl %edx,_edx
  77. end;
  78. amd_3d_support:=(_edx and $80000000)<>0;
  79. end
  80. else
  81. { a cpu with without cpuid instruction supports never mmx }
  82. amd_3d_support:=false;
  83. end;
  84. procedure emms;assembler;
  85. asm
  86. emms
  87. end;
  88. var
  89. oldexitproc : pointer;
  90. procedure mmxexitproc;
  91. begin
  92. exitproc:=oldexitproc;
  93. emms;
  94. end;
  95. begin
  96. if mmx_support then
  97. begin
  98. is_mmx_cpu:=true;
  99. { the exit code sets the fpu stack to empty }
  100. oldexitproc:=exitproc;
  101. exitproc:=@mmxexitproc;
  102. is_amd_3d_cpu:=amd_3d_support;
  103. end;
  104. end.
  105. {
  106. $Log$
  107. Revision 1.3 1998-11-13 10:10:54 peter
  108. * ATT reader
  109. Revision 1.2 1998/05/31 14:15:50 peter
  110. * force to use ATT or direct parsing
  111. }