Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Took the liberty to assume a few things explained below, but this kind of code (untested, may require a few modifications) should provide a good speedup compared to naive non-NEON version:</p> <pre><code>#include &lt;arm_neon.h&gt; #include &lt;stdint.h&gt; void convert(const restrict *uint16_t input, // the buffer to convert restrict *uint8_t output, // the buffer in which to store result int sz) { // their (common) size /* Assuming the buffer size is a multiple of 8 */ for (int i = 0; i &lt; sz; i += 8) { // Load a vector of 8 16-bit values: uint16x8_t v = vld1q_u16(buf+i); // Shift it by 4 to the right, narrowing it to 8 bit values. uint8x8_t shifted = vshrn_n_u16(v, 4); // Store it in output buffer vst1_u8(output+i, shifted); } } </code></pre> <p>Things I assumed here:</p> <ul> <li>that you're working with unsigned values. If it's not the case, it will be easy to adapt anyway (<code>uint*</code> -> <code>int*</code>, <code>*_u8</code>-><code>*_s8</code> and <code>*_u16</code>-><code>*_s16</code>)</li> <li>as the values are loaded 8 by 8, I assumed the buffer length was a multiple of 8 to avoid edge cases. If that's not the case, you should probably pad it artificially to a multiple of 8.</li> </ul> <p>Finally, the 2 resource pages used from the NEON documentation:</p> <ul> <li>about <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0348c/BABDCGGF.html" rel="nofollow">loads and stores</a> of vectors.</li> <li>about <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0348c/BABIBBJG.html" rel="nofollow">shifting vectors</a>.</li> </ul> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload