to put pixels on a window i found a somehow silly way:

invoke MoveToEx, hDC, x-pos, y-pos, NULL
invoke
Posted on 2002-10-31 05:21:05 by ploptor
darn it ... here's the complete one:

so, i was looking for a way to put pixels and found this way:

invoke MoveToEx, hDC, x, y, NULL
invoke LineTo, hDC, x, y

x and y can contain any value, but must be equal in both calls. i also used NULL to reject current position storage.

is there another way to achieve the same? preferably a faster algo?
Posted on 2002-10-31 05:25:47 by ploptor

invoke MoveToEx, hDC, x, y, NULL
invoke LineTo, hDC, x, y

x and y can contain any value, but must be equal in both calls. i also used NULL to reject current position storage.
is there another way to achieve the same? preferably a faster algo?


Well, you can save a few clocks by using registers for x, y and NULL. Pushing registers is faster than pushing immeds.


mov eax, x
mov ebx, y
xor ecx, ecx
mov edi, hDC
invoke MoveToEx, edi, eax, ebx, ecx
invoke LineTo, edi, eax, ecx
Posted on 2002-10-31 05:58:43 by scientica
Pushing immeds is equally as fast as pushing registers, the only difference being in the size of the operand. This could I suppose effect the speed of a loop as a whole due to cacheing issues, but the actual push itself will not be affected.

As for the code you propose, eax, and ecx will be trashed by the call to MoveToEx (although I presume you mean ebx rather than ecx anyway)...

The benefit of putting the variables in a register first is questionable in this case simply because there isn't enough reuse to warrant it. Cache performance will (unless MoveToEx is an incredibly long and has a voracious apetite for memory) probably make the register swaping redundant. I've not timed it, and its just a guess, so I'm not certain of this... But its my gut feeling...

Mirno
Posted on 2002-10-31 06:11:56 by Mirno

is there another way to achieve the same?


What about invoke SetPixel,hDc,x,y,COLOR

Or have I missed something silly here :rolleyes: .
Posted on 2002-10-31 10:53:23 by Eóin
Yes, ofcourse, stupid me :o
(I forgot that only ebx, edi and esi must be preserved, and the others are/can be trashed).

It should be this way:
mov edi, hDC

mov esi, x
mov ebx, y
invoke MoveToEx, edi, esi, ebx, 0
invoke LineTo, edi, esi, ebx


Well, "there isn't enough reuse to warrant it.", well I assumed two things:
1. That this pixel plotting will be done in an loop putting hDC in a reg (before the loop starts) I find warranted since it's used each in each loop (and it doesn't change, afaik anyhow).
2. The x and y vars are located in the memory, and it's so slow to push a mem var (4 ticks on 486es), I find it highly waranted to use registers (1 tick for moving mem to reg and 1 tick for pushing the reg, thus 2 ticks against 4 for pushing mem vars directly).

E?ins variant is faster, even unoptimized. It's possible to optimize by moving the vars to registers, if the variables are located in memory. But if the pixel plotting is not in a time critial loop there is no need...
Posted on 2002-10-31 11:11:12 by scientica