xref: /aosp_15_r20/external/XNNPACK/src/s16-vlshift/gen/neon-x32.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_x32(size_t batch,const int16_t * input,int16_t * output,uint32_t shift)20 void xnn_s16_vlshift_ukernel__neon_x32(
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 >= 32; batch -= 32) {
34     const int16x8_t vi0 = vld1q_s16(input); input += 8;
35     const int16x8_t vi1 = vld1q_s16(input); input += 8;
36     const int16x8_t vi2 = vld1q_s16(input); input += 8;
37     const int16x8_t vi3 = vld1q_s16(input); input += 8;
38 
39     const int16x8_t vout0 = vshlq_s16(vi0, vshift);
40     const int16x8_t vout1 = vshlq_s16(vi1, vshift);
41     const int16x8_t vout2 = vshlq_s16(vi2, vshift);
42     const int16x8_t vout3 = vshlq_s16(vi3, vshift);
43 
44     vst1q_s16(output, vout0); output += 8;
45     vst1q_s16(output, vout1); output += 8;
46     vst1q_s16(output, vout2); output += 8;
47     vst1q_s16(output, vout3); output += 8;
48   }
49 
50   // Remainder of full vectors
51   for (; batch >= 8; batch -= 8) {
52     const int16x8_t vi = vld1q_s16(input); input += 8;
53 
54     const int16x8_t vout = vshlq_s16(vi, vshift);
55 
56     vst1q_s16(output, vout); output += 8;
57   }
58 
59   // Remainder of 1 to 7 batch
60   if XNN_UNLIKELY(batch != 0) {
61     const int16x8_t vi = vld1q_s16(input);
62 
63     const int16x8_t vout = vshlq_s16(vi, vshift);
64     int16x4_t vout_lo = vget_low_s16(vout);
65 
66     if (batch & 4) {
67       vst1_s16(output, vout_lo); output += 4;
68       vout_lo = vget_high_s16(vout);
69     }
70     if (batch & 2) {
71       vst1_lane_u32((void*) output, vreinterpret_u32_s16(vout_lo), 0); output += 2;
72       vout_lo = vext_s16(vout_lo, vout_lo, 2);
73     }
74     if (batch & 1){
75       vst1_lane_s16(output, vout_lo, 0);
76     }
77   }
78 }
79