ale*_*exm 4 android arm simd neon
我正在 Android 中处理音频缓冲区,我的设置如下:
我想减少第 2 步和第 4 步的延迟,即short to float 和float to short 转换。(不考虑 3-DSP 中的延迟,因为我稍后会处理)。
所以,我想使用 NEON SIMD 一次计算多个值。
我目前拥有的 2 和 4 是以下代码:
#define CONV16BIT 32768
#define CONVMYFLT (1./32768.)
static int i;
float * floatBuffer;
short * shortInBuffer;
short * shortOutBuffer;
...(malloc and init buffers method)
...(inside callback)
//2- short to float
for(i = 0; i < bufferSize; i++) {
floatBuffer[i] = (float) (shortInBuffer[i] * CONVMYFLT);
}
...(do dsp)
//4- float to short
for(i = 0; i < bufferSize; i++) {
shortOutBuffer[i] = (short) (floatBuffer[i] * CONV16BIT);
}
Run Code Online (Sandbox Code Playgroud)
我相信我需要利用 NEON 的步骤是:
(为短浮动部分)
在这篇文章中找到了这个信息(选择的答案)
__m128 factor = _mm_set1_ps(1.0f / value);
for (int i = 0; i < W*H; i += 8)
{
// Load 8 16-bit ushorts.
// vi = {a,b,c,d,e,f,g,h}
__m128i vi = _mm_load_si128((const __m128i*)(source + i));
// Convert to 32-bit integers
// vi0 = {a,0,b,0,c,0,d,0}
// vi1 = {e,0,f,0,g,0,h,0}
__m128i vi0 = _mm_cvtepu16_epi32(vi);
__m128i vi1 = _mm_cvtepu16_epi32(_mm_unpackhi_epi64(vi,vi));
// Convert to float
__m128 vf0 = _mm_cvtepi32_ps(vi0);
__m128 vf1 = _mm_cvtepi32_ps(vi1);
// Multiply
vf0 = _mm_mul_ps(vf0,factor);
vf1 = _mm_mul_ps(vf1,factor);
// Store
_mm_store_ps(destination + i + 0,vf0);
_mm_store_ps(destination + i + 4,vf1);
}
Run Code Online (Sandbox Code Playgroud)
但是,这是用于英特尔 SSE4.1 的 SIMD,而不是用于 NEON。
Android 中 NEON 的等效实现是什么?(很难理解 NEON 内在函数)
更新 1 从 fsheikh 的回答中,我能够构建这个: - 我能够从系统回调中获得 int16_t - 我所有的缓冲区大小都是 8 的倍数:
int16x8_t i16v;
int32x4_t i32vl, i32vh;
float32x4_t f32vl, f32vh;
for(i = 0; i < bufferSize; i += 8) {
//load 8 16-bit lanes on vector
i16v = vld1q_s16((const int16x8_t*) int16_t_inBuffer[i]);
// convert into 32-bit signed integer
i32vl = vmovl_s16 (i16v);
i32vh = vmovl_s16 (vzipq_s16(i16v, i16v).val[0]);
//convert to 32-bit float
f32vl = vcvtq_f32_s32(i32vl);
f32vh = vcvtq_f32_s32(i32vh);
//multiply by scalar
f32vl = vmulq_n_f32(f32vl, CONVMYFLT);
f32vh = vmulq_n_f32(f32vh, CONVMYFLT);
//store in float buffer
vst1q_f32(floatBuffer[i], f32vl);
vst1q_f32(floatBuffer[i + 4], f32vh);
}
Run Code Online (Sandbox Code Playgroud)
这应该正确吗? 我怀疑我应该使用 vmovl_s16 返回的交错向量的低部分或高部分:
i32vh = vmovl_s16 (vzipq_s1 6(i16v, i16v).val[0]); 或者
i32vh = vmovl_s16 (vzipq_s16(i16v, i16v).val[1]);
拥有 SSE 版本后,您可以使用 GCC ARM NEON 内在函数列表将 SSE 宏移植到 NEON。https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/ARM-NEON-Intrinsics.html
例如:
// Load unsigned short
uint16x4_t vld1_u16 (const uint16_t *)
// Convert to unsigned int
uint32x4_t vmovl_u16 (uint16x4_t)
// Convert to float
float32x4_t vcvtq_f32_s32 (int32x4_t)
// Multiply floats with a scalar
float32x4_t vmulq_n_f32 (float32x4_t, float32_t)
// Store results into a float buffer
void vst1q_f32 (float32_t *, float32x4_t)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2389 次 |
| 最近记录: |