Showing results for 
Search instead for 
Did you mean: 


Journeyman III

unaligned-memory data reference without alignment checking enabled?

What happens when an unaligned-memory data reference is performed without alignment checking enabled? Specifically on a Ryzen Threadripper?

Does the hardware simply perform extra reads if necessary? Can an error ever occur, such as accessing the wrong memory?

1 Reply

When an unaligned-memory data reference is performed without alignment checking enabled, the behavior can vary depending on the specific processor architecture and settings.

In general, unaligned memory references mean that data is being accessed at a memory address that is not a multiple of its natural data size. For example, trying to read a 32-bit integer from an address that is not divisible by 4. Modern processors, including Ryzen Threadripper processors, often support unaligned memory access, which means they are capable of handling such requests.

When alignment checking is not enabled, the hardware may attempt to handle unaligned memory accesses in a couple of ways:

Extra Reads/Writes: The hardware might perform multiple memory reads or writes to fetch the unaligned data. For instance, if you're trying to read a 32-bit integer from an address that's not aligned to 4 bytes, the processor might perform two separate reads to get the bytes from two aligned memory locations and then combine them.

Handling in Hardware: Some processors have specific circuitry to handle unaligned accesses, converting them into aligned accesses internally. This can help avoid errors and performance penalties associated with unaligned memory accesses.

Performance Impact: Unaligned memory accesses can still have a performance impact, as they might require additional cycles to retrieve the data or perform the necessary conversions.

No Errors by Default: In most cases, modern processors do not generate errors for unaligned memory accesses by default. Instead, they handle them in hardware, as described above. This is because many software applications inadvertently perform unaligned memory accesses, and causing errors in these cases could lead to compatibility issues.

However, it's important to note that the behavior can differ based on the specific processor architecture and settings. While errors might not occur by default, some systems might allow enabling alignment checking for debugging purposes, and in such cases, unaligned memory accesses could trigger exceptions or errors.

PC Hardware Specialist