Advertisement

fastest way to clean an array

Started by October 06, 2000 05:51 AM
35 comments, last by Bruno 23 years, 7 months ago
Thanks for the replys guys..., but

Either with ZeroMemory, or memset, the cleaning is sloooowwww...
I loose around 80 fps when i make the cleaning..
Is there any other way, so that i don''t lose so much performance??
Who can i do this with MMX instructions???

thanks guys

Bruno
Ok, let''s say you already detected MMX.
then :

_asm
{
mov edi,_arr_ptr // load edi width address of arr.
mov ecx,num of bytes / 8 // clears 8 bytes per loop
pxor mm1,mm1 // reset MMX register mm1 to 0

Loop:

movq [edi],mm1
add edi, 8 // inc. ptr to next quadword
dec ecx
jnz Loop
}

Sorry if I have forgotten anything, but hope this helps for a start.

/ Tooon

Advertisement
Why are you clearing that much memory every frame anyway? I would suggest you redesign your system.

quote:
Original post by Mithrandir
MOV is an expensive operation. Most ASM guru''s use X xor X to clear a register/memory position.



Hmm... for a 468 it is:

xor mem, immediate value (or mem, register) - 3 clocks.
mov mem, immediate value (or mem, register) - 1 clock.

Doesn''t look faster to me :-)



Well, to understand what i''m doing, download this :
www.geocities.com/brunomtc/test.zip

It''s a c-buffer, and the array, has the pixels that were used.., i still don''t know how to use inline assembler, whatever assembler i put there, i always get an error message

Any of you guys, know how to link assembler made by masm with VC ???
mr BiCEPS >> I think xor mem,mem is faster than mov mem,0 but when setting mem to zero the xor method can''t be faster. Not in my world anyway
Advertisement
Wait... xor mem, mem - that isn''t possible at all, is it?
On of the operands got to be either reg or immediate.

At least that''s what my opcodes manual says.

And all mov operations involving a register, immediate value or a memory location only take one clock, so it doesn''t actually get faster than that.
What are you trying to zero, the screen buffer? In OpenGL just use glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
I'd like to point out 4 things:

as usual, a better method is needed, not better code, but here goes anyway...

you can't xor a memory location, xor is used to clear regs only, and I think it saves you two ticks over mov.

an array[200][200] is not necessarily continous ram, so memset(array, 0x0, 200*200*sizeof(array[0])) is not good idea, unless you've force the array to be continuous.

If you use MMX (128bit blocks right?) the array needs to fall evenly on a 16 byte block, which 200x200 does so I guess your ok. If you use a different sized array, you have stop short and use normal regs for the last few bytes.

        int x=200;int y=200;int** array=0;array = new int*[x];for(int i=0;i<y;i++)	array<i> = new int[y];//thats how array[][] is laid out//so doing stuff with it requires a for loop//buUuUuUut you can do this;int x=200;int y=200;int** array=0;int* temp = new int[x*y];array = new int*[x];for(int i=0;i<x;i++)	array<i> = &temp[y*i];//so you can cheat and use temp to treat the memory space of array linearly        


Edited by - Magmai Kai Holmlor on October 9, 2000 11:15:59 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Thanks a lot Magmai Kai..

Whatever.., my screen buffer is an array, that is exaclty a copy of the opengl screen, so i can''t clean it with gl commands.., but thanks anyway. :O

Bruno

This topic is closed to new replies.

Advertisement