• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-igemm/c4-armsimd32.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 
12 #include <arm_acle.h>
13 
14 #include <xnnpack/intrinsics-polyfill.h>
15 #include <xnnpack/math.h>
16 #include <xnnpack/gemm.h>
17 #include <xnnpack/unaligned.h>
18 
19 
xnn_qc8_igemm_minmax_fp32_ukernel_1x1c4__armsimd32(size_t mr,size_t nc,size_t kc,size_t ks,const int8_t ** restrict a,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const int8_t * zero,const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_qc8_igemm_minmax_fp32_ukernel_1x1c4__armsimd32(
21     size_t mr,
22     size_t nc,
23     size_t kc,
24     size_t ks,
25     const int8_t**restrict a,
26     const void*restrict w,
27     int8_t*restrict c,
28     size_t cm_stride,
29     size_t cn_stride,
30     size_t a_offset,
31     const int8_t* zero,
32     const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
33 {
34   assert(mr != 0);
35   assert(mr <= 1);
36   assert(nc != 0);
37   assert(kc != 0);
38   assert(ks != 0);
39   assert(ks % (1 * sizeof(void*)) == 0);
40   assert(a != NULL);
41   assert(w != NULL);
42   assert(c != NULL);
43 
44   kc = round_up_po2(kc, 4 * sizeof(int8_t));
45   int8_t* c0 = c;
46 
47   const float vmagic_bias = params->fp32_armsimd32.magic_bias;
48   do {
49     int32_t vacc0x0 = ((const int32_t*) w)[0];
50     w = (const void*) ((const int32_t*) w + 1);
51 
52     size_t p = ks;
53     do {
54       const int8_t* restrict a0 = a[0];
55       assert(a0 != NULL);
56       if XNN_UNPREDICTABLE(a0 != zero) {
57         a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
58       }
59       a += 1;
60 
61       size_t k = kc;
62       do {
63         const int8x4_t va0 = (int8x4_t) unaligned_load_s32(a0); a0 += 4;
64 
65         const int16x2_t va0c02 = __sxtb16(va0);
66         const int16x2_t va0c13 = __sxtb16(__ror(va0, 8));
67 
68         const int8x4_t vb0 = *((const int8x4_t*) w); w = (const int8_t*) w + 4;
69         const int16x2_t vb0c02 = __sxtb16(vb0);
70 
71         vacc0x0 = __smlad(va0c02, vb0c02, vacc0x0);
72 
73         const int16x2_t vb0c13 = __sxtb16(__ror(vb0, 8));
74         vacc0x0 = __smlad(va0c13, vb0c13, vacc0x0);
75 
76         k -= 4 * sizeof(int8_t);
77       } while (k != 0);
78       p -= 1 * sizeof(void*);
79     } while (p != 0);
80 
81     float vfpacc0x0 = (float) vacc0x0;
82 
83     const float vscale0 = ((const float*) w)[0];
84     vfpacc0x0 *= vscale0;
85     w = (const void*) ((const float*) w + 1);
86 
87     vfpacc0x0 += vmagic_bias;
88 
89     int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0);
90 
91     const int32_t vmagic_bias_less_zero_point = params->fp32_armsimd32.magic_bias_less_zero_point;
92     vout0x0 = __qsub(vout0x0, vmagic_bias_less_zero_point);
93 
94     vout0x0 = __ssat(vout0x0, 8);
95 
96     const uint32_t vout0 = (uint32_t) vout0x0;
97 
98     uint32_t vout = vout0;
99 
100     const int8x4_t voutput_min = (int8x4_t) params->fp32_armsimd32.output_min;
101     __ssub8((int8x4_t) vout, voutput_min);
102     vout = (uint32_t) __sel((uint8x4_t) vout, (uint8x4_t) voutput_min);
103 
104     const int8x4_t voutput_max = (int8x4_t) params->fp32_armsimd32.output_max;
105     __ssub8((int8x4_t) vout, voutput_max);
106     vout = (uint32_t) __sel((uint8x4_t) voutput_max, (uint8x4_t) vout);
107 
108     *c0 = (int8_t) vout;
109 
110     c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
111 
112     a = (const int8_t**restrict) ((uintptr_t) a - ks);
113     nc -= 1;
114   } while (nc != 0);
115 }
116