• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f16-spmm/neonfp16arith.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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_neon.h>
13 
14 #include <xnnpack/spmm.h>
15 
16 
xnn_f16_spmm_ukernel_8x1__neonfp16arith_unroll2(uint32_t m,uint32_t n,const void * restrict input,const void * restrict weights,const int32_t * restrict widx_dmap,const uint32_t * restrict nidx_nnzmap,void * restrict output,const struct xnn_f16_output_params params[restrict static1])17 void xnn_f16_spmm_ukernel_8x1__neonfp16arith_unroll2(
18     uint32_t m,
19     uint32_t n,
20     const void*restrict input,
21     const void*restrict weights,
22     const int32_t*restrict widx_dmap,
23     const uint32_t*restrict nidx_nnzmap,
24     void*restrict output,
25     const struct xnn_f16_output_params params[restrict static 1])
26 {
27   assert(m != 0);
28 
29   const __fp16*restrict a = input;
30   __fp16*restrict c = output;
31 
32   const float16x8_t vscale = vld1q_dup_f16((const __fp16*) &params->scale);
33   const float16x8_t vmax = vld1q_dup_f16((const __fp16*) &params->max);
34   const float16x8_t vmin = vld1q_dup_f16((const __fp16*) &params->min);
35 
36   size_t i = m;
37   while XNN_LIKELY(i >= 8) {
38     const __fp16*restrict w = weights;
39     const int32_t* dmap = widx_dmap;
40     const uint32_t* nnzmap = nidx_nnzmap;
41     size_t j = n;
42     do {
43       uint32_t nnz = *nnzmap++;
44       float16x8_t vacc01234567x0 = vld1q_dup_f16(w); w += 1;
45       float16x8_t vacc01234567x1 = vmovq_n_f16(0.0f);
46       for (; nnz >= 2; nnz -= 2) {
47         const intptr_t diff0 = dmap[0];
48         const intptr_t diff1 = dmap[1];
49         dmap += 2;
50         const float16x8_t va01234567x0 = vld1q_f16(a);
51         a = (const __fp16*restrict) ((uintptr_t) a + (uintptr_t) diff0);
52         const float16x8_t vb0 = vld1q_dup_f16(w); w += 1;
53         vacc01234567x0 = vfmaq_f16(vacc01234567x0, va01234567x0, vb0);
54         const float16x8_t va01234567x1 = vld1q_f16(a);
55         a = (const __fp16*restrict) ((uintptr_t) a + (uintptr_t) diff1);
56         const float16x8_t vb1 = vld1q_dup_f16(w); w += 1;
57         vacc01234567x1 = vfmaq_f16(vacc01234567x1, va01234567x1, vb1);
58       }
59       float16x8_t vacc01234567 = vacc01234567x0;
60       vacc01234567 = vaddq_f16(vacc01234567, vacc01234567x1);
61       if XNN_LIKELY(nnz != 0) {
62         do {
63           const intptr_t diff = *dmap++;
64           const float16x8_t va01234567 = vld1q_f16(a);
65           a = (const __fp16*restrict) ((uintptr_t) a + (uintptr_t) diff);
66           const float16x8_t vb = vld1q_dup_f16(w); w += 1;
67           vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
68         } while (--nnz != 0);
69       }
70       float16x8_t vout01234567 = vmulq_f16(vacc01234567, vscale);
71       vout01234567 = vminq_f16(vout01234567, vmax);
72       vout01234567 = vmaxq_f16(vout01234567, vmin);
73       vst1q_f16(c, vout01234567);
74       c += m;
75     } while (--j != 0);
76     c -= m * n;
77     c += 8;
78     a += 8;
79     i -= 8;
80   }
81   if XNN_UNLIKELY(i != 0) {
82     if (i & 4) {
83       const __fp16*restrict w = weights;
84       const int32_t* dmap = widx_dmap;
85       const uint32_t* nnzmap = nidx_nnzmap;
86       size_t j = n;
87       do {
88         uint32_t nnz = *nnzmap++;
89         float16x4_t vacc0123 = vld1_dup_f16(w); w += 1;
90         if XNN_LIKELY(nnz != 0) {
91           do {
92             const intptr_t diff = *dmap++;
93             const float16x4_t va0123 = vld1_f16(a);
94             a = (const __fp16*restrict) ((uintptr_t) a + (uintptr_t) diff);
95             const float16x4_t vb = vld1_dup_f16(w); w += 1;
96             vacc0123 = vfma_f16(vacc0123, va0123, vb);
97           } while (--nnz != 0);
98         }
99         float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
100         vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
101         vst1_f16(c, vout0123);
102         c += m;
103       } while (--j != 0);
104       c -= m * n;
105       c += 4;
106       a += 4;
107     }
108     if (i & 2) {
109       const __fp16*restrict w = weights;
110       const int32_t* dmap = widx_dmap;
111       const uint32_t* nnzmap = nidx_nnzmap;
112       size_t j = n;
113       do {
114         uint32_t nnz = *nnzmap++;
115         float16x4_t vacc01 = vld1_dup_f16(w); w += 1;
116         if XNN_LIKELY(nnz != 0) {
117           do {
118             const intptr_t diff = *dmap++;
119             const float16x4_t va01 = vreinterpret_f32_f16(vld1_dup_f32(__builtin_assume_aligned(a, 1)));
120             a = (const __fp16*restrict) ((uintptr_t) a + (uintptr_t) diff);
121             const float16x4_t vb = vld1_dup_f16(w); w += 1;
122             vacc01 = vfma_f16(vacc01, va01, vb);
123           } while (--nnz != 0);
124         }
125         float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
126         vout01 = vmax_f16(vout01, vget_low_f16(vmin));
127         vst1_lane_f32(__builtin_assume_aligned(c, 1), vreinterpret_f16_f32(vout01), 0);
128         c += m;
129       } while (--j != 0);
130       c -= m * n;
131       c += 2;
132       a += 2;
133     }
134     if (i & 1) {
135       const __fp16*restrict w = weights;
136       const int32_t* dmap = widx_dmap;
137       const uint32_t* nnzmap = nidx_nnzmap;
138       size_t j = n;
139       do {
140         uint32_t nnz = *nnzmap++;
141         float16x4_t vacc0 = vld1_dup_f16(w); w += 1;
142         if XNN_LIKELY(nnz != 0) {
143           do {
144             const intptr_t diff = *dmap++;
145             const float16x4_t va0 = vld1_dup_f16(a);
146             a = (const __fp16*restrict) ((uintptr_t) a + (uintptr_t) diff);
147             const float16x4_t vb = vld1_dup_f16(w); w += 1;
148             vacc0 = vfma_f16(vacc0, va0, vb);
149           } while (--nnz != 0);
150         }
151         float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
152         vout0 = vmax_f16(vout0, vget_low_f16(vmin));
153         vst1_lane_f16(c, vout0, 0);
154         c += m;
155       } while (--j != 0);
156       c -= m * n;
157       c += 1;
158       a += 1;
159     }
160   }
161 }
162