xref: /aosp_15_r20/external/XNNPACK/src/s16-vlshift/gen/neon-x16.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/s16-vlshift/neon.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2022 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 #include <stddef.h>
12 #include <stdint.h>
13 
14 #include <arm_neon.h>
15 
16 #include <xnnpack/math.h>
17 #include <xnnpack/vlshift.h>
18 
19 
xnn_s16_vlshift_ukernel__neon_x16(size_t batch,const int16_t * input,int16_t * output,uint32_t shift)20 void xnn_s16_vlshift_ukernel__neon_x16(
21     size_t batch,
22     const int16_t* input,
23     int16_t* output,
24     uint32_t shift)
25 {
26   assert(batch > 0);
27   assert(input != NULL);
28   assert(output != NULL);
29   assert(shift < 16);
30 
31   const int16x8_t vshift = vdupq_n_s16((int16_t) shift);
32 
33   for (; batch >= 16; batch -= 16) {
34     const int16x8_t vi0 = vld1q_s16(input); input += 8;
35     const int16x8_t vi1 = vld1q_s16(input); input += 8;
36 
37     const int16x8_t vout0 = vshlq_s16(vi0, vshift);
38     const int16x8_t vout1 = vshlq_s16(vi1, vshift);
39 
40     vst1q_s16(output, vout0); output += 8;
41     vst1q_s16(output, vout1); output += 8;
42   }
43 
44   // Remainder of full vectors
45   for (; batch >= 8; batch -= 8) {
46     const int16x8_t vi = vld1q_s16(input); input += 8;
47 
48     const int16x8_t vout = vshlq_s16(vi, vshift);
49 
50     vst1q_s16(output, vout); output += 8;
51   }
52 
53   // Remainder of 1 to 7 batch
54   if XNN_UNLIKELY(batch != 0) {
55     const int16x8_t vi = vld1q_s16(input);
56 
57     const int16x8_t vout = vshlq_s16(vi, vshift);
58     int16x4_t vout_lo = vget_low_s16(vout);
59 
60     if (batch & 4) {
61       vst1_s16(output, vout_lo); output += 4;
62       vout_lo = vget_high_s16(vout);
63     }
64     if (batch & 2) {
65       vst1_lane_u32((void*) output, vreinterpret_u32_s16(vout_lo), 0); output += 2;
66       vout_lo = vext_s16(vout_lo, vout_lo, 2);
67     }
68     if (batch & 1){
69       vst1_lane_s16(output, vout_lo, 0);
70     }
71   }
72 }
73