GNU Radio 3.6.4 C++ API
volk_16u_byteswap_u.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_16u_byteswap_u_H
2 #define INCLUDED_volk_16u_byteswap_u_H
3 
4 #include <inttypes.h>
5 #include <stdio.h>
6 
7 #ifdef LV_HAVE_SSE2
8 #include <emmintrin.h>
9 
10 /*!
11  \brief Byteswaps (in-place) an unaligned vector of int16_t's.
12  \param intsToSwap The vector of data to byte swap
13  \param numDataPoints The number of data points
14 */
15 static inline void volk_16u_byteswap_u_sse2(uint16_t* intsToSwap, unsigned int num_points){
16  unsigned int number = 0;
17  uint16_t* inputPtr = intsToSwap;
18  __m128i input, left, right, output;
19 
20  const unsigned int eighthPoints = num_points / 8;
21  for(;number < eighthPoints; number++){
22  // Load the 16t values, increment inputPtr later since we're doing it in-place.
23  input = _mm_loadu_si128((__m128i*)inputPtr);
24  // Do the two shifts
25  left = _mm_slli_epi16(input, 8);
26  right = _mm_srli_epi16(input, 8);
27  // Or the left and right halves together
28  output = _mm_or_si128(left, right);
29  // Store the results
30  _mm_storeu_si128((__m128i*)inputPtr, output);
31  inputPtr += 8;
32  }
33 
34  // Byteswap any remaining points:
35  number = eighthPoints*8;
36  for(; number < num_points; number++){
37  uint16_t outputVal = *inputPtr;
38  outputVal = (((outputVal >> 8) & 0xff) | ((outputVal << 8) & 0xff00));
39  *inputPtr = outputVal;
40  inputPtr++;
41  }
42 }
43 #endif /* LV_HAVE_SSE2 */
44 
45 #ifdef LV_HAVE_GENERIC
46 /*!
47  \brief Byteswaps (in-place) an unaligned vector of int16_t's.
48  \param intsToSwap The vector of data to byte swap
49  \param numDataPoints The number of data points
50 */
51 static inline void volk_16u_byteswap_u_generic(uint16_t* intsToSwap, unsigned int num_points){
52  unsigned int point;
53  uint16_t* inputPtr = intsToSwap;
54  for(point = 0; point < num_points; point++){
55  uint16_t output = *inputPtr;
56  output = (((output >> 8) & 0xff) | ((output << 8) & 0xff00));
57  *inputPtr = output;
58  inputPtr++;
59  }
60 }
61 #endif /* LV_HAVE_GENERIC */
62 
63 #endif /* INCLUDED_volk_16u_byteswap_u_H */