gr-baz Package
volk_32u_byteswap_u.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_32u_byteswap_u_H
2 #define INCLUDED_volk_32u_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 aligned vector of int32_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_32u_byteswap_u_sse2(uint32_t* intsToSwap, unsigned int num_points){
16  unsigned int number = 0;
17 
18  uint32_t* inputPtr = intsToSwap;
19  __m128i input, byte1, byte2, byte3, byte4, output;
20  __m128i byte2mask = _mm_set1_epi32(0x00FF0000);
21  __m128i byte3mask = _mm_set1_epi32(0x0000FF00);
22 
23  const uint64_t quarterPoints = num_points / 4;
24  for(;number < quarterPoints; number++){
25  // Load the 32t values, increment inputPtr later since we're doing it in-place.
26  input = _mm_loadu_si128((__m128i*)inputPtr);
27  // Do the four shifts
28  byte1 = _mm_slli_epi32(input, 24);
29  byte2 = _mm_slli_epi32(input, 8);
30  byte3 = _mm_srli_epi32(input, 8);
31  byte4 = _mm_srli_epi32(input, 24);
32  // Or bytes together
33  output = _mm_or_si128(byte1, byte4);
34  byte2 = _mm_and_si128(byte2, byte2mask);
35  output = _mm_or_si128(output, byte2);
36  byte3 = _mm_and_si128(byte3, byte3mask);
37  output = _mm_or_si128(output, byte3);
38  // Store the results
39  _mm_storeu_si128((__m128i*)inputPtr, output);
40  inputPtr += 4;
41  }
42 
43  // Byteswap any remaining points:
44  number = quarterPoints*4;
45  for(; number < num_points; number++){
46  uint32_t outputVal = *inputPtr;
47  outputVal = (((outputVal >> 24) & 0xff) | ((outputVal >> 8) & 0x0000ff00) | ((outputVal << 8) & 0x00ff0000) | ((outputVal << 24) & 0xff000000));
48  *inputPtr = outputVal;
49  inputPtr++;
50  }
51 }
52 #endif /* LV_HAVE_SSE2 */
53 
54 #ifdef LV_HAVE_GENERIC
55 /*!
56  \brief Byteswaps (in-place) an aligned vector of int32_t's.
57  \param intsToSwap The vector of data to byte swap
58  \param numDataPoints The number of data points
59 */
60 static inline void volk_32u_byteswap_u_generic(uint32_t* intsToSwap, unsigned int num_points){
61  uint32_t* inputPtr = intsToSwap;
62 
63  unsigned int point;
64  for(point = 0; point < num_points; point++){
65  uint32_t output = *inputPtr;
66  output = (((output >> 24) & 0xff) | ((output >> 8) & 0x0000ff00) | ((output << 8) & 0x00ff0000) | ((output << 24) & 0xff000000));
67 
68  *inputPtr = output;
69  inputPtr++;
70  }
71 }
72 #endif /* LV_HAVE_GENERIC */
73 
74 
75 
76 
77 #endif /* INCLUDED_volk_32u_byteswap_u_H */