mmx.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 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. {$ifdef HASFIXED}
  21. tmmxfixed = array[0..3] of fixed16;
  22. {$endif HASFIXED}
  23. tmmxlongint = array[0..1] of longint;
  24. tmmxcardinal = array[0..1] of cardinal;
  25. { for the AMD 3D }
  26. tmmxsingle = array[0..1] of single;
  27. pmmxshortint = ^tmmxshortint;
  28. pmmxbyte = ^tmmxbyte;
  29. pmmxword = ^tmmxword;
  30. pmmxinteger = ^tmmxinteger;
  31. {$ifdef HASFIXED}
  32. pmmxfixed = ^tmmxfixed;
  33. {$endif HASFIXED}
  34. pmmxlongint = ^tmmxlongint;
  35. pmmxcardinal = ^tmmxcardinal;
  36. { for the AMD 3D }
  37. pmmxsingle = ^tmmxsingle;
  38. const
  39. is_mmx_cpu : boolean = false;
  40. is_amd_3d_cpu : boolean = false;
  41. { sets all floating point registers to empty
  42. (use this after mmx usage)
  43. }
  44. procedure emms;
  45. implementation
  46. uses
  47. cpu;
  48. {$ASMMODE ATT}
  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 longint($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 2000-12-16 15:58:18 jonas
  108. * removed warnings about possible range check errors
  109. Revision 1.2 2000/07/13 11:33:41 michael
  110. + removed logs
  111. }