GNU Radio 3.4.0 C++ API
volk_32f_s32f_convert_16i_a16.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_volk_32f_s32f_convert_16i_a16_H
00002 #define INCLUDED_volk_32f_s32f_convert_16i_a16_H
00003 
00004 #include <inttypes.h>
00005 #include <stdio.h>
00006 
00007 #if LV_HAVE_SSE2
00008 #include <emmintrin.h>
00009   /*!
00010     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
00011     \param inputVector The floating point input data buffer
00012     \param outputVector The 16 bit output data buffer
00013     \param scalar The value multiplied against each point in the input buffer
00014     \param num_points The number of data values to be converted
00015   */
00016 static inline void volk_32f_s32f_convert_16i_a16_sse2(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00017   unsigned int number = 0;
00018 
00019   const unsigned int eighthPoints = num_points / 8;
00020     
00021   const float* inputVectorPtr = (const float*)inputVector;
00022   int16_t* outputVectorPtr = outputVector;
00023   __m128 vScalar = _mm_set_ps1(scalar);
00024   __m128 inputVal1, inputVal2;
00025   __m128i intInputVal1, intInputVal2;
00026 
00027   for(;number < eighthPoints; number++){
00028     inputVal1 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
00029     inputVal2 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
00030 
00031     intInputVal1 = _mm_cvtps_epi32(_mm_mul_ps(inputVal1, vScalar));
00032     intInputVal2 = _mm_cvtps_epi32(_mm_mul_ps(inputVal2, vScalar));
00033     
00034     intInputVal1 = _mm_packs_epi32(intInputVal1, intInputVal2);
00035 
00036     _mm_store_si128((__m128i*)outputVectorPtr, intInputVal1);
00037     outputVectorPtr += 8;
00038   }
00039 
00040   number = eighthPoints * 8;    
00041   for(; number < num_points; number++){
00042     *outputVectorPtr++ = (int16_t)(*inputVectorPtr++ * scalar);
00043   }
00044 }
00045 #endif /* LV_HAVE_SSE2 */
00046 
00047 #if LV_HAVE_SSE
00048 #include <xmmintrin.h>
00049   /*!
00050     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
00051     \param inputVector The floating point input data buffer
00052     \param outputVector The 16 bit output data buffer
00053     \param scalar The value multiplied against each point in the input buffer
00054     \param num_points The number of data values to be converted
00055   */
00056 static inline void volk_32f_s32f_convert_16i_a16_sse(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00057   unsigned int number = 0;
00058 
00059   const unsigned int quarterPoints = num_points / 4;
00060     
00061   const float* inputVectorPtr = (const float*)inputVector;
00062   int16_t* outputVectorPtr = outputVector;
00063   __m128 vScalar = _mm_set_ps1(scalar);
00064   __m128 ret;
00065 
00066   float outputFloatBuffer[4] __attribute__((aligned(128)));
00067 
00068   for(;number < quarterPoints; number++){
00069     ret = _mm_load_ps(inputVectorPtr);
00070     inputVectorPtr += 4;
00071 
00072     ret = _mm_mul_ps(ret, vScalar);
00073 
00074     _mm_store_ps(outputFloatBuffer, ret);
00075     *outputVectorPtr++ = (int16_t)(outputFloatBuffer[0]);
00076     *outputVectorPtr++ = (int16_t)(outputFloatBuffer[1]);
00077     *outputVectorPtr++ = (int16_t)(outputFloatBuffer[2]);
00078     *outputVectorPtr++ = (int16_t)(outputFloatBuffer[3]);
00079   }
00080 
00081   number = quarterPoints * 4;    
00082   for(; number < num_points; number++){
00083     *outputVectorPtr++ = (int16_t)(*inputVectorPtr++ * scalar);
00084   }
00085 }
00086 #endif /* LV_HAVE_SSE */
00087 
00088 #ifdef LV_HAVE_GENERIC
00089   /*!
00090     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
00091     \param inputVector The floating point input data buffer
00092     \param outputVector The 16 bit output data buffer
00093     \param scalar The value multiplied against each point in the input buffer
00094     \param num_points The number of data values to be converted
00095   */
00096 static inline void volk_32f_s32f_convert_16i_a16_generic(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00097   int16_t* outputVectorPtr = outputVector;
00098   const float* inputVectorPtr = inputVector;
00099   unsigned int number = 0;
00100 
00101   for(number = 0; number < num_points; number++){
00102     *outputVectorPtr++ = ((int16_t)(*inputVectorPtr++ * scalar));
00103   }
00104 }
00105 #endif /* LV_HAVE_GENERIC */
00106 
00107 
00108 
00109 
00110 #endif /* INCLUDED_volk_32f_s32f_convert_16i_a16_H */