c++ - 如何将编译扩展到函数或循环

标签 c++ performance compiler-construction build

我有一个带有循环的函数,我将在 C++ 代码中得到循环的扩展开发。我还有一个递归函数,我想得到相同的。

我需要的例子:

for (i = 0; i <4; i++)
{
      printf ("%d", "example");
}

应该是我需要的结果

printf ("%d", "example");
printf ("%d", "example");
printf ("%d", "example");
printf ("%d", "example");

这是一个简单的例子。但是我需要为更复杂的功能执行此操作。 对于它的值(value),我使用 visual c++。 我不知道是否有构建选项。

最佳答案

如果您使用 GCC 来编译您的代码,那么您可以使用 -funroll-loop 选项来取消循环。

documentation说,

  • -funroll-loops
    Unroll loops whose number of iterations can be determined at compile time or upon entry to the loop. -funroll-loops implies -frerun-cse-after-loop. This option makes code larger, and may or may not make it run faster.

还有另一个(类似的)选项:

  • -funroll-all-loops
    Unroll all loops, even if their number of iterations is uncertain when the loop is entered. This usually makes programs run more slowly. -funroll-all-loops implies the same options as -funroll-loops,

关于c++ - 如何将编译扩展到函数或循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13381649/

相关文章:

C++ Boost ptr_map 序列化错误

c++ - 放大 QGraphicsView 时如何保持 QPen 像素宽度相同

mysql - SQL从2个表的单个查询中的状态中选择地址

parsing - lexer是否可以将错误 token 传递给解析器?

c++ - 如何在 C++ 中获取多个句子作为输入?

c++ - 为什么 std::allocator 不可复制?

sql - MySQL:有效地查找列的内容是字符串开头的行

C# 按特定属性比较两个大型项目列表

c - 乱序执行——它能绕过控制语句吗?

c - `:>`(冒号,大于,又名笑脸)在 C 编程语言中是什么意思?