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_8x1__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 union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f16_spmm_minmax_ukernel_8x1__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 union xnn_f16_minmax_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 vmax = vreinterpretq_f16_u16(vld1q_dup_u16(¶ms->neon.max));
36 const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16(¶ms->neon.min));
37
38 size_t output_decrement = output_stride * nc - 8 * sizeof(__fp16);
39 while XNN_LIKELY(mc >= 8 * sizeof(__fp16)) {
40 const __fp16*restrict w = (const __fp16*) weights;
41 const int32_t* dmap = widx_dmap;
42 const uint32_t* nnzmap = nidx_nnzmap;
43 size_t n = nc;
44 do {
45 uint32_t nnz = *nnzmap++;
46 float16x8_t vacc01234567 = vld1q_dup_f16(w); w += 1;
47 if XNN_LIKELY(nnz != 0) {
48 do {
49 const intptr_t diff = *dmap++;
50 const float16x8_t va01234567 = vld1q_f16(i);
51 i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
52 const float16x8_t vb = vld1q_dup_f16(w); w += 1;
53 vacc01234567 = vfmaq_f16(vacc01234567, va01234567, vb);
54 } while (--nnz != 0);
55 }
56 float16x8_t vout01234567 = vminq_f16(vacc01234567, vmax);
57 vout01234567 = vmaxq_f16(vout01234567, vmin);
58 vst1q_f16(o, vout01234567);
59 o = (__fp16*restrict) ((uintptr_t) o + output_stride);
60 } while (--n != 0);
61 o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
62 i += 8;
63 mc -= 8 * sizeof(__fp16);
64 }
65 if XNN_UNLIKELY(mc != 0) {
66 output_decrement += 4 * sizeof(__fp16);
67 if (mc & (4 * sizeof(__fp16))) {
68 const __fp16*restrict w = (const __fp16*) weights;
69 const int32_t* dmap = widx_dmap;
70 const uint32_t* nnzmap = nidx_nnzmap;
71 size_t n = nc;
72 do {
73 uint32_t nnz = *nnzmap++;
74 float16x4_t vacc0123 = vld1_dup_f16(w); w += 1;
75 if XNN_LIKELY(nnz != 0) {
76 do {
77 const intptr_t diff = *dmap++;
78 const float16x4_t va0123 = vld1_f16(i);
79 i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
80 const float16x4_t vb = vld1_dup_f16(w); w += 1;
81 vacc0123 = vfma_f16(vacc0123, va0123, vb);
82 } while (--nnz != 0);
83 }
84 float16x4_t vout0123 = vmin_f16(vacc0123, vget_low_f16(vmax));
85 vout0123 = vmax_f16(vout0123, vget_low_f16(vmin));
86 vst1_f16(o, vout0123);
87 o = (__fp16*restrict) ((uintptr_t) o + output_stride);
88 } while (--n != 0);
89 o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
90 i += 4;
91 }
92 output_decrement += 2 * sizeof(__fp16);
93 if (mc & (2 * sizeof(__fp16))) {
94 const __fp16*restrict w = (const __fp16*) weights;
95 const int32_t* dmap = widx_dmap;
96 const uint32_t* nnzmap = nidx_nnzmap;
97 size_t n = nc;
98 do {
99 uint32_t nnz = *nnzmap++;
100 float16x4_t vacc01 = vld1_dup_f16(w); w += 1;
101 if XNN_LIKELY(nnz != 0) {
102 do {
103 const intptr_t diff = *dmap++;
104 const float16x4_t va01 = vreinterpret_f16_f32(vld1_dup_f32((const void*) i));
105 i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
106 const float16x4_t vb = vld1_dup_f16(w); w += 1;
107 vacc01 = vfma_f16(vacc01, va01, vb);
108 } while (--nnz != 0);
109 }
110 float16x4_t vout01 = vmin_f16(vacc01, vget_low_f16(vmax));
111 vout01 = vmax_f16(vout01, vget_low_f16(vmin));
112 vst1_lane_f32((void*) o, vreinterpret_f32_f16(vout01), 0);
113 o = (__fp16*restrict) ((uintptr_t) o + output_stride);
114 } while (--n != 0);
115 o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
116 i += 2;
117 }
118 output_decrement += 1 * sizeof(__fp16);
119 if (mc & (1 * sizeof(__fp16))) {
120 const __fp16*restrict w = (const __fp16*) weights;
121 const int32_t* dmap = widx_dmap;
122 const uint32_t* nnzmap = nidx_nnzmap;
123 size_t n = nc;
124 do {
125 uint32_t nnz = *nnzmap++;
126 float16x4_t vacc0 = vld1_dup_f16(w); w += 1;
127 if XNN_LIKELY(nnz != 0) {
128 do {
129 const intptr_t diff = *dmap++;
130 const float16x4_t va0 = vld1_dup_f16(i);
131 i = (const __fp16*restrict) ((uintptr_t) i + (uintptr_t) diff);
132 const float16x4_t vb = vld1_dup_f16(w); w += 1;
133 vacc0 = vfma_f16(vacc0, va0, vb);
134 } while (--nnz != 0);
135 }
136 float16x4_t vout0 = vmin_f16(vacc0, vget_low_f16(vmax));
137 vout0 = vmax_f16(vout0, vget_low_f16(vmin));
138 vst1_lane_f16(o, vout0, 0);
139 o = (__fp16*restrict) ((uintptr_t) o + output_stride);
140 } while (--n != 0);
141 o = (__fp16*restrict) ((uintptr_t) o - output_decrement);
142 i += 1;
143 }
144 }
145 }
146