Thank you all for your time and insight on this interesting nugget. My approach is indeed a 6-step binary chop as hv suggested, and after taking in and considering everything you guys have said, it seems clear that while this is the most efficient logical concept, I am hard pressed to do it justice in pure Perl. A proper C implementation would bring very significant gains in speed and could even take advantage of possible hardware support ikegami spoke of.

If gcc has a builtin MSSB function, I have a mind to suggest that a future version of Perl could rock one. When we justifiably resort to bit twiddling, we are either trying to save memory, or optimize tight loops which iterate billions of times. In these cases, the best I can do in Perl (or might do in XS) would be glaringly inferior to a builtin function in both performance and maintainability.

I would be curious about the recommended path to go about delivering such a thing to the community, not to be an entitled freeloader or to lack initiative. I have to admit that if there were ever any significant interest in this function among Perl users I'd see evidence of that as a module that provides it. For whatever reason, some ideas just aren't very popular, and I accept that.

I understand there are many Perl functions which simply wrap C functions, and this seems almost like that. I would submit that while it may not be the most widely used feature, it may be a great addition, if it's no more difficult to implement.

In reply to Re: Most Significant Set Bit by coldr3ality
in thread Most Significant Set Bit by coldr3ality

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.