URN Logo
UNIX Resources » Linux » China Linux Forum » C/C++编程版 » 35 » 不明白strcat的优化
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
不明白strcat的优化
不明白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)]
 
Subject: 不明白strcat的优化
Author: yeahnix    Posted: 2005-03-31 17:27    Length: 737 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]
Subject: Re: 不明白strcat的优化
Author: wandys    Posted: 2005-03-31 19:36    Length: 389 byte(s)
[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]
Subject: Re: wandys
Author: yeahnix    Posted: 2005-04-02 23:06    Length: 284 byte(s)
[Original] [Print] [Top]
非常感谢。
从你的回答中,我感觉到:
1、对多流水线,s2访存和++s1操作是肯定可以并行的
2、对单流水线是否也起到充满流水线的作用呢?
3、变量C的作用是指示临时寄存器?可否直接写成:

s1 -= 2
*++s1 = *s2++;
----
just do it
[Original] [Print] [Top]
Subject: Re: wandys
Author: kangjie501    Posted: 2005-04-03 10:49    Length: 175 byte(s)
[Original] [Print] [Top]
如果处理器能支持乱序执行,这种写法也能提高单流水线的效率。

变量C的作用就是为了让读写操作分开,以便于指令的并行执行。去掉它在效果上是一样的,但效率上会下降。
[Original] [Print] [Top]
« Previous thread
请教各位大侠:怎样写一个读文件的程序呀?
C/C++编程版
35
Next thread »
grep如何这样搜?
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 03:53:04, cost 0.037474155426025 ms.