GNU Radio 3.6.3.1 C++ API
volk_16u_byteswap_a.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_16u_byteswap_a_H
2 #define INCLUDED_volk_16u_byteswap_a_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 aligned 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_a_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_load_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_store_si128((__m128i*)inputPtr, output);
31  inputPtr += 8;
32  }
33 
34 
35  // Byteswap any remaining points:
36  number = eighthPoints*8;
37  for(; number < num_points; number++){
38  uint16_t outputVal = *inputPtr;
39  outputVal = (((outputVal >> 8) & 0xff) | ((outputVal << 8) & 0xff00));
40  *inputPtr = outputVal;
41  inputPtr++;
42  }
43 }
44 #endif /* LV_HAVE_SSE2 */
45 
46 #ifdef LV_HAVE_GENERIC
47 /*!
48  \brief Byteswaps (in-place) an aligned vector of int16_t's.
49  \param intsToSwap The vector of data to byte swap
50  \param numDataPoints The number of data points
51 */
52 static inline void volk_16u_byteswap_a_generic(uint16_t* intsToSwap, unsigned int num_points){
53  unsigned int point;
54  uint16_t* inputPtr = intsToSwap;
55  for(point = 0; point < num_points; point++){
56  uint16_t output = *inputPtr;
57  output = (((output >> 8) & 0xff) | ((output << 8) & 0xff00));
58  *inputPtr = output;
59  inputPtr++;
60  }
61 }
62 #endif /* LV_HAVE_GENERIC */
63 
64 #ifdef LV_HAVE_ORC
65 /*!
66  \brief Byteswaps (in-place) an aligned vector of int16_t's.
67  \param intsToSwap The vector of data to byte swap
68  \param numDataPoints The number of data points
69 */
70 extern void volk_16u_byteswap_a_orc_impl(uint16_t* intsToSwap, unsigned int num_points);
71 static inline void volk_16u_byteswap_a_orc(uint16_t* intsToSwap, unsigned int num_points){
72  volk_16u_byteswap_a_orc_impl(intsToSwap, num_points);
73 }
74 #endif /* LV_HAVE_ORC */
75 
76 
77 #endif /* INCLUDED_volk_16u_byteswap_a_H */