<html><head></head><body>Same semantics, but a faster implementation.<br><br><div class="gmail_quote">On October 19, 2016 1:58:14 PM EDT, Rui Ueyama <ruiu@google.com> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr">This seems a binary search, so how it is different from std::upper_bound?</div><div class="gmail_extra"><br /><div class="gmail_quote">On Wed, Oct 19, 2016 at 7:17 AM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br /><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br />
Date: Wed Oct 19 09:17:36 2016<br />
New Revision: 284594<br />
<br />
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284594&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr />project?rev=284594&view=rev</a><br />
Log:<br />
Add a faster binary search.<br />
<br />
Even with the hash table cache, binary search was still pretty<br />
hot. This can be made even faster with prefetching.<br />
<br />
Idea from <a href="http://cglab.ca/~morin/misc/arraylayout-v2/" rel="noreferrer" target="_blank">http://cglab.ca/~morin/misc/<wbr />arraylayout-v2/</a><br />
<br />
I will suggest moving this to llvm.<br />
<br />
Modified:<br />
    lld/trunk/ELF/InputSection.cpp<br />
<br />
Modified: lld/trunk/ELF/InputSection.cpp<br />
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=284594&r1=284593&r2=284594&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr />project/lld/trunk/ELF/<wbr />InputSection.cpp?rev=284594&<wbr />r1=284593&r2=284594&view=diff</a><br />
==============================<wbr />==============================<wbr />==================<br />
--- lld/trunk/ELF/InputSection.cpp (original)<br />
+++ lld/trunk/ELF/InputSection.cpp Wed Oct 19 09:17:36 2016<br />
@@ -651,6 +651,19 @@ SectionPiece *MergeInputSection<ELFT>::g<br />
   return const_cast<SectionPiece *>(This->getSectionPiece(<wbr />Offset));<br />
 }<br />
<br />
+template <class It, class T, class Compare><br />
+static It fastUpperBound(It First, It Last, const T &Value, Compare Comp) {<br />
+  size_t Size = std::distance(First, Last);<br />
+  assert(Size != 0);<br />
+  while (Size != 1) {<br />
+    size_t H = Size / 2;<br />
+    const It MI = First + H;<br />
+    Size -= H;<br />
+    First = Comp(Value, *MI) ? First : First + H;<br />
+  }<br />
+  return Comp(Value, *First) ? First : First + 1;<br />
+}<br />
+<br />
 template <class ELFT><br />
 const SectionPiece *<br />
 MergeInputSection<ELFT>::<wbr />getSectionPiece(uintX_t Offset) const {<br />
@@ -659,7 +672,7 @@ MergeInputSection<ELFT>::<wbr />getSectionPiece<br />
     fatal(getName(this) + ": entry is past the end of the section");<br />
<br />
   // Find the element this offset points to.<br />
-  auto I = std::upper_bound(<br />
+  auto I = fastUpperBound(<br />
       Pieces.begin(), Pieces.end(), Offset,<br />
       [](const uintX_t &A, const SectionPiece &B) { return A < B.InputOff; });<br />
   --I;<br />
<br />
<br />
______________________________<wbr />_________________<br />
llvm-commits mailing list<br />
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br />
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr />mailman/listinfo/llvm-commits</a><br />
</blockquote></div><br /></div>
</blockquote></div><br>
-- <br>
Sent from my Android device with K-9 Mail. Please excuse my brevity.</body></html>