GNU Radio 3.4.2 C++ API
volk_32f_s32f_convert_32i_a.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_volk_32f_s32f_convert_32i_a_H
00002 #define INCLUDED_volk_32f_s32f_convert_32i_a_H
00003 
00004 #include <volk/volk_common.h>
00005 #include <inttypes.h>
00006 #include <stdio.h>
00007 
00008 #ifdef LV_HAVE_AVX
00009 #include <immintrin.h>
00010   /*!
00011     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
00012     \param inputVector The floating point input data buffer
00013     \param outputVector The 32 bit output data buffer
00014     \param scalar The value multiplied against each point in the input buffer
00015     \param num_points The number of data values to be converted
00016   */
00017 static inline void volk_32f_s32f_convert_32i_a_avx(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00018   unsigned int number = 0;
00019 
00020   const unsigned int eighthPoints = num_points / 8;
00021     
00022   const float* inputVectorPtr = (const float*)inputVector;
00023   int32_t* outputVectorPtr = outputVector;
00024   __m256 vScalar = _mm256_set1_ps(scalar);
00025   __m256 inputVal1;
00026   __m256i intInputVal1;
00027 
00028   for(;number < eighthPoints; number++){
00029     inputVal1 = _mm256_load_ps(inputVectorPtr); inputVectorPtr += 8;
00030 
00031     intInputVal1 = _mm256_cvtps_epi32(_mm256_mul_ps(inputVal1, vScalar));
00032 
00033     _mm256_store_si256((__m256i*)outputVectorPtr, intInputVal1);
00034     outputVectorPtr += 8;
00035   }
00036 
00037   number = eighthPoints * 8;    
00038   for(; number < num_points; number++){
00039     outputVector[number] = (int32_t)(inputVector[number] * scalar);
00040   }
00041 }
00042 #endif /* LV_HAVE_AVX */
00043 
00044 #ifdef LV_HAVE_SSE2
00045 #include <emmintrin.h>
00046   /*!
00047     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
00048     \param inputVector The floating point input data buffer
00049     \param outputVector The 32 bit output data buffer
00050     \param scalar The value multiplied against each point in the input buffer
00051     \param num_points The number of data values to be converted
00052   */
00053 static inline void volk_32f_s32f_convert_32i_a_sse2(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00054   unsigned int number = 0;
00055 
00056   const unsigned int quarterPoints = num_points / 4;
00057     
00058   const float* inputVectorPtr = (const float*)inputVector;
00059   int32_t* outputVectorPtr = outputVector;
00060   __m128 vScalar = _mm_set_ps1(scalar);
00061   __m128 inputVal1;
00062   __m128i intInputVal1;
00063 
00064   for(;number < quarterPoints; number++){
00065     inputVal1 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
00066 
00067     intInputVal1 = _mm_cvtps_epi32(_mm_mul_ps(inputVal1, vScalar));
00068 
00069     _mm_store_si128((__m128i*)outputVectorPtr, intInputVal1);
00070     outputVectorPtr += 4;
00071   }
00072 
00073   number = quarterPoints * 4;    
00074   for(; number < num_points; number++){
00075     outputVector[number] = (int32_t)(inputVector[number] * scalar);
00076   }
00077 }
00078 #endif /* LV_HAVE_SSE2 */
00079 
00080 #ifdef LV_HAVE_SSE
00081 #include <xmmintrin.h>
00082   /*!
00083     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
00084     \param inputVector The floating point input data buffer
00085     \param outputVector The 32 bit output data buffer
00086     \param scalar The value multiplied against each point in the input buffer
00087     \param num_points The number of data values to be converted
00088   */
00089 static inline void volk_32f_s32f_convert_32i_a_sse(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00090   unsigned int number = 0;
00091 
00092   const unsigned int quarterPoints = num_points / 4;
00093     
00094   const float* inputVectorPtr = (const float*)inputVector;
00095   int32_t* outputVectorPtr = outputVector;
00096   __m128 vScalar = _mm_set_ps1(scalar);
00097   __m128 ret;
00098 
00099   __VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
00100 
00101   for(;number < quarterPoints; number++){
00102     ret = _mm_load_ps(inputVectorPtr);
00103     inputVectorPtr += 4;
00104 
00105     ret = _mm_mul_ps(ret, vScalar);
00106 
00107     _mm_store_ps(outputFloatBuffer, ret);
00108     *outputVectorPtr++ = (int32_t)(outputFloatBuffer[0]);
00109     *outputVectorPtr++ = (int32_t)(outputFloatBuffer[1]);
00110     *outputVectorPtr++ = (int32_t)(outputFloatBuffer[2]);
00111     *outputVectorPtr++ = (int32_t)(outputFloatBuffer[3]);
00112   }
00113 
00114   number = quarterPoints * 4;    
00115   for(; number < num_points; number++){
00116     outputVector[number] = (int32_t)(inputVector[number] * scalar);
00117   }
00118 }
00119 #endif /* LV_HAVE_SSE */
00120 
00121 #ifdef LV_HAVE_GENERIC
00122   /*!
00123     \brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 32 bit integer value
00124     \param inputVector The floating point input data buffer
00125     \param outputVector The 32 bit output data buffer
00126     \param scalar The value multiplied against each point in the input buffer
00127     \param num_points The number of data values to be converted
00128   */
00129 static inline void volk_32f_s32f_convert_32i_a_generic(int32_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
00130   int32_t* outputVectorPtr = outputVector;
00131   const float* inputVectorPtr = inputVector;
00132   unsigned int number = 0;
00133 
00134   for(number = 0; number < num_points; number++){
00135     *outputVectorPtr++ = ((int32_t)(*inputVectorPtr++  * scalar));
00136   }
00137 }
00138 #endif /* LV_HAVE_GENERIC */
00139 
00140 
00141 
00142 
00143 #endif /* INCLUDED_volk_32f_s32f_convert_32i_a_H */