Ignore:
Timestamp:
Apr 9, 2015, 9:58:36 PM (9 years ago)
Author:
chronos
Message:
  • Fixed: Use csOpaque control style also to Image, PaintBox and OpenGLControl.
  • Modified: Change size of test frame with SpinEdits as delayed using timer.
  • Updated: BRGABitmap package to version 8.1.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgrasse.pas

    r452 r472  
    22
    33{$mode objfpc}{$H+}
     4
     5{$i bgrasse.inc}
    46
    57interface
     
    1921var UseSSE, UseSSE2, UseSSE3 : boolean;
    2022
    21 {$ifdef CPUI386}
     23{$ifdef BGRASSE_AVAILABLE}
    2224  {$asmmode intel}
    2325  //SSE rotate singles
     
    3739  procedure Normalize3D_128_SqLen(var v: TPoint3D_128; out SqLen: single);
    3840  operator * (const v1: TPoint3D_128; const factor: single): TPoint3D_128;
    39   operator + (const v1,v2: TPoint3D_128): TPoint3D_128;
     41  operator + (constref v1,v2: TPoint3D_128): TPoint3D_128;
    4042  operator - (const v1,v2: TPoint3D_128): TPoint3D_128;
    4143  operator - (const v: TPoint3D_128): TPoint3D_128; inline;
    4244  operator = (const v1,v2: TPoint3D_128): boolean; inline;
    4345  procedure ClearPoint3D_128(out v: TPoint3D_128);
    44   {$IFDEF CPUI386}
     46  {$IFDEF BGRASSE_AVAILABLE}
    4547  procedure ClearPoint3D_128_AlignedSSE(out v: TPoint3D_128);
    4648  {$ENDIF}
     
    4850
    4951var
    50   Add3D_Aligned : procedure (var dest: TPoint3D_128; const src: TPoint3D_128);
     52  Add3D_Aligned : procedure (var dest: TPoint3D_128; constref src: TPoint3D_128);
    5153  Normalize3D_128 : procedure (var v: TPoint3D_128);
    5254  VectProduct3D_128 : procedure (const u,v: TPoint3D_128; out w: TPoint3D_128);
    53   DotProduct3D_128 : function (const v1,v2: TPoint3D_128): single;
     55  DotProduct3D_128 : function (constref v1,v2: TPoint3D_128): single;
    5456
    5557const
     
    125127end;
    126128
    127 operator + (const v1,v2: TPoint3D_128): TPoint3D_128;
     129operator + (constref v1,v2: TPoint3D_128): TPoint3D_128;
    128130{$ifdef CPUI386} assembler;
    129131asm
     
    152154{$endif}
    153155
    154 {$ifdef CPUI386}
    155 procedure Add3D_AlignedSSE(var dest: TPoint3D_128; const src: TPoint3D_128); assembler;
    156 asm
    157   movaps xmm0, [eax]
    158   movups xmm1, [edx]
     156{$ifdef BGRASSE_AVAILABLE}
     157procedure Add3D_AlignedSSE(var dest: TPoint3D_128; constref src: TPoint3D_128); assembler;
     158asm
     159  movaps xmm0, [dest]
     160  movups xmm1, [src]
    159161  addps xmm0, xmm1
    160   movaps [eax], xmm0
    161 end;
    162 {$endif}
    163 
    164 procedure Add3D_NoSSE(var dest: TPoint3D_128; const src: TPoint3D_128);
     162  movaps [dest], xmm0
     163end;
     164{$endif}
     165
     166procedure Add3D_NoSSE(var dest: TPoint3D_128; constref src: TPoint3D_128);
    165167{$ifdef CPUI386} assembler;
    166168asm
     
    226228
    227229procedure ClearPoint3D_128(out v: TPoint3D_128);
    228 {$ifdef CPUI386}
    229 begin
     230{$ifdef cpux86_64} assembler;
     231asm
     232  push rbx
     233  mov rax,v
     234  xor rbx,rbx
     235  mov [rax],rbx
     236  mov [rax+8],rbx
     237  pop rbx
     238end;
     239{$else}
     240  {$ifdef CPUI386} assembler;
     241  asm
     242    push ebx
     243    mov eax,v
     244    xor ebx,ebx
     245    mov [eax],ebx
     246    mov [eax+4],ebx
     247    mov [eax+8],ebx
     248    pop ebx
     249  end;
     250  {$else}
     251  var p: pdword;
     252  begin
     253    p := @v;
     254    p^ := 0;
     255    inc(p);
     256    p^ := 0;
     257    inc(p);
     258    p^ := 0;
     259  end;
     260  {$endif}
     261{$endif}
     262
     263procedure ClearPoint3D_128_AlignedSSE(out v: TPoint3D_128);
     264{$ifdef BGRASSE_AVAILABLE} assembler;
    230265 asm
    231    push ebx
    232    mov eax,v
    233    xor ebx,ebx
    234    mov [eax],ebx
    235    mov [eax+4],ebx
    236    mov [eax+8],ebx
    237    pop ebx
     266  xorps xmm0,xmm0
     267  {$ifdef cpux86_64}
     268  mov rax,v
     269  movaps [rax],xmm0
     270  {$else}
     271  mov eax,v
     272  movaps [eax],xmm0
     273  {$endif}
    238274 end;
    239 end;
    240275{$else}
    241276var p: pdword;
     
    250285{$endif}
    251286
    252 procedure ClearPoint3D_128_AlignedSSE(out v: TPoint3D_128);
    253 {$ifdef CPUI386}
    254 begin
    255  asm
    256    xorps xmm0,xmm0
    257    movaps [eax],xmm0
    258  end;
    259 end;
    260 {$else}
    261 var p: pdword;
    262 begin
    263   p := @v;
    264   p^ := 0;
    265   inc(p);
    266   p^ := 0;
    267   inc(p);
    268   p^ := 0;
    269 end;
    270 {$endif}
    271 
    272287function IsPoint3D_128_Zero(const v: TPoint3D_128): boolean;
    273288begin
     
    302317{$endif}
    303318
    304 {$ifdef CPUI386}
    305 function DotProduct3D_128_SSE3(const v1,v2: TPoint3D_128): single; assembler;
     319{$ifdef BGRASSE_AVAILABLE}
     320function DotProduct3D_128_SSE3(constref v1,v2: TPoint3D_128): single; assembler;
    306321asm
    307322  movups xmm0, [v1]
     
    315330{$endif}
    316331
    317 function DotProduct3D_128_NoSSE(const v1,v2: TPoint3D_128): single;
     332function DotProduct3D_128_NoSSE(constref v1,v2: TPoint3D_128): single;
    318333begin
    319334  result := v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
     
    331346end;
    332347
    333 {$ifdef CPUI386}
     348{$ifdef BGRASSE_AVAILABLE}
    334349procedure Normalize3D_128_SSE1(var v: TPoint3D_128);
    335350var len: single;
    336351begin
    337352  asm
    338     mov eax, v
    339     movups xmm0, [eax]
    340     movaps xmm1, xmm0
    341     mulps xmm0, xmm0
     353    {$i sseloadv.inc}
     354    movaps xmm2, xmm1
     355    mulps xmm2, xmm2
    342356
    343357    //mix1
    344     movaps xmm7, xmm0
     358    movaps xmm7, xmm2
    345359    shufps xmm7, xmm7, $4e
    346     addps xmm0, xmm7
     360    addps xmm2, xmm7
    347361    //mix2
    348     movaps xmm7, xmm0
     362    movaps xmm7, xmm2
    349363    shufps xmm7, xmm7, $11
    350     addps xmm0, xmm7
    351 
    352     movss len, xmm0
     364    addps xmm2, xmm7
     365
     366    movss len, xmm2
    353367  end;
    354368  if (len = 0) then exit;
     
    361375  end else
    362376  asm
    363     rsqrtps xmm0, xmm0
    364     mulps xmm0, xmm1  //apply
    365     mov eax, v
    366     movups [eax], xmm0
    367   end;
    368 end;
    369 {$endif}
    370 
    371 {$ifdef CPUI386}
     377    rsqrtps xmm2, xmm2
     378    mulps xmm1, xmm2  //apply
     379    {$i ssesavev.inc}
     380  end;
     381end;
     382{$endif}
     383
     384{$ifdef BGRASSE_AVAILABLE}
    372385procedure Normalize3D_128_SSE3(var v: TPoint3D_128);
    373386var len: single;
    374387begin
    375388  asm
    376     mov eax, v
    377     movups xmm0, [eax]
    378     movaps xmm1, xmm0
    379     mulps xmm0, xmm0
    380 
    381     haddps xmm0,xmm0
    382     haddps xmm0,xmm0
    383 
    384     movss len, xmm0
     389    {$i sseloadv.inc}
     390    movaps xmm2, xmm1
     391    mulps xmm2, xmm2
     392
     393    haddps xmm2,xmm2
     394    haddps xmm2,xmm2
     395
     396    movss len, xmm2
    385397  end;
    386398  if (len = 0) then exit;
     
    393405  end else
    394406  asm
    395     rsqrtps xmm0, xmm0
    396     mulps xmm0, xmm1  //apply
    397     mov eax, v
    398     movups [eax], xmm0
     407    rsqrtps xmm2, xmm2
     408    mulps xmm1, xmm2  //apply
     409    {$i ssesavev.inc}
    399410  end;
    400411end;
     
    404415var InvLen: single;
    405416begin
    406   {$ifdef CPUI386}
     417  {$ifdef BGRASSE_AVAILABLE}
    407418    if UseSSE then
    408419    begin
    409420      asm
    410         mov eax, v
    411         movups xmm0, [eax]
    412         movaps xmm1, xmm0
    413         mulps xmm0, xmm0
     421        {$i sseloadv.inc}
     422        movaps xmm2, xmm1
     423        mulps xmm2, xmm2
    414424      end;
    415425      if UseSSE3 then
    416426      asm
    417         haddps xmm0,xmm0
    418         haddps xmm0,xmm0
    419         movss SqLen, xmm0
     427        haddps xmm2,xmm2
     428        haddps xmm2,xmm2
     429        movss SqLen, xmm2
    420430      end else
    421431      asm
    422432        //mix1
    423         movaps xmm7, xmm0
     433        movaps xmm7, xmm2
    424434        shufps xmm7, xmm7, $4e
    425         addps xmm0, xmm7
     435        addps xmm2, xmm7
    426436        //mix2
    427         movaps xmm7, xmm0
     437        movaps xmm7, xmm2
    428438        shufps xmm7, xmm7, $11
    429         addps xmm0, xmm7
    430         movss SqLen, xmm0
     439        addps xmm2, xmm7
     440        movss SqLen, xmm2
    431441      end;
    432442      if SqLen = 0 then exit;
     
    439449      end else
    440450      asm
    441         rsqrtps xmm0, xmm0
    442         mulps xmm0, xmm1  //apply
    443         mov eax, v
    444         movups [eax], xmm0
     451        rsqrtps xmm2, xmm2
     452        mulps xmm1, xmm2  //apply
     453        {$i ssesavev.inc}
    445454      end;
    446455    end
     
    465474end;
    466475
    467 {$ifdef CPUI386}
    468 procedure VectProduct3D_128_SSE(const u,v: TPoint3D_128; out w: TPoint3D_128); assembler;
    469 asm
    470   mov eax, u
    471   movups xmm6, [eax]
     476{$ifdef BGRASSE_AVAILABLE}
     477procedure VectProduct3D_128_SSE(constref u,v: TPoint3D_128; out w: TPoint3D_128); assembler;
     478asm
     479  {$ifdef cpux86_64}
     480  mov rax,u
     481  movups xmm6,[rax]
     482  {$else}
     483  mov eax,u
     484  movups xmm6,[eax]
     485  {$endif}
    472486  movaps xmm4, xmm6
    473487  shufps xmm6, xmm6, Shift231
    474488
    475   mov eax, v
    476   movups xmm7, [eax]
     489  {$ifdef cpux86_64}
     490  mov rax,v
     491  movups xmm7,[rax]
     492  {$else}
     493  mov eax,v
     494  movups xmm7,[eax]
     495  {$endif}
    477496  movaps xmm5,xmm7
    478497  shufps xmm7, xmm7, Shift312
     
    487506  subps xmm3,xmm4
    488507
     508  {$ifdef cpux86_64}
     509  mov rax,w
     510  movups [rax],xmm3
     511  {$else}
    489512  mov eax,w
    490   movups [eax], xmm3
     513  movups [eax],xmm3
     514  {$endif}
    491515end;
    492516{$endif}
     
    496520{$hints off}
    497521constructor TMemoryBlockAlign128.Create(size: integer);
    498 {$IFDEF CPUI386}
     522{$IFDEF BGRASSE_AVAILABLE}
    499523var
    500   delta: cardinal;
     524  delta: PtrUInt;
    501525begin
    502526  getmem(FContainer, size+15);
    503   delta := cardinal(FContainer) and 15;
     527  delta := PtrUInt(FContainer) and 15;
    504528  if delta <> 0 then delta := 16-delta;
    505529  FData := pbyte(FContainer)+delta;
     
    519543end;
    520544
    521 {$ifdef CPUI386}   {$ASMMODE ATT}
     545{$ifdef BGRASSE_AVAILABLE}
    522546function sse3_support : boolean;
    523547
     
    526550
    527551  begin
     552    {$IFDEF CPUI386}
    528553     if cpuid_support then
    529554       begin
    530555          asm
    531              pushl %ebx
    532              movl $1,%eax
     556             push ebx
     557             mov eax,1
    533558             cpuid
    534              movl %ecx,_ecx
    535              popl %ebx
     559             mov _ecx,ecx
     560             pop ebx
    536561          end;
    537562          sse3_support:=(_ecx and 1)<>0;
     
    539564     else
    540565       sse3_support:=false;
     566    {$ELSE}
     567    asm
     568       push rbx
     569       mov eax,1
     570       cpuid
     571       mov _ecx,ecx
     572       pop rbx
     573    end;
     574    sse3_support:=(_ecx and 1)<>0;
     575    {$ENDIF}
    541576  end;
    542577{$endif}
     
    546581  {$ifdef CPUI386}
    547582  UseSSE := is_sse_cpu and FLAG_ENABLED_SSE;
     583  {$else}
     584    {$ifdef cpux86_64}
     585    UseSSE := FLAG_ENABLED_SSE;
     586    {$else}
     587    UseSSE := false;
     588    {$endif}
     589  {$endif}
     590
     591  {$IFDEF BGRASSE_AVAILABLE}
    548592  if UseSSE then
    549593  begin
     594    {$ifdef cpux86_64}
     595    UseSSE2 := true;
     596    {$else}
    550597    UseSSE2 := is_sse2_cpu;
     598    {$endif}
    551599    UseSSE3 := sse3_support;
    552600
     
    565613  end
    566614  else
    567   {$endif}
     615  {$ENDIF}
    568616  begin
    569617    UseSSE := false;
Note: See TracChangeset for help on using the changeset viewer.