🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.basm
18 messages
18 total messages Started by ADS Thu, 29 Aug 2002 15:49
Faster code that this
#306
Author: ADS
Date: Thu, 29 Aug 2002 15:49
11 lines
1138 bytes
Hi,

in a delphi app I use scanline so I want to check if  (y>=0) and (y<height)
and the same
for  (x>=0) and (x<bmp.Width).

what is the equivalent code in assembly?

thanks

Armindo
Re: Faster code that this
#307
Author: Andrew Rybenkov
Date: Thu, 29 Aug 2002 17:55
22 lines
1498 bytes
> in a delphi app I use scanline so I want to check if  (y>=0) and (y<height)
> and the same
> for  (x>=0) and (x<bmp.Width).
>
> what is the equivalent code in assembly?

Depends on what do you want to do with values out of bounds -
for example:
if y < 0 then y := 0;
or
if y < 0 then Continue;
or
while y < 0 do Inc(y, bmp.Height);
etc.

--
Andrew Rybenkov.

create labels, logos, image lists
for your programs and websites with
  "Imagizer: Click and Get It",
  http://www.geocities.com/arybenkov/imagizer/
Re: Faster code that this
#309
Author: ADS
Date: Fri, 30 Aug 2002 06:41
16 lines
1307 bytes
> Depends on what do you want to do with values out of bounds -

in fact I must check if the value is inside a bound to avoid error.

I would like to get a function like this

Function IsInsideBound(X,XMAX):boolean;

this function have to check if X>=0 and X<XMax.

any idea of how to do it in assembly?

thanks

Armindo
Re: Faster code that this
#311
Author: Guido Gybels
Date: Fri, 30 Aug 2002 09:04
20 lines
1911 bytes
"Eric Grange" <egrange@glscene.org> wrote in message
news:3D6F2AFA.2D16A22F@glscene.org...
> meaning that the function call, and all it could do would be pure
> overhead.

I can only agree with that, and as I also pointed out: the bounds checking
should be part of the overall routine. Besides, in general checking
preconditions happens outside any timecritical loop anyway and thus there is
not much to be gained by coding that part in assembly. It all boils down to
concentrating on the real bottlenecks, rather than on events on the
sidelines if one wants to improve the overall performance of an application.

Guido


--
Guido Gybels
http://www.optimalcode.com/Guido
(Disclaimer: all remarks made apply to Intel processors unless specified
otherwise)
Re: Faster code that this
#313
Author: Torjei Kvinen
Date: Fri, 30 Aug 2002 10:33
23 lines
1529 bytes
"ADS" <nospam@wanadoo.fr> wrote in message

> in fact I must check if the value is inside a bound to avoid error.
>
> I would like to get a function like this
>
> Function IsInsideBound(X,XMAX):boolean;


function IsInsideBound(X, XMax : Integer) : Boolean;
asm
    XOR     ECX, ECX
    CMP     EAX, EDX
    MOV     EAX, 01h
    CMOVA   EAX, ECX
end;

About 10 % faster than Guidos example :-)


--
Regards
Torjei Kvinen
Re: Faster code that this
#314
Author: Guido Gybels
Date: Fri, 30 Aug 2002 11:40
28 lines
2067 bytes
"Torjei Kvinen" <torjei@hahaha_bluezone.no> wrote in message
news:3d6f4a15@newsgroups.borland.com...
> function IsInsideBound(X, XMax : Integer) : Boolean;
> asm
>     XOR     ECX, ECX
>     CMP     EAX, EDX
>     MOV     EAX, 01h
>     CMOVA   EAX, ECX
> end;
>
> About 10 % faster than Guidos example :-)

I'm not so sure about that, the reason I introduced the more complicated
algorithm involving edx was that it removes a potentially harmful dependency
chain:

 MOV     EAX, 01h
 CMOVA   EAX, ECX

The first instruction has to retire before the next one can execute. On the
other hand, by focussing on that dependency chain, I had to introduce a
significant number of extra code, so I might have lost the benefit again. I
didn't perceive it to be important enough to do proper optimisation or
profiling on it :o), in the end the idea was just to show it is a rather
trivial problem. And finally: the speed loss is in the additional overhead
of the function calling, not inside the code itself.

Guido
Re: Faster code that this
#316
Author: Andrew Rybenkov
Date: Fri, 30 Aug 2002 11:51
12 lines
1630 bytes
it's yet another example that shows clearly weakness of Delphi/Object Pascal in matter of
optimization. The language has neither optimization pragmas for compiler, nor macro/inline
functions. Additionally, (AFAI heard it) it has porblems linking other compilers' output (Intel one's,
for example).

--
Andrew Rybenkov.

create labels, logos, image lists
for your programs and websites with
  "Imagizer: Click and Get It",
  http://www.geocities.com/arybenkov/imagizer/
Re: Faster code that this
#317
Author: Eric Grange
Date: Fri, 30 Aug 2002 12:21
10 lines
1389 bytes
> it's yet another example that shows clearly weakness 
> of Delphi/Object Pascal in matter of [...]

???

No amount of inlining could do you any good in that case,
whatever you could have in that inlined code would be
unnecessary extra code.

Eric
Re: Faster code that this
#318
Author: Andrew Rybenkov
Date: Fri, 30 Aug 2002 16:20
22 lines
1739 bytes
> No amount of inlining could do you any good in that case,
> whatever you could have in that inlined code would be
> unnecessary extra code.

Not at all. Consider
inBounds(x,y,width,height).

Calling via function - 4 params!
Calling via macro/inline - no one :) - it's just inline, that decent compiler can optimize farther.

