mmx.pp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. { returns true, if the processor supports the mmx instructions }
  45. function mmx_support : boolean;
  46. var
  47. _edx : longint;
  48. begin
  49. if cpuid_support then
  50. begin
  51. asm
  52. movl $1,%eax
  53. cpuid
  54. movl %edx,-4(%ebp) // _edx is ebp-4
  55. end;
  56. mmx_support:=(_edx and $800000)<>0;
  57. end
  58. else
  59. { a cpu with without cpuid instruction supports never mmx }
  60. mmx_support:=false;
  61. end;
  62. function amd_3d_support : boolean;
  63. var
  64. _edx : longint;
  65. begin
  66. if cpuid_support then
  67. begin
  68. asm
  69. movl $0x80000001,%eax
  70. cpuid
  71. movl %edx,-4(%ebp) // _edx is ebp-4
  72. end;
  73. amd_3d_support:=(_edx and $80000000)<>0;
  74. end
  75. else
  76. { a cpu with without cpuid instruction supports never mmx }
  77. amd_3d_support:=false;
  78. end;
  79. procedure emms;assembler;
  80. asm
  81. emms
  82. end;
  83. var
  84. oldexitproc : pointer;
  85. procedure mmxexitproc;
  86. begin
  87. exitproc:=oldexitproc;
  88. emms;
  89. end;
  90. begin
  91. if mmx_support then
  92. begin
  93. is_mmx_cpu:=true;
  94. { the exit code sets the fpu stack to empty }
  95. oldexitproc:=exitproc;
  96. exitproc:=@mmxexitproc;
  97. is_amd_3d_cpu:=amd_3d_support;
  98. end;
  99. end.
  100. {
  101. $Log$
  102. Revision 1.1 1998-03-25 11:18:43 root
  103. Initial revision
  104. Revision 1.7 1998/03/24 09:32:57 peter
  105. * fixed comments
  106. Revision 1.6 1998/03/22 12:41:51 florian
  107. * fix of amd_3d_support procedure
  108. Revision 1.5 1998/03/20 23:27:48 florian
  109. + some AMD 3D support:
  110. single type and detection of AMD 3D
  111. Revision 1.4 1998/03/03 22:47:01 florian
  112. * small problems fixed
  113. Revision 1.3 1998/02/09 23:48:18 florian
  114. + exit handler added (executes emms)
  115. + is_mmx_cpu variable added
  116. Revision 1.2 1998/02/05 22:30:48 florian
  117. + types for fixed mmx type
  118. Revision 1.1 1998/02/04 23:00:30 florian
  119. + Initial revision
  120. + basic data types
  121. + emms procedure
  122. + mmx detection from unit cpu inserted
  123. }