问题标签 [loop-unrolling]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - 将 duff 的设备从 C 移植到 JavaScript
我在 C 语言中有这种 Duff 的设备,它工作正常(将文本格式化为钱):
输出:
但是我在尝试在 Javascript 中实现相同的功能时遇到了问题:
nodejs 返回此错误:
我的问题是:javascript 是否支持计算的 GOTO 语句?
PD:我不想要替代方案,我只想知道为什么不起作用。
相关问题:Duff 的设备是否支持其他语言?
c++ - 在 g++ 上进行聚合初始化的 std::array 会生成大量代码
在 g++ 4.9.2 和 5.3.1 上,此代码需要几秒钟才能编译并生成 52,776 字节的可执行文件:
增加size
似乎会线性增加编译时间和可执行文件大小。我无法使用 clang 3.5 或 Visual C++ 2015 重现此行为。使用-Os
没有区别。
检查汇编代码显示初始化a
已展开,生成4096 movl
条指令:
这只发生在T
具有非平凡构造函数并且数组使用{}
. 如果我执行以下任何操作,g++ 会生成一个简单的循环:
- 删除
S::S()
; - 删除
S::S()
并初始化S::f
课堂; - 移除聚合初始化(
= {}
); - 编译不带
-O2
.
我完全赞成将循环展开作为一种优化,但我认为这不是一个很好的优化。在我将此报告为错误之前,有人可以确认这是否是预期的行为吗?
[编辑:我为此打开了一个新错误,因为其他错误似乎不匹配。它们更多的是关于较长的编译时间,而不是奇怪的代码生成。]
c - GCC 5.1 循环展开
给定以下代码
使用 GCC 5.1 或更高版本
部分循环展开,它展开循环十次,然后进行条件跳转。
但是使用 GCC 的旧版本(例如 4.9.2)会创建所需的汇编
有没有办法强制 GCC 的更高版本产生相同的输出?
使用https://godbolt.org/g/D1AR6i生成程序集
编辑:没有重复的问题,因为使用更高版本的 GCC 完全展开循环的问题尚未解决。传递--param max-completely-peeled-insns=1000 --param max-completely-peel-times=10000
对使用 GCC >= 5.1 生成的程序集没有影响
c - 在 C 中的内联函数中循环展开,以实现速度优化的多寄存器多位访问
我有一个问题如何最优雅地解决与微控制器的离散 IO 检查相关的以下问题:
.c 文件的内容:
使用 --O3 --funroll-loops 编译后的预期结果应进行速度优化,例如以下等效的 testfunction C 代码,前提是 N_USED 定义为 7 并且 REGx_ADDR 也定义为有效寄存器地址:
我将 GCC 编译器用于 ARM v7。当使用上述由 testfunction 调用的内联函数 Dinputs 时,这是否按预期工作,并具有优化的机器代码输出?是否有可能强制 Dinputs 函数的展开和内联?不是很重要,但出于好奇:由于上述示例中的结构传输 DIO 仅由展开的内联函数使用,因此编译器没有必要将此数据接管到目标文件的数据部分。什么是预期的行为。这个?
我不想在我的项目中使用等效代码的原因是,如果 N_USED 在编译时应在 0 到 7 的范围内(在此示例中),并且使用其他 DIO 的变体,这将需要许多额外的预处理器命令通过只交换表格而不是任何代码来更容易地定义表格。
c++ - Loop unrolling behaviour in GCC
This question is in part a follow up question to GCC 5.1 Loop unrolling.
According to the GCC documentation, and as stated in my answer to the above question, flags such as -funroll-loops
turn on "complete loop peeling (i.e. complete removal of loops with a small constant number of iterations)". Therefore, when such a flag is enabled, the compiler can choose to unroll a loop if it determines that this would optimise the execution of a given piece of code.
Nevertheless, I noticed in one of my projects that GCC would sometimes unroll loops even though the relevant flags were not enabled. For instance, consider the following simple piece of code:
When compiling with -O1
, the loop is unrolled and the following assembly code is generated with any modern version of GCC:
Even when compiling with the additional -fno-unroll-loops -fno-peel-loops
to make sure the flags are disabled, GCC unexpectedly still performs loop unrolling on the example described above.
This observation leads me to the following closely related questions. Why does GCC perform loop unrolling even though the flags corresponding to this behaviour are disabled? Is unrolling also controlled by other flags which can make the compiler unroll a loop in some cases even though -funroll-loops
is disabled? Is there a way to completely disable loop unrolling in GCC (a part from compiling with -O0
)?
Interestingly the Clang compiler has the expected behaviour here, and seems to only perform unrolling when -funroll-loops
is enabled, and not in other cases.
Thanks in advance, any additional insights on this matter would be greatly appreciated!
c - 第一次调用 C 函数比后续调用慢
我试图近似 C 中的函数调用开销。所以我有一个具有属性((optimize("O0"))) 的空函数,因此它不会被 GCC 优化掉。
我正在使用论文http://www.intel.com/content/www/us/en/embedded/training/ia-32-ia-64-benchmark-code-execution-paper.html中描述的方法 来确定时间,所以它非常准确。
所以我多次在循环中调用该函数并测量执行时间:
我注意到第一次调用该函数(i = 0)时,它比后续调用需要更多的周期(~10x)。为什么会这样?
metaprogramming - 循环展开?在 Julia 中使用元编程
有没有办法“元编程”获得具有以下结构的代码块:
谢谢!
c - C循环的优化
我有以下函数来计算系数:
我正在寻找优化循环。我尝试了循环展开,但效果不大。我还可以做些什么?
c - C 编译器循环展开说明
我无法理解 MSVC 编译器如何展开以下循环(对不起,我对汇编语言的理解不佳):
这是生成的程序集:
我理解这部分(循环的开始):
但是我不明白后续跳转指令如何跳过下一lea
条指令,如果我查看地址(这是假设发生了跳转) -请注意,我在上面的列表中省略了跳转之间的指令:
如果每次跳转都发生,它似乎只是交替test r8d,r8d
和test edx,edx
指令,而不加载下一个值。
我在这里解释不正确?
assembly - 展开 y86 循环
我正在尝试在 y86 代码中展开循环,但是当我尝试运行测试程序时,我得到了 2 个不同的值。注册。代码是:
我制作的展开版本是:
我应该得到的结果是 2,但从展开的结果返回的结果是 3。我知道有一个额外的iaddq
被执行,但我不确定在哪里。我将循环展开两次,以便改为检查 2 个值。