// Copyright 2021 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include #include #include #include #include #include void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, float* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; float* c0 = c; // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. const int32x4_t vinput_zero_point0 = vld1q_dup_s32(&quantization_params[0].zero_point); const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point0); const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point0); const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vmulq_s32(vksum89AB, vinput_zero_point0); const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point0); // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB); float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF); const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale); const float32x4_t vbscale0123 = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x0123 = vmulq_f32(vinput_scale0, vbscale0123); const float32x4_t vbscale4567 = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x4567 = vmulq_f32(vinput_scale0, vbscale4567); const float32x4_t vbscale89AB = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x89AB = vmulq_f32(vinput_scale0, vbscale89AB); const float32x4_t vbscaleCDEF = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0xCDEF = vmulq_f32(vinput_scale0, vbscaleCDEF); const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vscale0x0123); #else vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vscale0x0123); #endif const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vscale0x4567); #else vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vscale0x4567); #endif const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vscale0x89AB); #else vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vscale0x89AB); #endif const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vscale0xCDEF); #else vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vscale0xCDEF); #endif const float32x4_t voutput_min = vld1q_dup_f32(¶ms->scalar.min); vout0x0123 = vmaxq_f32(vout0x0123, voutput_min); vout0x4567 = vmaxq_f32(vout0x4567, voutput_min); vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min); vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min); const float32x4_t voutput_max = vld1q_dup_f32(¶ms->scalar.max); vout0x0123 = vminq_f32(vout0x0123, voutput_max); vout0x4567 = vminq_f32(vout0x4567, voutput_max); vout0x89AB = vminq_f32(vout0x89AB, voutput_max); vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max); if XNN_LIKELY(nc >= 16) { vst1q_f32(c0, vout0x0123); vst1q_f32(c0 + 4, vout0x4567); vst1q_f32(c0 + 8, vout0x89AB); vst1q_f32(c0 + 12, vout0xCDEF); a0 = (const int8_t*) ((uintptr_t) a0 - kc); c0 = (float*) ((uintptr_t) c0 + cn_stride); nc -= 16; } else { if (nc & 8) { vst1q_f32(c0, vout0x0123); c0 += 4; vout0x0123 = vout0x89AB; vst1q_f32(c0, vout0x4567); c0 += 4; vout0x4567 = vout0xCDEF; } if (nc & 4) { vst1q_f32(c0, vout0x0123); c0 += 4; vout0x0123 = vout0x4567; } float32x2_t vout0x01 = vget_low_f32(vout0x0123); if (nc & 2) { vst1_f32(c0, vout0x01); c0 += 2; vout0x01 = vget_high_f32(vout0x0123); } if (nc & 1) { vst1_lane_f32(c0, vout0x01, 0); } nc = 0; } } while (nc != 0); } void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, float* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; float* c0 = c; // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. const int32x4_t vinput_zero_point0 = vld1q_dup_s32(&quantization_params[0].zero_point); const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point0); const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point0); // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); } float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567); const float32x4_t vinput_scale0 = vld1q_dup_f32(&quantization_params[0].inv_scale); const float32x4_t vbscale0123 = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x0123 = vmulq_f32(vinput_scale0, vbscale0123); const float32x4_t vbscale4567 = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x4567 = vmulq_f32(vinput_scale0, vbscale4567); const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vscale0x0123); #else vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vscale0x0123); #endif const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vscale0x4567); #else vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vscale0x4567); #endif const float32x4_t voutput_min = vld1q_dup_f32(¶ms->scalar.min); vout0x0123 = vmaxq_f32(vout0x0123, voutput_min); vout0x4567 = vmaxq_f32(vout0x4567, voutput_min); const float32x4_t voutput_max = vld1q_dup_f32(¶ms->scalar.max); vout0x0123 = vminq_f32(vout0x0123, voutput_max); vout0x4567 = vminq_f32(vout0x4567, voutput_max); if XNN_LIKELY(nc >= 8) { vst1q_f32(c0, vout0x0123); vst1q_f32(c0 + 4, vout0x4567); a0 = (const int8_t*) ((uintptr_t) a0 - kc); c0 = (float*) ((uintptr_t) c0 + cn_stride); nc -= 8; } else { if (nc & 4) { vst1q_f32(c0, vout0x0123); c0 += 4; vout0x0123 = vout0x4567; } float32x2_t vout0x01 = vget_low_f32(vout0x0123); if (nc & 2) { vst1_f32(c0, vout0x01); c0 += 2; vout0x01 = vget_high_f32(vout0x0123); } if (nc & 1) { vst1_lane_f32(c0, vout0x01, 0); } nc = 0; } } while (nc != 0); } void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, float* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)], const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; float* c0 = c; const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride); float* c1 = (float*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride); float* c2 = (float*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride); float* c3 = (float*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. const int32x4_t vinput_zero_point01 = vld1q_s32(&quantization_params[0].zero_point); const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point01), 0); int32x4_t vacc1x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point01), 0); const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point01), 0); int32x4_t vacc1x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point01), 0); const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vmulq_lane_s32(vksum89AB, vget_low_s32(vinput_zero_point01), 0); int32x4_t vacc1x89AB = vmulq_lane_s32(vksum89AB, vget_high_s32(vinput_zero_point01), 0); const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vmulq_lane_s32(vksumCDEF, vget_low_s32(vinput_zero_point01), 0); int32x4_t vacc1xCDEF = vmulq_lane_s32(vksumCDEF, vget_high_s32(vinput_zero_point01), 0); const int32x4_t vinput_zero_point23 = vld1q_s32(&quantization_params[2].zero_point); int32x4_t vacc2x0123 = vmulq_lane_s32(vksum0123, vget_low_s32(vinput_zero_point23), 0); int32x4_t vacc3x0123 = vmulq_lane_s32(vksum0123, vget_high_s32(vinput_zero_point23), 0); int32x4_t vacc2x4567 = vmulq_lane_s32(vksum4567, vget_low_s32(vinput_zero_point23), 0); int32x4_t vacc3x4567 = vmulq_lane_s32(vksum4567, vget_high_s32(vinput_zero_point23), 0); int32x4_t vacc2x89AB = vmulq_lane_s32(vksum89AB, vget_low_s32(vinput_zero_point23), 0); int32x4_t vacc3x89AB = vmulq_lane_s32(vksum89AB, vget_high_s32(vinput_zero_point23), 0); int32x4_t vacc2xCDEF = vmulq_lane_s32(vksumCDEF, vget_low_s32(vinput_zero_point23), 0); int32x4_t vacc3xCDEF = vmulq_lane_s32(vksumCDEF, vget_high_s32(vinput_zero_point23), 0); // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4; // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB); float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF); float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123); float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567); float32x4_t vout1x89AB = vcvtq_f32_s32(vacc1x89AB); float32x4_t vout1xCDEF = vcvtq_f32_s32(vacc1xCDEF); float32x4_t vout2x0123 = vcvtq_f32_s32(vacc2x0123); float32x4_t vout2x4567 = vcvtq_f32_s32(vacc2x4567); float32x4_t vout2x89AB = vcvtq_f32_s32(vacc2x89AB); float32x4_t vout2xCDEF = vcvtq_f32_s32(vacc2xCDEF); float32x4_t vout3x0123 = vcvtq_f32_s32(vacc3x0123); float32x4_t vout3x4567 = vcvtq_f32_s32(vacc3x4567); float32x4_t vout3x89AB = vcvtq_f32_s32(vacc3x89AB); float32x4_t vout3xCDEF = vcvtq_f32_s32(vacc3xCDEF); const float32x4_t vinput_scale01 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[0].zero_point)); const float32x4_t vbscale0123 = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x0123 = vmulq_lane_f32(vbscale0123, vget_low_f32(vinput_scale01), 1); const float32x4_t vscale1x0123 = vmulq_lane_f32(vbscale0123, vget_high_f32(vinput_scale01), 1); const float32x4_t vbscale4567 = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x4567 = vmulq_lane_f32(vbscale4567, vget_low_f32(vinput_scale01), 1); const float32x4_t vscale1x4567 = vmulq_lane_f32(vbscale4567, vget_high_f32(vinput_scale01), 1); const float32x4_t vbscale89AB = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0x89AB = vmulq_lane_f32(vbscale89AB, vget_low_f32(vinput_scale01), 1); const float32x4_t vscale1x89AB = vmulq_lane_f32(vbscale89AB, vget_high_f32(vinput_scale01), 1); const float32x4_t vbscaleCDEF = vld1q_f32(w); w = (const float*) w + 4; const float32x4_t vscale0xCDEF = vmulq_lane_f32(vbscaleCDEF, vget_low_f32(vinput_scale01), 1); const float32x4_t vscale1xCDEF = vmulq_lane_f32(vbscaleCDEF, vget_high_f32(vinput_scale01), 1); const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vscale0x0123); vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vscale1x0123); #else vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vscale0x0123); vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vscale1x0123); #endif const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vscale0x4567); vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vscale1x4567); #else vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vscale0x4567); vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vscale1x4567); #endif const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vscale0x89AB); vout1x89AB = vfmaq_f32(vbias89AB, vout1x89AB, vscale1x89AB); #else vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vscale0x89AB); vout1x89AB = vmlaq_f32(vbias89AB, vout1x89AB, vscale1x89AB); #endif const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4; #if XNN_ARCH_ARM64 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vscale0xCDEF); vout1xCDEF = vfmaq_f32(vbiasCDEF, vout1xCDEF, vscale1xCDEF); #else vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vscale0xCDEF); vout1xCDEF = vmlaq_f32(vbiasCDEF, vout1xCDEF, vscale1xCDEF); #endif const float32x4_t vinput_scale23 = vreinterpretq_f32_s32(vld1q_s32(&quantization_params[2].zero_point)); const float32x4_t vscale2x0123 = vmulq_lane_f32(vbscale0123, vget_low_f32(vinput_scale23), 1); const float32x4_t vscale3x0123 = vmulq_lane_f32(vbscale0123, vget_high_f32(vinput_scale23), 1); const float32x4_t vscale2x4567 = vmulq_lane_f32(vbscale4567, vget_low_f32(vinput_scale23), 1); const float32x4_t vscale3x4567 = vmulq_lane_f32(vbscale4567, vget_high_f32(vinput_scale23), 1); const float32x4_t vscale2x89AB = vmulq_lane_f32(vbscale89AB, vget_low_f32(vinput_scale23), 1); const float32x4_t vscale3x89AB = vmulq_lane_f32(vbscale89AB, vget_high_f32(vinput_scale23), 1); const float32x4_t vscale2xCDEF = vmulq_lane_f32(vbscaleCDEF, vget_low_f32(vinput_scale23), 1); const float32x4_t vscale3xCDEF = vmulq_lane_f32(vbscaleCDEF, vget_high_f32(vinput_scale23), 1); #if XNN_ARCH_ARM64 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vscale2x0123); vout3x0123 = vfmaq_f32(vbias0123, vout3x0123, vscale3x0123); #else vout2x0123 = vmlaq_f32(vbias0123, vout2x0123, vscale2x0123); vout3x0123 = vmlaq_f32(vbias0123, vout3x0123, vscale3x0123); #endif #if XNN_ARCH_ARM64 vout2x4567 = vfmaq_f32(vbias4567, vout2x4567, vscale2x4567); vout3x4567 = vfmaq_f32(vbias4567, vout3x4567, vscale3x4567); #else vout2x4567 = vmlaq_f32(vbias4567, vout2x4567, vscale2x4567); vout3x4567 = vmlaq_f32(vbias4567, vout3x4567, vscale3x4567); #endif #if XNN_ARCH_ARM64 vout2x89AB = vfmaq_f32(vbias89AB, vout2x89AB, vscale2x89AB); vout3x89AB = vfmaq_f32(vbias89AB, vout3x89AB, vscale3x89AB); #else vout2x89AB = vmlaq_f32(vbias89AB, vout2x89AB, vscale2x89AB); vout3x89AB = vmlaq_f32(vbias89AB, vout3x89AB, vscale3x89AB); #endif #if XNN_ARCH_ARM64 vout2xCDEF = vfmaq_f32(vbiasCDEF, vout2xCDEF, vscale2xCDEF); vout3xCDEF = vfmaq_f32(vbiasCDEF, vout3xCDEF, vscale3xCDEF); #else vout2xCDEF = vmlaq_f32(vbiasCDEF, vout2xCDEF, vscale2xCDEF); vout3xCDEF = vmlaq_f32(vbiasCDEF, vout3xCDEF, vscale3xCDEF); #endif const float32x4_t voutput_min = vld1q_dup_f32(¶ms->scalar.min); vout0x0123 = vmaxq_f32(vout0x0123, voutput_min); vout0x4567 = vmaxq_f32(vout0x4567, voutput_min); vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min); vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min); vout1x0123 = vmaxq_f32(vout1x0123, voutput_min); vout1x4567 = vmaxq_f32(vout1x4567, voutput_min); vout1x89AB = vmaxq_f32(vout1x89AB, voutput_min); vout1xCDEF = vmaxq_f32(vout1xCDEF, voutput_min); vout2x0123 = vmaxq_f32(vout2x0123, voutput_min); vout2x4567 = vmaxq_f32(vout2x4567, voutput_min); vout2x89AB = vmaxq_f32(vout2x89AB, voutput_min); vout2xCDEF = vmaxq_f32(vout2xCDEF, voutput_min); vout3x0123 = vmaxq_f32(vout3x0123, voutput_min); vout3x4567 = vmaxq_f32(vout3x4567, voutput_min); vout3x89AB = vmaxq_f32(vout3x89AB, voutput_min); vout3xCDEF = vmaxq_f32(vout3xCDEF, voutput_min); const float32x4_t voutput_max = vld1q_dup_f32(¶ms->scalar.max); vout0x0123 = vminq_f32(vout0x0123, voutput_max); vout0x4567 = vminq_f32(vout0x4567, voutput_max); vout0x89AB = vminq_f32(vout0x89AB, voutput_max); vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max); vout1x0123 = vminq_f32(vout1x0123, voutput_max); vout1x4567 = vminq_f32(vout1x4567, voutput_max); vout1x89AB = vminq_f32(vout1x89AB, voutput_max); vout1xCDEF = vminq_f32(vout1xCDEF, voutput_max); vout2x0123 = vminq_f32(vout2x0123, voutput_max); vout2x4567 = vminq_f32(vout2x4567, voutput_max); vout2x89AB = vminq_f32(vout2x89AB, voutput_max); vout2xCDEF = vminq_f32(vout2xCDEF, voutput_max); vout3x0123 = vminq_f32(vout3x0123, voutput_max); vout3x4567 = vminq_f32(vout3x4567, voutput_max); vout3x89AB = vminq_f32(vout3x89AB, voutput_max); vout3xCDEF = vminq_f32(vout3xCDEF, voutput_max); if XNN_LIKELY(nc >= 16) { vst1q_f32(c3, vout3x0123); vst1q_f32(c3 + 4, vout3x4567); vst1q_f32(c3 + 8, vout3x89AB); vst1q_f32(c3 + 12, vout3xCDEF); vst1q_f32(c2, vout2x0123); vst1q_f32(c2 + 4, vout2x4567); vst1q_f32(c2 + 8, vout2x89AB); vst1q_f32(c2 + 12, vout2xCDEF); vst1q_f32(c1, vout1x0123); vst1q_f32(c1 + 4, vout1x4567); vst1q_f32(c1 + 8, vout1x89AB); vst1q_f32(c1 + 12, vout1xCDEF); vst1q_f32(c0, vout0x0123); vst1q_f32(c0 + 4, vout0x4567); vst1q_f32(c0 + 8, vout0x89AB); vst1q_f32(c0 + 12, vout0xCDEF); a0 = (const int8_t*) ((uintptr_t) a0 - kc); a1 = (const int8_t*) ((uintptr_t) a1 - kc); a2 = (const int8_t*) ((uintptr_t) a2 - kc); a3 = (const int8_t*) ((uintptr_t) a3 - kc); c0 = (float*) ((uintptr_t) c0 + cn_stride); c1 = (float*) ((uintptr_t) c1 + cn_stride); c2 = (float*) ((uintptr_t) c2 + cn_stride); c3 = (float*) ((uintptr_t) c3 + cn_stride); nc -= 16; } else { if (nc & 8) { vst1q_f32(c3, vout3x0123); c3 += 4; vout3x0123 = vout3x89AB; vst1q_f32(c2, vout2x0123); c2 += 4; vout2x0123 = vout2x89AB; vst1q_f32(c1, vout1x0123); c1 += 4; vout1x0123 = vout1x89AB; vst1q_f32(c0, vout0x0123); c0 += 4; vout0x0123 = vout0x89AB; vst1q_f32(c3, vout3x4567); c3 += 4; vout3x4567 = vout3xCDEF; vst1q_f32(c2, vout2x4567); c2 += 4; vout2x4567 = vout2xCDEF; vst1q_f32(c1, vout1x4567); c1 += 4; vout1x4567 = vout1xCDEF; vst1q_f32(c0, vout0x4567); c0 += 4; vout0x4567 = vout0xCDEF; } if (nc & 4) { vst1q_f32(c3, vout3x0123); c3 += 4; vout3x0123 = vout3x4567; vst1q_f32(c2, vout2x0123); c2 += 4; vout2x0123 = vout2x4567; vst1q_f32(c1, vout1x0123); c1 += 4; vout1x0123 = vout1x4567; vst1q_f32(c0, vout0x0123); c0 += 4; vout0x0123 = vout0x4567; } float32x2_t vout3x01 = vget_low_f32(vout3x0123); float32x2_t vout2x01 = vget_low_f32(vout2x0123); float32x2_t vout1x01 = vget_low_f32(vout1x0123); float32x2_t vout0x01 = vget_low_f32(vout0x0123); if (nc & 2) { vst1_f32(c3, vout3x01); c3 += 2; vst1_f32(c2, vout2x01); c2 += 2; vst1_f32(c1, vout1x01); c1 += 2; vst1_f32(c0, vout0x01); c0 += 2; vout3x01 = vget_high_f32(vout3x0123); vout2x01 = vget_high_f32(vout2x0123); vout1x01 = vget_high_f32(vout1x0123); vout0x01 = vget_high_f32(vout0x0123); } if (nc & 1) { vst1_lane_f32(c3, vout3x01, 0); vst1_lane_f32(c2, vout2x01, 0); vst1_lane_f32(c1, vout1x01, 0); vst1_lane_f32(c0, vout0x01, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_gemm_minmax_rndnu_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { // Main case where there the 16 columns fit in the destination. vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); // Advance to the next 16 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); nc -= 16; } else { // Final case where not all of the 16 columns fit in the destination. int8x8_t vout0x01234567 = vget_low_s8(vout0x0123456789ABCDEF); if (nc & 8) { vst1_s8(c0, vout0x01234567); c0 += 8; vout0x01234567 = vget_high_s8(vout0x0123456789ABCDEF); } if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_gemm_minmax_rndnu_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); } const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #endif const int8x8_t voutput_min = vld1_dup_s8(¶ms->rndnu_neon.output_min); const int8x8_t voutput_max = vld1_dup_s8(¶ms->rndnu_neon.output_max); vout0x01234567 = vmax_s8(vout0x01234567, voutput_min); vout0x01234567 = vmin_s8(vout0x01234567, voutput_max); if (nc >= 8) { // Main case where there the 8 columns fit in the destination. vst1_s8(c0 + 0, vout0x01234567); // Advance to the next 8 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); nc -= 8; } else { // Final case where not all of the 8 columns fit in the destination. if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_gemm_minmax_rndnu_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride); int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride); int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride); int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc1x89AB = vacc0x89AB; int32x4_t vacc1xCDEF = vacc0xCDEF; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc2x89AB = vacc0x89AB; int32x4_t vacc2xCDEF = vacc0xCDEF; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; int32x4_t vacc3x89AB = vacc0x89AB; int32x4_t vacc3xCDEF = vacc0xCDEF; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4; // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift); vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift); vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift); vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift); vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift); vacc2x89AB = vqshlq_s32(vacc2x89AB, vright_pre_shift); vacc2xCDEF = vqshlq_s32(vacc2xCDEF, vright_pre_shift); vacc3x0123 = vqshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vqshlq_s32(vacc3x4567, vright_pre_shift); vacc3x89AB = vqshlq_s32(vacc3x89AB, vright_pre_shift); vacc3xCDEF = vqshlq_s32(vacc3xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier); vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier); vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc3x89AB = vqdmulhq_s32(vacc3x89AB, vmultiplier); vacc3xCDEF = vqdmulhq_s32(vacc3xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift); vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift); vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_post_shift); vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF); int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF); int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF)); int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF)); int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min); vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min); vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max); vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max); vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max); if (nc >= 16) { // Main case where there the 16 columns fit in the destination. vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); vst1q_s8(c1 + 0, vout1x0123456789ABCDEF); vst1q_s8(c2 + 0, vout2x0123456789ABCDEF); vst1q_s8(c3 + 0, vout3x0123456789ABCDEF); // Advance to the next 16 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); a1 = (const int8_t*) ((uintptr_t) a1 - kc); a2 = (const int8_t*) ((uintptr_t) a2 - kc); a3 = (const int8_t*) ((uintptr_t) a3 - kc); nc -= 16; } else { // Final case where not all of the 16 columns fit in the destination. int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF)); int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF)); if (nc & 8) { vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8; vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8; vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8; vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8; vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF)); vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF)); } if (nc & 4) { vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); } nc = 0; } } while (nc != 0); } void xnn_qs8_gemm_minmax_rndnu_ukernel_4x8c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride); int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride); int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride); int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4; // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); } const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift); vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift); vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift); vacc3x0123 = vqshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vqshlq_s32(vacc3x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max); if (nc >= 8) { // Main case where there the 8 columns fit in the destination. vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567)); vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567)); // Advance to the next 8 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); a1 = (const int8_t*) ((uintptr_t) a1 - kc); a2 = (const int8_t*) ((uintptr_t) a2 - kc); a3 = (const int8_t*) ((uintptr_t) a3 - kc); nc -= 8; } else { // Final case where not all of the 8 columns fit in the destination. if (nc & 4) { vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); } nc = 0; } } while (nc != 0); } void xnn_qs8_igemm_minmax_rndnu_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (1 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } a += 1; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } p -= 1 * sizeof(void*); } while (p != 0); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 16; } else { int8x8_t vout0x01234567 = vget_low_s8(vout0x0123456789ABCDEF); if (nc & 8) { vst1_s8(c0, vout0x01234567); c0 += 8; vout0x01234567 = vget_high_s8(vout0x0123456789ABCDEF); } if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_igemm_minmax_rndnu_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (1 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } a += 1; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); } p -= 1 * sizeof(void*); } while (p != 0); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #endif const int8x8_t voutput_min = vld1_dup_s8(¶ms->rndnu_neon.output_min); const int8x8_t voutput_max = vld1_dup_s8(¶ms->rndnu_neon.output_max); vout0x01234567 = vmax_s8(vout0x01234567, voutput_min); vout0x01234567 = vmin_s8(vout0x01234567, voutput_max); if (nc >= 8) { vst1_s8(c0 + 0, vout0x01234567); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 8; } else { if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_igemm_minmax_rndnu_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { c1 = c0; } int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { c2 = c1; } int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { c3 = c2; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc1x89AB = vacc0x89AB; int32x4_t vacc1xCDEF = vacc0xCDEF; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc2x89AB = vacc0x89AB; int32x4_t vacc2xCDEF = vacc0xCDEF; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; int32x4_t vacc3x89AB = vacc0x89AB; int32x4_t vacc3xCDEF = vacc0xCDEF; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); const int8x8_t va1x01234567 = vld1_s8(a1); const int8x8_t va2x01234567 = vld1_s8(a2); const int8x8_t va3x01234567 = vld1_s8(a3); // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } p -= 4 * sizeof(void*); } while (p != 0); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift); vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift); vacc1x89AB = vshlq_s32(vacc1x89AB, vright_pre_shift); vacc1xCDEF = vshlq_s32(vacc1xCDEF, vright_pre_shift); vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift); vacc2x89AB = vshlq_s32(vacc2x89AB, vright_pre_shift); vacc2xCDEF = vshlq_s32(vacc2xCDEF, vright_pre_shift); vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift); vacc3x89AB = vshlq_s32(vacc3x89AB, vright_pre_shift); vacc3xCDEF = vshlq_s32(vacc3xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier); vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier); vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc3x89AB = vqdmulhq_s32(vacc3x89AB, vmultiplier); vacc3xCDEF = vqdmulhq_s32(vacc3xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift); vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift); vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_post_shift); vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF); int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF); int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF)); int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF)); int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max); vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min); vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min); vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max); vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max); vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_s8(c3 + 0, vout3x0123456789ABCDEF); vst1q_s8(c2 + 0, vout2x0123456789ABCDEF); vst1q_s8(c1 + 0, vout1x0123456789ABCDEF); vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 16; } else { int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF)); if (nc & 8) { vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8; vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8; vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8; vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8; vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF)); vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF)); } if (nc & 4) { vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_igemm_minmax_rndnu_ukernel_4x8c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { c1 = c0; } int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { c2 = c1; } int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { c3 = c2; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); const int8x8_t va1x01234567 = vld1_s8(a1); const int8x8_t va2x01234567 = vld1_s8(a2); const int8x8_t va3x01234567 = vld1_s8(a3); // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); } p -= 4 * sizeof(void*); } while (p != 0); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift); vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift); vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567)); vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567)); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 8; } else { if (nc & 4) { vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_gemm_minmax_fp32_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vfpacc0x89AB = vcvtq_f32_s32(vacc0x89AB); float32x4_t vfpacc0xCDEF = vcvtq_f32_s32(vacc0xCDEF); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x89AB = vmulq_f32(vfpacc0x89AB, vscale89AB); const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0xCDEF = vmulq_f32(vfpacc0xCDEF, vscaleCDEF); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc0x89AB = vcvtnq_s32_f32(vfpacc0x89AB); vacc0xCDEF = vcvtnq_s32_f32(vfpacc0xCDEF); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { // Main case where there the 16 columns fit in the destination. vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); // Advance to the next 16 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); nc -= 16; } else { // Final case where not all of the 16 columns fit in the destination. int8x8_t vout0x01234567 = vget_low_s8(vout0x0123456789ABCDEF); if (nc & 8) { vst1_s8(c0, vout0x01234567); c0 += 8; vout0x01234567 = vget_high_s8(vout0x0123456789ABCDEF); } if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_gemm_minmax_fp32_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); } float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #endif const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neonv8.output_min); const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neonv8.output_max); vout0x01234567 = vmax_s8(vout0x01234567, voutput_min); vout0x01234567 = vmin_s8(vout0x01234567, voutput_max); if (nc >= 8) { // Main case where there the 8 columns fit in the destination. vst1_s8(c0 + 0, vout0x01234567); // Advance to the next 8 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); nc -= 8; } else { // Final case where not all of the 8 columns fit in the destination. if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_gemm_minmax_fp32_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride); int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride); int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride); int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc1x89AB = vacc0x89AB; int32x4_t vacc1xCDEF = vacc0xCDEF; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc2x89AB = vacc0x89AB; int32x4_t vacc2xCDEF = vacc0xCDEF; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; int32x4_t vacc3x89AB = vacc0x89AB; int32x4_t vacc3xCDEF = vacc0xCDEF; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4; // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vfpacc0x89AB = vcvtq_f32_s32(vacc0x89AB); float32x4_t vfpacc0xCDEF = vcvtq_f32_s32(vacc0xCDEF); float32x4_t vfpacc1x0123 = vcvtq_f32_s32(vacc1x0123); float32x4_t vfpacc1x4567 = vcvtq_f32_s32(vacc1x4567); float32x4_t vfpacc1x89AB = vcvtq_f32_s32(vacc1x89AB); float32x4_t vfpacc1xCDEF = vcvtq_f32_s32(vacc1xCDEF); float32x4_t vfpacc2x0123 = vcvtq_f32_s32(vacc2x0123); float32x4_t vfpacc2x4567 = vcvtq_f32_s32(vacc2x4567); float32x4_t vfpacc2x89AB = vcvtq_f32_s32(vacc2x89AB); float32x4_t vfpacc2xCDEF = vcvtq_f32_s32(vacc2xCDEF); float32x4_t vfpacc3x0123 = vcvtq_f32_s32(vacc3x0123); float32x4_t vfpacc3x4567 = vcvtq_f32_s32(vacc3x4567); float32x4_t vfpacc3x89AB = vcvtq_f32_s32(vacc3x89AB); float32x4_t vfpacc3xCDEF = vcvtq_f32_s32(vacc3xCDEF); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); vfpacc3x0123 = vmulq_f32(vfpacc3x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567); vfpacc3x4567 = vmulq_f32(vfpacc3x4567, vscale4567); const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x89AB = vmulq_f32(vfpacc0x89AB, vscale89AB); vfpacc1x89AB = vmulq_f32(vfpacc1x89AB, vscale89AB); vfpacc2x89AB = vmulq_f32(vfpacc2x89AB, vscale89AB); vfpacc3x89AB = vmulq_f32(vfpacc3x89AB, vscale89AB); const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0xCDEF = vmulq_f32(vfpacc0xCDEF, vscaleCDEF); vfpacc1xCDEF = vmulq_f32(vfpacc1xCDEF, vscaleCDEF); vfpacc2xCDEF = vmulq_f32(vfpacc2xCDEF, vscaleCDEF); vfpacc3xCDEF = vmulq_f32(vfpacc3xCDEF, vscaleCDEF); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc0x89AB = vcvtnq_s32_f32(vfpacc0x89AB); vacc0xCDEF = vcvtnq_s32_f32(vfpacc0xCDEF); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); vacc1x89AB = vcvtnq_s32_f32(vfpacc1x89AB); vacc1xCDEF = vcvtnq_s32_f32(vfpacc1xCDEF); vacc2x0123 = vcvtnq_s32_f32(vfpacc2x0123); vacc2x4567 = vcvtnq_s32_f32(vfpacc2x4567); vacc2x89AB = vcvtnq_s32_f32(vfpacc2x89AB); vacc2xCDEF = vcvtnq_s32_f32(vfpacc2xCDEF); vacc3x0123 = vcvtnq_s32_f32(vfpacc3x0123); vacc3x4567 = vcvtnq_s32_f32(vfpacc3x4567); vacc3x89AB = vcvtnq_s32_f32(vfpacc3x89AB); vacc3xCDEF = vcvtnq_s32_f32(vfpacc3xCDEF); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF); int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF); int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF)); int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF)); int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min); vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min); vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max); vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max); vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max); if (nc >= 16) { // Main case where there the 16 columns fit in the destination. vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); vst1q_s8(c1 + 0, vout1x0123456789ABCDEF); vst1q_s8(c2 + 0, vout2x0123456789ABCDEF); vst1q_s8(c3 + 0, vout3x0123456789ABCDEF); // Advance to the next 16 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); a1 = (const int8_t*) ((uintptr_t) a1 - kc); a2 = (const int8_t*) ((uintptr_t) a2 - kc); a3 = (const int8_t*) ((uintptr_t) a3 - kc); nc -= 16; } else { // Final case where not all of the 16 columns fit in the destination. int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF)); int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF)); if (nc & 8) { vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8; vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8; vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8; vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8; vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF)); vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF)); } if (nc & 4) { vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_gemm_minmax_fp32_ukernel_4x8c4__neondot( size_t mr, size_t nc, size_t kc, const int8_t* restrict a, size_t a_stride, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); const int8_t* a0 = a; int8_t* c0 = c; const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride); int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride); int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride); int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 4; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 4; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 4; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 4; // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); } float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vfpacc1x0123 = vcvtq_f32_s32(vacc1x0123); float32x4_t vfpacc1x4567 = vcvtq_f32_s32(vacc1x4567); float32x4_t vfpacc2x0123 = vcvtq_f32_s32(vacc2x0123); float32x4_t vfpacc2x4567 = vcvtq_f32_s32(vacc2x4567); float32x4_t vfpacc3x0123 = vcvtq_f32_s32(vacc3x0123); float32x4_t vfpacc3x4567 = vcvtq_f32_s32(vacc3x4567); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); vfpacc3x0123 = vmulq_f32(vfpacc3x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567); vfpacc3x4567 = vmulq_f32(vfpacc3x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); vacc2x0123 = vcvtnq_s32_f32(vfpacc2x0123); vacc2x4567 = vcvtnq_s32_f32(vfpacc2x4567); vacc3x0123 = vcvtnq_s32_f32(vfpacc3x0123); vacc3x4567 = vcvtnq_s32_f32(vfpacc3x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max); if (nc >= 8) { // Main case where there the 8 columns fit in the destination. vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567)); vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567)); // Advance to the next 8 columns. c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); a0 = (const int8_t*) ((uintptr_t) a0 - kc); a1 = (const int8_t*) ((uintptr_t) a1 - kc); a2 = (const int8_t*) ((uintptr_t) a2 - kc); a3 = (const int8_t*) ((uintptr_t) a3 - kc); nc -= 8; } else { // Final case where not all of the 8 columns fit in the destination. if (nc & 4) { vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (1 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } a += 1; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } p -= 1 * sizeof(void*); } while (p != 0); float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vfpacc0x89AB = vcvtq_f32_s32(vacc0x89AB); float32x4_t vfpacc0xCDEF = vcvtq_f32_s32(vacc0xCDEF); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x89AB = vmulq_f32(vfpacc0x89AB, vscale89AB); const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0xCDEF = vmulq_f32(vfpacc0xCDEF, vscaleCDEF); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc0x89AB = vcvtnq_s32_f32(vfpacc0x89AB); vacc0xCDEF = vcvtnq_s32_f32(vfpacc0xCDEF); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 16; } else { int8x8_t vout0x01234567 = vget_low_s8(vout0x0123456789ABCDEF); if (nc & 8) { vst1_s8(c0, vout0x01234567); c0 += 8; vout0x01234567 = vget_high_s8(vout0x0123456789ABCDEF); } if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (1 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } a += 1; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 1x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); } p -= 1 * sizeof(void*); } while (p != 0); float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); int8x8_t vout0x01234567 = vqmovn_s16(vacc0x01234567); #endif const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neonv8.output_min); const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neonv8.output_max); vout0x01234567 = vmax_s8(vout0x01234567, voutput_min); vout0x01234567 = vmin_s8(vout0x01234567, voutput_max); if (nc >= 8) { vst1_s8(c0 + 0, vout0x01234567); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 8; } else { if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_s8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_s8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_s8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_s8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { c1 = c0; } int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { c2 = c1; } int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { c3 = c2; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x89AB = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc1x89AB = vacc0x89AB; int32x4_t vacc1xCDEF = vacc0xCDEF; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc2x89AB = vacc0x89AB; int32x4_t vacc2xCDEF = vacc0xCDEF; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; int32x4_t vacc3x89AB = vacc0x89AB; int32x4_t vacc3xCDEF = vacc0xCDEF; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); const int8x8_t va1x01234567 = vld1_s8(a1); const int8x8_t va2x01234567 = vld1_s8(a2); const int8x8_t va3x01234567 = vld1_s8(a3); // Load a 4x16 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0); vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0); vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0); vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0); vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } p -= 4 * sizeof(void*); } while (p != 0); float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vfpacc0x89AB = vcvtq_f32_s32(vacc0x89AB); float32x4_t vfpacc0xCDEF = vcvtq_f32_s32(vacc0xCDEF); float32x4_t vfpacc1x0123 = vcvtq_f32_s32(vacc1x0123); float32x4_t vfpacc1x4567 = vcvtq_f32_s32(vacc1x4567); float32x4_t vfpacc1x89AB = vcvtq_f32_s32(vacc1x89AB); float32x4_t vfpacc1xCDEF = vcvtq_f32_s32(vacc1xCDEF); float32x4_t vfpacc2x0123 = vcvtq_f32_s32(vacc2x0123); float32x4_t vfpacc2x4567 = vcvtq_f32_s32(vacc2x4567); float32x4_t vfpacc2x89AB = vcvtq_f32_s32(vacc2x89AB); float32x4_t vfpacc2xCDEF = vcvtq_f32_s32(vacc2xCDEF); float32x4_t vfpacc3x0123 = vcvtq_f32_s32(vacc3x0123); float32x4_t vfpacc3x4567 = vcvtq_f32_s32(vacc3x4567); float32x4_t vfpacc3x89AB = vcvtq_f32_s32(vacc3x89AB); float32x4_t vfpacc3xCDEF = vcvtq_f32_s32(vacc3xCDEF); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); vfpacc3x0123 = vmulq_f32(vfpacc3x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567); vfpacc3x4567 = vmulq_f32(vfpacc3x4567, vscale4567); const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x89AB = vmulq_f32(vfpacc0x89AB, vscale89AB); vfpacc1x89AB = vmulq_f32(vfpacc1x89AB, vscale89AB); vfpacc2x89AB = vmulq_f32(vfpacc2x89AB, vscale89AB); vfpacc3x89AB = vmulq_f32(vfpacc3x89AB, vscale89AB); const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0xCDEF = vmulq_f32(vfpacc0xCDEF, vscaleCDEF); vfpacc1xCDEF = vmulq_f32(vfpacc1xCDEF, vscaleCDEF); vfpacc2xCDEF = vmulq_f32(vfpacc2xCDEF, vscaleCDEF); vfpacc3xCDEF = vmulq_f32(vfpacc3xCDEF, vscaleCDEF); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc0x89AB = vcvtnq_s32_f32(vfpacc0x89AB); vacc0xCDEF = vcvtnq_s32_f32(vfpacc0xCDEF); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); vacc1x89AB = vcvtnq_s32_f32(vfpacc1x89AB); vacc1xCDEF = vcvtnq_s32_f32(vfpacc1xCDEF); vacc2x0123 = vcvtnq_s32_f32(vfpacc2x0123); vacc2x4567 = vcvtnq_s32_f32(vfpacc2x4567); vacc2x89AB = vcvtnq_s32_f32(vfpacc2x89AB); vacc2xCDEF = vcvtnq_s32_f32(vfpacc2xCDEF); vacc3x0123 = vcvtnq_s32_f32(vfpacc3x0123); vacc3x4567 = vcvtnq_s32_f32(vfpacc3x4567); vacc3x89AB = vcvtnq_s32_f32(vfpacc3x89AB); vacc3xCDEF = vcvtnq_s32_f32(vfpacc3xCDEF); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF); int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF); int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF); int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point); int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF)); int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF)); int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF)); int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max); vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min); vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min); vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min); vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max); vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max); vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max); vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_s8(c3 + 0, vout3x0123456789ABCDEF); vst1q_s8(c2 + 0, vout2x0123456789ABCDEF); vst1q_s8(c1 + 0, vout1x0123456789ABCDEF); vst1q_s8(c0 + 0, vout0x0123456789ABCDEF); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 16; } else { int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF)); if (nc & 8) { vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8; vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8; vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8; vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8; vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF)); vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF)); } if (nc & 4) { vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x8c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const int8_t** restrict a, const void* restrict w, int8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const int8_t* zero, const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { c1 = c0; } int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { c2 = c1; } int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { c3 = c2; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc0x4567 = vld1q_s32(w); w = (const int32_t*) w + 4; int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = vacc0x4567; int32x4_t vacc3x0123 = vacc0x0123; int32x4_t vacc3x4567 = vacc0x4567; size_t p = ks; do { const int8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(int8_t)) { // Load a 4x8 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8; const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8; const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8; const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8; // Load a 8x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x8 * 8x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const int8x8_t va0x01234567 = vld1_s8(a0); const int8x8_t va1x01234567 = vld1_s8(a1); const int8x8_t va2x01234567 = vld1_s8(a2); const int8x8_t va3x01234567 = vld1_s8(a3); // Load a 4x8 block of weights. const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16; const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16; // Multiply-accumulate: 4x4 * 4x8 --> 4x8. vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0); vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0); vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0); vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0); vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0); vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0); vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0); vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0); } p -= 4 * sizeof(void*); } while (p != 0); float32x4_t vfpacc0x0123 = vcvtq_f32_s32(vacc0x0123); float32x4_t vfpacc0x4567 = vcvtq_f32_s32(vacc0x4567); float32x4_t vfpacc1x0123 = vcvtq_f32_s32(vacc1x0123); float32x4_t vfpacc1x4567 = vcvtq_f32_s32(vacc1x4567); float32x4_t vfpacc2x0123 = vcvtq_f32_s32(vacc2x0123); float32x4_t vfpacc2x4567 = vcvtq_f32_s32(vacc2x4567); float32x4_t vfpacc3x0123 = vcvtq_f32_s32(vacc3x0123); float32x4_t vfpacc3x4567 = vcvtq_f32_s32(vacc3x4567); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); vfpacc3x0123 = vmulq_f32(vfpacc3x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567); vfpacc3x4567 = vmulq_f32(vfpacc3x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); vacc2x0123 = vcvtnq_s32_f32(vfpacc2x0123); vacc2x4567 = vcvtnq_s32_f32(vfpacc2x4567); vacc3x0123 = vcvtnq_s32_f32(vfpacc3x0123); vacc3x4567 = vcvtnq_s32_f32(vfpacc3x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567)); vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567)); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 8; } else { if (nc & 4) { vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2; vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8); vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qu8_gemm_minmax_rndnu_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, const uint8_t* restrict a, size_t a_stride, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); const uint8_t* a0 = a; uint8_t* c0 = c; const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x89AB = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0xCDEF = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x2_t vnacc0 = vmov_n_u32(0); // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 1x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; // Load a 8x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb4567x89AB, va0x01234567, 1); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; // Load a 4x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); int32x4_t vacc0x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc0x89AB, vnacc0x0123)); int32x4_t vacc0xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc0xCDEF, vnacc0x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc0x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc0x89ABCDEF)); #endif const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min); const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_u8(vout0x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_u8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_u8(c0 + 0, vout0x0123456789ABCDEF); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const uint8_t*) ((uintptr_t) a0 - kc); nc -= 16; } else { uint8x8_t vout0x01234567 = vget_low_u8(vout0x0123456789ABCDEF); if (nc & 8) { vst1_u8(c0, vout0x01234567); c0 += 8; vout0x01234567 = vget_high_u8(vout0x0123456789ABCDEF); } if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_u8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_u8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_u8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qu8_gemm_minmax_rndnu_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, const uint8_t* restrict a, size_t a_stride, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); const uint8_t* a0 = a; uint8_t* c0 = c; const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x2_t vnacc0 = vmov_n_u32(0); // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 1x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; // Load a 8x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; // Load a 4x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); } // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); uint8x8_t vout0x01234567 = vqmovun_s16(vacc0x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); uint8x8_t vout0x01234567 = vqmovun_s16(vacc0x01234567); #endif const uint8x8_t voutput_min = vld1_dup_u8(¶ms->rndnu_neon.output_min); const uint8x8_t voutput_max = vld1_dup_u8(¶ms->rndnu_neon.output_max); vout0x01234567 = vmax_u8(vout0x01234567, voutput_min); vout0x01234567 = vmin_u8(vout0x01234567, voutput_max); if (nc >= 8) { vst1_u8(c0 + 0, vout0x01234567); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a0 = (const uint8_t*) ((uintptr_t) a0 - kc); nc -= 8; } else { if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_u8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_u8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_u8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qu8_gemm_minmax_rndnu_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, const uint8_t* restrict a, size_t a_stride, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); const uint8_t* a0 = a; uint8_t* c0 = c; const uint8_t* a1 = (const uint8_t*) ((uintptr_t) a0 + a_stride); uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const uint8_t* a2 = (const uint8_t*) ((uintptr_t) a1 + a_stride); uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const uint8_t* a3 = (const uint8_t*) ((uintptr_t) a2 + a_stride); uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); // Loop over groups of 16 columns. do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x89AB = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0xCDEF = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc1x0123 = vpacc0x0123; uint32x4_t vpacc1x4567 = vpacc0x4567; uint32x4_t vpacc1x89AB = vpacc0x89AB; uint32x4_t vpacc1xCDEF = vpacc0xCDEF; uint32x4_t vpacc2x0123 = vpacc0x0123; uint32x4_t vpacc2x4567 = vpacc0x4567; uint32x4_t vpacc2x89AB = vpacc0x89AB; uint32x4_t vpacc2xCDEF = vpacc0xCDEF; uint32x4_t vpacc3x0123 = vpacc0x0123; uint32x4_t vpacc3x4567 = vpacc0x4567; uint32x4_t vpacc3x89AB = vpacc0x89AB; uint32x4_t vpacc3xCDEF = vpacc0xCDEF; uint32x2_t vnacc0 = vmov_n_u32(0); uint32x2_t vnacc1 = vmov_n_u32(0); uint32x2_t vnacc2 = vmov_n_u32(0); uint32x2_t vnacc3 = vmov_n_u32(0); // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 4x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; const uint8x8_t va1x01234567 = vld1_u8(a1); a1 += 8; const uint8x8_t va2x01234567 = vld1_u8(a2); a2 += 8; const uint8x8_t va3x01234567 = vld1_u8(a3); a3 += 8; // Load a 8x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb4567x89AB, va0x01234567, 1); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0); vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb4567x0123, va1x01234567, 1); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb4567x4567, va1x01234567, 1); vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb4567x89AB, va1x01234567, 1); vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb0123x89AB, va2x01234567, 0); vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb4567x0123, va2x01234567, 1); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb4567x4567, va2x01234567, 1); vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb4567x89AB, va2x01234567, 1); vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); vpacc3x89AB = vdotq_lane_u32(vpacc3x89AB, vb0123x89AB, va3x01234567, 0); vpacc3xCDEF = vdotq_lane_u32(vpacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb4567x0123, va3x01234567, 1); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb4567x4567, va3x01234567, 1); vpacc3x89AB = vdotq_lane_u32(vpacc3x89AB, vb4567x89AB, va3x01234567, 1); vpacc3xCDEF = vdotq_lane_u32(vpacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; const uint8x8_t va1x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a1, vmov_n_u32(0), 0)); a1 += 4; const uint8x8_t va2x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a2, vmov_n_u32(0), 0)); a2 += 4; const uint8x8_t va3x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a3, vmov_n_u32(0), 0)); a3 += 4; // Load a 4x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0); vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb0123x89AB, va2x01234567, 0); vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); vpacc3x89AB = vdotq_lane_u32(vpacc3x89AB, vb0123x89AB, va3x01234567, 0); vpacc3xCDEF = vdotq_lane_u32(vpacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); int32x4_t vacc0x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc0x89AB, vnacc0x0123)); int32x4_t vacc0xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc0xCDEF, vnacc0x0123)); vnacc1 = vpadd_u32(vnacc1, vnacc1); const uint32x4_t vnacc1x0123 = vcombine_u32(vnacc1, vnacc1); int32x4_t vacc1x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x0123, vnacc1x0123)); int32x4_t vacc1x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x4567, vnacc1x0123)); int32x4_t vacc1x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc1x89AB, vnacc1x0123)); int32x4_t vacc1xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc1xCDEF, vnacc1x0123)); vnacc2 = vpadd_u32(vnacc2, vnacc2); const uint32x4_t vnacc2x0123 = vcombine_u32(vnacc2, vnacc2); int32x4_t vacc2x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x0123, vnacc2x0123)); int32x4_t vacc2x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x4567, vnacc2x0123)); int32x4_t vacc2x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc2x89AB, vnacc2x0123)); int32x4_t vacc2xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc2xCDEF, vnacc2x0123)); vnacc3 = vpadd_u32(vnacc3, vnacc3); const uint32x4_t vnacc3x0123 = vcombine_u32(vnacc3, vnacc3); int32x4_t vacc3x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x0123, vnacc3x0123)); int32x4_t vacc3x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x4567, vnacc3x0123)); int32x4_t vacc3x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc3x89AB, vnacc3x0123)); int32x4_t vacc3xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc3xCDEF, vnacc3x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift); vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift); vacc1x89AB = vshlq_s32(vacc1x89AB, vright_pre_shift); vacc1xCDEF = vshlq_s32(vacc1xCDEF, vright_pre_shift); vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift); vacc2x89AB = vshlq_s32(vacc2x89AB, vright_pre_shift); vacc2xCDEF = vshlq_s32(vacc2xCDEF, vright_pre_shift); vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift); vacc3x89AB = vshlq_s32(vacc3x89AB, vright_pre_shift); vacc3xCDEF = vshlq_s32(vacc3xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier); vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier); vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc3x89AB = vqdmulhq_s32(vacc3x89AB, vmultiplier); vacc3xCDEF = vqdmulhq_s32(vacc3xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift); vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift); vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_post_shift); vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc0x89ABCDEF); uint8x16_t vout1x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc1x01234567), vacc1x89ABCDEF); uint8x16_t vout2x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc2x01234567), vacc2x89ABCDEF); uint8x16_t vout3x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc3x01234567), vacc3x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc0x89ABCDEF)); uint8x16_t vout1x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc1x01234567), vqmovun_s16(vacc1x89ABCDEF)); uint8x16_t vout2x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc2x01234567), vqmovun_s16(vacc2x89ABCDEF)); uint8x16_t vout3x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc3x01234567), vqmovun_s16(vacc3x89ABCDEF)); #endif const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min); const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_u8(vout0x0123456789ABCDEF, voutput_min); vout1x0123456789ABCDEF = vmaxq_u8(vout1x0123456789ABCDEF, voutput_min); vout2x0123456789ABCDEF = vmaxq_u8(vout2x0123456789ABCDEF, voutput_min); vout3x0123456789ABCDEF = vmaxq_u8(vout3x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_u8(vout0x0123456789ABCDEF, voutput_max); vout1x0123456789ABCDEF = vminq_u8(vout1x0123456789ABCDEF, voutput_max); vout2x0123456789ABCDEF = vminq_u8(vout2x0123456789ABCDEF, voutput_max); vout3x0123456789ABCDEF = vminq_u8(vout3x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_u8(c0 + 0, vout0x0123456789ABCDEF); vst1q_u8(c1 + 0, vout1x0123456789ABCDEF); vst1q_u8(c2 + 0, vout2x0123456789ABCDEF); vst1q_u8(c3 + 0, vout3x0123456789ABCDEF); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride); c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride); c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride); a0 = (const uint8_t*) ((uintptr_t) a0 - kc); a1 = (const uint8_t*) ((uintptr_t) a1 - kc); a2 = (const uint8_t*) ((uintptr_t) a2 - kc); a3 = (const uint8_t*) ((uintptr_t) a3 - kc); nc -= 16; } else { uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vget_low_u8(vout0x0123456789ABCDEF), vget_low_u8(vout1x0123456789ABCDEF)); uint8x16_t vout2x01234567_3x01234567 = vcombine_u8(vget_low_u8(vout2x0123456789ABCDEF), vget_low_u8(vout3x0123456789ABCDEF)); if (nc & 8) { vst1_u8(c0, vget_low_u8(vout0x01234567_1x01234567)); c0 += 8; vst1_u8(c1, vget_high_u8(vout0x01234567_1x01234567)); c1 += 8; vst1_u8(c2, vget_low_u8(vout2x01234567_3x01234567)); c2 += 8; vst1_u8(c3, vget_high_u8(vout2x01234567_3x01234567)); c3 += 8; vout0x01234567_1x01234567 = vcombine_u8(vget_high_u8(vout0x0123456789ABCDEF), vget_high_u8(vout1x0123456789ABCDEF)); vout2x01234567_3x01234567 = vcombine_u8(vget_high_u8(vout2x0123456789ABCDEF), vget_high_u8(vout3x0123456789ABCDEF)); } if (nc & 4) { vst1q_lane_u32((void*) c0, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c3, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 2); c3 += 4; vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c0, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c3, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 4); c3 += 2; vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); } if (nc & 1) { vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0); vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_u8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_u8(c3, vout2x01234567_3x01234567, 8); } nc = 0; } } while (nc != 0); } void xnn_qu8_gemm_minmax_rndnu_ukernel_4x8c4__neondot( size_t mr, size_t nc, size_t kc, const uint8_t* restrict a, size_t a_stride, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(kc % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); const uint8_t* a0 = a; uint8_t* c0 = c; const uint8_t* a1 = (const uint8_t*) ((uintptr_t) a0 + a_stride); uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { a1 = a0; c1 = c0; } const uint8_t* a2 = (const uint8_t*) ((uintptr_t) a1 + a_stride); uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { a2 = a1; c2 = c1; } const uint8_t* a3 = (const uint8_t*) ((uintptr_t) a2 + a_stride); uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { a3 = a2; c3 = c2; } const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); // Loop over groups of 8 columns. do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc1x0123 = vpacc0x0123; uint32x4_t vpacc1x4567 = vpacc0x4567; uint32x4_t vpacc2x0123 = vpacc0x0123; uint32x4_t vpacc2x4567 = vpacc0x4567; uint32x4_t vpacc3x0123 = vpacc0x0123; uint32x4_t vpacc3x4567 = vpacc0x4567; uint32x2_t vnacc0 = vmov_n_u32(0); uint32x2_t vnacc1 = vmov_n_u32(0); uint32x2_t vnacc2 = vmov_n_u32(0); uint32x2_t vnacc3 = vmov_n_u32(0); // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 4x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; const uint8x8_t va1x01234567 = vld1_u8(a1); a1 += 8; const uint8x8_t va2x01234567 = vld1_u8(a2); a2 += 8; const uint8x8_t va3x01234567 = vld1_u8(a3); a3 += 8; // Load a 8x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x8 * 8x8 --> 4x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb4567x0123, va1x01234567, 1); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb4567x4567, va1x01234567, 1); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb4567x0123, va2x01234567, 1); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb4567x4567, va2x01234567, 1); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb4567x0123, va3x01234567, 1); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb4567x4567, va3x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; const uint8x8_t va1x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a1, vmov_n_u32(0), 0)); a1 += 4; const uint8x8_t va2x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a2, vmov_n_u32(0), 0)); a2 += 4; const uint8x8_t va3x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a3, vmov_n_u32(0), 0)); a3 += 4; // Load a 4x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x4 * 4x8 --> 4x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); } // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); vnacc1 = vpadd_u32(vnacc1, vnacc1); const uint32x4_t vnacc1x0123 = vcombine_u32(vnacc1, vnacc1); int32x4_t vacc1x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x0123, vnacc1x0123)); int32x4_t vacc1x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x4567, vnacc1x0123)); vnacc2 = vpadd_u32(vnacc2, vnacc2); const uint32x4_t vnacc2x0123 = vcombine_u32(vnacc2, vnacc2); int32x4_t vacc2x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x0123, vnacc2x0123)); int32x4_t vacc2x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x4567, vnacc2x0123)); vnacc3 = vpadd_u32(vnacc3, vnacc3); const uint32x4_t vnacc3x0123 = vcombine_u32(vnacc3, vnacc3); int32x4_t vacc3x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x0123, vnacc3x0123)); int32x4_t vacc3x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x4567, vnacc3x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift); vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift); vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); uint8x16_t vout0x01234567_1x01234567 = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc1x01234567); uint8x16_t vout2x01234567_3x01234567 = vqmovun_high_s16(vqmovun_s16(vacc2x01234567), vacc3x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc1x01234567)); uint8x16_t vout2x01234567_3x01234567 = vcombine_u8(vqmovun_s16(vacc2x01234567), vqmovun_s16(vacc3x01234567)); #endif const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min); const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max); vout0x01234567_1x01234567 = vmaxq_u8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_u8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vminq_u8(vout0x01234567_1x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_u8(vout2x01234567_3x01234567, voutput_max); if (nc >= 8) { vst1_u8(c0 + 0, vget_low_u8(vout0x01234567_1x01234567)); vst1_u8(c1 + 0, vget_high_u8(vout0x01234567_1x01234567)); vst1_u8(c2 + 0, vget_low_u8(vout2x01234567_3x01234567)); vst1_u8(c3 + 0, vget_high_u8(vout2x01234567_3x01234567)); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride); c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride); c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride); a0 = (const uint8_t*) ((uintptr_t) a0 - kc); a1 = (const uint8_t*) ((uintptr_t) a1 - kc); a2 = (const uint8_t*) ((uintptr_t) a2 - kc); a3 = (const uint8_t*) ((uintptr_t) a3 - kc); nc -= 8; } else { if (nc & 4) { vst1q_lane_u32((void*) c0, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c3, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 2); c3 += 4; vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c0, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c3, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 4); c3 += 2; vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); } if (nc & 1) { vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0); vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_u8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_u8(c3, vout2x01234567_3x01234567, 8); } nc = 0; } } while (nc != 0); } void xnn_qu8_igemm_minmax_rndnu_ukernel_1x16c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const uint8_t** restrict a, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const uint8_t* zero, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (1 * sizeof(void*)) == 0); assert(a_offset % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); uint8_t* c0 = c; const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x89AB = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0xCDEF = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x2_t vnacc0 = vmov_n_u32(0); size_t p = ks; do { const uint8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset); } a += 1; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 1x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; // Load a 8x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x8 * 8x16 --> 1x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb4567x89AB, va0x01234567, 1); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb4567xCDEF, va0x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; // Load a 4x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x4 * 4x16 --> 1x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); } p -= 1 * sizeof(void*); } while (p != 0); // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); int32x4_t vacc0x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc0x89AB, vnacc0x0123)); int32x4_t vacc0xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc0xCDEF, vnacc0x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc0x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc0x89ABCDEF)); #endif const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min); const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_u8(vout0x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_u8(vout0x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_u8(c0 + 0, vout0x0123456789ABCDEF); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a = (const uint8_t**restrict) ((uintptr_t) a - ks); nc -= 16; } else { uint8x8_t vout0x01234567 = vget_low_u8(vout0x0123456789ABCDEF); if (nc & 8) { vst1_u8(c0, vout0x01234567); c0 += 8; // This line vout0x01234567 = vget_high_u8(vout0x0123456789ABCDEF); } if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_u8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_u8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_u8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qu8_igemm_minmax_rndnu_ukernel_1x8c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const uint8_t** restrict a, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const uint8_t* zero, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 1); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (1 * sizeof(void*)) == 0); assert(a_offset % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); uint8_t* c0 = c; const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x2_t vnacc0 = vmov_n_u32(0); size_t p = ks; do { const uint8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset); } a += 1; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 1x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; // Load a 8x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x8 * 8x8 --> 1x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 1x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; // Load a 4x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 1x4 * 4x8 --> 1x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); } p -= 1 * sizeof(void*); } while (p != 0); // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); uint8x8_t vout0x01234567 = vqmovun_s16(vacc0x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); uint8x8_t vout0x01234567 = vqmovun_s16(vacc0x01234567); #endif const uint8x8_t voutput_min = vld1_dup_u8(¶ms->rndnu_neon.output_min); const uint8x8_t voutput_max = vld1_dup_u8(¶ms->rndnu_neon.output_max); vout0x01234567 = vmax_u8(vout0x01234567, voutput_min); vout0x01234567 = vmin_u8(vout0x01234567, voutput_max); if (nc >= 8) { vst1_u8(c0 + 0, vout0x01234567); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a = (const uint8_t**restrict) ((uintptr_t) a - ks); nc -= 8; } else { if (nc & 4) { vst1_lane_u32((void*) c0, vreinterpret_u32_u8(vout0x01234567), 0); c0 += 4; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c0, vreinterpret_u16_u8(vout0x01234567), 0); c0 += 2; vout0x01234567 = vext_u8(vout0x01234567, vout0x01234567, 2); } if (nc & 1) { vst1_lane_u8(c0, vout0x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qu8_igemm_minmax_rndnu_ukernel_4x16c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const uint8_t** restrict a, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const uint8_t* zero, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a_offset % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); uint8_t* c0 = c; uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { c1 = c0; } uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { c2 = c1; } uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { c3 = c2; } const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); do { // Initialize accumulators with bias. 16 bias values are loaded from the // weight matrix, at the start of the group of 16 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x89AB = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0xCDEF = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc1x0123 = vpacc0x0123; uint32x4_t vpacc1x4567 = vpacc0x4567; uint32x4_t vpacc1x89AB = vpacc0x89AB; uint32x4_t vpacc1xCDEF = vpacc0xCDEF; uint32x4_t vpacc2x0123 = vpacc0x0123; uint32x4_t vpacc2x4567 = vpacc0x4567; uint32x4_t vpacc2x89AB = vpacc0x89AB; uint32x4_t vpacc2xCDEF = vpacc0xCDEF; uint32x4_t vpacc3x0123 = vpacc0x0123; uint32x4_t vpacc3x4567 = vpacc0x4567; uint32x4_t vpacc3x89AB = vpacc0x89AB; uint32x4_t vpacc3xCDEF = vpacc0xCDEF; uint32x2_t vnacc0 = vmov_n_u32(0); uint32x2_t vnacc1 = vmov_n_u32(0); uint32x2_t vnacc2 = vmov_n_u32(0); uint32x2_t vnacc3 = vmov_n_u32(0); size_t p = ks; do { const uint8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset); } const uint8_t* restrict a1 = a[1]; if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset); } const uint8_t* restrict a2 = a[2]; if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset); } const uint8_t* restrict a3 = a[3]; if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const uint8_t*) ((uintptr_t) a3 + a_offset); } a += 4; // Inner accumulation loop along the 16 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 4x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; const uint8x8_t va1x01234567 = vld1_u8(a1); a1 += 8; const uint8x8_t va2x01234567 = vld1_u8(a2); a2 += 8; const uint8x8_t va3x01234567 = vld1_u8(a3); a3 += 8; // Load a 8x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x8 * 8x16 --> 4x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb4567x89AB, va0x01234567, 1); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb4567xCDEF, va0x01234567, 1); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0); vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb4567x0123, va1x01234567, 1); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb4567x4567, va1x01234567, 1); vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb4567x89AB, va1x01234567, 1); vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb4567xCDEF, va1x01234567, 1); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb0123x89AB, va2x01234567, 0); vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb4567x0123, va2x01234567, 1); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb4567x4567, va2x01234567, 1); vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb4567x89AB, va2x01234567, 1); vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb4567xCDEF, va2x01234567, 1); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); vpacc3x89AB = vdotq_lane_u32(vpacc3x89AB, vb0123x89AB, va3x01234567, 0); vpacc3xCDEF = vdotq_lane_u32(vpacc3xCDEF, vb0123xCDEF, va3x01234567, 0); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb4567x0123, va3x01234567, 1); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb4567x4567, va3x01234567, 1); vpacc3x89AB = vdotq_lane_u32(vpacc3x89AB, vb4567x89AB, va3x01234567, 1); vpacc3xCDEF = vdotq_lane_u32(vpacc3xCDEF, vb4567xCDEF, va3x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; const uint8x8_t va1x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a1, vmov_n_u32(0), 0)); a1 += 4; const uint8x8_t va2x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a2, vmov_n_u32(0), 0)); a2 += 4; const uint8x8_t va3x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a3, vmov_n_u32(0), 0)); a3 += 4; // Load a 4x16 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x4 * 4x16 --> 4x16. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0); vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0); vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb0123x89AB, va2x01234567, 0); vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb0123xCDEF, va2x01234567, 0); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); vpacc3x89AB = vdotq_lane_u32(vpacc3x89AB, vb0123x89AB, va3x01234567, 0); vpacc3xCDEF = vdotq_lane_u32(vpacc3xCDEF, vb0123xCDEF, va3x01234567, 0); } p -= 4 * sizeof(void*); } while (p != 0); // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); int32x4_t vacc0x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc0x89AB, vnacc0x0123)); int32x4_t vacc0xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc0xCDEF, vnacc0x0123)); vnacc1 = vpadd_u32(vnacc1, vnacc1); const uint32x4_t vnacc1x0123 = vcombine_u32(vnacc1, vnacc1); int32x4_t vacc1x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x0123, vnacc1x0123)); int32x4_t vacc1x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x4567, vnacc1x0123)); int32x4_t vacc1x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc1x89AB, vnacc1x0123)); int32x4_t vacc1xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc1xCDEF, vnacc1x0123)); vnacc2 = vpadd_u32(vnacc2, vnacc2); const uint32x4_t vnacc2x0123 = vcombine_u32(vnacc2, vnacc2); int32x4_t vacc2x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x0123, vnacc2x0123)); int32x4_t vacc2x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x4567, vnacc2x0123)); int32x4_t vacc2x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc2x89AB, vnacc2x0123)); int32x4_t vacc2xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc2xCDEF, vnacc2x0123)); vnacc3 = vpadd_u32(vnacc3, vnacc3); const uint32x4_t vnacc3x0123 = vcombine_u32(vnacc3, vnacc3); int32x4_t vacc3x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x0123, vnacc3x0123)); int32x4_t vacc3x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x4567, vnacc3x0123)); int32x4_t vacc3x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc3x89AB, vnacc3x0123)); int32x4_t vacc3xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc3xCDEF, vnacc3x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift); vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift); vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift); vacc1x89AB = vshlq_s32(vacc1x89AB, vright_pre_shift); vacc1xCDEF = vshlq_s32(vacc1xCDEF, vright_pre_shift); vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift); vacc2x89AB = vshlq_s32(vacc2x89AB, vright_pre_shift); vacc2xCDEF = vshlq_s32(vacc2xCDEF, vright_pre_shift); vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift); vacc3x89AB = vshlq_s32(vacc3x89AB, vright_pre_shift); vacc3xCDEF = vshlq_s32(vacc3xCDEF, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier); vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier); vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier); vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc3x89AB = vqdmulhq_s32(vacc3x89AB, vmultiplier); vacc3xCDEF = vqdmulhq_s32(vacc3xCDEF, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift); vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift); vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift); vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_post_shift); vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc0x89ABCDEF); uint8x16_t vout1x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc1x01234567), vacc1x89ABCDEF); uint8x16_t vout2x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc2x01234567), vacc2x89ABCDEF); uint8x16_t vout3x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc3x01234567), vacc3x89ABCDEF); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point); uint8x16_t vout0x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc0x89ABCDEF)); uint8x16_t vout1x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc1x01234567), vqmovun_s16(vacc1x89ABCDEF)); uint8x16_t vout2x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc2x01234567), vqmovun_s16(vacc2x89ABCDEF)); uint8x16_t vout3x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc3x01234567), vqmovun_s16(vacc3x89ABCDEF)); #endif const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min); const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max); vout0x0123456789ABCDEF = vmaxq_u8(vout0x0123456789ABCDEF, voutput_min); vout1x0123456789ABCDEF = vmaxq_u8(vout1x0123456789ABCDEF, voutput_min); vout2x0123456789ABCDEF = vmaxq_u8(vout2x0123456789ABCDEF, voutput_min); vout3x0123456789ABCDEF = vmaxq_u8(vout3x0123456789ABCDEF, voutput_min); vout0x0123456789ABCDEF = vminq_u8(vout0x0123456789ABCDEF, voutput_max); vout1x0123456789ABCDEF = vminq_u8(vout1x0123456789ABCDEF, voutput_max); vout2x0123456789ABCDEF = vminq_u8(vout2x0123456789ABCDEF, voutput_max); vout3x0123456789ABCDEF = vminq_u8(vout3x0123456789ABCDEF, voutput_max); if (nc >= 16) { vst1q_u8(c3 + 0, vout3x0123456789ABCDEF); vst1q_u8(c2 + 0, vout2x0123456789ABCDEF); vst1q_u8(c1 + 0, vout1x0123456789ABCDEF); vst1q_u8(c0 + 0, vout0x0123456789ABCDEF); c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride); c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride); c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a = (const uint8_t**restrict) ((uintptr_t) a - ks); nc -= 16; } else { uint8x16_t vout2x01234567_3x01234567 = vcombine_u8(vget_low_u8(vout2x0123456789ABCDEF), vget_low_u8(vout3x0123456789ABCDEF)); uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vget_low_u8(vout0x0123456789ABCDEF), vget_low_u8(vout1x0123456789ABCDEF)); if (nc & 8) { vst1_u8(c3, vget_high_u8(vout2x01234567_3x01234567)); c3 += 8; vst1_u8(c2, vget_low_u8(vout2x01234567_3x01234567)); c2 += 8; vst1_u8(c1, vget_high_u8(vout0x01234567_1x01234567)); c1 += 8; vst1_u8(c0, vget_low_u8(vout0x01234567_1x01234567)); c0 += 8; vout2x01234567_3x01234567 = vcombine_u8(vget_high_u8(vout2x0123456789ABCDEF), vget_high_u8(vout3x0123456789ABCDEF)); vout0x01234567_1x01234567 = vcombine_u8(vget_high_u8(vout0x0123456789ABCDEF), vget_high_u8(vout1x0123456789ABCDEF)); } if (nc & 4) { vst1q_lane_u32((void*) c3, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 2); c3 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4; vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c3, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 4); c3 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c0, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2; vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_u8(c3, vout2x01234567_3x01234567, 8); vst1q_lane_u8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); } void xnn_qu8_igemm_minmax_rndnu_ukernel_4x8c4__neondot( size_t mr, size_t nc, size_t kc, size_t ks, const uint8_t** restrict a, const void* restrict w, uint8_t* restrict c, size_t cm_stride, size_t cn_stride, size_t a_offset, const uint8_t* zero, const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a_offset % sizeof(uint8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 4 * sizeof(uint8_t)); uint8_t* c0 = c; uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr < 2) { c1 = c0; } uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride); if XNN_UNPREDICTABLE(mr <= 2) { c2 = c1; } uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride); if XNN_UNPREDICTABLE(mr != 4) { c3 = c2; } const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]); do { // Initialize accumulators with bias. 8 bias values are loaded from the // weight matrix, at the start of the group of 8 columns. uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4); uint32x4_t vpacc1x0123 = vpacc0x0123; uint32x4_t vpacc1x4567 = vpacc0x4567; uint32x4_t vpacc2x0123 = vpacc0x0123; uint32x4_t vpacc2x4567 = vpacc0x4567; uint32x4_t vpacc3x0123 = vpacc0x0123; uint32x4_t vpacc3x4567 = vpacc0x4567; uint32x2_t vnacc0 = vmov_n_u32(0); uint32x2_t vnacc1 = vmov_n_u32(0); uint32x2_t vnacc2 = vmov_n_u32(0); uint32x2_t vnacc3 = vmov_n_u32(0); size_t p = ks; do { const uint8_t* restrict a0 = a[0]; if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset); } const uint8_t* restrict a1 = a[1]; if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset); } const uint8_t* restrict a2 = a[2]; if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset); } const uint8_t* restrict a3 = a[3]; if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const uint8_t*) ((uintptr_t) a3 + a_offset); } a += 4; // Inner accumulation loop along the 8 columns. size_t k = kc; // 2x partial unrolled loop to load 8 bytes at a time. while (k >= 8 * sizeof(uint8_t)) { // Load a 4x8 block of activations. const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8; const uint8x8_t va1x01234567 = vld1_u8(a1); a1 += 8; const uint8x8_t va2x01234567 = vld1_u8(a2); a2 += 8; const uint8x8_t va3x01234567 = vld1_u8(a3); a3 += 8; // Load a 8x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x8 * 8x8 --> 4x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb4567x0123, va1x01234567, 1); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb4567x4567, va1x01234567, 1); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb4567x0123, va2x01234567, 1); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb4567x4567, va2x01234567, 1); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb4567x0123, va3x01234567, 1); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb4567x4567, va3x01234567, 1); k -= 8 * sizeof(uint8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 4x4 block of activations. const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4; const uint8x8_t va1x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a1, vmov_n_u32(0), 0)); a1 += 4; const uint8x8_t va2x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a2, vmov_n_u32(0), 0)); a2 += 4; const uint8x8_t va3x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a3, vmov_n_u32(0), 0)); a3 += 4; // Load a 4x8 block of weights. const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16); // Multiply-accumulate: 4x4 * 4x8 --> 4x8. vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567); vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0); vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0); vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567); vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0); vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0); vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567); vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0); vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0); vnacc3 = vdot_u32(vnacc3, va_zero_point, va3x01234567); vpacc3x0123 = vdotq_lane_u32(vpacc3x0123, vb0123x0123, va3x01234567, 0); vpacc3x4567 = vdotq_lane_u32(vpacc3x4567, vb0123x4567, va3x01234567, 0); } p -= 4 * sizeof(void*); } while (p != 0); // Subtract zero point from accumulators. vnacc0 = vpadd_u32(vnacc0, vnacc0); const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0); int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123)); int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123)); vnacc1 = vpadd_u32(vnacc1, vnacc1); const uint32x4_t vnacc1x0123 = vcombine_u32(vnacc1, vnacc1); int32x4_t vacc1x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x0123, vnacc1x0123)); int32x4_t vacc1x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x4567, vnacc1x0123)); vnacc2 = vpadd_u32(vnacc2, vnacc2); const uint32x4_t vnacc2x0123 = vcombine_u32(vnacc2, vnacc2); int32x4_t vacc2x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x0123, vnacc2x0123)); int32x4_t vacc2x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x4567, vnacc2x0123)); vnacc3 = vpadd_u32(vnacc3, vnacc3); const uint32x4_t vnacc3x0123 = vcombine_u32(vnacc3, vnacc3); int32x4_t vacc3x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x0123, vnacc3x0123)); int32x4_t vacc3x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc3x4567, vnacc3x0123)); const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift); const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier); const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift); vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift); vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift); vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift); vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift); vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift); vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift); vacc3x0123 = vshlq_s32(vacc3x0123, vright_pre_shift); vacc3x4567 = vshlq_s32(vacc3x4567, vright_pre_shift); vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier); vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier); vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier); vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier); vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier); vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier); vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier); vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier); vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift); vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift); vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift); vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift); vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift); vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift); vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift); vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift); const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point); #if XNN_ARCH_ARM64 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point); uint8x16_t vout0x01234567_1x01234567 = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc1x01234567); uint8x16_t vout2x01234567_3x01234567 = vqmovun_high_s16(vqmovun_s16(vacc2x01234567), vacc3x01234567); #else const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point); const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point); const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point); const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point); uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc1x01234567)); uint8x16_t vout2x01234567_3x01234567 = vcombine_u8(vqmovun_s16(vacc2x01234567), vqmovun_s16(vacc3x01234567)); #endif const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min); const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max); vout0x01234567_1x01234567 = vmaxq_u8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_u8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vminq_u8(vout0x01234567_1x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_u8(vout2x01234567_3x01234567, voutput_max); if (nc >= 8) { vst1_u8(c3 + 0, vget_high_u8(vout2x01234567_3x01234567)); vst1_u8(c2 + 0, vget_low_u8(vout2x01234567_3x01234567)); vst1_u8(c1 + 0, vget_high_u8(vout0x01234567_1x01234567)); vst1_u8(c0 + 0, vget_low_u8(vout0x01234567_1x01234567)); c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride); c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride); c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride); c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride); a = (const uint8_t**restrict) ((uintptr_t) a - ks); nc -= 8; } else { if (nc & 4) { vst1q_lane_u32((void*) c3, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 2); c3 += 4; vst1q_lane_u32((void*) c2, vreinterpretq_u32_u8(vout2x01234567_3x01234567), 0); c2 += 4; vst1q_lane_u32((void*) c1, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4; vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4); vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1q_lane_u16((void*) c3, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 4); c3 += 2; vst1q_lane_u16((void*) c2, vreinterpretq_u16_u8(vout2x01234567_3x01234567), 0); c2 += 2; vst1q_lane_u16((void*) c1, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2; vst1q_lane_u16((void*) c0, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2; vout2x01234567_3x01234567 = vextq_u8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2); vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_u8(c3, vout2x01234567_3x01234567, 8); vst1q_lane_u8(c2, vout2x01234567_3x01234567, 0); vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }