vec's no good because it only does powers of 2-bits.

Just out of interest (and to try to get my head around how it works) I thought I'd see if I could come up with a vec solution although I didn't expect it to challenge in the speed stakes. By combining 4-bit and 2-bit vecs with 2- or 4-bit shifts you can obtain your 6-bit values. As expected, it trails the field. (I didn't test the C solutions as I don't have Inline installed).

sub johngg { map { my $offsetVec4 = $_ * 6; my $offsetVec2 = $_ * 12; my @vals = ( ( ( vec( $_[0], $offsetVec4 + 1, 4 ) << 2 ) + vec( $_[0], $offsetVec2 + 1, 2 ) ), ( ( vec( $_[0], $offsetVec2, 2 ) << 4 ) + vec( $_[0], $offsetVec4 + 3, 4 ) ), ( ( vec( $_[0], $offsetVec4 + 2, 4 ) << 2 ) + vec( $_[0], $offsetVec2 + 11, 2 ) ), ( ( vec( $_[0], $offsetVec2 + 10, 2 ) << 4 ) + vec( $_[0], $offsetVec4 + 4, 4 ) ), ); } 0 .. 7; }
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 2 +3 24 25 26 27 28 29 30 31 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 2 +3 24 25 26 27 28 29 30 31 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 2 +3 24 25 26 27 28 29 30 31 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 2 +3 24 25 26 27 28 29 30 31 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 2 +3 24 25 26 27 28 29 30 31 Rate johngg buk jethro jmcnamara salva johngg 22191/s -- -3% -29% -42% -51% buk 22974/s 4% -- -27% -39% -49% jethro 31438/s 42% 37% -- -17% -30% jmcnamara 37959/s 71% 65% 21% -- -16% salva 45081/s 103% 96% 43% 19% --

I hope this is of interest.

Cheers,

JohnGG


In reply to Re: unpacking 6-bit values by johngg
in thread unpacking 6-bit values by BrowserUk

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.