Boost C++ Libraries: Ticket #9231: Suboptimal assignment https://svn.boost.org/trac10/ticket/9231 <p> Hi, we're using your MP library, with the cpp_int_backend and fixed sized numbers, along with the "Maybe Boost Hash" library to implement lightweight RSA signature verification (previously done with <a class="missing wiki">LibTomCrypt</a>+<a class="missing wiki">LibTomMath</a>), so first of all thanks for making this possible ;) </p> <p> Unless otherwise stated, always assume I'm using MSVC10 32bit (with /Oxs /GL /LTCG) with the above use case (fixed sized, unchecked, unsigned cpp_ints)... </p> <p> Now, onto the issues ;D </p> <p> I would expect do_assign() to simply evaluate to simply std::memcpy, however it does not: </p> <ul><li>it seems that the this-&gt;resize(other.size(), other.size()); call fails to resolve to a nop (check your code) </li><li>why are you using "checked std::copy" instead of a straigh std::memcpy? </li></ul><p> ps. MSVC has a very nice debugger and disassembly window so I'll refrain from posting codegen in any of my tickets. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9231 Trac 1.4.3 Domagoj Šarić Fri, 11 Oct 2013 13:05:37 GMT component changed; owner set https://svn.boost.org/trac10/ticket/9231#comment:1 https://svn.boost.org/trac10/ticket/9231#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">multiprecision</span> </li> </ul> Ticket John Maddock Sat, 12 Oct 2013 08:19:31 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9231#comment:2 https://svn.boost.org/trac10/ticket/9231#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86258" title="Optimize copying of allocator-free cpp_int's via memcpy. Fix ...">[86258]</a>) Optimize copying of allocator-free cpp_int's via memcpy. Fix consistency of checks for exponents &lt; 0 in powm. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9231" title="#9231: Bugs: Suboptimal assignment (closed: fixed)">#9231</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9236" title="#9236: Bugs: Catch programmer errors with asserts, not exceptions (closed: wontfix)">#9236</a>. </p> Ticket anonymous Sat, 12 Oct 2013 08:37:26 GMT <link>https://svn.boost.org/trac10/ticket/9231#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9231#comment:3</guid> <description> <p> Thanks... ps. did you check why this-&gt;resize(other.size(), other.size()); does not evaluate to a nop (I forgot to add that this happens in powm when it copy-constructs the double_type)_? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Domagoj Šarić</dc:creator> <pubDate>Sat, 12 Oct 2013 08:38:53 GMT</pubDate> <title>description changed https://svn.boost.org/trac10/ticket/9231#comment:4 https://svn.boost.org/trac10/ticket/9231#comment:4 <ul> <li><strong>description</strong> modified (<a href="/trac10/ticket/9231?action=diff&amp;version=4">diff</a>) </li> </ul> Ticket John Maddock Sat, 12 Oct 2013 10:02:41 GMT <link>https://svn.boost.org/trac10/ticket/9231#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9231#comment:5</guid> <description> <blockquote class="citation"> <p> Thanks... ps. did you check why this-&gt;resize(other.size(), other.size()); does not evaluate to a nop (I forgot to add that this happens in powm when it copy-constructs the double_type)_? </p> </blockquote> <p> Sigh.... this is harder to optimize away - it goes via a general N bit to M bit conversion routine (which is already split many different ways, I really don't want to split it up any more or it becomes unmaintainable) so there is a check that the new size requested doesn't exceed the space available. This situation can also happen in calls to resize() from addition/subtraction/multiplication/shift routines, as it has to handle overflow in these cases. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Domagoj Šarić</dc:creator> <pubDate>Sat, 12 Oct 2013 11:56:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9231#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9231#comment:6</guid> <description> <p> MSVC is good at propagating constants (which need not be actual ICEs, but can be resolved as such at LTCG time) so that resize() is receiving two constants there...the fact that the compiler wasn't able to fully eliminate the code (the function call isn't there, it was inlined but not fully eliminated, I could see some branching) smells of something 'weird' being done in the resize() function...don't have time currently to examine the matter further... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 12 Oct 2013 12:02:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9231#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9231#comment:7</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86262" title="Use memcpy in more places. Add optimized bitwise operations for ...">[86262]</a>) Use memcpy in more places. Add optimized bitwise operations for unsigned integers. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9243" title="#9243: Bugs: Subopimal bitwise or (with bytes) (closed: fixed)">#9243</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9231" title="#9231: Bugs: Suboptimal assignment (closed: fixed)">#9231</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>