| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
#include <arm_neon.h> |
| 14 |
|
| 15 |
#include "xnnpack/igemm.h" |
| 16 |
#include "xnnpack/intrinsics-polyfill.h" |
| 17 |
|
| 18 |
|
| 19 |
void xnn_f16_igemm_minmax_ukernel_1x16__neonfp16arith_ld64( |
| 20 |
size_t mr, |
| 21 |
size_t nc, |
| 22 |
size_t kc, |
| 23 |
size_t ks, |
| 24 |
const xnn_float16** restrict a, |
| 25 |
const xnn_float16* restrict w, |
| 26 |
xnn_float16* restrict c, |
| 27 |
size_t cm_stride, |
| 28 |
size_t cn_stride, |
| 29 |
size_t a_offset, |
| 30 |
const xnn_float16* zero, |
| 31 |
const union xnn_f16_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 32 |
{ |
| 33 |
assert(mr != 0); |
| 34 |
assert(mr <= 1); |
| 35 |
assert(nc != 0); |
| 36 |
assert(kc != 0); |
| 37 |
assert(kc % sizeof(uint16_t) == 0); |
| 38 |
assert(ks != 0); |
| 39 |
assert(ks % (1 * sizeof(void*)) == 0); |
| 40 |
assert(a_offset % sizeof(uint16_t) == 0); |
| 41 |
assert(a != NULL); |
| 42 |
assert(w != NULL); |
| 43 |
assert(c != NULL); |
| 44 |
|
| 45 |
uint16_t* c0 = (uint16_t*) c; |
| 46 |
|
| 47 |
do { |
| 48 |
float16x8_t vacc0x0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 49 |
float16x8_t vacc0x1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 50 |
|
| 51 |
size_t p = ks; |
| 52 |
do { |
| 53 |
const uint16_t* restrict a0 = (const uint16_t*) a[0]; |
| 54 |
assert(a0 != NULL); |
| 55 |
if XNN_UNPREDICTABLE(a0 != (const uint16_t*) zero) { |
| 56 |
a0 = (const uint16_t*) ((uintptr_t) a0 + a_offset); |
| 57 |
} |
| 58 |
a += 1; |
| 59 |
|
| 60 |
size_t k = kc; |
| 61 |
for (; k >= 4 * sizeof(uint16_t); k -= 4 * sizeof(uint16_t)) { |
| 62 |
const float16x4_t va0 = vreinterpret_f16_u16(vld1_u16(a0)); a0 += 4; |
| 63 |
|
| 64 |
const float16x8_t vb0c0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 65 |
const float16x8_t vb1c0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 66 |
|
| 67 |
#if XNN_ARCH_ARM64 |
| 68 |
vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c0, va0, 0); |
| 69 |
vacc0x1 = vfmaq_lane_f16(vacc0x1, vb1c0, va0, 0); |
| 70 |
#else |
| 71 |
vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c0, va0, 0); |
| 72 |
vacc0x1 = vmlaq_lane_f16(vacc0x1, vb1c0, va0, 0); |
| 73 |
#endif |
| 74 |
const float16x8_t vb0c1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 75 |
const float16x8_t vb1c1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 76 |
|
| 77 |
#if XNN_ARCH_ARM64 |
| 78 |
vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c1, va0, 1); |
| 79 |
vacc0x1 = vfmaq_lane_f16(vacc0x1, vb1c1, va0, 1); |
| 80 |
#else |
| 81 |
vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c1, va0, 1); |
| 82 |
vacc0x1 = vmlaq_lane_f16(vacc0x1, vb1c1, va0, 1); |
| 83 |
#endif |
| 84 |
const float16x8_t vb0c2 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 85 |
const float16x8_t vb1c2 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 86 |
|
| 87 |
#if XNN_ARCH_ARM64 |
| 88 |
vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c2, va0, 2); |
| 89 |
vacc0x1 = vfmaq_lane_f16(vacc0x1, vb1c2, va0, 2); |
| 90 |
#else |
| 91 |
vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c2, va0, 2); |
| 92 |
vacc0x1 = vmlaq_lane_f16(vacc0x1, vb1c2, va0, 2); |
| 93 |
#endif |
| 94 |
const float16x8_t vb0c3 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 95 |
const float16x8_t vb1c3 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 96 |
|
| 97 |
#if XNN_ARCH_ARM64 |
| 98 |
vacc0x0 = vfmaq_lane_f16(vacc0x0, vb0c3, va0, 3); |
| 99 |
vacc0x1 = vfmaq_lane_f16(vacc0x1, vb1c3, va0, 3); |
| 100 |
#else |
| 101 |
vacc0x0 = vmlaq_lane_f16(vacc0x0, vb0c3, va0, 3); |
| 102 |
vacc0x1 = vmlaq_lane_f16(vacc0x1, vb1c3, va0, 3); |
| 103 |
#endif |
| 104 |
} |
| 105 |
if XNN_UNLIKELY(k != 0) { |
| 106 |
do { |
| 107 |
const float16x8_t va0 = vreinterpretq_f16_u16(vld1q_dup_u16(a0)); a0 += 1; |
| 108 |
|
| 109 |
const float16x8_t vb0 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 110 |
const float16x8_t vb1 = vreinterpretq_f16_u16(vld1q_u16((const uint16_t*) w)); w = (const xnn_float16*) w + 8; |
| 111 |
|
| 112 |
vacc0x0 = vfmaq_f16(vacc0x0, va0, vb0); |
| 113 |
vacc0x1 = vfmaq_f16(vacc0x1, va0, vb1); |
| 114 |
|
| 115 |
k -= sizeof(uint16_t); |
| 116 |
} while (k != 0); |
| 117 |
} |
| 118 |
p -= 1 * sizeof(void*); |
| 119 |
} while (p != 0); |
| 120 |
|
| 121 |
|
| 122 |
const float16x8_t vmin = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) ¶ms->scalar.min)); |
| 123 |
vacc0x0 = vmaxq_f16(vacc0x0, vmin); |
| 124 |
vacc0x1 = vmaxq_f16(vacc0x1, vmin); |
| 125 |
|
| 126 |
const float16x8_t vmax = vreinterpretq_f16_u16(vld1q_dup_u16((const uint16_t*) ¶ms->scalar.max)); |
| 127 |
vacc0x0 = vminq_f16(vacc0x0, vmax); |
| 128 |
vacc0x1 = vminq_f16(vacc0x1, vmax); |
| 129 |
|
| 130 |
if XNN_LIKELY(nc >= 16) { |
| 131 |
vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x0)); |
| 132 |
vst1q_u16(c0 + 8, vreinterpretq_u16_f16(vacc0x1)); |
| 133 |
c0 = (uint16_t*) ((uintptr_t) c0 + cn_stride); |
| 134 |
|
| 135 |
a = (const xnn_float16**restrict) ((uintptr_t) a - ks); |
| 136 |
nc -= 16; |
| 137 |
} else { |
| 138 |
if (nc & 8) { |
| 139 |
vst1q_u16(c0, vreinterpretq_u16_f16(vacc0x0)); c0 += 8; |
| 140 |
|
| 141 |
vacc0x0 = vacc0x1; |
| 142 |
} |
| 143 |
float16x4_t vacc0 = vget_low_f16(vacc0x0); |
| 144 |
if (nc & 4) { |
| 145 |
vst1_u16(c0, vreinterpret_u16_f16(vacc0)); c0 += 4; |
| 146 |
|
| 147 |
vacc0 = vget_high_f16(vacc0x0); |
| 148 |
} |
| 149 |
if (nc & 2) { |
| 150 |
vst1_lane_u32((void*) c0, vreinterpret_u32_f16(vacc0), 0); c0 += 2; |
| 151 |
|
| 152 |
vacc0 = vext_f16(vacc0, vacc0, 2); |
| 153 |
} |
| 154 |
if (nc & 1) { |
| 155 |
vst1_lane_u16(c0, vreinterpret_u16_f16(vacc0), 0); |
| 156 |
} |
| 157 |
|
| 158 |
nc = 0; |
| 159 |
} |
| 160 |
} while (nc != 0); |
| 161 |
} |