|
|
|
|
 不明白strcat的优化 - yeahnix [ 2005-03-31 17:27 | 737 byte(s)]
 Re: 不明白strcat的优化 - wandys [ 2005-03-31 19:36 | 389 byte(s)]
 Re: wandys - yeahnix [ 2005-04-02 23:06 | 284 byte(s)]
 Re: wandys - kangjie501 [ 2005-04-03 10:49 | 175 byte(s)]
|
|
|
|
[Original]
[Print]
[Top]
|
看uclibc中strcat的代码时,下面的东西不是很明白:
strcat (dest, src)
char *dest;
const char *src;
{
char *s1 = dest;
const char *s2 = src;
reg_char c;
/* Find the end of the string. */
do
c = *s1++;
while (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++;
*++s1 = c;
}
while (c != ' ');
return dest;
|
|
|
----
just do it
|
|
[Original]
[Print]
[Top]
|
|
[Original]
[Print]
[Top]
|
s1 -= 2, s1指向要写内存的前一个字符处,
c = *s2++;
*++s1 = c;
对多流水线cpu, 读内存(s2指向的字符) 和 s1的加一 这两个操作可以同时进行。
如果 s1 -= 1
c = *s2++;
*s1++ = c;
那s1加一操作就不能在读内存时同时进行, 要等读写内存完了才行。 (think and see?)
|
|
|
----
UN*X is user^H^H^H^Hfriend-friendly.
|
|
[Original]
[Print]
[Top]
|
|
[Original]
[Print]
[Top]
|
非常感谢。
从你的回答中,我感觉到:
1、对多流水线,s2访存和++s1操作是肯定可以并行的
2、对单流水线是否也起到充满流水线的作用呢?
3、变量C的作用是指示临时寄存器?可否直接写成:
s1 -= 2
*++s1 = *s2++;
|
|
|
----
just do it
|
|
[Original]
[Print]
[Top]
|
|
|