- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行一些测试来比较 C 和 Java 并遇到了一些有趣的事情。在 main 调用的函数中而不是在 main 本身中运行优化级别 1 (-O1) 的完全相同的基准代码,导致性能大约翻倍。我正在打印 test_t 的大小,以毫无疑问地验证代码是否正在编译为 x64。
我将可执行文件发送给运行 i7-7700HQ 的 friend 并得到了类似的结果。我正在运行 i7-6700。
这是较慢的代码:
#include <stdio.h>
#include <time.h>
#include <stdint.h>
int main() {
printf("Size = %I64u\n", sizeof(size_t));
int start = clock();
for(int64_t i = 0; i < 10000000000L; i++) {
}
printf("%ld\n", clock() - start);
return 0;
}
并且更快:
#include <stdio.h>
#include <time.h>
#include <stdint.h>
void test() {
printf("Size = %I64u\n", sizeof(size_t));
int start = clock();
for(int64_t i = 0; i < 10000000000L; i++) {
}
printf("%ld\n", clock() - start);
}
int main() {
test();
return 0;
}
我还将提供汇编代码供您深入研究。我不知道组装。
.file "dummy.c"
.text
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.LC0:
.ascii "Size = %I64u\12\0"
.LC1:
.ascii "%ld\12\0"
.text
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
pushq %rbx
.seh_pushreg %rbx
subq $32, %rsp
.seh_stackalloc 32
.seh_endprologue
call __main
movl $8, %edx
leaq .LC0(%rip), %rcx
call printf
call clock
movl %eax, %ebx
movabsq $10000000000, %rax
.L2:
subq $1, %rax
jne .L2
call clock
subl %ebx, %eax
movl %eax, %edx
leaq .LC1(%rip), %rcx
call printf
movl $0, %eax
addq $32, %rsp
popq %rbx
ret
.seh_endproc
.ident "GCC: (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0"
.def printf; .scl 2; .type 32; .endef
.def clock; .scl 2; .type 32; .endef
快点:
.file "dummy.c"
.text
.section .rdata,"dr"
.LC0:
.ascii "Size = %I64u\12\0"
.LC1:
.ascii "%ld\12\0"
.text
.globl test
.def test; .scl 2; .type 32; .endef
.seh_proc test
test:
pushq %rbx
.seh_pushreg %rbx
subq $32, %rsp
.seh_stackalloc 32
.seh_endprologue
movl $8, %edx
leaq .LC0(%rip), %rcx
call printf
call clock
movl %eax, %ebx
movabsq $10000000000, %rax
.L2:
subq $1, %rax
jne .L2
call clock
subl %ebx, %eax
movl %eax, %edx
leaq .LC1(%rip), %rcx
call printf
nop
addq $32, %rsp
popq %rbx
ret
.seh_endproc
.def __main; .scl 2; .type 32; .endef
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call __main
call test
movl $0, %eax
addq $40, %rsp
ret
.seh_endproc
.ident "GCC: (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0"
.def printf; .scl 2; .type 32; .endef
.def clock; .scl 2; .type 32; .endef
这是我用于编译的批处理脚本:
@echo off
set /p file= File to compile:
del compiled.exe
gcc -Wall -Wextra -std=c17 -O1 -o compiled.exe %file%.c
compiled.exe
PAUSE
对于编译到汇编:
@echo off
set /p file= File to compile:
del %file%.s
gcc -S -Wall -Wextra -std=c17 -O1 %file%.c
PAUSE
最佳答案
慢版:
请注意 sub rax, 1 \ jne
对正好越过 ..80
的边界(这是一个 32 字节的边界)。这是Intels document regarding this issue中提到的案例之一即如下图:
所以这个 op/branch 对受 the fix for the JCC erratum 的影响(这会导致它不会被缓存在 µop 缓存中)。我不确定这是否是原因,还有其他因素在起作用,但这是一回事。
在快速版本中,分支不会“触及”32 字节的边界,因此不受影响。
可能还有其他适用的效果。仍然由于跨越 32 字节边界,在缓慢的情况下,循环分布在 µop 缓存中的 2 个块中,即使没有修复 JCC 错误,如果循环无法从循环执行,则可能导致它每次迭代运行 2 个周期流检测器(在某些处理器上被其他勘误的其他修复程序禁用,SKL150)。参见例如这个关于 loop performance 的答案.
为了解决各种评论说他们无法重现这一点,是的,有多种可能发生的方式:
关于c - 如果在 Intel Skylake CPU 上作为函数调用,为什么我的空循环运行速度快两倍?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67877913/
我是Intel pin工具的新手,最近开始研究pin工具。在教程中,描述了pin工具的模式: Sometimes, however, it can be useful to look at diffe
我是Intel pin工具的新手,最近开始研究pin工具。在教程中,描述了pin工具的模式: Sometimes, however, it can be useful to look at diffe
我得到了这份工作:1。产生一个正弦信号。2。使用 FFT 构建其频谱。首先,我为 visual studio 2010 安装了 Intel Parallel Studio XE 2011。在 vs 2
看起来 Intel 提供了许多 OpenCL 实现。 ArchWiki描述 OpenCL 实现。它说 beignet 和 intel-opencl 已弃用。那么,intel-compute-runti
我正在尝试通过阅读 Intel Intrinsics Guide 来开始使用 AVX512 内在函数但到目前为止我发现它没有定义命名数据类型或用于解释的伪代码语法。没有这样的定义,所谓的指南对我起码没
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
在 Android SDK 管理器中,我可以看到 3 种类型的 Intel Atom 图像。有人可以解释“Intel Atom Image”、“Google APIs Intel Atom Image
我写了这个 pintool: #include "pin.H" #include #include VOID Instruction(INS ins, VOID *v) { cou
我正在尝试了解 _mm256_permute2f128_ps() 的作用,但无法完全理解 intel's code-example . DEFINE SELECT4(src1, src2, contr
我正在开发一个性能关键应用程序,该应用程序必须移植到仅支持 MMX、SSE、SSE2 和 SSE3 的英特尔凌动处理器中。我以前的应用程序支持 SSSE3 和 AVX,现在我想将其降级为 Intel
我有最新版本的 Intel Pin 3.0 版本 76887。 我有一个支持 MPX 的玩具示例: #include int g[10]; int main(int argc, char **arg
我想研究和比较elf、SPARC和PA-RISC的可执行文件结构。 为了进行研究,我想在 Intel 机器 (Core2Duo) 上安装 OpenSolaris。 但我有一个基本的疑问,它会起作用吗?
我尝试使用 g++ 用 intel mkl 11.1 进行编译: g++ -m32 test.c -lmkl_intel -lmkl_intel_thread -lmkl_core -liomp5 -
我正在按照以下说明进行操作: https://software.intel.com/en-us/articles/building-boost-with-intel-c-compiler-150 Co
我正在尝试在我的 C 程序中使用内联汇编程序 __asm,使用 Intel 语法而不是 AT&T 语法。我正在使用 gcc -S -masm=intel test.c 进行编译但它给出了错误。下面是我
我是 OpenCL 的新手,目前对其性能有一些疑问。 我有 Intel(R) Core(TM) i5-4460 CPU @ 3.20GHz + ubuntu + Beignet(Intel 开源 op
我在/ex 文件夹中有一个 main.f90。 f77 子程序文件在/ex/src 中。子程序文件再次使用 BLAS 和 LAPACK 库。对于 BLAS 和 LAPACK,我必须使用英特尔数学核心函
我的团队最近从 2015 年英特尔编译器(并行工作室)升级到 2018 年版本,我们遇到了一个链接器问题,让每个人都焦头烂额。 我有以下类(为简洁起见进行了适度编辑),用于处理子进程的包装以及与它们对
在最后几天,我观察到我无法解释的新工作站的行为。对这个问题做一些研究,INTEL Haswell architecture 中可能存在一个可能的错误。以及在当前的 Skylake Generation
我的 HAXM 安装存在问题。事情是这样的。每次尝试为我的计算机安装 HAXM 时,我都会收到此错误: 问题是,我的计算机支持虚拟化技术(见下图)。知道如何解决这个问题吗? 最佳答案 只需执行以下步骤
我是一名优秀的程序员,十分优秀!