在x86中对齐16字节边界的含义是什么 [英] What does alignment to 16-byte boundary mean in x86

查看:503
本文介绍了在x86中对齐16字节边界的含义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Intel's official optimization guide has a chapter on converting from MMX commands to SSE where they state the fallowing statment:

使用可能未与16字节边界对齐的内存操作数的计算指令必须替换为未对齐的128位加载(MOVDQU),然后执行与使用寄存器操作数相同的计算操作.

Computation instructions which use a memory operand that may not be aligned to a 16-byte boundary must be replaced with an unaligned 128-bit load (MOVDQU) followed by the same computation operation that uses instead register operands.

(第5.8章从64位转换为128位SIMD整数,第5-43页)

(chapter 5.8 Converting from 64-bit to 128-bit SIMD Integers, pg. 5-43)

我不明白它们的含义是可能未与16字节边界对齐",请您说明清楚并举一些例子吗?

I can't understand what they mean by "may not be aligned to a 16-byte boundary", could you please clarify it and give some examples?

推荐答案

某些 SIMD 说明对多个数据执行相同指令的,要求该数据的存储器地址与某个字节边界对齐.这实际上意味着需要将数据所驻留的内存地址除以指令所需的字节数.

Certain SIMD instructions, which perform the same instruction on multiple data, require that the memory address of this data is aligned to a certain byte boundary. This effectively means that the address of the memory your data resides in needs to be divisible by the number of bytes required by the instruction.

因此,在您的情况下,对齐方式为16个字节(128位),这意味着数据的内存地址需要为16的倍数. 0x00010将对齐16个字节,而0x00011则不对齐.

So in your case the alignment is 16 bytes (128 bits), which means the memory address of your data needs to be a multiple of 16. E.g. 0x00010 would be 16 byte aligned, while 0x00011 would not be.

如何使数据保持一致取决于您使用的编程语言(有时是编译器).大多数具有内存地址概念的语言还将为您提供指定对齐方式的方法.

How to get your data to be aligned depends on the programming language (and sometimes compiler) you are using. Most languages that have the notion of a memory address will also provide you with means to specify the alignment.

这篇关于在x86中对齐16字节边界的含义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