Results 1 to 7 of 7

Thread: MemCpy_QUAD

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    MemCpy_QUAD

    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.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: MemCpy_QUAD

    Quote Originally Posted by Halsafar
    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.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  3. #3

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: MemCpy_QUAD

    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.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  4. #4
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: MemCpy_QUAD

    Quote Originally Posted by Halsafar
    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.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  5. #5

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: MemCpy_QUAD

    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.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  6. #6
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: MemCpy_QUAD

    Quote Originally Posted by Halsafar
    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.
    Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde

  7. #7
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004

    Re: MemCpy_QUAD

    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/art...article369.asp)
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width