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