PDA

Click to See Complete Forum and Search --> : MemCpy_QUAD


Halsafar
Jan 11th, 2005, 03:12 PM
Alright I got a function which acts like memset except instead of filling the variable passed the single bytes it works in QUADS -- 4bytes at a time.

//dest = &variable
//data = 0
//count = sizeof(variable) / 4;
inline void MemSet_QUAD(void* dest, unsigned int data, int count)
{
_asm
{
mov edi, dest;
mov ecx, count;
mov eax, data;
rep stosd;
}
}


I was wondering if anyone could help me create a function which MemCpy_QUAD.
Copy 4 bytes at a time -- assuming that regular memcpy only does 1 byte at a time.

Maven
Jan 12th, 2005, 03:21 AM
Alright I got a function which acts like memset except instead of filling the variable passed the single bytes it works in QUADS -- 4bytes at a time.

//dest = &variable
//data = 0
//count = sizeof(variable) / 4;
inline void MemSet_QUAD(void* dest, unsigned int data, int count)
{
_asm
{
mov edi, dest;
mov ecx, count;
mov eax, data;
rep stosd;
}
}


I was wondering if anyone could help me create a function which MemCpy_QUAD.
Copy 4 bytes at a time -- assuming that regular memcpy only does 1 byte at a time.

1. That isn't doing it by quad (8) bytes. It's doing it by dword (4) bytes.

2. You may want to avoid using any instruction like rep or stosd. Those instructions aren't too fast with newer processors.

There is several ways you can go about this. If you're working with null terminated strings then you could simply test to see if a null is in the 4 bytes before storing it.

If you're not then you could step a register by 4 until it's either equal to or greater then the count. Then deal with the odd bytes afterwards.

Halsafar
Jan 12th, 2005, 12:39 PM
I know little to zero assemble.
By QUAD i meant 4 bytes...quad = 4...I didn't know that there was a term like WORD, DWORD which meant 8 bytes, which is a QUAD right -- two DWORDs.

Is it possible to work with a QUAD in Windows on old processors? isn't a quad then 64 bits?

I know what I am trying too acomplish I just don't know how to code in assemble.
But yes that is what I figured -- copy by DWORDS then until you have less than 4 bytes left -- deal with those last few bytes as normal.

Maven
Jan 12th, 2005, 01:40 PM
I know little to zero assemble.
By QUAD i meant 4 bytes...quad = 4...I didn't know that there was a term like WORD, DWORD which meant 8 bytes, which is a QUAD right -- two DWORDs.

Is it possible to work with a QUAD in Windows on old processors? isn't a quad then 64 bits?

I know what I am trying too acomplish I just don't know how to code in assemble.
But yes that is what I figured -- copy by DWORDS then until you have less than 4 bytes left -- deal with those last few bytes as normal.

A Quadword is 64 bits or 8 bytes.

You can use quad registers when you use .mmx. I think the very first one to adopt it is pentium pro.

If I wasn't having to work tonight I'd write it for you. I'm about to go to work in about 10 mins. Anyway, If nobody has done it by this weekend, then I'll show you how (Unless I'm working this weekend of course).

In the meantime you can look at "The art of asm", just do a search for it on google.

Halsafar
Jan 12th, 2005, 09:15 PM
Yah i"ve been slowly reading a bit of ASM stuff...
Seems quite specific to certain systems. x86 or whatever...I'm to tired...Assemble is different between these platforms?

Is there anyway I can assume any windows system is a certain type?
or any pentium system?
or whats the most common?

You posted a math asm link in a previous thread and I wish to use some of that to create a very quick 2D/3D vector class. But I want to know what that code will work with.

Maven
Jan 13th, 2005, 03:49 AM
Yah i"ve been slowly reading a bit of ASM stuff...
Seems quite specific to certain systems. x86 or whatever...I'm to tired...Assemble is different between these platforms?

Is there anyway I can assume any windows system is a certain type?
or any pentium system?
or whats the most common?

You posted a math asm link in a previous thread and I wish to use some of that to create a very quick 2D/3D vector class. But I want to know what that code will work with.

You can write code for anything intel or amd.

Darkwraith
May 16th, 2005, 02:47 PM
For REP STOS (from what I remember), is ok, but from what I found, there is really no speed enhancement in using REP STOS for the newer processors.

(http://www.gamedev.net/reference/articles/article369.asp)