mmx.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. 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. {$ASMMODE ATT}
  45. { returns true, if the processor supports the mmx instructions }
  46. function mmx_support : boolean;
  47. var
  48. _edx : longint;
  49. begin
  50. if cpuid_support then
  51. begin
  52. asm
  53. movl $1,%eax
  54. cpuid
  55. movl %edx,_edx
  56. end;
  57. mmx_support:=(_edx and $800000)<>0;
  58. end
  59. else
  60. { a cpu with without cpuid instruction supports never mmx }
  61. mmx_support:=false;
  62. end;
  63. function amd_3d_support : boolean;
  64. var
  65. _edx : longint;
  66. begin
  67. if cpuid_support then
  68. begin
  69. asm
  70. movl $0x80000001,%eax
  71. cpuid
  72. movl %edx,_edx
  73. end;
  74. amd_3d_support:=(_edx and $80000000)<>0;
  75. end
  76. else
  77. { a cpu with without cpuid instruction supports never mmx }
  78. amd_3d_support:=false;
  79. end;
  80. procedure emms;assembler;
  81. asm
  82. emms
  83. end;
  84. var
  85. oldexitproc : pointer;
  86. procedure mmxexitproc;
  87. begin
  88. exitproc:=oldexitproc;
  89. emms;
  90. end;
  91. begin
  92. if mmx_support then
  93. begin
  94. is_mmx_cpu:=true;
  95. { the exit code sets the fpu stack to empty }
  96. oldexitproc:=exitproc;
  97. exitproc:=@mmxexitproc;
  98. is_amd_3d_cpu:=amd_3d_support;
  99. end;
  100. end.
  101. {
  102. $Log$
  103. Revision 1.6 2000-02-09 16:59:29 peter
  104. * truncated log
  105. Revision 1.5 2000/01/07 16:41:33 daniel
  106. * copyright 2000
  107. }