xref: /aosp_15_r20/external/XNNPACK/src/cs16-vsquareabs/gen/scalar-x2.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/cs16-vsquareabs/scalar.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 <xnnpack/math.h>
15 #include <xnnpack/vsquareabs.h>
16 
17 
xnn_cs16_vsquareabs_ukernel__scalar_x2(size_t batch,const int16_t * input,uint32_t * output)18 void xnn_cs16_vsquareabs_ukernel__scalar_x2(
19     size_t batch,
20     const int16_t* input,
21     uint32_t* output) {
22 
23   assert(batch != 0);
24   assert(input != NULL);
25   assert(output != NULL);
26 
27   for (; batch >= 2; batch -= 2) {
28     const int32_t vr0 = (int32_t) input[0];
29     const int32_t vi0 = (int32_t) input[1];
30     const int32_t vr1 = (int32_t) input[2];
31     const int32_t vi1 = (int32_t) input[3];
32     input += 2 * 2;
33 
34     const uint32_t vrsquare0 = (uint32_t) (vr0 * vr0);
35     const uint32_t visquare0 = (uint32_t) (vi0 * vi0);
36     const uint32_t vrsquare1 = (uint32_t) (vr1 * vr1);
37     const uint32_t visquare1 = (uint32_t) (vi1 * vi1);
38 
39     const uint32_t vout0 = vrsquare0 + visquare0;
40     const uint32_t vout1 = vrsquare1 + visquare1;
41 
42     output[0] = vout0;
43     output[1] = vout1;
44     output += 2;
45   }
46 
47   if XNN_UNLIKELY(batch != 0) {
48     do {
49       const int32_t vr = (int32_t) input[0];
50       const int32_t vi = (int32_t) input[1];
51       input += 2;
52 
53       const uint32_t vrsquare = (uint32_t) (vr * vr);
54       const uint32_t visquare = (uint32_t) (vi * vi);
55 
56       const uint32_t vout = vrsquare + visquare;
57 
58       *output++ = vout;
59     } while (--batch != 0);
60   }
61 }
62