GNU Radio 3.7.2 C++ API
volk_16u_byteswap.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_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 */
64 #ifndef INCLUDED_volk_16u_byteswap_a_H
65 #define INCLUDED_volk_16u_byteswap_a_H
66 
67 #include <inttypes.h>
68 #include <stdio.h>
69 
70 #ifdef LV_HAVE_SSE2
71 #include <emmintrin.h>
72 
73 /*!
74  \brief Byteswaps (in-place) an aligned vector of int16_t's.
75  \param intsToSwap The vector of data to byte swap
76  \param numDataPoints The number of data points
77 */
78 static inline void volk_16u_byteswap_a_sse2(uint16_t* intsToSwap, unsigned int num_points){
79  unsigned int number = 0;
80  uint16_t* inputPtr = intsToSwap;
81  __m128i input, left, right, output;
82 
83  const unsigned int eighthPoints = num_points / 8;
84  for(;number < eighthPoints; number++){
85  // Load the 16t values, increment inputPtr later since we're doing it in-place.
86  input = _mm_load_si128((__m128i*)inputPtr);
87  // Do the two shifts
88  left = _mm_slli_epi16(input, 8);
89  right = _mm_srli_epi16(input, 8);
90  // Or the left and right halves together
91  output = _mm_or_si128(left, right);
92  // Store the results
93  _mm_store_si128((__m128i*)inputPtr, output);
94  inputPtr += 8;
95  }
96 
97 
98  // Byteswap any remaining points:
99  number = eighthPoints*8;
100  for(; number < num_points; number++){
101  uint16_t outputVal = *inputPtr;
102  outputVal = (((outputVal >> 8) & 0xff) | ((outputVal << 8) & 0xff00));
103  *inputPtr = outputVal;
104  inputPtr++;
105  }
106 }
107 #endif /* LV_HAVE_SSE2 */
108 
109 #ifdef LV_HAVE_GENERIC
110 /*!
111  \brief Byteswaps (in-place) an aligned vector of int16_t's.
112  \param intsToSwap The vector of data to byte swap
113  \param numDataPoints The number of data points
114 */
115 static inline void volk_16u_byteswap_a_generic(uint16_t* intsToSwap, unsigned int num_points){
116  unsigned int point;
117  uint16_t* inputPtr = intsToSwap;
118  for(point = 0; point < num_points; point++){
119  uint16_t output = *inputPtr;
120  output = (((output >> 8) & 0xff) | ((output << 8) & 0xff00));
121  *inputPtr = output;
122  inputPtr++;
123  }
124 }
125 #endif /* LV_HAVE_GENERIC */
126 
127 #ifdef LV_HAVE_ORC
128 /*!
129  \brief Byteswaps (in-place) an aligned vector of int16_t's.
130  \param intsToSwap The vector of data to byte swap
131  \param numDataPoints The number of data points
132 */
133 extern void volk_16u_byteswap_a_orc_impl(uint16_t* intsToSwap, unsigned int num_points);
134 static inline void volk_16u_byteswap_u_orc(uint16_t* intsToSwap, unsigned int num_points){
135  volk_16u_byteswap_a_orc_impl(intsToSwap, num_points);
136 }
137 #endif /* LV_HAVE_ORC */
138 
139 
140 #endif /* INCLUDED_volk_16u_byteswap_a_H */
unsigned short uint16_t
Definition: stdint.h:79