Ror can do byteswaps all right, but it's not very remarkable at that.

#! /usr/bin/perl use Inline C => Config => CC => 'gcc', OPTIMIZE => '-O3 -mssse3 -funro +ll-all-loops'; use Inline C => <<'__CUT__', NAME => 'swab'; #include <x86intrin.h> void swab_ror(SV *v) { STRLEN slen; char *s = SvPV(v, slen); uint16_t *w = (uint16_t*) s; size_t n = slen >> 1; for (; n; n--) { asm("rorw $8, %0" : "+r,m" (w[n-1]) : : "cc"); } } void swab_sse(SV *v) { STRLEN slen; char *s = SvPV(v, slen); __m128i x, t; size_t n = slen & ~(size_t)1; for (; (n & 0xe); n -= 2) { uint16_t *w = (uint16_t*) &s[n-2]; *w = __rorw(*w, 8); } t = _mm_set_epi8(14,15,12,13,10,11,8,9,6,7,4,5,2,3,0,1); for (; n; n -= 16) { x = _mm_lddqu_si128((__m128i*)&s[n-16]); x = _mm_shuffle_epi8(x, t); _mm_storeu_si128((__m128i*)&s[n-16], x); } } __CUT__ our $str = pack "C*", map rand(256), 1..34567; use Benchmark 'cmpthese'; cmpthese -5, { swab_ror => q( swab_ror $str ), swab_sse => q( swab_sse $str ), };


In reply to Re^2: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678) by oiskuu
in thread Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678) by james28909

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.