C 在读取内存时递增变量
当我阅读glibc源代码时,我在strcat.c中发现了这个有趣的注释。 有人能解释一下这种优化是如何工作的吗C 在读取内存时递增变量,c,memory,gcc,glibc,strcat,C,Memory,Gcc,Glibc,Strcat,当我阅读glibc源代码时,我在strcat.c中发现了这个有趣的注释。 有人能解释一下这种优化是如何工作的吗 /* Make S1 point before the next character, so we can increment it while memory is read (wins on pipelined cpus). */ s1 -= 2; do { c = *s2++; *
/* Make S1 point before the next character, so we can increment
it while memory is read (wins on pipelined cpus). */
s1 -= 2;
do
{
c = *s2++;
*++s1 = c;
}
while (c != '\0');
流水线CPU可以并行处理一些事情。例如,它可以增加S1的地址,同时读取它用来指向的地址 这只是意味着可以在从
*s2
提取字符的同时增加s1
,因此它是免费的。编译并objdump它这将揭示任何奇迹。D