<div dir="ltr">We used to represent alignments both in 2^n and log2, and I streamlined it by using 2^n consistently because it was confusing. So I'm inclined not to go back to that state unless you show saving a few bits is worth doing.<div><br></div><div>As to the division, I think alignTo in MathExtras.h is too powerful that it can handle alignment of non-power-of-2. It can take any number as an alignment. Do we really need it? I'm wondering if we can replace the implementation with this</div><div><br></div><div> inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew = 0) {</div><div> assert(Align != 0 && "Align can't be 0.");</div><div> assert(!isPowerOf2_64(Align) && "Align must be a power of 2.");</div><div> // return (Value + Align - 1 - Skew) / Align * Align + Skew;</div><div> return ((Value - Skew + Align - 1) & -Align) + Skew;<br> }</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 6, 2016 at 11:31 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Since we are talking alignment:<br>
<br>
We use alignTo quite often and that causes a divq. That is<br>
surprisingly fast on modern cpus, but I wonder if we should normalize<br>
the alignment to its log2. That would also have the advantage of<br>
requiring far fewer bits to store.<br>
<br>
If we do that it should definitely be another patch.<br>
<br>
Cheers,<br>
Rafael<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On 6 October 2016 at 14:25, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> ruiu added inline comments.<br>
><br>
><br>
>> InputSection.cpp:48<br>
>> // no alignment constraits.<br>
>> - if (Header->sh_addralign > UINT32_MAX)<br>
>> - fatal(getFilename(File) + ": section sh_addralign is too large");<br>
>> + if (Header->sh_addralign > UINT32_MAX ||<br>
>> + (Header->sh_addralign && !isPowerOf2_32(Header->sh_<wbr>addralign)))<br>
><br>
> Also, please leave a comment here to say that we reject object files having insanely large alignment requirements and may want to relax this limitation in the future.<br>
><br>
> binutils-ish tools have incredible long lifetime -- GNU ld has been used for decades now for example. We want to leave a hint why we are doing this, so that people who look at this code 10 years later won't have to wonder why we reject 4GB-aligned sections when they are creating 10 terabyte executable.<br>
><br>
> <a href="https://reviews.llvm.org/D25324" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D25324</a><br>
><br>
><br>
><br>
</div></div></blockquote></div><br></div>