Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does alignment to 16-byte boundary mean in x86

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

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.

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

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?

like image 549
SIMEL Avatar asked Apr 19 '12 08:04

SIMEL


People also ask

What is alignment boundary?

Configuration group. Cache Manager. memory alignment boundary determines the memory address boundary on which data caches are aligned. Some machines perform I/O more efficiently when structures are aligned on a particular memory address boundary.

What does byte alignment mean?

"X bytes aligned" means that the base address of your data must be a multiple of X. It can be used for using some special hardware like a DMA in some special hardware, for a faster access by the cpu, etc...

What does it mean to be 32-bit aligned?

Alignment refers to a piece of data's location in memory. A variable is naturally aligned if it exists at a memory address that is a multiple of its size. For example, a 32-bit type is naturally aligned if it is located in memory at an address that is a multiple of four (that is, its lowest two bits are zero).

What is data alignment explain with example?

Each drawer is of the same size in bytes which is equal to a power of 2, and we can somehow choose which power it is. For example, the whole memory could be made up of 4-byte blocks. We still can address every byte, but only the first address in each block is “aligned”. That is the address alignment.


1 Answers

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.

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.

like image 195
Jakob Avatar answered Oct 20 '22 07:10

Jakob