Changeset 472 for GraphicTest/Packages/bgrabitmap/bgrasse.pas
- Timestamp:
- Apr 9, 2015, 9:58:36 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgrasse.pas
r452 r472 2 2 3 3 {$mode objfpc}{$H+} 4 5 {$i bgrasse.inc} 4 6 5 7 interface … … 19 21 var UseSSE, UseSSE2, UseSSE3 : boolean; 20 22 21 {$ifdef CPUI386}23 {$ifdef BGRASSE_AVAILABLE} 22 24 {$asmmode intel} 23 25 //SSE rotate singles … … 37 39 procedure Normalize3D_128_SqLen(var v: TPoint3D_128; out SqLen: single); 38 40 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; 40 42 operator - (const v1,v2: TPoint3D_128): TPoint3D_128; 41 43 operator - (const v: TPoint3D_128): TPoint3D_128; inline; 42 44 operator = (const v1,v2: TPoint3D_128): boolean; inline; 43 45 procedure ClearPoint3D_128(out v: TPoint3D_128); 44 {$IFDEF CPUI386}46 {$IFDEF BGRASSE_AVAILABLE} 45 47 procedure ClearPoint3D_128_AlignedSSE(out v: TPoint3D_128); 46 48 {$ENDIF} … … 48 50 49 51 var 50 Add3D_Aligned : procedure (var dest: TPoint3D_128; const src: TPoint3D_128);52 Add3D_Aligned : procedure (var dest: TPoint3D_128; constref src: TPoint3D_128); 51 53 Normalize3D_128 : procedure (var v: TPoint3D_128); 52 54 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; 54 56 55 57 const … … 125 127 end; 126 128 127 operator + (const v1,v2: TPoint3D_128): TPoint3D_128;129 operator + (constref v1,v2: TPoint3D_128): TPoint3D_128; 128 130 {$ifdef CPUI386} assembler; 129 131 asm … … 152 154 {$endif} 153 155 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} 157 procedure Add3D_AlignedSSE(var dest: TPoint3D_128; constref src: TPoint3D_128); assembler; 158 asm 159 movaps xmm0, [dest] 160 movups xmm1, [src] 159 161 addps xmm0, xmm1 160 movaps [ eax], xmm0161 end; 162 {$endif} 163 164 procedure Add3D_NoSSE(var dest: TPoint3D_128; const src: TPoint3D_128);162 movaps [dest], xmm0 163 end; 164 {$endif} 165 166 procedure Add3D_NoSSE(var dest: TPoint3D_128; constref src: TPoint3D_128); 165 167 {$ifdef CPUI386} assembler; 166 168 asm … … 226 228 227 229 procedure ClearPoint3D_128(out v: TPoint3D_128); 228 {$ifdef CPUI386} 229 begin 230 {$ifdef cpux86_64} assembler; 231 asm 232 push rbx 233 mov rax,v 234 xor rbx,rbx 235 mov [rax],rbx 236 mov [rax+8],rbx 237 pop rbx 238 end; 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 263 procedure ClearPoint3D_128_AlignedSSE(out v: TPoint3D_128); 264 {$ifdef BGRASSE_AVAILABLE} assembler; 230 265 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} 238 274 end; 239 end;240 275 {$else} 241 276 var p: pdword; … … 250 285 {$endif} 251 286 252 procedure ClearPoint3D_128_AlignedSSE(out v: TPoint3D_128);253 {$ifdef CPUI386}254 begin255 asm256 xorps xmm0,xmm0257 movaps [eax],xmm0258 end;259 end;260 {$else}261 var p: pdword;262 begin263 p := @v;264 p^ := 0;265 inc(p);266 p^ := 0;267 inc(p);268 p^ := 0;269 end;270 {$endif}271 272 287 function IsPoint3D_128_Zero(const v: TPoint3D_128): boolean; 273 288 begin … … 302 317 {$endif} 303 318 304 {$ifdef CPUI386}305 function DotProduct3D_128_SSE3(const v1,v2: TPoint3D_128): single; assembler;319 {$ifdef BGRASSE_AVAILABLE} 320 function DotProduct3D_128_SSE3(constref v1,v2: TPoint3D_128): single; assembler; 306 321 asm 307 322 movups xmm0, [v1] … … 315 330 {$endif} 316 331 317 function DotProduct3D_128_NoSSE(const v1,v2: TPoint3D_128): single;332 function DotProduct3D_128_NoSSE(constref v1,v2: TPoint3D_128): single; 318 333 begin 319 334 result := v1.x*v2.x + v1.y*v2.y + v1.z*v2.z; … … 331 346 end; 332 347 333 {$ifdef CPUI386}348 {$ifdef BGRASSE_AVAILABLE} 334 349 procedure Normalize3D_128_SSE1(var v: TPoint3D_128); 335 350 var len: single; 336 351 begin 337 352 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 342 356 343 357 //mix1 344 movaps xmm7, xmm 0358 movaps xmm7, xmm2 345 359 shufps xmm7, xmm7, $4e 346 addps xmm 0, xmm7360 addps xmm2, xmm7 347 361 //mix2 348 movaps xmm7, xmm 0362 movaps xmm7, xmm2 349 363 shufps xmm7, xmm7, $11 350 addps xmm 0, xmm7351 352 movss len, xmm 0364 addps xmm2, xmm7 365 366 movss len, xmm2 353 367 end; 354 368 if (len = 0) then exit; … … 361 375 end else 362 376 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; 381 end; 382 {$endif} 383 384 {$ifdef BGRASSE_AVAILABLE} 372 385 procedure Normalize3D_128_SSE3(var v: TPoint3D_128); 373 386 var len: single; 374 387 begin 375 388 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 385 397 end; 386 398 if (len = 0) then exit; … … 393 405 end else 394 406 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} 399 410 end; 400 411 end; … … 404 415 var InvLen: single; 405 416 begin 406 {$ifdef CPUI386}417 {$ifdef BGRASSE_AVAILABLE} 407 418 if UseSSE then 408 419 begin 409 420 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 414 424 end; 415 425 if UseSSE3 then 416 426 asm 417 haddps xmm 0,xmm0418 haddps xmm 0,xmm0419 movss SqLen, xmm 0427 haddps xmm2,xmm2 428 haddps xmm2,xmm2 429 movss SqLen, xmm2 420 430 end else 421 431 asm 422 432 //mix1 423 movaps xmm7, xmm 0433 movaps xmm7, xmm2 424 434 shufps xmm7, xmm7, $4e 425 addps xmm 0, xmm7435 addps xmm2, xmm7 426 436 //mix2 427 movaps xmm7, xmm 0437 movaps xmm7, xmm2 428 438 shufps xmm7, xmm7, $11 429 addps xmm 0, xmm7430 movss SqLen, xmm 0439 addps xmm2, xmm7 440 movss SqLen, xmm2 431 441 end; 432 442 if SqLen = 0 then exit; … … 439 449 end else 440 450 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} 445 454 end; 446 455 end … … 465 474 end; 466 475 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} 477 procedure VectProduct3D_128_SSE(constref u,v: TPoint3D_128; out w: TPoint3D_128); assembler; 478 asm 479 {$ifdef cpux86_64} 480 mov rax,u 481 movups xmm6,[rax] 482 {$else} 483 mov eax,u 484 movups xmm6,[eax] 485 {$endif} 472 486 movaps xmm4, xmm6 473 487 shufps xmm6, xmm6, Shift231 474 488 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} 477 496 movaps xmm5,xmm7 478 497 shufps xmm7, xmm7, Shift312 … … 487 506 subps xmm3,xmm4 488 507 508 {$ifdef cpux86_64} 509 mov rax,w 510 movups [rax],xmm3 511 {$else} 489 512 mov eax,w 490 movups [eax], xmm3 513 movups [eax],xmm3 514 {$endif} 491 515 end; 492 516 {$endif} … … 496 520 {$hints off} 497 521 constructor TMemoryBlockAlign128.Create(size: integer); 498 {$IFDEF CPUI386}522 {$IFDEF BGRASSE_AVAILABLE} 499 523 var 500 delta: cardinal;524 delta: PtrUInt; 501 525 begin 502 526 getmem(FContainer, size+15); 503 delta := cardinal(FContainer) and 15;527 delta := PtrUInt(FContainer) and 15; 504 528 if delta <> 0 then delta := 16-delta; 505 529 FData := pbyte(FContainer)+delta; … … 519 543 end; 520 544 521 {$ifdef CPUI386} {$ASMMODE ATT}545 {$ifdef BGRASSE_AVAILABLE} 522 546 function sse3_support : boolean; 523 547 … … 526 550 527 551 begin 552 {$IFDEF CPUI386} 528 553 if cpuid_support then 529 554 begin 530 555 asm 531 push l %ebx532 mov l $1,%eax556 push ebx 557 mov eax,1 533 558 cpuid 534 mov l %ecx,_ecx535 pop l %ebx559 mov _ecx,ecx 560 pop ebx 536 561 end; 537 562 sse3_support:=(_ecx and 1)<>0; … … 539 564 else 540 565 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} 541 576 end; 542 577 {$endif} … … 546 581 {$ifdef CPUI386} 547 582 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} 548 592 if UseSSE then 549 593 begin 594 {$ifdef cpux86_64} 595 UseSSE2 := true; 596 {$else} 550 597 UseSSE2 := is_sse2_cpu; 598 {$endif} 551 599 UseSSE3 := sse3_support; 552 600 … … 565 613 end 566 614 else 567 {$ endif}615 {$ENDIF} 568 616 begin 569 617 UseSSE := false;
Note:
See TracChangeset
for help on using the changeset viewer.