• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-f32-vcvt/neon.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9 
10 #include <assert.h>
11 
12 #include <arm_neon.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 #include <xnnpack/vcvt.h>
17 
18 
xnn_qu8_f32_vcvt_ukernel__neon_x8(size_t n,const uint8_t * x,float * y,const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qu8_f32_vcvt_ukernel__neon_x8(
20     size_t n,
21     const uint8_t* x,
22     float* y,
23     const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25   assert(n != 0);
26   assert(n % sizeof(uint8_t) == 0);
27   assert(x != NULL);
28   assert(y != NULL);
29 
30   const int16x8_t vminus_zero_point = vreinterpretq_s16_u32(vld1q_dup_u32((const void*) params->neon.minus_zero_point));
31   const float32x4_t vscale = vld1q_dup_f32(&params->neon.scale);
32   for (; n >= 8 * sizeof(uint8_t); n -= 8 * sizeof(uint8_t)) {
33     const uint8x8_t vx = vld1_u8(x); x += 8;
34 
35     const int16x8_t vhx = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(vminus_zero_point), vx));
36 
37     const int32x4_t vwx_lo = vmovl_s16(vget_low_s16(vhx));
38     const int32x4_t vwx_hi = vmovl_s16(vget_high_s16(vhx));
39 
40     float32x4_t vy_lo = vcvtq_f32_s32(vwx_lo);
41     float32x4_t vy_hi = vcvtq_f32_s32(vwx_hi);
42 
43     vy_lo = vmulq_f32(vy_lo, vscale);
44     vy_hi = vmulq_f32(vy_hi, vscale);
45 
46     vst1q_f32(y, vy_lo); y += 4;
47     vst1q_f32(y, vy_hi); y += 4;
48   }
49   if XNN_UNLIKELY(n != 0) {
50     assert(n >= 1 * sizeof(uint8_t));
51     assert(n <= 7 * sizeof(uint8_t));
52 
53     const uint8x8_t vx = vld1_u8(x);
54 
55     const int16x8_t vhx = vreinterpretq_s16_u16(vaddw_u8(vreinterpretq_u16_s16(vminus_zero_point), vx));
56 
57     const int32x4_t vwx_lo = vmovl_s16(vget_low_s16(vhx));
58     const int32x4_t vwx_hi = vmovl_s16(vget_high_s16(vhx));
59 
60     float32x4_t vy = vcvtq_f32_s32(vwx_lo);
61     vy = vmulq_f32(vy, vscale);
62 
63     if (n & (4 * sizeof(uint8_t))) {
64       vst1q_f32(y, vy); y += 4;
65       vy = vcvtq_f32_s32(vwx_hi);
66       vy = vmulq_f32(vy, vscale);
67     }
68     float32x2_t vy_lo = vget_low_f32(vy);
69     if (n & (2 * sizeof(uint8_t))) {
70       vst1_f32(y, vy_lo); y += 2;
71       vy_lo = vget_high_f32(vy);
72     }
73     if (n & (1 * sizeof(uint8_t))) {
74       vst1_lane_f32(y, vy_lo, 0);
75     }
76   }
77 }
78