1 // Copyright 2021 Google LLC 2 // 3 // This source code is licensed under the BSD-style license found in the 4 // LICENSE file in the root directory of this source tree. 5 6 #include <assert.h> 7 #include <stddef.h> 8 #include <stdint.h> 9 10 #include <arm_neon.h> 11 12 #include <xnnpack/intrinsics-polyfill.h> 13 #include <xnnpack/math-stubs.h> 14 15 xnn_math_f32_qu8_cvt__neonv8(size_t n,const float * input,uint8_t * output,uint8_t output_zero_point)16void xnn_math_f32_qu8_cvt__neonv8( 17 size_t n, 18 const float* input, 19 uint8_t* output, 20 uint8_t output_zero_point) 21 { 22 assert(n % (8 * sizeof(int8_t)) == 0); 23 24 const int16x8_t voutput_zero_point = vdupq_n_s16((int16_t) (uint16_t) output_zero_point); 25 for (; n != 0; n -= 8 * sizeof(int8_t)) { 26 const float32x4_t vx_lo = vld1q_f32(input); input += 4; 27 const float32x4_t vx_hi = vld1q_f32(input); input += 4; 28 29 const int32x4_t vy_lo = vcvtnq_s32_f32(vx_lo); 30 const int32x4_t vy_hi = vcvtnq_s32_f32(vx_hi); 31 32 const int16x8_t vy = vqaddq_s16(vcombine_s16(vqmovn_s32(vy_lo), vqmovn_s32(vy_hi)), voutput_zero_point); 33 34 const uint8x8_t vout = vqmovun_s16(vy); 35 vst1_u8(output, vout); output += 8; 36 } 37 } 38