【问题标题】:incrementing the variable while the memory is read在读取内存时递增变量
【发布时间】:2014-04-01 02:28:43
【问题描述】:

在阅读 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++;
          *++s1 = c;
        }
      while (c != '\0');

【问题讨论】:

  • 编译并转储它,这将揭示任何奇迹。 :D

标签: c memory gcc glibc strcat


【解决方案1】:

流水线 CPU 可以并行执行一些操作。例如,它可以增加 S1 的地址,同时从它曾经指向的地址读取。

【讨论】:

    【解决方案2】:

    这只是意味着s1的增量可以在从*s2获取字符时完成,所以它是免费的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 2015-11-28
      • 1970-01-01
      • 2012-02-01
      • 2019-11-16
      • 2018-02-04
      相关资源
      最近更新 更多