|
In the early 80x86 processors, the string instructions provided the most efficient way to manipulate strings and blocks of data. However, these instructions are not part of Intel's "RISC Core" instruction set and, as such, they can be slower than doing the same operations using discrete instructions. Intel has optimized the movs instruction on later processors so that it operates about as rapidly as possible, but the other string instructions can be fairly slow. As always, it's a good idea to implement performance-critical algorithms using different algorithms (with and without the string instructions) and compare their performance to determine which solution to use.
Keep in mind that the string instructions run at different speeds relative to other instructions depending on which processor you're using. So the fact that you "prove" one way is faster than another on a given processor really doesn't prove much. The reverse could be true on a different processor. Therefore, it's a good idea to try your experiments on the processors where you expect your code to run. Note that on most processors, the movs instruction is faster than the corresponding discrete instructions. Intel has worked hard to keep movs optimized because so much performance-critical code uses it.
Although the string instructions can be slower than discrete instructions, there is no question that the string instructions are generally more compact than the discrete code that achieves the same result.
|