Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some problems.
I try to convert standard SIMD instructions to other using libsimdpp.
libsimdpp is a portable header-only zero-overhead C++ wrapper around single-instruction multiple-data (SIMD) intrinsics found in many compilers.https://github.com/p12tic/libsimdpp[^]

C++
__m128i v_zero = _mm_setzero_si128();
  for ( ; j <= width - 8; j += 8)
  {
       __m128i v_dx = _mm_loadu_si128((const __m128i *)(_dx + j));
       __m128i v_dy = _mm_loadu_si128((const __m128i *)(_dy + j));
       v_dx = _mm_max_epi16(v_dx, _mm_sub_epi16(v_zero, v_dx));
       v_dy = _mm_max_epi16(v_dy, _mm_sub_epi16(v_zero, v_dy));

       __m128i v_norm = _mm_add_epi32(_mm_unpacklo_epi16(v_dx, v_zero), _mm_unpacklo_epi16(v_dy, v_zero));
       _mm_storeu_si128((__m128i *)(_norm + j), v_norm);

       v_norm = _mm_add_epi32(_mm_unpackhi_epi16(v_dx, v_zero), _mm_unpackhi_epi16(v_dy, v_zero));
      _mm_storeu_si128((__m128i *)(_norm + j + 4), v_norm);
}


this code is using standard simd intrinsics.

How to write this code using libsimdpp?

Thanks
Posted
Updated 28-Jan-15 23:11pm
v2
Comments
[no name] 29-Jan-15 12:47pm    
You can read through the source code.

Start with the test code. Look at ...

https://github.com/p12tic/libsimdpp/blob/master/test/utils/test_helpers.h

https://github.com/p12tic/libsimdpp/blob/master/test/insn/math_int.cc

In particular, look at the code following this comment in math_int.cc:

| // Vectors with 16-bit integer elements

I am puzzled by this statement:

| v_dx = _mm_max_epi16(v_dx, _mm_sub_epi16(v_zero, v_dx));

This looks to be v_dx = max(v_dx, -v_dx) ... which would be v_dx. Seems like nonsense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900