Einzelnen Beitrag anzeigen

mathias l.

Registriert seit: 23. Dez 2003
Ort: Bei Hamburg
4 Beiträge
 
#7

Re: SIMD-Dll in asm für Delphi

  Alt 26. Dez 2003, 13:05
Hi, vielen Dank für Eure Hilfe, hab's jetzt hinbekommen - hier der dll und delphi-code, die jetzt beide funktionieren:

Code:
.586 
.xmm
.model flat, stdcall
option casemap: none

.code

MultMatrix proc ths: DWORD, m1: DWORD, m2:DWORD    ; This are two adresses of 4x4Matrices
                                           ; which are 16*4 Bytes long
  push esi
  push edi
  push eax
  push edx

  mov edi, m1 

  movaps xmm4, [edi]
  movaps xmm5, [edi+16]
  movaps xmm6, [edi+32]
  movaps xmm7, [edi+48]

  mov esi, ths
  mov eax, 0 

  L1:
  movaps xmm0, [esi+eax]
  movaps xmm1, xmm0 
  movaps xmm2, xmm0 
  movaps xmm3, xmm0 

  shufps xmm0, xmm2, 000h
  shufps xmm1, xmm2, 055h
  shufps xmm2, xmm2, 0AAh
  shufps xmm3, xmm3, 0FFh

  mulps xmm0, [edi]
  mulps xmm1, [edi+16]
  mulps xmm2, [edi+32]
  mulps xmm3, [edi+48]

  addps xmm0, xmm1 
  addps xmm0, xmm2 
  addps xmm0, xmm3 

  mov edx, m2 
  add edx, eax
  movaps [edx], xmm0 

  add eax, 16 
  cmp eax, 48 
  jle L1 

  pop edx
  pop eax
  pop edi
  pop esi

  ret
MultMatrix endp

DllMain proc   hInstDll     :DWORD,
            dwNotification  :DWORD,
            lpReserved     :DWORD
  ret
DllMain endp

end

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TMyMatrix = array[0..15] of Single;
  PMyMatrix = ^TMyMatrix;

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen } 

  public
    { Public-Deklarationen } 
  end;

var
  Form1: TForm1;

procedure MultMatrix(x, y, z: Pointer); stdcall; external 'test.dll';

implementation

{$R *.DFM} 

procedure TForm1.Button1Click(Sender: TObject);
var
  pa, pb, pc: PMyMatrix;
  p1, p2, p3: Pointer;
  i: Integer;
 begin


  GetMem(p1, SizeOf(TMyMatrix)+15);
  pa:= PMyMatrix((Integer(p1)+$0F) and $FFFFFFF0);
  ZeroMemory(pa, SizeOf(TMyMatrix));

  GetMem(p2, SizeOf(TMyMatrix)+15);
  pb:= PMyMatrix((Integer(p2)+$0F) and $FFFFFFF0);
  ZeroMemory(pb, SizeOf(TMyMatrix));

  GetMem(p3, SizeOf(TMyMatrix)+15);
  pc:= PMyMatrix((Integer(p3)+$0F) and $FFFFFFF0);
  ZeroMemory(pc, SizeOf(TMyMatrix));

  for i:=0 to 15 do pc^[i]:=0.0; // pc is an empty matrix, pa, bb are
                                       // arbitrary 4x4 Matrices

  pa^[00]:= 1.0; pa^[01]:= 2.0; pa^[02]:= 3.0; pa^[03]:= 1.0;
  pa^[04]:= 2.0; pa^[05]:= 3.0; pa^[06]:= 1.0; pa^[07]:= 2.0;
  pa^[08]:= 3.0; pa^[09]:= 1.0; pa^[10]:= 2.0; pa^[11]:= 3.0;
  pa^[12]:= 1.0; pa^[13]:= 2.0; pa^[14]:= 3.0; pa^[15]:= 1.0;

  pb^[00]:= 3.0; pb^[01]:= 2.0; pb^[02]:= 1.0; pb^[03]:= 3.0;
  pb^[04]:= 2.0; pb^[05]:= 1.0; pb^[06]:= 3.0; pb^[07]:= 2.0;
  pb^[08]:= 1.0; pb^[09]:= 3.0; pb^[10]:= 2.0; pb^[11]:= 1.0;
  pb^[12]:= 3.0; pb^[13]:= 2.0; pb^[14]:= 1.0; pb^[15]:= 3.0;




  MultMatrix(pa, pb, pc);

  //pc is the Result

  FreeMem(p1);
  FreeMem(p2);
  FreeMem(p3);
end;

end.

Frohe Weihnachten noch!
  Mit Zitat antworten Zitat