By: Jörn Engel (joern.delete@this.purestorage.com), May 22, 2022 1:49 pm
Room: Moderated Discussions
Charlie Burnes (charlie.burnes.delete@this.no-spam.com) on May 22, 2022 1:53 pm wrote:
>
> I don’t follow your reasoning here. If there is a performance difference between aligned and unaligned
> data, why not just use aligned data to avoid lower performance? What do you mean by “the decision
> is whether you prefer runtime faults for unaligned data or lower performance”? If the data is
> aligned, I would think you would not get either runtime faults for unaligned data or lower performance.
> I also don’t know how it would be possible to always have aligned instructions given the variable
> length nature of the x86 instruction set. Sorry if this is a dumb question.
If all your data is aligned, it doesn't matter. So the question is what you do about unaligned data. One approach is to have two instructions, load vs. loadu or something like that. Typing loadu is annoying, so by default everyone uses load. If you really legitimately need to handle unaligned data, you have to use loadu. Basically, you're leaving warts all over the code.
Another approach is to only provide load, which is implemented using the unaligned variant. Now all code looks the same. If people unintentionally have unaligned data, performance suffers. And it can take quite a while until such mistakes are noticed.
So, what is better? Warts all over the code and potential runtime fault in case of mistakes? Or hiding the distinction between aligned and unaligned and making it easier to hurt performance? Big endian or little endian? Emacs or vi?
>
> I don’t follow your reasoning here. If there is a performance difference between aligned and unaligned
> data, why not just use aligned data to avoid lower performance? What do you mean by “the decision
> is whether you prefer runtime faults for unaligned data or lower performance”? If the data is
> aligned, I would think you would not get either runtime faults for unaligned data or lower performance.
> I also don’t know how it would be possible to always have aligned instructions given the variable
> length nature of the x86 instruction set. Sorry if this is a dumb question.
If all your data is aligned, it doesn't matter. So the question is what you do about unaligned data. One approach is to have two instructions, load vs. loadu or something like that. Typing loadu is annoying, so by default everyone uses load. If you really legitimately need to handle unaligned data, you have to use loadu. Basically, you're leaving warts all over the code.
Another approach is to only provide load, which is implemented using the unaligned variant. Now all code looks the same. If people unintentionally have unaligned data, performance suffers. And it can take quite a while until such mistakes are noticed.
So, what is better? Warts all over the code and potential runtime fault in case of mistakes? Or hiding the distinction between aligned and unaligned and making it easier to hurt performance? Big endian or little endian? Emacs or vi?