Recent

Author Topic: need some optimization  (Read 9270 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8279
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: need some optimization
« Reply #15 on: March 22, 2013, 10:00:47 pm »
Surprisingly, changing blend_avg procedure to:
Code: [Select]
function blend_avg(const source,target:longword):longword;
var
   sourcer,sourceg,sourceb,targetr,targetg,targetb : longword;
begin
    sourcer := (source shr  0) and $ff;
    sourceg := (source shr  8) and $ff;
    sourceb := (source shr 16) and $ff;
    targetr := (target shr  0) and $ff;
    targetg := (target shr  8) and $ff;
    targetb := (target shr 16) and $ff;

    targetr := (sourcer + targetr) shl 1;
    targetg := (sourceg + targetg) shl 1;
    targetb := (sourceb + targetb) shl 1;

    result := (targetr shl  0) or (targetg shl  8) or (targetb shl 16);
end;
boosts the code 3-4 times! Now I get 120 fps :o

airpas

  • Full Member
  • ***
  • Posts: 179
Re: need some optimization
« Reply #16 on: July 02, 2013, 03:55:08 pm »
hi again
ok this is old post , we was talking about how to speed up float calculation with fpc ,i though the only way to make real optimization is by using asm directly , but i was wrong , we can use gcc instead

ok what i did is compiling 2 functions (blend_avg , scaleblit) using  gcc with -O3  -ffast-math -msse2 -mfpmath=sse switchs , then link the generated object with FPC .

what make me amazed is now FPC version is faster than gcc one with 15%

i add the attachments

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: need some optimization
« Reply #17 on: July 02, 2013, 05:20:37 pm »
I noticed still line like this:
Code: [Select]
trunc(320 + sin(d * 0.0034) * sin(d * 0.0134) * 300)it's actually 320.0 floating point sum, pascal just does the conversion automatically. It might optimize tiny bit if you sum integers instead of floats
Code: [Select]
320 + trunc(sin(d * 0.0034) * sin(d * 0.0134) * 300.0)
Another small thing you can do is calculate (tick * 0.2 + i) into variable first, because you do that 3 times.

And lastly i wonder if you actually have to draw single pixels with SDL. Isn't there functions which can optimally draw whole images with 1 command?
« Last Edit: July 02, 2013, 05:32:53 pm by User137 »

airpas

  • Full Member
  • ***
  • Posts: 179
Re: need some optimization
« Reply #18 on: July 02, 2013, 06:40:49 pm »
Quote
's actually 320.0 floating point sum, pascal just does the conversion automatically. It might optimize tiny bit if you sum integers instead of floats

yes you're right , but since this loop is just 128 time it doesn't metter .

Quote
And lastly i wonder if you actually have to draw single pixels with SDL. Isn't there functions which can optimally draw whole images with 1 command?
there are alot of situation where u need to draw single pixel (raytracing for example)

 

TinyPortal © 2005-2018