• 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_24x1__neonfp16arith(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_24x1__neonfp16arith(
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 - 24 * sizeof(__fp16);
40   while XNN_LIKELY(mc >= 24 * 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 vacc01234567 = vld1q_dup_f16(w); w += 1;
48       float16x8_t vacc89ABCDEF = vacc01234567;
49       float16x8_t vaccGHIJKLMN = vacc01234567;
50       if XNN_LIKELY(nnz != 0) {
51         do {
52           const intptr_t diff = *dmap++;
53           const float16x8_t va01234567 = vld1q_f16(i);
54           const float16x8_t va89ABCDEF = vld1q_f16(i + 8);
55           const float16x8_t vaGHIJKLMN = vld1q_f16(i + 16);
56           i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
57           const float16x8_t vb = vld1q_dup_f16(w); w += 1;
58           vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
59           vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, va89ABCDEF, vb);
60           vaccGHIJKLMN = vfmaq_f16(vaccGHIJKLMN, vaGHIJKLMN, vb);
61         } while (--nnz != 0);
62       }
63       float16x8_t vout01234567 = vmulq_f16(vacc01234567, vscale);
64       float16x8_t vout89ABCDEF = vmulq_f16(vacc89ABCDEF, vscale);
65       float16x8_t voutGHIJKLMN = vmulq_f16(vaccGHIJKLMN, vscale);
66       vout01234567 = vminq_f16(vout01234567, vmax);
67       vout89ABCDEF = vminq_f16(vout89ABCDEF, vmax);
68       voutGHIJKLMN = vminq_f16(voutGHIJKLMN, vmax);
69       vout01234567 = vmaxq_f16(vout01234567, vmin);
70       vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
71       voutGHIJKLMN = vmaxq_f16(voutGHIJKLMN, vmin);
72       vst1q_f16(o, vout01234567);
73       vst1q_f16(o + 8, vout89ABCDEF);
74       vst1q_f16(o + 16, voutGHIJKLMN);
75       o = (__fp16*restrict) ((uintptr_t) o + output_stride);
76     } while (--n != 0);
77     o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
78     i += 24;
79     mc -= 24 * sizeof(__fp16);
80   }
81   if XNN_UNLIKELY(mc != 0) {
82     output_decrement += 8 * sizeof(__fp16);
83     if (mc & (16 * sizeof(__fp16))) {
84       const __fp16*restrict w = (const __fp16*) weights;
85       const int32_t* dmap = widx_dmap;
86       const uint32_t* nnzmap = nidx_nnzmap;
87       size_t n = nc;
88       do {
89         uint32_t nnz = *nnzmap++;
90         float16x8_t vacc01234567 = vld1q_dup_f16(w); w += 1;
91         float16x8_t vacc89ABCDEF = vacc01234567;
92         if XNN_LIKELY(nnz != 0) {
93           do {
94             const intptr_t diff = *dmap++;
95             const float16x8_t va01234567 = vld1q_f16(i);
96             const float16x8_t va89ABCDEF = vld1q_f16(i + 8);
97             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
98             const float16x8_t vb = vld1q_dup_f16(w); w += 1;
99             vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
100             vacc89ABCDEF = vfmaq_f16(vacc89ABCDEF, va89ABCDEF, vb);
101           } while (--nnz != 0);
102         }
103         float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
104         float16x8_t vout89ABCDEF = vminq_f16(vacc89ABCDEF, vmax);
105         vout01234567 = vmaxq_f16(vout01234567, vmin);
106         vout89ABCDEF = vmaxq_f16(vout89ABCDEF, vmin);
107         vst1q_f16(o, vout01234567);
108         vst1q_f16(o + 8, vout89ABCDEF);
109         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
110       } while (--n != 0);
111       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
112       i += 16;
113     }
114     output_decrement += 8 * sizeof(__fp16);
115     if (mc & (8 * sizeof(__fp16))) {
116       const __fp16*restrict w = (const __fp16*) weights;
117       const int32_t* dmap = widx_dmap;
118       const uint32_t* nnzmap = nidx_nnzmap;
119       size_t n = nc;
120       do {
121         uint32_t nnz = *nnzmap++;
122         float16x8_t vacc01234567 = vld1q_dup_f16(w); w += 1;
123         if XNN_LIKELY(nnz != 0) {
124           do {
125             const intptr_t diff = *dmap++;
126             const float16x8_t va01234567 = vld1q_f16(i);
127             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
128             const float16x8_t vb = vld1q_dup_f16(w); w += 1;
129             vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
130           } while (--nnz != 0);
131         }
132         float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
133         vout01234567 = vmaxq_f16(vout01234567, vmin);
134         vst1q_f16(o, vout01234567);
135         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
136       } while (--n != 0);
137       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
138       i += 8;
139     }
140     output_decrement += 4 * sizeof(__fp16);
141     if (mc & (4 * sizeof(__fp16))) {
142       const __fp16*restrict w = (const __fp16*) weights;
143       const int32_t* dmap = widx_dmap;
144       const uint32_t* nnzmap = nidx_nnzmap;
145       size_t n = nc;
146       do {
147         uint32_t nnz = *nnzmap++;
148         float16x4_t vacc0123 = vld1_dup_f16(w); w += 1;
149         if XNN_LIKELY(nnz != 0) {
150           do {
151             const intptr_t diff = *dmap++;
152             const float16x4_t va0123 = vld1_f16(i);
153             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
154             const float16x4_t vb = vld1_dup_f16(w); w += 1;
155             vacc0123 = vfma_f16(vacc0123, va0123, vb);
156           } while (--nnz != 0);
157         }
158         float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
159         vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
160         vst1_f16(o, vout0123);
161         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
162       } while (--n != 0);
163       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
164       i += 4;
165     }
166     output_decrement += 2 * sizeof(__fp16);
167     if (mc & (2 * sizeof(__fp16))) {
168       const __fp16*restrict w = (const __fp16*) weights;
169       const int32_t* dmap = widx_dmap;
170       const uint32_t* nnzmap = nidx_nnzmap;
171       size_t n = nc;
172       do {
173         uint32_t nnz = *nnzmap++;
174         float16x4_t vacc01 = vld1_dup_f16(w); w += 1;
175         if XNN_LIKELY(nnz != 0) {
176           do {
177             const intptr_t diff = *dmap++;
178             const float16x4_t va01 = vreinterpret_f16_f32(vld1_dup_f32(__builtin_assume_aligned(i, 1)));
179             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
180             const float16x4_t vb = vld1_dup_f16(w); w += 1;
181             vacc01 = vfma_f16(vacc01, va01, vb);
182           } while (--nnz != 0);
183         }
184         float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
185         vout01 = vmax_f16(vout01, vget_low_f16(vmin));
186         vst1_lane_f32(__builtin_assume_aligned(o, 1), vreinterpret_f32_f16(vout01), 0);
187         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
188       } while (--n != 0);
189       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
190       i += 2;
191     }
192     output_decrement += 1 * sizeof(__fp16);
193     if (mc & (1 * sizeof(__fp16))) {
194       const __fp16*restrict w = (const __fp16*) weights;
195       const int32_t* dmap = widx_dmap;
196       const uint32_t* nnzmap = nidx_nnzmap;
197       size_t n = nc;
198       do {
199         uint32_t nnz = *nnzmap++;
200         float16x4_t vacc0 = vld1_dup_f16(w); w += 1;
201         if XNN_LIKELY(nnz != 0) {
202           do {
203             const intptr_t diff = *dmap++;
204             const float16x4_t va0 = vld1_dup_f16(i);
205             i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
206             const float16x4_t vb = vld1_dup_f16(w); w += 1;
207             vacc0 = vfma_f16(vacc0, va0, vb);
208           } while (--nnz != 0);
209         }
210         float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
211         vout0 = vmax_f16(vout0, vget_low_f16(vmin));
212         vst1_lane_f16(o, vout0, 0);
213         o = (__fp16*restrict) ((uintptr_t) o + output_stride);
214       } while (--n != 0);
215       o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
216       i += 1;
217     }
218   }
219 }
220