Also consider next mnemonics, for example:

inBounds(x,y,width%ECX%,height%EDX%).


--
Andrew Rybenkov.

create labels, logos, image lists
for your programs and websites with
  "Imagizer: Click and Get It",
  http://www.geocities.com/arybenkov/imagizer/
Re: Faster code that this
#319
Author: Torjei Kvinen
Date: Fri, 30 Aug 2002 21:30
17 lines
1542 bytes
"Guido Gybels" <guido.gybels@rnid.org.uk> wrote in message

> I'm not so sure about that

Your code takes 3 clocks, mine only 2. I added the overhead for a procedure
call, and then it's 10 to 9. Only tested on a Celeron 800 MHz but should be
the same for PIII, and equal or better for Pentium 4 and Xeon.

This test is done under absolute perfect conditions. The real word is a
little different.

Have a nice week end.


--
Regards
Torjei Kvinen
Re: Faster code that this
#358
Author: Andrew Rybenkov
Date: Mon, 02 Sep 2002 17:35
12 lines
1561 bytes
> hehe, I think you're missing the point ;)

Nope. I considered function for (x in [0..Width-1]) and (y in [0..Height-1])).
So it is slghtly more than 1 "Direct unsigned compare" :)

--
Andrew Rybenkov.

create labels, logos, image lists
for your programs and websites with
  "Imagizer: Click and Get It",
  http://www.geocities.com/arybenkov/imagizer/
Re: Faster code that this
#359
Author: Robert Lee
Date: Mon, 02 Sep 2002 19:16
13 lines
1625 bytes
Andrew Rybenkov wrote:

> > hehe, I think you're missing the point ;)
>
> Nope. I considered function for (x in [0..Width-1]) and (y in [0..Height-1])).
> So it is slghtly more than 1 "Direct unsigned compare" :)

It could be a lookup though, if x and y were reasonably constrained somehow.


--
Bob Lee
High Performance Delphi - http://www.optimalcode.com/
Re: Faster code that this
#361
Author: Andrew Rybenkov
Date: Mon, 02 Sep 2002 20:24
15 lines
1789 bytes
> It could be a lookup though, if x and y were reasonably constrained somehow.

Aha! Here we returning to origin of the thread :)

Sure solution of this little problem depends wholly on context, and for a while
ADS did not tell it.

Lookup idea is cool anyway :)
--
Andrew Rybenkov.

create labels, logos, image lists
for your programs and websites with
  "Imagizer: Click and Get It",
  http://www.geocities.com/arybenkov/imagizer/
Faster code than this
#365
Author: ADS
Date: Tue, 03 Sep 2002 07:47
15 lines
1292 bytes
Hi there,

Well I have done some test on a PII 300 and Eric's code seems to be the
faster.

Now  have a particular case where I have to do something like that

function IsInBounds(AValue, AMin,AMax: Integer): Boolean;

any idea?

thanks

Armindo
Re: Faster code that this
#367
Author: Eric Grange
Date: Tue, 03 Sep 2002 08:41
13 lines
1775 bytes
> So it is slghtly more than 1 "Direct unsigned compare" :)

Two Direct unsigned compares then.
But since you would need at least two extra instructions 
in your inlined function. Even with a single opcode MMX
compare, you would need a MMX->Register test, meaning
you're still slower with at least an extra test :)

Anyway, the point is that whatever performance improvement
was required by the original poster, it could not be found
in otpimizing the compare itself, but at a higher level.

Eric
Re: Faster code than this
#368
Author: Guido Gybels
Date: Tue, 03 Sep 2002 09:15
17 lines
1548 bytes
"ADS" <nospam@wanadoo.fr> wrote in message
news:3d7468fa@newsgroups.borland.com...
> Well I have done some test on a PII 300 and Eric's code seems to be the
> faster.

Are you talking about the inlined Pascal evaluation? I believe many of us
already pointed out that would always be faster because of the overhead of
calling a separate assembly function.

> any idea?

Why have I got the feeling we need to do somebody else's homework here? The
solution will be similar (untested):

((Cardinal(AValue)>=Cardinal(AMin)) and (Cardinal(AValue)<=Cardinal(AMax)))

Guido
Re: Faster code than this
#371
Author: ADS
Date: Tue, 03 Sep 2002 09:59
20 lines
1631 bytes
> IMO if you have a min/max then the "best" code will depend
> on the data you have to test, more precisely:

In fact I do this test because I have to stretch a part of a bitmap to a
part of another one

and sometimes XValue are a little bit bigger than XMax and sometime a
littlebit smaller than XMin

so I have something like this :

xpt := (((DstRect.Left + Trunc(j * WidthRatio)) - DstX) + SrcX);
                if ((xpt < SrcRect.Left) or
                  (xpt >= SrcRect.Right)) then
                  begin
                    continue;
                  end;


Armindo
Re: Faster code than this
#373
Author: ADS
Date: Tue, 03 Sep 2002 10:05
23 lines
1601 bytes
>
> Are you talking about the inlined Pascal evaluation?
Yes
>
> Why have I got the feeling we need to do somebody else's homework here?

You're misundestanding something I'm a newbie in assembly not a top
programmer like you:-)

The
> solution will be similar (untested):
>
> ((Cardinal(AValue)>=Cardinal(AMin)) and
(Cardinal(AValue)<=Cardinal(AMax)))

I don't think that this would be faster than   : if (AValue>=Amin) and
(AValue<=Amax) then ....

so I don't know if assembly here would be helpfull....

thanks for your help

Armindo
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads