Vector Processing

A vector is a one-dimensional array. This gives rise to the term vector processing for the simultaneous execution of an operation on different data items in an array. Our use of MMX (Multi-Media Extension) for vector processing is an example of SIMD (Single Instruction Multiple Data). We show below a trivial example. In the following section we demonstrate the decryption of large files using the MMX unit in Lazarus. The third section shows how you can use MMX in Delphi by writing in-line assembler code for the 64-bit mm0 .. mm7 registers. The final section shows as a speed comparison the corresponding encryption without using MMX.

program MMX_Demo;
uses
  MMX;
const
  w1 : tmmxword = (10, 20, 30, 40); //array of word
  w2 : tmmxword = (1, 2, 3, 4);
var
  w3 : tmmxword;
  i : integer;
begin
  {$mmx+} //Turn on MMX
  writeln('Addition:');
  w3 := w1 + w2;
  for i := 0 to 3 do
    begin
      write(w1[i] : 3, ' +');
      write(w2[i] : 2, ' =');
      write(w3[i] : 3);
      writeln;
    end;
  writeln('Subtraction:');
  w3 := w1 - w2;
  for i := 0 to 3 do
    begin
      write(w1[i] : 3, ' -');
      write(w2[i] : 2, ' =');
      write(w3[i] : 3);
      writeln;
    end;
  writeln('Multiplication:');
  w3 := w1 * w2;
  for i := 0 to 3 do
    begin
      write(w1[i] : 3, ' x');
      write(w2[i] : 2, ' =');
      write(w3[i] : 3);
      writeln;
    end;
  {$mmx-} //Turn off MMX
  readln;
end.
Programming - a skill for life!

Further ways of using arrays for confident programmers