Comments on: Aligned vs. unaligned memory access http://www.alexonlinux.com/aligned-vs-unaligned-memory-access Tue, 16 May 2023 15:06:12 +0000 hourly 1 https://wordpress.org/?v=4.9.23 By: taro http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-112702 Fri, 01 Apr 2022 08:15:12 +0000 http://www.alexandersandler.net/wp#comment-112702 I strongly agree with your opinion that ‘things get not so pretty when you read from a memory address that is not on a cache line boundary.’. I have reproduced the same scene with cpp and go language.

It’s worth noting that the question raised by @barbie is very important(Is there still a significant difference between the aligned and unaligned reads once the data is in the cache ? The processor still has to do some work to get the data from the unaligned data in cache to its registers, so I imagine it could still have a measurable impact.).

I have made some try.
One experiment uses indent 0,1 and sequentially read uint32_t (4 bytes) data from 4MB buffer. The result shows there is no significant difference between the aligned (indent 0) and unaligned reads(indent 1. The indent is not multiple of 4, obviously there are many reads will cross a word (8 byte)).

In another experiment, I randomly generated some addresses with the remainder of 8 equal to 5 and some addresses equal to multiple of 8. Next, read uint32_t (4 bytes) data from the generated addresses. The results show there have significant difference between the aligned(read uint32_t from addresses which are equal to multiple of 8) and unaligned reads (read uint32_t from addresses with the remainder of 8 equal to 5). There is a difference of about 17%.

I don’t know why experiment 1 and experiment 2 shows very different results. Just because sequential reading and randomly reading?

]]>
By: Danilo http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-83040 Sat, 18 Feb 2017 10:51:26 +0000 http://www.alexandersandler.net/wp#comment-83040 Im actually curious why it took longer to access that 62 offset unaligned memory address since you are only retrieving 1 byte (*char). Is that because the processor is actually retrieving 8 bytes and silently erasing the 7 most significant bytes?

]]>
By: New article announcement – Aligned vs unaligned memory access - Alex on Linux http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-37968 Tue, 05 Nov 2013 05:26:50 +0000 http://www.alexandersandler.net/wp#comment-37968 […] This concludes a long research that I’ve made. I wanted to know if unaligned memory access is really that bad, or not a big deal. Eventually I made some quiet interesting discoveries. Read on. […]

]]>
By: Akhil http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-30037 Fri, 09 Nov 2012 05:55:26 +0000 http://www.alexandersandler.net/wp#comment-30037 Thanks a lot for this post! Very informative

]]>
By: Data alignment for speed: myth or reality? http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-29440 Thu, 31 May 2012 17:46:27 +0000 http://www.alexandersandler.net/wp#comment-29440 […] 2008, Alexander Sandler reported that unaligned accesses could require twice the number of clock cycles. Tweet Comments […]

]]>
By: Alexander Sandler http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-28442 Sun, 05 Feb 2012 21:16:52 +0000 http://www.alexandersandler.net/wp#comment-28442 @Steve
My pleasure. Please visit again.

]]>
By: Alexander Sandler http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-28441 Sun, 05 Feb 2012 21:16:36 +0000 http://www.alexandersandler.net/wp#comment-28441 @Rajath
Hmm… Seems fine to me.

]]>
By: Steve http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-28278 Tue, 24 Jan 2012 19:25:49 +0000 http://www.alexandersandler.net/wp#comment-28278 Great article! Thanks a lot for writing it up. I too would be curious about the results for unaligned access to cached memory (as in the postscript).

On the subject of typos, you have misspelled “quite” every time as “quiet”.

]]>
By: Memory Manager: Part 1 | Dead Pixel Studios http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-28177 Fri, 13 Jan 2012 19:30:25 +0000 http://www.alexandersandler.net/wp#comment-28177 […] Dump: http://www.alexonlinux.com/aligned-vs-unaligned-memory-access http://groups.csail.mit.edu/commit/papers/01/MIT-LCS-TM-621.pdf […]

]]>
By: Rajath http://www.alexonlinux.com/aligned-vs-unaligned-memory-access/comment-page-1#comment-28153 Wed, 11 Jan 2012 05:03:48 +0000 http://www.alexandersandler.net/wp#comment-28153 Thanks for sharing!
Is there a typo in the first sentence?
“So many times I’ve <> people mentioning aligned memory access”

]]>