Reputation: 123
I'm a newbie to arm neon intrinsics and I would like to scale the float32 array with a scalar (2^13 = 8192) and typecast to int16_t array. I believe I need to perform the below steps:
Could you please check and correct the below code:
// convert float to int16
uint32_t blk_cnt;
float32x4_t f32x4;
int32x4_t i32x4;
int16x4_t i16x4;
float32_t scale = 8192.0;
/* Compute 4 complex samples at a time */
blk_cnt = sz >> 2U;
while (blk_cnt > 0U) {
f32x4 = vld1q_f32 ((float32_t *) inpout);
f32x4 = vmulq_n_f32(f32x4, scale);
i32x4 = vcvtq_s32_f32 (f32x4);
i16x4 = vmovn_s32 (i32x4);
vst1_s16 (out, i16x4);
/* Increment pointers */
out += 4;
inpout += 4;
/* Decrement the loop counter */
blk_cnt--;
}
Upvotes: 0
Views: 328
Reputation: 6354
You are most probably dealing with q13 (13 fraction bits) fixed point values.
You just need to convert the floats to q13 int32 (vcvt_n_s32_f32
), then shrink them to int16 by vqmovn
.
Upvotes: 1