- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在 Windows 和 Linux (x86-64) 上运行一个程序。它使用相同的编译器(Intel Parallel Studio XE 2017)和相同的选项编译,Windows 版本比 Linux 版本快 3 倍。罪魁祸首是调用std::erf
这两种情况都在英特尔数学库中得到解决(默认情况下,它在 Windows 上是动态链接,在 Linux 上是静态链接,但在 Linux 上使用动态链接可以获得相同的性能)。
这是一个重现问题的简单程序。
#include <cmath>
#include <cstdio>
int main() {
int n = 100000000;
float sum = 1.0f;
for (int k = 0; k < n; k++) {
sum += std::erf(sum);
}
std::printf("%7.2f\n", sum);
}
当我使用 vTune 分析这个程序时,我发现程序集在 Windows 和 Linux 版本之间有点不同。这是 Windows 上的调用站点(循环)
Block 3:
"vmovaps xmm0, xmm6"
call 0x1400023e0 <erff>
Block 4:
inc ebx
"vaddss xmm6, xmm6, xmm0"
"cmp ebx, 0x5f5e100"
jl 0x14000103f <Block 3>
以及在 Windows 上调用的 erf 函数的开头
Block 1:
push rbp
"sub rsp, 0x40"
"lea rbp, ptr [rsp+0x20]"
"lea rcx, ptr [rip-0xa6c81]"
"movd edx, xmm0"
"movups xmmword ptr [rbp+0x10], xmm6"
"movss dword ptr [rbp+0x30], xmm0"
"mov eax, edx"
"and edx, 0x7fffffff"
"and eax, 0x80000000"
"add eax, 0x3f800000"
"mov dword ptr [rbp], eax"
"movss xmm6, dword ptr [rbp]"
"cmp edx, 0x7f800000"
...
在 Linux 上,代码有点不同。调用地点是:
Block 3
"vmovaps %xmm1, %xmm0"
"vmovssl %xmm1, (%rsp)"
callq 0x400bc0 <erff>
Block 4
inc %r12d
"vmovssl (%rsp), %xmm1"
"vaddss %xmm0, %xmm1, %xmm1" <-------- hotspot here
"cmp $0x5f5e100, %r12d"
jl 0x400b6b <Block 3>
而被调用函数(erf)的开头是:
"movd %xmm0, %edx"
"movssl %xmm0, -0x10(%rsp)" <-------- hotspot here
"mov %edx, %eax"
"and $0x7fffffff, %edx"
"and $0x80000000, %eax"
"add $0x3f800000, %eax"
"movl %eax, -0x18(%rsp)"
"movssl -0x18(%rsp), %xmm0"
"cmp $0x7f800000, %edx"
jnl 0x400dac <Block 8>
...
我已经展示了在 Linux 上浪费时间的 2 点。
有没有人足够了解汇编来解释这两个代码的区别以及为什么 Linux 版本慢了 3 倍?
最佳答案
根据 Windows 和 GNU/Linux 上各自的调用约定,在这两种情况下,参数和结果仅在寄存器中传递。
在 GNU/Linux 变体中,xmm1
用于累积总和。由于它是一个 call-clobbered 寄存器(又名 caller-saved),它在每次调用时存储(并恢复)在调用者的堆栈帧中。
在 Windows 变体中,xmm6
用于累积总和。此寄存器在 Windows 调用约定中是被调用者保存的(但不是在 GNU/Linux 中)。
因此,总而言之,GNU/Linux 版本保存/恢复 xmm0
(在被调用者 [1] 中)和 xmm1
(在调用者中),而Windows 版本仅保存/恢复 xmm6
(在被调用者中)。
[1] 需要查看 std::errf
找出原因。
关于c++ - 使用 Intel 编译器 : looking at the assembly 的 Windows 和 Linux 之间的性能差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40522841/
我尝试实现此正则表达式来检查字符串("username")的长度是否在3到30之间,是否仅包含字母(a-z),数字(0-9)和句点(.)(不连续): use regex::Regex; // 1.3.
我又在与正则表达式作斗争了。我一直在尝试添加使用转义字符来转义自定义标记,例如 至 和 至 .在乔治的帮助下,here , 在尝试转义方法之前,以下表达式会产生所需的结果。 ('This is a
我试图根据Python中的正常语法规则正确地分割句子。 我要拆分的句子是 s = """Mr. Smith bought cheapsite.com for 1.5 million dollars,
我有以下将字符串与模式匹配的正则表达式: (?i)(?
我想使用正则表达式过滤掉不使用“\r\n”作为换行符的文件。例如,如果文件包含单个“\n”或单个“\r”,则将被过滤为不合格文件。 我已经找到了: new Regex(@"(?
我正在尝试编写一个正则表达式替换模式,以便替换散列中的数字,如下所示: regexr link some_dict = { TEST: 123 } 这样就可以捕获和替换 123 个。(? " T
因此,我正在使用此查询查询Logstash,该查询返回堆栈顶部的所有内容: { "query": { "match_all": { } }, "size": 7, "_source": { "incl
我正在为 Android 开发 html/javascript 游戏。这是一款棋盘游戏,具有以下功能。它具有不同颜色的图 block ,用户可以在板上放置一个图 block (以编程方式选择)。如果我
所以我目前正在尝试创建一个函数,它将采用两个 3D 点 A 和 B,并为我提供代表 A 点“观察”B 点所需的旋转的四元数(这样点 A 的局部 Z轴穿过点 B,如果你愿意的话)。 我最初找到了this
比如: 第一个数字是:1。 看着第一个数字你可以说1个1,那么第二个数字就是:11。 看着第二个数字你可以说2个1,即第三个数字是:21。 看着第三个
基本上,要点在主题中。 当我创建两个具有固定高度 (2px) 的相同 div,并将缩放比例更改为 75% 或 125% 时,由于某种原因它们“看起来”不同,有人可以解释一下这里发生了什么吗?我该如何解
我正在使用 chrome://inspect/#devices通过cordova检查我的android-app构建的WebView。它在我的 Mac 上运行模拟器。可以找到该设备,但如果我在 WebV
如何使 Angular 服务代码“看起来同步”? 当我清理 Controller 并将业务逻辑代码放入服务中时,我的问题出现了。到目前为止,一切都很好。现在我想在服务函数中“等待”,直到所有异步调用都
标准的 Delphi 控件(面板、按钮等)都有这种斜角效果(顶部和左侧的白线),这给它们带来了 3D 感觉,但今天这让它们看起来很老式。 有没有办法至少在 Delphi 7 中删除这种“3D 外观”?
我有一个在 Win7 上使用 JFileChooser 的 java 应用程序。奇怪的是,有时(经常)但并非总是如此 - 驱动器名称在“查找范围:”组合框中看起来很奇怪: 有没有人知道是什么原因造成的
正在处理一些2015 AoC学习 clojure 的问题...下面的代码对于第 40 次迭代来说足够快,但在那之后很长时间就陷入了停滞。我与其他一些人的解决方案进行了比较,但我并不清楚为什么这么慢。我
我有一个在 Win7 上使用 JFileChooser 的 java 应用程序。奇怪的是,有时(经常)但并非总是如此 - 驱动器名称在“查找范围:”组合框中看起来很奇怪: 有没有人知道是什么原因造成的
我从 JUnit 开始,尝试找到测试的最佳断言方法。 假设我有一个函数来测试它 不返回值 如果输入无效则抛出异常 例如 void foo (int a) throws Exception { if
为了我的优化,我想在 Rcpp 中获得一个像样的 toupper。我对 C++ 很陌生,据我所知,我已经做到了: #include using namespace Rcpp; void C_toup
我在这里不知所措。我有一个简单的地形生成算法在工作,并且通过扩展 ViewPlatformAWTBehavior 和处理我自己的事件,我有一些简单的键盘导航在工作。一切都很好,我可以跟随地形。万岁!
我是一名优秀的程序员,十分优秀!