assembly - 不同 CPU 上未对齐的 MOVSD 会发生什么情况?

标签 assembly x86 x86-64 sse2

基本上问题说的是,如果我在各种 CPU 上执行不是 8 字节(甚至 4 字节)对齐的 MOVSD,会发生什么?它是否会对性能产生影响,是否会出现段错误等?

最佳答案

摘自英特尔规范第 1 卷第 4.1 节

4.1.1 Alignment of Words, Doublewords, Quadwords, and Double Quadwords

Words, doublewords, and quadwords do not need to be aligned in memory on natural boundaries. The natural boundaries for words, double words, and quadwords are even-numbered addresses, addresses evenly divisible by four, and addresses evenly divisible by eight, respectively. However, to improve the performance of programs, data structures (especially stacks) should be aligned on natural boundaries when- ever possible. The reason for this is that the processor requires two memory accesses to make an unaligned memory access; aligned accesses require only one memory access. A word or doubleword operand that crosses a 4-byte boundary or a quadword operand that crosses an 8-byte boundary is considered unaligned and requires two separate memory bus cycles for access.

在“正常”情况下,未处理的 movsd 将需要 2 个周期才能完成。

如果您打开对齐检查(在 EFLAGS 中),则 CPU 将发出 AC 信号。它的主要目的是帮助您检测未对齐的访问。

关于assembly - 不同 CPU 上未对齐的 MOVSD 会发生什么情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9543148/

相关文章:

assembly - 汇编语言中 "ds:"的含义

c++ - arm和x86架构下的c/c++语言有什么区别

windows - Delphi 10.2 for Win64 Release Target 下的 FillChar 和 StringOfChar

assembly - 在 64 位平台上使用 ld 生成 32 位可执行文件

assembly - 虚拟机 Ubuntu 上的 NASM : Cannot execute binary file exec format error

assembly - GAS 是否像 NASM 那样支持字符串文字作为数字常量?

c++ - 如何自动并行化堆数组?

linux - 如何为汇编语言程序制作 Makefile?

c++ - 为什么 __int128_t 在 x86-64 GCC 上比 long long 快?

assembly - 基址指针和堆栈指针