xref: /aosp_15_r20/external/XNNPACK/src/cs16-vsquareabs/gen/neon-mlal-ld128-x12.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/cs16-vsquareabs/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/vsquareabs.h>
17 
18 
xnn_cs16_vsquareabs_ukernel__neon_mlal_ld128_x12(size_t batch,const int16_t * input,uint32_t * output)19 void xnn_cs16_vsquareabs_ukernel__neon_mlal_ld128_x12(
20     size_t batch,
21     const int16_t* input,
22     uint32_t* output) {
23 
24   assert(batch != 0);
25   assert(input != NULL);
26   assert(output != NULL);
27 
28   for (; batch >= 12; batch -= 12) {
29     const int16x4x2_t vi0 = vld2_s16(input); input += 8;
30     const int16x4x2_t vi1 = vld2_s16(input); input += 8;
31     const int16x4x2_t vi2 = vld2_s16(input); input += 8;
32 
33     int32x4_t vacc0 = vmull_s16(vi0.val[0], vi0.val[0]);
34     vacc0 = vmlal_s16(vacc0, vi0.val[1], vi0.val[1]);
35     int32x4_t vacc1 = vmull_s16(vi1.val[0], vi1.val[0]);
36     vacc1 = vmlal_s16(vacc1, vi1.val[1], vi1.val[1]);
37     int32x4_t vacc2 = vmull_s16(vi2.val[0], vi2.val[0]);
38     vacc2 = vmlal_s16(vacc2, vi2.val[1], vi2.val[1]);
39 
40     vst1q_u32(output, vreinterpretq_u32_s32(vacc0)); output += 4;
41     vst1q_u32(output, vreinterpretq_u32_s32(vacc1)); output += 4;
42     vst1q_u32(output, vreinterpretq_u32_s32(vacc2)); output += 4;
43   }
44 
45   // Remainder of full vectors
46   for (; batch >= 4; batch -= 4) {
47     const int16x4x2_t vi = vld2_s16(input); input += 8;
48 
49     int32x4_t vacc = vmull_s16(vi.val[0], vi.val[0]);
50 
51     vacc = vmlal_s16(vacc, vi.val[1], vi.val[1]);
52 
53     vst1q_u32(output, vreinterpretq_u32_s32(vacc)); output += 4;
54   }
55 
56   // Remainder of 1 to 3 elements
57   if XNN_UNLIKELY(batch != 0) {
58     const int16x4x2_t vi = vld2_s16(input);
59 
60     int32x4_t vacc = vmull_s16(vi.val[0], vi.val[0]);
61     vacc = vmlal_s16(vacc, vi.val[1], vi.val[1]);
62 
63     uint32x2_t vacc_lo = vreinterpret_u32_s32(vget_low_s32(vacc));
64     if (batch & 2) {
65       vst1_u32(output, vacc_lo); output += 2;
66       vacc_lo = vreinterpret_u32_s32(vget_high_s32(vacc));
67     }
68     if (batch & 1) {
69       vst1_lane_u32(output, vacc_lo, 0);
70     }
71   }
72 }
73