5 ms·
I haven't done assembler for a long time, but if my memory serves me well on x86 there's the rep movsb commands that will do effectively a memcpy-like operation
by hannob 5y ago
I haven't done assembler for a long time, but if my memory serves me well on x86 there's the rep movsb commands that will do effectively a memcpy-like operation.
- hyperman1 5y agoCorrect. There is the whole rep family doing all kinds of fun stuff. You can add the rep/repnz/repz prefixes to at least: movs[b|w|d]: move data in bytes/words/doublewords aka memcpy stos[b|w|d]: put a value in bytes/words/dwords aka memset cmps[b|w|d]: compare values aka memcmp scas[b|w|d]: scan for a value aka memchr ins[b|w|maybe d]: read from IO port outs[b|w|maybe d]: write to IO port. lods[b|w|d] : read from memory was probably not meant to be combined with rep as it would just throw everything but the last byte away. I once saw a rep lodsb to do repeated reads from EGA video ram. The video card saw which bytes were touched and did something to them based on plane mask. This way touching 1 bit changed the color of a whole 4 bit pixel, speeding up things with a factor 4. Then one day, someone found that rep movs was not the fastest way to copy data on an x86 and they all went out of vogue. I think rep stos recently came back as fastest memset, as it had a very specific CPU optimization applied. Update: See https://stackoverflow.com/questions/33480999/how-can-the-rep-stosb-instruction-execute-faster-than-the-equivalent-loop https://stackoverflow.com/questions/33480999/how-can-the-rep...