mmx.tex 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The MMX unit}
  22. This chapter describes the \file{MMX} unit. This unit allows you to use the
  23. \var{MMX} capabilities of the \fpc compiler. It was written by Florian
  24. Kl\"ampfl for the \var{I386} processor.
  25. \section{Variables, Types and constants}
  26. The following types are defined in the \var{MMX} unit:
  27. \begin{verbatim}
  28. tmmxshortint = array[0..7] of shortint;
  29. tmmxbyte = array[0..7] of byte;
  30. tmmxword = array[0..3] of word;
  31. tmmxinteger = array[0..3] of integer;
  32. tmmxfixed = array[0..3] of fixed16;
  33. tmmxlongint = array[0..1] of longint;
  34. tmmxcardinal = array[0..1] of cardinal;
  35. { for the AMD 3D }
  36. tmmxsingle = array[0..1] of single;
  37. \end{verbatim}
  38. And the following pointers to the above types:
  39. \begin{verbatim}
  40. pmmxshortint = ^tmmxshortint;
  41. pmmxbyte = ^tmmxbyte;
  42. pmmxword = ^tmmxword;
  43. pmmxinteger = ^tmmxinteger;
  44. pmmxfixed = ^tmmxfixed;
  45. pmmxlongint = ^tmmxlongint;
  46. pmmxcardinal = ^tmmxcardinal;
  47. { for the AMD 3D }
  48. pmmxsingle = ^tmmxsingle;
  49. \end{verbatim}
  50. The following initialized constants allow you to determine if the computer
  51. has \var{MMX} extensions. They are set correctly in the unit's
  52. initialization code.
  53. \begin{verbatim}
  54. is_mmx_cpu : boolean = false;
  55. is_amd_3d_cpu : boolean = false;
  56. \end{verbatim}
  57. \section{Functions and Procedures}
  58. \Procedure{Emms}
  59. {\var{Emms} sets all floating point registers to empty. This procedure must
  60. be called after you have used any \var{MMX} instructions, if you want to use
  61. floating point arithmetic. If you just want to move floating point data
  62. around, it isn't necessary to call this function, the compiler doesn't use
  63. the FPU registers when moving data. Only when doing calculations, you should
  64. use this function.
  65. }
  66. {None.}
  67. { \progref }
  68. \begin{FPCList}
  69. \item[Example:]
  70. \begin{verbatim}
  71. Program MMXDemo;
  72. uses mmx;
  73. var
  74. d1 : double;
  75. a : array[0..10000] of double;
  76. i : longint;
  77. begin
  78. d1:=1.0;
  79. {$mmx+}
  80. { floating point data is used, but we do _no_ arithmetic }
  81. for i:=0 to 10000 do
  82. a[i]:=d2; { this is done with 64 bit moves }
  83. {$mmx-}
  84. emms; { clear fpu }
  85. { now we can do floating point arithmetic again }
  86. end.
  87. \end{verbatim}
  88. \end{FPCList}