1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#ifndef INCLUDED_volk_32f_s32f_convert_16i_a_H
#define INCLUDED_volk_32f_s32f_convert_16i_a_H
#include <volk/volk_common.h>
#include <inttypes.h>
#include <stdio.h>
#ifdef LV_HAVE_SSE2
#include <emmintrin.h>
/*!
\brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
\param inputVector The floating point input data buffer
\param outputVector The 16 bit output data buffer
\param scalar The value multiplied against each point in the input buffer
\param num_points The number of data values to be converted
*/
static inline void volk_32f_s32f_convert_16i_a_sse2(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
unsigned int number = 0;
const unsigned int eighthPoints = num_points / 8;
const float* inputVectorPtr = (const float*)inputVector;
int16_t* outputVectorPtr = outputVector;
__m128 vScalar = _mm_set_ps1(scalar);
__m128 inputVal1, inputVal2;
__m128i intInputVal1, intInputVal2;
for(;number < eighthPoints; number++){
inputVal1 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
inputVal2 = _mm_load_ps(inputVectorPtr); inputVectorPtr += 4;
intInputVal1 = _mm_cvtps_epi32(_mm_mul_ps(inputVal1, vScalar));
intInputVal2 = _mm_cvtps_epi32(_mm_mul_ps(inputVal2, vScalar));
intInputVal1 = _mm_packs_epi32(intInputVal1, intInputVal2);
_mm_store_si128((__m128i*)outputVectorPtr, intInputVal1);
outputVectorPtr += 8;
}
number = eighthPoints * 8;
for(; number < num_points; number++){
*outputVectorPtr++ = (int16_t)(*inputVectorPtr++ * scalar);
}
}
#endif /* LV_HAVE_SSE2 */
#ifdef LV_HAVE_SSE
#include <xmmintrin.h>
/*!
\brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
\param inputVector The floating point input data buffer
\param outputVector The 16 bit output data buffer
\param scalar The value multiplied against each point in the input buffer
\param num_points The number of data values to be converted
*/
static inline void volk_32f_s32f_convert_16i_a_sse(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
unsigned int number = 0;
const unsigned int quarterPoints = num_points / 4;
const float* inputVectorPtr = (const float*)inputVector;
int16_t* outputVectorPtr = outputVector;
__m128 vScalar = _mm_set_ps1(scalar);
__m128 ret;
__VOLK_ATTR_ALIGNED(16) float outputFloatBuffer[4];
for(;number < quarterPoints; number++){
ret = _mm_load_ps(inputVectorPtr);
inputVectorPtr += 4;
ret = _mm_mul_ps(ret, vScalar);
_mm_store_ps(outputFloatBuffer, ret);
*outputVectorPtr++ = (int16_t)(outputFloatBuffer[0]);
*outputVectorPtr++ = (int16_t)(outputFloatBuffer[1]);
*outputVectorPtr++ = (int16_t)(outputFloatBuffer[2]);
*outputVectorPtr++ = (int16_t)(outputFloatBuffer[3]);
}
number = quarterPoints * 4;
for(; number < num_points; number++){
*outputVectorPtr++ = (int16_t)(*inputVectorPtr++ * scalar);
}
}
#endif /* LV_HAVE_SSE */
#ifdef LV_HAVE_GENERIC
/*!
\brief Multiplies each point in the input buffer by the scalar value, then converts the result into a 16 bit integer value
\param inputVector The floating point input data buffer
\param outputVector The 16 bit output data buffer
\param scalar The value multiplied against each point in the input buffer
\param num_points The number of data values to be converted
*/
static inline void volk_32f_s32f_convert_16i_a_generic(int16_t* outputVector, const float* inputVector, const float scalar, unsigned int num_points){
int16_t* outputVectorPtr = outputVector;
const float* inputVectorPtr = inputVector;
unsigned int number = 0;
for(number = 0; number < num_points; number++){
*outputVectorPtr++ = ((int16_t)(*inputVectorPtr++ * scalar));
}
}
#endif /* LV_HAVE_GENERIC */
#endif /* INCLUDED_volk_32f_s32f_convert_16i_a_H */
|