<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi,</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">[…]</div></blockquote><blockquote type="cite" class=""><div class=""><div class="">           col[0] /= 9.0, col[1] /= 9.0, col[2] /= 9.0, col[3] /= 9.0;<br class="">0x5a39 pxor   %xmm0,%xmm0<br class="">[…]<br class=""><br class="">Notice, how line, containing chain of divisions, is compiled to single<br class="">sse operation.</div></div></blockquote><br class=""></div><div class="">I don’t see any SSE operation here. The pxor is just to zero the xmm0 register.</div><div class=""><br class=""></div><div class="">It’s a bit difficult to know what you are doing here, not having context and not knowing the datatypes, but it does indeed look like this code could benefit from vectorisation, since you are doing calculation in blocks of 4. E.g. you can multiply 4 floating points in a single SSE instruction, add 4 floating points in a single SSE instructions, etc.</div><div class=""><br class=""></div><div class="">e.g.</div><div class=""><br class=""></div><div class="">__m128 factor = _mm_set_ps1 (1.0f/9.0f);</div><div class=""><div class="">__m128 result = _mm_mul_ps (packed, factor);</div><div class=""><br class=""></div><div class="">would divide the 4 floats in packed by 9. (We could use _mm_div_ps , but multiplication is faster than division)</div></div><div class=""><br class=""></div><div class="">(See <a href="https://software.intel.com/sites/landingpage/IntrinsicsGuide/" class="">https://software.intel.com/sites/landingpage/IntrinsicsGuide/</a> )</div><div class=""><br class=""></div><div class="">Depending on your data, it might be faster to stay in the floating point domain as long as possible to use SSE floating point operations, and convert to integer at the last moment.</div><div class=""><br class=""></div><div class="">If you do want/need to stay in the integer domain, note that their is no SIMD instruction for integer division, but you could use a multiplication here as well:</div><div class=""><br class=""></div><div class="">__m128i _mm_mulhi_epi16 (__m128i a, __m128i b)</div><div class=""><br class=""></div><div class="">multiplies the packed 16-bit integers in a and b (so 8 at the same time), producing intermediate 32-bit integers, and stores the high 16 bits of the intermediate integers in the result.</div><div class=""><br class=""></div><div class="">Taking the high 16 bits of the 32 bit intermediate result is effectively dividing by 65536. Since x/9 can be expressed (with some error) as x*<span class="" style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);">7281/65536:</span></div><div class=""><br class=""></div><div class=""><div class="">__m128i factor = _mm_set1_epi16 (7282);</div><div class="">__m128i result = _mm_mulhi_epi16(packed, factor)</div><div class=""><br class=""></div><div class="">Of course you would have to get your 8 bit integers (I assume) into/out of the packed 16 bit registers.</div><div class=""><br class=""></div><div class="">That said, whether you want to do this kind of vectorisation by hand is a different matter. The compiler is pretty good in doing these kind of optimisations. Make sure you pass the right flags to turn on SSE and AVX at the levels you want to support. But it certainly is possible to improve what the compilers does. I have obtained significant speed boosts though rewriting inner loops with SSE intrinsics. But even if you choose to stay in C, having some knowledge of the SSE instruction set certainly might help.</div><div class=""><br class=""></div><div class="">Maarten</div></div></body></html>