Divide by floating-point number using NEON intrinsics

邮差的信 提交于 2019-12-03 05:22:49

The NEON instruction set does not have a floating-point divide.

If you know a priori that your values are not poorly scaled, and you do not require correct rounding (this is almost certainly the case if you're doing image processing), then you can use a reciprocal estimate, refinement step, and multiply instead of a divide:

// get an initial estimate of 1/b.
float32x4_t reciprocal = vrecpeq_f32(b);

// use a couple Newton-Raphson steps to refine the estimate.  Depending on your
// application's accuracy requirements, you may be able to get away with only
// one refinement (instead of the two used here).  Be sure to test!
reciprocal = vmulq_f32(vrecpsq_f32(b, reciprocal), reciprocal);
reciprocal = vmulq_f32(vrecpsq_f32(b, reciprocal), reciprocal);

// and finally, compute a/b = a*(1/b)
float32x4_t result = vmulq_f32(a,reciprocal);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!