• 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_minmax_ukernel_16x1__neonfp16arith_x2(size_t mc,size_t nc,const void * restrict input,const void * restrict weights,const int32_t * restrict widx_dmap,const uint32_t * restrict nidx_nnzmap,void * restrict output,size_t output_stride,const struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f16_spmm_minmax_ukernel_16x1__neonfp16arith_x2(
18     size_t mc,
19     size_t nc,
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     size_t output_stride,
26     const struct xnn_f16_scaleminmax_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28   assert(mc != 0);
29   assert(mc % sizeof(__fp16) == 0);
30   assert(nc != 0);
31 
32   const __fp16*restrict i = (const __fp16*) input;
33   __fp16*restrict o = (__fp16*) output;
34 
35   const float16x8_t vscale = vld1q_dup_f16((const __fp16*) &params->scale);
36   const float16x8_t vmax = vld1q_dup_f16((const __fp16*) &params->max);
37   const float16x8_t vmin = vld1q_dup_f16((const __fp16*) &params->min);
38 
39   size_t output_decrement = output_stride * nc - 16 * sizeof(__fp16);
40   while XNN_LIKELY(mc >= 16 * sizeof(__fp16)) {
41     const __fp16*restrict w = (const __fp16*) weights;
42     const int32_t* dmap = widx_dmap;
43     const uint32_t* nnzmap = nidx_nnzmap;
44     size_t n = nc;
45     do {
46       uint32_t nnz = *nnzmap++;
47       float16x8_t vacc01234567x0 = vld1q_dup_f16(w); w += 1;
48       float16x8_t vacc01234567x1 = vmovq_n_f16(0.0f);
49       float16x8_t vacc89ABCDEFx0 = vacc01234567x0;
50       float16x8_t vacc89ABCDEFx1 = vmovq_n_f16(0.0f);
51       for (; nnz >= 2; nnz -= 2) {
52         const intptr_t diff0 = dmap[0];
53         const intptr_t diff1 = dmap[1];
54         dmap += 2;
55         const float16x8_t va01234567x0 = vld1q_f16(i);
56         const float16x8_t va89ABCDEFx0 = vld1q_f16(i + 8);
57         i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff0);
58         const float16x8_t vb0 = vld1q_dup_f16(w); w += 1;
59         vacc01234567x0 = vfmaq_f16(vacc01234567x0, va01234567x0, vb0);
60         vacc89ABCDEFx0 = vfmaq_f16(vacc89ABCDEFx0, va89ABCDEFx0, vb0);
61         const float16x8_t va01234567x1 = vld1q_f16(i);
62         const float16x8_t va89ABCDEFx1 = vld1q_f16(i + 8);
63         i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff1);
64         const float16x8_t vb1 = vld1q_dup_f16(w); w += 1;
65         vacc01234567x1 = vfmaq_f16(vacc01234567x1, va01234567x1, vb1);
66         vacc89ABCDEFx1 = vfmaq_f16(vacc89ABCDEFx1, va89ABCDEFx1, vb1);
67       }
68       float16x8_t vacc01234567 = vacc01234567x0;
69       float16x8_t vacc89ABCDEF = vacc89ABCDEFx0;
70       vacc01234567 = vaddq_f16(vacc01234567, vacc01234567x1);
71       vacc89ABCDEF = vaddq_f16(vacc89ABCDEF, vacc89ABCDEFx1);
72       if XNN_LIKELY(nnz != 0) {
73         do {
74           const intptr_t diff = *dmap++;
75           const float16x8_t va01234567 = vld1q_f16(i);
76           const float16x8_t va89ABCDEF = vld1q_f16(i + 8);
77           i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
78           const float16x8_t vb = vld1q_dup_f16(w); w += 1;
79           vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
80           vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, va89ABCDEF, vb);
81         } while (--nnz != 0);
82       }
83       float16x8_t vout01234567 = vmulq_f16(vacc01234567, vscale);
84       float16x8_t vout89ABCDEF = vmulq_f16(vacc89ABCDEF, vscale);
85       vout01234567 = vminq_f16(vout01234567, vmax);
86       vout89ABCDEF = vminq_f16(vout89ABCDEF, vmax);
87       vout01234567 = vmaxq_f16(vout01234567, vmin);
88       vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
89       vst1q_f16(o, vout01234567);
90       vst1q_f16(o + 8, vout89ABCDEF);
91       o = (__fp16*restrict) ((uintptr_t) o + output_stride);
92     } while (--n != 0);
93     o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
94     i += 16;
95     mc -= 16 * sizeof(__fp16);
96   }
97   if XNN_UNLIKELY(mc != 0) {
98     output_decrement += 8 * sizeof(__fp16);
99     if (mc & (8 * sizeof(__fp16))) {
100       const __fp16*restrict w = (const __fp16*) weights;
101       const int32_t* dmap = widx_dmap;
102       const uint32_t* nnzmap = nidx_nnzmap;
103       size_t n = nc;
104       do {
105         uint32_t nnz = *nnzmap++;
106         float16x8_t vacc01234567 = vld1q_dup_f16(w); w += 1;
107         if XNN_LIKELY(nnz != 0) {
108           do {
109             const intptr_t diff = *dmap++;
110             const float16x8_t va01234567 = vld1q_f16(i);
111             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
112             const float16x8_t vb = vld1q_dup_f16(w); w += 1;
113             vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
114           } while (--nnz != 0);
115         }
116         float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
117         vout01234567 = vmaxq_f16(vout01234567, vmin);
118         vst1q_f16(o, vout01234567);
119         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
120       } while (--n != 0);
121       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
122       i += 8;
123     }
124     output_decrement += 4 * sizeof(__fp16);
125     if (mc & (4 * sizeof(__fp16))) {
126       const __fp16*restrict w = (const __fp16*) weights;
127       const int32_t* dmap = widx_dmap;
128       const uint32_t* nnzmap = nidx_nnzmap;
129       size_t n = nc;
130       do {
131         uint32_t nnz = *nnzmap++;
132         float16x4_t vacc0123 = vld1_dup_f16(w); w += 1;
133         if XNN_LIKELY(nnz != 0) {
134           do {
135             const intptr_t diff = *dmap++;
136             const float16x4_t va0123 = vld1_f16(i);
137             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
138             const float16x4_t vb = vld1_dup_f16(w); w += 1;
139             vacc0123 = vfma_f16(vacc0123, va0123, vb);
140           } while (--nnz != 0);
141         }
142         float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
143         vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
144         vst1_f16(o, vout0123);
145         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
146       } while (--n != 0);
147       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
148       i += 4;
149     }
150     output_decrement += 2 * sizeof(__fp16);
151     if (mc & (2 * sizeof(__fp16))) {
152       const __fp16*restrict w = (const __fp16*) weights;
153       const int32_t* dmap = widx_dmap;
154       const uint32_t* nnzmap = nidx_nnzmap;
155       size_t n = nc;
156       do {
157         uint32_t nnz = *nnzmap++;
158         float16x4_t vacc01 = vld1_dup_f16(w); w += 1;
159         if XNN_LIKELY(nnz != 0) {
160           do {
161             const intptr_t diff = *dmap++;
162             const float16x4_t va01 = vreinterpret_f16_f32(vld1_dup_f32(__builtin_assume_aligned(i, 1)));
163             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
164             const float16x4_t vb = vld1_dup_f16(w); w += 1;
165             vacc01 = vfma_f16(vacc01, va01, vb);
166           } while (--nnz != 0);
167         }
168         float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
169         vout01 = vmax_f16(vout01, vget_low_f16(vmin));
170         vst1_lane_f32(__builtin_assume_aligned(o, 1), vreinterpret_f32_f16(vout01), 0);
171         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
172       } while (--n != 0);
173       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
174       i += 2;
175     }
176     output_decrement += 1 * sizeof(__fp16);
177     if (mc & (1 * sizeof(__fp16))) {
178       const __fp16*restrict w = (const __fp16*) weights;
179       const int32_t* dmap = widx_dmap;
180       const uint32_t* nnzmap = nidx_nnzmap;
181       size_t n = nc;
182       do {
183         uint32_t nnz = *nnzmap++;
184         float16x4_t vacc0 = vld1_dup_f16(w); w += 1;
185         if XNN_LIKELY(nnz != 0) {
186           do {
187             const intptr_t diff = *dmap++;
188             const float16x4_t va0 = vld1_dup_f16(i);
189             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
190             const float16x4_t vb = vld1_dup_f16(w); w += 1;
191             vacc0 = vfma_f16(vacc0, va0, vb);
192           } while (--nnz != 0);
193         }
194         float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
195         vout0 = vmax_f16(vout0, vget_low_f16(vmin));
196         vst1_lane_f16(o, vout0, 0);
197         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
198       } while (--n != 0);
199       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
200       i += 1;
201     }
202   }
203 }
204