mmx.tex 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. \begin{procedure}{Emms}
  59. \Declaration
  60. Procedure Emms ;
  61. \Description
  62. \var{Emms} sets all floating point registers to empty. This procedure must
  63. be called after you have used any \var{MMX} instructions, if you want to use
  64. floating point arithmetic. If you just want to move floating point data
  65. around, it isn't necessary to call this function, the compiler doesn't use
  66. the FPU registers when moving data. Only when doing calculations, you should
  67. use this function.
  68. \Errors
  69. None.
  70. \SeeAlso
  71. \progref
  72. \end{procedure}
  73. \begin{FPCList}
  74. \item[Example:]
  75. \begin{verbatim}
  76. Program MMXDemo;
  77. uses mmx;
  78. var
  79. d1 : double;
  80. a : array[0..10000] of double;
  81. i : longint;
  82. begin
  83. d1:=1.0;
  84. {$mmx+}
  85. { floating point data is used, but we do _no_ arithmetic }
  86. for i:=0 to 10000 do
  87. a[i]:=d2; { this is done with 64 bit moves }
  88. {$mmx-}
  89. emms; { clear fpu }
  90. { now we can do floating point arithmetic again }
  91. end.
  92. \end{verbatim}
  93. \end{FPCList}