GNU Radio 3.6.5 C++ API

volk_16u_byteswap_u.h

Go to the documentation of this file.
00001 #ifndef INCLUDED_volk_16u_byteswap_u_H
00002 #define INCLUDED_volk_16u_byteswap_u_H
00003 
00004 #include <inttypes.h>
00005 #include <stdio.h>
00006 
00007 #ifdef LV_HAVE_SSE2
00008 #include <emmintrin.h>
00009 
00010 /*!
00011   \brief Byteswaps (in-place) an unaligned vector of int16_t's.
00012   \param intsToSwap The vector of data to byte swap
00013   \param numDataPoints The number of data points
00014 */
00015 static inline void volk_16u_byteswap_u_sse2(uint16_t* intsToSwap, unsigned int num_points){
00016   unsigned int number = 0;
00017   uint16_t* inputPtr = intsToSwap;
00018   __m128i input, left, right, output;
00019 
00020   const unsigned int eighthPoints = num_points / 8;
00021   for(;number < eighthPoints; number++){
00022     // Load the 16t values, increment inputPtr later since we're doing it in-place.
00023     input = _mm_loadu_si128((__m128i*)inputPtr);
00024     // Do the two shifts
00025     left = _mm_slli_epi16(input, 8);
00026     right = _mm_srli_epi16(input, 8);
00027     // Or the left and right halves together
00028     output = _mm_or_si128(left, right);
00029     // Store the results
00030     _mm_storeu_si128((__m128i*)inputPtr, output);
00031     inputPtr += 8;
00032   }
00033 
00034   // Byteswap any remaining points:
00035   number = eighthPoints*8;
00036   for(; number < num_points; number++){
00037     uint16_t outputVal = *inputPtr;
00038     outputVal = (((outputVal >> 8) & 0xff) | ((outputVal << 8) & 0xff00));
00039     *inputPtr = outputVal;
00040     inputPtr++;
00041   }
00042 }
00043 #endif /* LV_HAVE_SSE2 */
00044 
00045 #ifdef LV_HAVE_GENERIC
00046 /*!
00047   \brief Byteswaps (in-place) an unaligned vector of int16_t's.
00048   \param intsToSwap The vector of data to byte swap
00049   \param numDataPoints The number of data points
00050 */
00051 static inline void volk_16u_byteswap_u_generic(uint16_t* intsToSwap, unsigned int num_points){
00052   unsigned int point;
00053   uint16_t* inputPtr = intsToSwap;
00054   for(point = 0; point < num_points; point++){
00055     uint16_t output = *inputPtr;
00056     output = (((output >> 8) & 0xff) | ((output << 8) & 0xff00));
00057     *inputPtr = output;
00058     inputPtr++;
00059   }
00060 }
00061 #endif /* LV_HAVE_GENERIC */
00062 
00063 #endif /* INCLUDED_volk_16u_byteswap_u_H */