▲ | praptak 4 hours ago | |
I was curious about the rep movsb, so I tried to compare this with how a compiler would copy a known small size chunk of memory. It seems pretty complicated. I didn't manage to make a compiler generate the `rep movsb` idiom but I managed to find out some interesting stuff: - small, known size moves are stitched from a fixed number of mov instructions, sometimes overlapped. For example 21 bytes is qword (8 bytes) + xmmword (16 bytes), overlapped. - char-copying loops like "a++ = b++ c times" with c not known at compile time are either realized as simple increase, compare, conditional jump, or, at higher optimization, a monster that has like 10 branches to use anything from xmmword to byte depending on the amount of data - big, known size moves (> 256 bytes) just generate a call to memcpy |