- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Apparently ,现代处理器可以判断您是否做了一些愚蠢的事情,例如将寄存器移动到自身 ( mov %eax, %eax
) 并将其优化。为了验证该声明,我运行了以下程序:
#include <stdio.h>
#include <time.h>
static inline void f1() {
for (int i = 0; i < 100000000; i++)
__asm__(
"mov %eax, %eax;"
"nop;"
);
}
static inline void f2() {
for (int i = 0; i < 100000000; i++)
__asm__(
"nop;"
);
}
static inline void f3() {
for (int i = 0; i < 100000000; i++)
__asm__(
"mov %ebx, %eax;"
"nop;"
);
}
int main() {
int NRUNS = 10;
clock_t t, t1, t2, t3;
t1 = t2 = t3 = 0;
for (int run = 0; run < NRUNS; run++) {
t = clock(); f1(); t1 += clock()-t;
t = clock(); f2(); t2 += clock()-t;
t = clock(); f3(); t3 += clock()-t;
}
printf("f1() took %f cycles on avg\n", (float) t1/ (float) NRUNS);
printf("f2() took %f cycles on avg\n", (float) t2/ (float) NRUNS);
printf("f3() took %f cycles on avg\n", (float) t3/ (float) NRUNS);
return 0;
}
f1() took 175587.093750 cycles on avg
f2() took 188313.906250 cycles on avg
f3() took 194654.296875 cycles on avg
f3()
出来最慢。但令人惊讶的是(至少对我而言),
f1()
比
f2()
快.这是为什么?
-falign-loops
定性地给出相同的结果:
f1() took 164271.000000 cycles on avg
f2() took 173783.296875 cycles on avg
f3() took 177765.203125 cycles on avg
最佳答案
The part of the linked article that made me think that this can be optimized away is: "the move function takes care of checking for equivalent locations"
(move r x)
SBCL 中的函数,而不是 x86
mov
操作说明。它谈论的是从低级中间语言生成代码期间的优化,而不是硬件在运行时的优化。
mov %eax, %eax
也不是
nop
完全免费。它们都消耗前端吞吐量,并且
mov %eax,%eax
在 64 位模式下甚至不是 NOP(它将 EAX 零扩展到 RAX,并且因为它是相同的寄存器,所以在 Intel CPU 上移动消除失败。)
mov %ebx, %eax;
f3
中的错误在启用优化的情况下成功编译。在不告诉编译器的情况下破坏 EAX 将踩到编译器生成的代码。你没有解释你试图用它测试什么,所以 IDK 如果它是一个错字。
关于gcc - 为什么 `mov %eax, %eax; nop` 比 `nop` 快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52992723/
这个问题在这里已经有了答案: Test whether a register is zero with CMP reg,0 vs OR reg,reg? (2 个回答) 3年前关闭。 or eax,e
test eax, eax 是否比 cmp eax, 0 更高效?是否存在需要 test eax, eax 而 cmp eax, 0 不满足要求的情况? 最佳答案 正如臧明杰在评论中已经说过的,tes
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: x86 Assembly - ‘testl’ eax against eax? 我对汇编语言编程非常陌生,我目前正在
我有一些未知的 C++ 代码是在发布版本中编译的,因此对其进行了优化。我正在努力解决的问题是: xor al, al add esp, 8 cmp byte ptr [ebp+
GCC 给我做了一些汇编代码,里面有这个语句: lea eax, [ebx+eax] (英特尔语法) 只是好奇,这有什么区别,和: add eax, ebx 是? eax 和 ebx 包含函数的返回值
leal (%eax, %eax) 是什么意思做? %eax * 2 处的内容是否会相乘,因为它有括号? 最佳答案 它将使用 eax 的总和加载目标操作数和 eax , IOW, 2* eax . 关
我正在尝试理解一些汇编。 程序集如下,我对teSTL行感兴趣: 000319df 8b4508 movl 0x08(%ebp), %eax 000319e2 8b4004
LEA EAX, [EAX] 我在使用 Microsoft C 编译器编译的二进制文件中遇到了这条指令。它显然不能改变 EAX 的值。那它为什么在那里? 最佳答案 这是一个NOP。 以下通常用作NOP
我正在二进制文件中搜索特定指令,对于 xor eax,eax 指令,我有一个函数,如: int foo(){ return 0; } 如果我用 GCC 4.7.2 和 -O2 或 -O3 优化标志
我正在二进制文件中搜索特定指令,对于 xor eax,eax 指令,我有一个函数,如: int foo(){ return 0; } 如果我用 GCC 4.7.2 和 -O2 或 -O3 优化标志
什么是 0x01b55ee2 mov 0x40(%eax),%eax 是什么意思?我应该如何解释 0x40(),因为我的代码在该位置崩溃时遇到问题。 %eax寄存器的内容为0。 最佳答案
我知道 dword ptr 是一个 size 指令,它指示移动内容的大小,我知道 mov eax, eax 是一种 nop 代码形式,但这有什么作用? 我认为它将 eax 的地址与内部的十六进制值交换
这个问题已经有答案了: What is the meaning of MOV (%r11,%r12,1), %edx? (2 个回答) 已关闭 5 年前。 一直在从事 assembly 作业,并且在很
我在 GAS 源代码中定义了一个 MACRO。但是不是gcc编译的。 下面是我定义的MACRO。 #define MSGSCHEDULE0(index) \ movl (index*4)(%r
我在组装方面完全是个菜鸟,只是四处看看发生了什么。无论如何,我写了一个非常简单的函数: void multA(double *x,long size) { long i; for(i=0; i
GCC 4.4.3 生成了以下 x86_64 程序集。让我困惑的部分是 mov %eax,%eax .将寄存器移至自身?为什么? 23b6c: 31 c9
两条线有什么区别 push eax mov [esp], eax 不将 eax 压入堆栈(esp 所指向的位置与 mov [esp]、eax 一样?) 最佳答案 “push”会自动改变“esp”(你的
以下说明有何意义? xor eax,eax mov eax,[eax] 当您对 eax 进行 XOR 时,大多数情况下您会得到零,那么您可以取消引用地址 [eax] 中的内容(在本例中 eax 包含
我是一个初学者,正在编写汇编程序以使用以下代码打印从 1 到 9 的数字: section .text global _start _start:
Apparently ,现代处理器可以判断您是否做了一些愚蠢的事情,例如将寄存器移动到自身 ( mov %eax, %eax ) 并将其优化。为了验证该声明,我运行了以下程序: #include #
我是一名优秀的程序员,十分优秀!