repo
stringlengths
1
152
file
stringlengths
14
221
code
stringlengths
501
25k
file_length
int64
501
25k
avg_line_length
float64
20
99.5
max_line_length
int64
21
134
extension_type
stringclasses
2 values
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c2-minmax-fp32-neonv8-mlal-dup.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c2-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c2__neonv8_mlal_dup( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int8x8_t va0x0 = vld1_s8(a0); a0 += 8; const int8x8_t va0x1 = vld1_s8(a0); a0 += 8; const int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 0)); const int8x8_t va0c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 0)); const int8x8_t va1c0x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 0)); const int8x8_t va1c0x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 0)); int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0); const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1); vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0); const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1); vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 1)); const int8x8_t va0c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 1)); const int8x8_t va1c1x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 1)); const int8x8_t va1c1x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 1)); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0); const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1); vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0); const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1); vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 2)); const int8x8_t va0c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 2)); const int8x8_t va1c2x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 2)); const int8x8_t va1c2x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 2)); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0); const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1); vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0); const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1); vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x0), 3)); const int8x8_t va0c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0x1), 3)); const int8x8_t va1c3x0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x0), 3)); const int8x8_t va1c3x1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1x1), 3)); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0); const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1); vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0); const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1); vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)); const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)); const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)); const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3)); const int8x8_t va1c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3)); const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3); const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3); const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); } } } p -= 2 * 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
18,901
52.851852
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c2-minmax-fp32-neonv8-mlal-ld1r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c2-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c2__neonv8_mlal_ld1r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int16x4_t va00x0 = vld1_dup_s16((const void*)a0); const int16x4_t va01x0 = vld1_dup_s16((const void*)(a0 + 2)); const int16x4_t va02x0 = vld1_dup_s16((const void*)(a0 + 4)); const int16x4_t va03x0 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8; const int16x4_t va00x1 = vld1_dup_s16((const void*)a0); const int16x4_t va01x1 = vld1_dup_s16((const void*)(a0 + 2)); const int16x4_t va02x1 = vld1_dup_s16((const void*)(a0 + 4)); const int16x4_t va03x1 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8; const int16x4_t va10x0 = vld1_dup_s16((const void*)a1); const int16x4_t va11x0 = vld1_dup_s16((const void*)(a1 + 2)); const int16x4_t va12x0 = vld1_dup_s16((const void*)(a1 + 4)); const int16x4_t va13x0 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8; const int16x4_t va10x1 = vld1_dup_s16((const void*)a1); const int16x4_t va11x1 = vld1_dup_s16((const void*)(a1 + 2)); const int16x4_t va12x1 = vld1_dup_s16((const void*)(a1 + 4)); const int16x4_t va13x1 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s16(va00x0); const int8x8_t va0c0x1 = vreinterpret_s8_s16(va00x1); const int8x8_t va1c0x0 = vreinterpret_s8_s16(va10x0); const int8x8_t va1c0x1 = vreinterpret_s8_s16(va10x1); int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0); const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1); vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0); const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1); vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1x0 = vreinterpret_s8_s16(va01x0); const int8x8_t va0c1x1 = vreinterpret_s8_s16(va01x1); const int8x8_t va1c1x0 = vreinterpret_s8_s16(va11x0); const int8x8_t va1c1x1 = vreinterpret_s8_s16(va11x1); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0); const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1); vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0); const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1); vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2x0 = vreinterpret_s8_s16(va02x0); const int8x8_t va0c2x1 = vreinterpret_s8_s16(va02x1); const int8x8_t va1c2x0 = vreinterpret_s8_s16(va12x0); const int8x8_t va1c2x1 = vreinterpret_s8_s16(va12x1); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0); const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1); vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0); const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1); vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3x0 = vreinterpret_s8_s16(va03x0); const int8x8_t va0c3x1 = vreinterpret_s8_s16(va03x1); const int8x8_t va1c3x0 = vreinterpret_s8_s16(va13x0); const int8x8_t va1c3x1 = vreinterpret_s8_s16(va13x1); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0); const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1); vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0); const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1); vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int16x4_t va00 = vld1_dup_s16((const void*)a0); const int16x4_t va01 = vld1_dup_s16((const void*)(a0 + 2)); const int16x4_t va02 = vld1_dup_s16((const void*)(a0 + 4)); const int16x4_t va03 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8; const int16x4_t va10 = vld1_dup_s16((const void*)a1); const int16x4_t va11 = vld1_dup_s16((const void*)(a1 + 2)); const int16x4_t va12 = vld1_dup_s16((const void*)(a1 + 4)); const int16x4_t va13 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8; const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(va00); const int8x8_t va1c0 = vreinterpret_s8_s16(va10); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1 = vreinterpret_s8_s16(va01); const int8x8_t va1c1 = vreinterpret_s8_s16(va11); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2 = vreinterpret_s8_s16(va02); const int8x8_t va1c2 = vreinterpret_s8_s16(va12); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3 = vreinterpret_s8_s16(va03); const int8x8_t va1c3 = vreinterpret_s8_s16(va13); const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3); const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3); const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); } } } p -= 2 * 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
19,358
51.463415
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c2-minmax-fp32-neonv8-mlal-ld2r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c2-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c2__neonv8_mlal_ld2r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int16x4x2_t va00x0 = vld2_dup_s16((const void*)a0); const int16x4x2_t va01x0 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8; const int16x4x2_t va00x1 = vld2_dup_s16((const void*)a0); const int16x4x2_t va01x1 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8; const int16x4x2_t va10x0 = vld2_dup_s16((const void*)a1); const int16x4x2_t va11x0 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8; const int16x4x2_t va10x1 = vld2_dup_s16((const void*)a1); const int16x4x2_t va11x1 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s16(va00x0.val[0]); const int8x8_t va0c0x1 = vreinterpret_s8_s16(va00x1.val[0]); const int8x8_t va1c0x0 = vreinterpret_s8_s16(va10x0.val[0]); const int8x8_t va1c0x1 = vreinterpret_s8_s16(va10x1.val[0]); int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0); const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1); vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0); const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1); vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1x0 = vreinterpret_s8_s16(va00x0.val[1]); const int8x8_t va0c1x1 = vreinterpret_s8_s16(va00x1.val[1]); const int8x8_t va1c1x0 = vreinterpret_s8_s16(va10x0.val[1]); const int8x8_t va1c1x1 = vreinterpret_s8_s16(va10x1.val[1]); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0); const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1); vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0); const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1); vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2x0 = vreinterpret_s8_s16(va01x0.val[0]); const int8x8_t va0c2x1 = vreinterpret_s8_s16(va01x1.val[0]); const int8x8_t va1c2x0 = vreinterpret_s8_s16(va11x0.val[0]); const int8x8_t va1c2x1 = vreinterpret_s8_s16(va11x1.val[0]); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0); const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1); vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0); const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1); vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3x0 = vreinterpret_s8_s16(va01x0.val[1]); const int8x8_t va0c3x1 = vreinterpret_s8_s16(va01x1.val[1]); const int8x8_t va1c3x0 = vreinterpret_s8_s16(va11x0.val[1]); const int8x8_t va1c3x1 = vreinterpret_s8_s16(va11x1.val[1]); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0); const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1); vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0); const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1); vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int16x4x2_t va00 = vld2_dup_s16((const void*)a0); const int16x4x2_t va01 = vld2_dup_s16((const void*)(a0 + 4)); a0 += 8; const int16x4x2_t va10 = vld2_dup_s16((const void*)a1); const int16x4x2_t va11 = vld2_dup_s16((const void*)(a1 + 4)); a1 += 8; const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(va00.val[0]); const int8x8_t va1c0 = vreinterpret_s8_s16(va10.val[0]); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1 = vreinterpret_s8_s16(va00.val[1]); const int8x8_t va1c1 = vreinterpret_s8_s16(va10.val[1]); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2 = vreinterpret_s8_s16(va01.val[0]); const int8x8_t va1c2 = vreinterpret_s8_s16(va11.val[0]); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3 = vreinterpret_s8_s16(va01.val[1]); const int8x8_t va1c3 = vreinterpret_s8_s16(va11.val[1]); const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3); const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3); const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); } } } p -= 2 * 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
18,718
51.434174
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c2-minmax-fp32-neonv8-mlal-ld4r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c2-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c2__neonv8_mlal_ld4r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t)); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int16x4x4_t va0x0 = vld4_dup_s16((const void*)a0); a0 += 8; const int16x4x4_t va0x1 = vld4_dup_s16((const void*)a0); a0 += 8; const int16x4x4_t va1x0 = vld4_dup_s16((const void*)a1); a1 += 8; const int16x4x4_t va1x1 = vld4_dup_s16((const void*)a1); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s16(va0x0.val[0]); const int8x8_t va0c0x1 = vreinterpret_s8_s16(va0x1.val[0]); const int8x8_t va1c0x0 = vreinterpret_s8_s16(va1x0.val[0]); const int8x8_t va1c0x1 = vreinterpret_s8_s16(va1x1.val[0]); int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0c0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1c0x0); const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0c0x1); vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1c0x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0c0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1c0x0); const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0c0x1); vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1c0x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1x0 = vreinterpret_s8_s16(va0x0.val[1]); const int8x8_t va0c1x1 = vreinterpret_s8_s16(va0x1.val[1]); const int8x8_t va1c1x0 = vreinterpret_s8_s16(va1x0.val[1]); const int8x8_t va1c1x1 = vreinterpret_s8_s16(va1x1.val[1]); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0c1x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1c1x0); const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0c1x1); vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1c1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0c1x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1c1x0); const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0c1x1); vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1c1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2x0 = vreinterpret_s8_s16(va0x0.val[2]); const int8x8_t va0c2x1 = vreinterpret_s8_s16(va0x1.val[2]); const int8x8_t va1c2x0 = vreinterpret_s8_s16(va1x0.val[2]); const int8x8_t va1c2x1 = vreinterpret_s8_s16(va1x1.val[2]); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0c2x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1c2x0); const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0c2x1); vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1c2x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0c2x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1c2x0); const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0c2x1); vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1c2x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3x0 = vreinterpret_s8_s16(va0x0.val[3]); const int8x8_t va0c3x1 = vreinterpret_s8_s16(va0x1.val[3]); const int8x8_t va1c3x0 = vreinterpret_s8_s16(va1x0.val[3]); const int8x8_t va1c3x1 = vreinterpret_s8_s16(va1x1.val[3]); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0c3x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1c3x0); const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0c3x1); vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1c3x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0c3x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1c3x0); const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0c3x1); vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1c3x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int16x4x4_t va0 = vld4_dup_s16((const void*)a0); a0 += 8; const int16x4x4_t va1 = vld4_dup_s16((const void*)a1); a1 += 8; const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(va0.val[0]); const int8x8_t va1c0 = vreinterpret_s8_s16(va1.val[0]); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); const int8x8_t va0c1 = vreinterpret_s8_s16(va0.val[1]); const int8x8_t va1c1 = vreinterpret_s8_s16(va1.val[1]); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); const int8x8_t va0c2 = vreinterpret_s8_s16(va0.val[2]); const int8x8_t va1c2 = vreinterpret_s8_s16(va1.val[2]); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); const int8x8_t va0c3 = vreinterpret_s8_s16(va0.val[3]); const int8x8_t va1c3 = vreinterpret_s8_s16(va1.val[3]); const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3); const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3); const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0)); const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0)); const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1)); const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1)); const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2)); const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2)); const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); } } } p -= 2 * 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
18,260
51.025641
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c2s4-minmax-fp32-neon-mlal.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c2-neon-mull-shuffle.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c2s4__neon_mlal( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); 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; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va0x1 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1x0); const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0x1); vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1x0); const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0x1); vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); va0x0 = vext_s8(va0x0, va0x0, 2); va0x1 = vext_s8(va0x1, va0x1, 2); va1x0 = vext_s8(va1x0, va1x0, 2); va1x1 = vext_s8(va1x1, va1x1, 2); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1x0); const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0x1); vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1x0); const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0x1); vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); va0x0 = vext_s8(va0x0, va0x0, 2); va0x1 = vext_s8(va0x1, va0x1, 2); va1x0 = vext_s8(va1x0, va1x0, 2); va1x1 = vext_s8(va1x1, va1x1, 2); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1x0); const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0x1); vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1x0); const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0x1); vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); va0x0 = vext_s8(va0x0, va0x0, 2); va0x1 = vext_s8(va0x1, va0x1, 2); va1x0 = vext_s8(va1x0, va1x0, 2); va1x1 = vext_s8(va1x1, va1x1, 2); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1x0); const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0x1); vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1x0); const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0x1); vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 16 * sizeof(int8_t); } if (k != 0) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); va0x0 = vext_s8(va0x0, va0x0, 2); va1x0 = vext_s8(va1x0, va1x0, 2); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); va0x0 = vext_s8(va0x0, va0x0, 2); va1x0 = vext_s8(va1x0, va1x0, 2); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); va0x0 = vext_s8(va0x0, va0x0, 2); va1x0 = vext_s8(va1x0, va1x0, 2); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); } p -= 2 * 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
13,444
46.01049
125
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c2s4-minmax-fp32-neonv8-mlal.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c2-neon-mull-shuffle.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c2s4__neonv8_mlal( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); 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; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va0x1 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1x0); const int8x8_t vb0123c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c0 = vmlal_s8(vprod0x0123c0, vb0123c0x1, va0x1); vprod1x0123c0 = vmlal_s8(vprod1x0123c0, vb0123c0x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1x0); const int8x8_t vb4567c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c0 = vmlal_s8(vprod0x4567c0, vb4567c0x1, va0x1); vprod1x4567c0 = vmlal_s8(vprod1x4567c0, vb4567c0x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); va0x0 = vext_s8(va0x0, va0x0, 2); va0x1 = vext_s8(va0x1, va0x1, 2); va1x0 = vext_s8(va1x0, va1x0, 2); va1x1 = vext_s8(va1x1, va1x1, 2); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1x0); const int8x8_t vb0123c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c1 = vmlal_s8(vprod0x0123c1, vb0123c1x1, va0x1); vprod1x0123c1 = vmlal_s8(vprod1x0123c1, vb0123c1x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1x0); const int8x8_t vb4567c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c1 = vmlal_s8(vprod0x4567c1, vb4567c1x1, va0x1); vprod1x4567c1 = vmlal_s8(vprod1x4567c1, vb4567c1x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); va0x0 = vext_s8(va0x0, va0x0, 2); va0x1 = vext_s8(va0x1, va0x1, 2); va1x0 = vext_s8(va1x0, va1x0, 2); va1x1 = vext_s8(va1x1, va1x1, 2); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1x0); const int8x8_t vb0123c2x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c2 = vmlal_s8(vprod0x0123c2, vb0123c2x1, va0x1); vprod1x0123c2 = vmlal_s8(vprod1x0123c2, vb0123c2x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1x0); const int8x8_t vb4567c2x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c2 = vmlal_s8(vprod0x4567c2, vb4567c2x1, va0x1); vprod1x4567c2 = vmlal_s8(vprod1x4567c2, vb4567c2x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); va0x0 = vext_s8(va0x0, va0x0, 2); va0x1 = vext_s8(va0x1, va0x1, 2); va1x0 = vext_s8(va1x0, va1x0, 2); va1x1 = vext_s8(va1x1, va1x1, 2); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1x0); const int8x8_t vb0123c3x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x0123c3 = vmlal_s8(vprod0x0123c3, vb0123c3x1, va0x1); vprod1x0123c3 = vmlal_s8(vprod1x0123c3, vb0123c3x1, va1x1); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1x0); const int8x8_t vb4567c3x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x4567c3 = vmlal_s8(vprod0x4567c3, vb4567c3x1, va0x1); vprod1x4567c3 = vmlal_s8(vprod1x4567c3, vb4567c3x1, va1x1); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); k -= 16 * sizeof(int8_t); } if (k != 0) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t vb0123c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c2x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb0123c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb4567c3x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0x0, va0x0); int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0); int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0x0, va0x0); int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0); va0x0 = vext_s8(va0x0, va0x0, 2); va1x0 = vext_s8(va1x0, va1x0, 2); int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1x0, va0x0); int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1); int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1x0, va0x0); int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1); va0x0 = vext_s8(va0x0, va0x0, 2); va1x0 = vext_s8(va1x0, va1x0, 2); int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2x0, va0x0); int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2); int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2x0, va0x0); int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2); va0x0 = vext_s8(va0x0, va0x0, 2); va1x0 = vext_s8(va1x0, va1x0, 2); int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3x0, va0x0); int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3x0, va1x0); vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3); vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3); int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3x0, va0x0); int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3x0, va1x0); vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3); vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3); } p -= 2 * 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
13,222
45.396491
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4-minmax-fp32-neon-mlal-dup.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4__neon_mlal_dup( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * 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; } do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int8x8_t va0x0 = vld1_s8(a0); a0 += 8; const int8x8_t va0x1 = vld1_s8(a0); a0 += 8; const int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x0), 0)); const int8x8_t va0c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x1), 0)); const int8x8_t va1c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x0), 0)); const int8x8_t va1c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x1), 0)); int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x0), 1)); const int8x8_t va0c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x1), 1)); const int8x8_t va1c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x0), 1)); const int8x8_t va1c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x1), 1)); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 1)); const int8x8_t va1c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 1)); const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1); const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1); const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1); const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1); const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
17,731
51.306785
128
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4-minmax-fp32-neon-mlal-ld1r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4__neon_mlal_ld1r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * 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; } do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int32x2_t va00x0 = vld1_dup_s32((const void*)a0); const int32x2_t va01x0 = vld1_dup_s32((const void*)(a0 + 4)); a0 += 8; const int32x2_t va00x1 = vld1_dup_s32((const void*)a0); const int32x2_t va01x1 = vld1_dup_s32((const void*)(a0 + 4)); a0 += 8; const int32x2_t va10x0 = vld1_dup_s32((const void*)a1); const int32x2_t va11x0 = vld1_dup_s32((const void*)(a1 + 4)); a1 += 8; const int32x2_t va10x1 = vld1_dup_s32((const void*)a1); const int32x2_t va11x1 = vld1_dup_s32((const void*)(a1 + 4)); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s32(va00x0); const int8x8_t va0c0x1 = vreinterpret_s8_s32(va00x1); const int8x8_t va1c0x0 = vreinterpret_s8_s32(va10x0); const int8x8_t va1c0x1 = vreinterpret_s8_s32(va10x1); int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1x0 = vreinterpret_s8_s32(va01x0); const int8x8_t va0c1x1 = vreinterpret_s8_s32(va01x1); const int8x8_t va1c1x0 = vreinterpret_s8_s32(va11x0); const int8x8_t va1c1x1 = vreinterpret_s8_s32(va11x1); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int32x2_t va00 = vld1_dup_s32((const void*)a0); const int32x2_t va01 = vld1_dup_s32((const void*)(a0 + 4)); a0 += 8; const int32x2_t va10 = vld1_dup_s32((const void*)a1); const int32x2_t va11 = vld1_dup_s32((const void*)(a1 + 4)); a1 += 8; const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(va00); const int8x8_t va1c0 = vreinterpret_s8_s32(va10); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1 = vreinterpret_s8_s32(va01); const int8x8_t va1c1 = vreinterpret_s8_s32(va11); const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1); const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1); const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1); const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1); const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
17,812
50.631884
128
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4-minmax-fp32-neon-mlal-ld2r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4__neon_mlal_ld2r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * 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; } do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int32x2x2_t va0x0 = vld2_dup_s32((const void*)a0); a0 += 8; const int32x2x2_t va0x1 = vld2_dup_s32((const void*)a0); a0 += 8; const int32x2x2_t va1x0 = vld2_dup_s32((const void*)a1); a1 += 8; const int32x2x2_t va1x1 = vld2_dup_s32((const void*)a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s32(va0x0.val[0]); const int8x8_t va0c0x1 = vreinterpret_s8_s32(va0x1.val[0]); const int8x8_t va1c0x0 = vreinterpret_s8_s32(va1x0.val[0]); const int8x8_t va1c0x1 = vreinterpret_s8_s32(va1x1.val[0]); int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1x0 = vreinterpret_s8_s32(va0x0.val[1]); const int8x8_t va0c1x1 = vreinterpret_s8_s32(va0x1.val[1]); const int8x8_t va1c1x0 = vreinterpret_s8_s32(va1x0.val[1]); const int8x8_t va1c1x1 = vreinterpret_s8_s32(va1x1.val[1]); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int32x2x2_t va0 = vld2_dup_s32((const void*)a0); a0 += 8; const int32x2x2_t va1 = vld2_dup_s32((const void*)a1); a1 += 8; const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(va0.val[0]); const int8x8_t va1c0 = vreinterpret_s8_s32(va1.val[0]); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1 = vreinterpret_s8_s32(va0.val[1]); const int8x8_t va1c1 = vreinterpret_s8_s32(va1.val[1]); const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1); const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1); const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1); const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1); const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
17,474
50.548673
128
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4-minmax-fp32-neonv8-mlal-dup.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4__neonv8_mlal_dup( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * 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; } do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int8x8_t va0x0 = vld1_s8(a0); a0 += 8; const int8x8_t va0x1 = vld1_s8(a0); a0 += 8; const int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x0), 0)); const int8x8_t va0c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x1), 0)); const int8x8_t va1c0x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x0), 0)); const int8x8_t va1c0x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x1), 0)); int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x0), 1)); const int8x8_t va0c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0x1), 1)); const int8x8_t va1c1x0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x0), 1)); const int8x8_t va1c1x1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1x1), 1)); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 1)); const int8x8_t va1c1 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 1)); const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1); const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1); const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1); const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1); const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
17,509
50.804734
128
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4-minmax-fp32-neonv8-mlal-ld1r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4__neonv8_mlal_ld1r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * 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; } do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int32x2_t va00x0 = vld1_dup_s32((const void*)a0); const int32x2_t va01x0 = vld1_dup_s32((const void*)(a0 + 4)); a0 += 8; const int32x2_t va00x1 = vld1_dup_s32((const void*)a0); const int32x2_t va01x1 = vld1_dup_s32((const void*)(a0 + 4)); a0 += 8; const int32x2_t va10x0 = vld1_dup_s32((const void*)a1); const int32x2_t va11x0 = vld1_dup_s32((const void*)(a1 + 4)); a1 += 8; const int32x2_t va10x1 = vld1_dup_s32((const void*)a1); const int32x2_t va11x1 = vld1_dup_s32((const void*)(a1 + 4)); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s32(va00x0); const int8x8_t va0c0x1 = vreinterpret_s8_s32(va00x1); const int8x8_t va1c0x0 = vreinterpret_s8_s32(va10x0); const int8x8_t va1c0x1 = vreinterpret_s8_s32(va10x1); int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1x0 = vreinterpret_s8_s32(va01x0); const int8x8_t va0c1x1 = vreinterpret_s8_s32(va01x1); const int8x8_t va1c1x0 = vreinterpret_s8_s32(va11x0); const int8x8_t va1c1x1 = vreinterpret_s8_s32(va11x1); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int32x2_t va00 = vld1_dup_s32((const void*)a0); const int32x2_t va01 = vld1_dup_s32((const void*)(a0 + 4)); a0 += 8; const int32x2_t va10 = vld1_dup_s32((const void*)a1); const int32x2_t va11 = vld1_dup_s32((const void*)(a1 + 4)); a1 += 8; const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(va00); const int8x8_t va1c0 = vreinterpret_s8_s32(va10); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1 = vreinterpret_s8_s32(va01); const int8x8_t va1c1 = vreinterpret_s8_s32(va11); const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1); const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1); const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1); const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1); const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
17,590
50.136628
128
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4-minmax-fp32-neonv8-mlal-ld2r.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-dup.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4__neonv8_mlal_ld2r( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * 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; } do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const void*) ((uintptr_t) w + 2 * sizeof(int32_t)); int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { const int32x2x2_t va0x0 = vld2_dup_s32((const void*)a0); a0 += 8; const int32x2x2_t va0x1 = vld2_dup_s32((const void*)a0); a0 += 8; const int32x2x2_t va1x0 = vld2_dup_s32((const void*)a1); a1 += 8; const int32x2x2_t va1x1 = vld2_dup_s32((const void*)a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0x0 = vreinterpret_s8_s32(va0x0.val[0]); const int8x8_t va0c0x1 = vreinterpret_s8_s32(va0x1.val[0]); const int8x8_t va1c0x0 = vreinterpret_s8_s32(va1x0.val[0]); const int8x8_t va1c0x1 = vreinterpret_s8_s32(va1x1.val[0]); int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0c0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1c0x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0c0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1c0x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0c0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1c0x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0c0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1c0x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0c0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1c0x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0c0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1c0x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0c0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1c0x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0c0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1c0x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1x0 = vreinterpret_s8_s32(va0x0.val[1]); const int8x8_t va0c1x1 = vreinterpret_s8_s32(va0x1.val[1]); const int8x8_t va1c1x0 = vreinterpret_s8_s32(va1x0.val[1]); const int8x8_t va1c1x1 = vreinterpret_s8_s32(va1x1.val[1]); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0c1x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1c1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0c1x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1c1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0c1x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1c1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0c1x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1c1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0c1x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1c1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0c1x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1c1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0c1x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1c1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0c1x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1c1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k >= 8 * sizeof(int8_t)) { const int32x2x2_t va0 = vld2_dup_s32((const void*)a0); a0 += 8; const int32x2x2_t va1 = vld2_dup_s32((const void*)a1); a1 += 8; const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb01c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(va0.val[0]); const int8x8_t va1c0 = vreinterpret_s8_s32(va1.val[0]); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); const int8x8_t va0c1 = vreinterpret_s8_s32(va0.val[1]); const int8x8_t va1c1 = vreinterpret_s8_s32(va1.val[1]); const int16x8_t vprod0x01c1 = vmull_s8(vb01c1, va0c1); const int16x8_t vprod1x01c1 = vmull_s8(vb01c1, va1c1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); const int16x8_t vprod0x23c1 = vmull_s8(vb23c1, va0c1); const int16x8_t vprod1x23c1 = vmull_s8(vb23c1, va1c1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); const int16x8_t vprod0x45c1 = vmull_s8(vb45c1, va0c1); const int16x8_t vprod1x45c1 = vmull_s8(vb45c1, va1c1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); const int16x8_t vprod0x67c1 = vmull_s8(vb67c1, va0c1); const int16x8_t vprod1x67c1 = vmull_s8(vb67c1, va1c1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int8x8_t vb01c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb23c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb45c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t vb67c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int8x8_t va0c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va0), 0)); const int16x8_t vprod0x01c0 = vmull_s8(vb01c0, va0c0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); const int16x8_t vprod0x23c0 = vmull_s8(vb23c0, va0c0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); const int16x8_t vprod0x45c0 = vmull_s8(vb45c0, va0c0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); const int16x8_t vprod0x67c0 = vmull_s8(vb67c0, va0c0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); const int8x8_t va1c0 = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(va1), 0)); const int16x8_t vprod1x01c0 = vmull_s8(vb01c0, va1c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); const int16x8_t vprod1x23c0 = vmull_s8(vb23c0, va1c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); const int16x8_t vprod1x45c0 = vmull_s8(vb45c0, va1c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); const int16x8_t vprod1x67c0 = vmull_s8(vb67c0, va1c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
17,252
50.044379
128
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4s2-minmax-fp32-neon-mlal.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-shuffle.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4s2__neon_mlal( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va0x1 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); va0x0 = vext_s8(va0x0, va0x0, 4); va0x1 = vext_s8(va0x1, va0x1, 4); va1x0 = vext_s8(va1x0, va1x0, 4); va1x1 = vext_s8(va1x1, va1x1, 4); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k != 0) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); va0x0 = vext_s8(va0x0, va0x0, 4); va1x0 = vext_s8(va1x0, va1x0, 4); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32(w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32(w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
13,979
45.912752
125
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c4s2-minmax-fp32-neonv8-mlal.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neon-mull-shuffle.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/gemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c4s2__neonv8_mlal( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); do { int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2; int32x4_t vacc1x01 = vacc0x01; int32x4_t vacc1x23 = vacc0x23; int32x4_t vacc1x45 = vacc0x45; int32x4_t vacc1x67 = vacc0x67; 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); } a += 2; size_t k = kc; while (k >= 16 * sizeof(int8_t)) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va0x1 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0); const int8x8_t vb01c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0x1); vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0); const int8x8_t vb23c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0x1); vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0); const int8x8_t vb45c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0x1); vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0); const int8x8_t vb67c0x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0x1); vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); va0x0 = vext_s8(va0x0, va0x0, 4); va0x1 = vext_s8(va0x1, va0x1, 4); va1x0 = vext_s8(va1x0, va1x0, 4); va1x1 = vext_s8(va1x1, va1x1, 4); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0); const int8x8_t vb01c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0x1); vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1x1); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0); const int8x8_t vb23c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0x1); vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1x1); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0); const int8x8_t vb45c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0x1); vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1x1); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0); const int8x8_t vb67c1x1 = vld1_s8(w); w = (const int8_t*) w + 8; vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0x1); vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1x1); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); k -= 16 * sizeof(int8_t); } if (k != 0) { int8x8_t va0x0 = vld1_s8(a0); a0 += 8; int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8; int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0); int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0); int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0); int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0); int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0); int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0); int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0); int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0); va0x0 = vext_s8(va0x0, va0x0, 4); va1x0 = vext_s8(va1x0, va1x0, 4); int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0); int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0); vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1); vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1); int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0); int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0); vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1); vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1); int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0); int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0); vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1); vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1); int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0); int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0); vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1); vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23); int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67); int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23); int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67); #else const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01)); const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23)); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23); const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45)); const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67)); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67); const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01)); const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23)); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23); const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45)); const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67)); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67); #endif 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); const float32x4_t vscale0123 = vld1q_f32(w); w = (const float*) w + 4; vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32(w); w = (const float*) w + 4; vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
13,757
45.323232
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c8-minmax-fp32-avx2.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx8c8-avx2.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <immintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c8__avx2( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { const __m128i vbias0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); const __m128i vbias0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m256i vacc0x01 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x0), vbias0x1, 1); const __m128i vbias0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); const __m128i vbias0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m256i vacc0x23 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x2), vbias0x3, 1); const __m128i vbias0x4 = _mm_cvtsi32_si128(((const int*) w)[4]); const __m128i vbias0x5 = _mm_cvtsi32_si128(((const int*) w)[5]); __m256i vacc0x45 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x4), vbias0x5, 1); const __m128i vbias0x6 = _mm_cvtsi32_si128(((const int*) w)[6]); const __m128i vbias0x7 = _mm_cvtsi32_si128(((const int*) w)[7]); __m256i vacc0x67 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x6), vbias0x7, 1); __m256i vacc1x01 = vacc0x01; __m256i vacc1x23 = vacc0x23; __m256i vacc1x45 = vacc0x45; __m256i vacc1x67 = vacc0x67; w = (const int32_t*) w + 8; 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); } a += 2; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0)); const __m256i vxa0 = _mm256_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a1)); const __m256i vxa1 = _mm256_cvtepi8_epi16(va1); a1 += 8; const __m128i vb01 = _mm_load_si128((const __m128i*) w); const __m256i vxb01 = _mm256_cvtepi8_epi16(vb01); vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01)); vacc1x01 = _mm256_add_epi32(vacc1x01, _mm256_madd_epi16(vxa1, vxb01)); const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); const __m256i vxb23 = _mm256_cvtepi8_epi16(vb23); vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23)); vacc1x23 = _mm256_add_epi32(vacc1x23, _mm256_madd_epi16(vxa1, vxb23)); const __m128i vb45 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 32)); const __m256i vxb45 = _mm256_cvtepi8_epi16(vb45); vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45)); vacc1x45 = _mm256_add_epi32(vacc1x45, _mm256_madd_epi16(vxa1, vxb45)); const __m128i vb67 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 48)); const __m256i vxb67 = _mm256_cvtepi8_epi16(vb67); vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67)); vacc1x67 = _mm256_add_epi32(vacc1x67, _mm256_madd_epi16(vxa1, vxb67)); w = (const void*) ((const int8_t*) w + 64); k += 8 * sizeof(int8_t); } p -= 2 * sizeof(void*); } while (p != 0); const __m256i vacc0x0213 = _mm256_hadd_epi32(vacc0x01, vacc0x23); const __m256i vacc0x4657 = _mm256_hadd_epi32(vacc0x45, vacc0x67); const __m256i vacc1x0213 = _mm256_hadd_epi32(vacc1x01, vacc1x23); const __m256i vacc1x4657 = _mm256_hadd_epi32(vacc1x45, vacc1x67); const __m256i vacc0x02461357 = _mm256_hadd_epi32(vacc0x0213, vacc0x4657); const __m256i vacc1x02461357 = _mm256_hadd_epi32(vacc1x0213, vacc1x4657); const __m256i vpermute_mask = _mm256_set_epi32(7, 3, 6, 2, 5, 1, 4, 0); __m256i vacc0x01234567 = _mm256_permutevar8x32_epi32(vacc0x02461357, vpermute_mask); __m256i vacc1x01234567 = _mm256_permutevar8x32_epi32(vacc1x02461357, vpermute_mask); __m256 vscaled0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567); __m256 vscaled1x01234567 = _mm256_cvtepi32_ps(vacc1x01234567); const __m256 vscale01234567 = _mm256_load_ps(w); w = (const void*) ((const float*) w + 8); vscaled0x01234567 = _mm256_mul_ps(vscaled0x01234567, vscale01234567); vscaled1x01234567 = _mm256_mul_ps(vscaled1x01234567, vscale01234567); const __m256 voutput_max_less_zero_point = _mm256_load_ps(params->fp32_avx2.output_max_less_zero_point); vscaled0x01234567 = _mm256_min_ps(vscaled0x01234567, voutput_max_less_zero_point); vscaled1x01234567 = _mm256_min_ps(vscaled1x01234567, voutput_max_less_zero_point); vacc0x01234567 = _mm256_cvtps_epi32(vscaled0x01234567); vacc1x01234567 = _mm256_cvtps_epi32(vscaled1x01234567); const __m256i voutput_zero_point = _mm256_load_si256((const __m256i*) params->fp32_avx2.output_zero_point); __m256i vacc01x01234567 = _mm256_adds_epi16(_mm256_packs_epi32(vacc0x01234567, vacc1x01234567), voutput_zero_point); vacc01x01234567 = _mm256_permute4x64_epi64(vacc01x01234567, _MM_SHUFFLE(3, 1, 2, 0)); __m256i vout = _mm256_packs_epi16(vacc01x01234567, vacc01x01234567); vout = _mm256_max_epi8(vout, _mm256_load_si256((const __m256i*) params->fp32_avx2.output_min)); __m128i vout_lo = _mm256_castsi256_si128(vout); __m128i vout_hi = _mm256_extracti128_si256(vout, 1); if (nc >= 8) { _mm_storel_epi64((__m128i*) c1, vout_hi); _mm_storel_epi64((__m128i*) c0, vout_lo); 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) { _mm_storeu_si32(c1, vout_hi); _mm_storeu_si32(c0, vout_lo); c1 += 4; c0 += 4; vout_lo = _mm_srli_epi64(vout_lo, 32); vout_hi = _mm_srli_epi64(vout_hi, 32); } if (nc & 2) { unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout_hi, 0)); unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout_lo, 0)); c1 += 2; c0 += 2; vout_lo = _mm_srli_epi32(vout_lo, 16); vout_hi = _mm_srli_epi32(vout_hi, 16); } if (nc & 1) { *c1 = (int8_t) _mm_extract_epi8(vout_hi, 0); *c0 = (int8_t) _mm_extract_epi8(vout_lo, 0); } nc = 0; } } while (nc != 0); }
7,521
36.989899
120
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c8-minmax-fp32-neon-mlal.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c8-neon-mull.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c8__neon_mlal( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { int32x4_t vacc0x0 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x1 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x2 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x3 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x4 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x5 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x6 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x7 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc1x0 = vacc0x0; int32x4_t vacc1x1 = vacc0x1; int32x4_t vacc1x2 = vacc0x2; int32x4_t vacc1x3 = vacc0x3; int32x4_t vacc1x4 = vacc0x4; int32x4_t vacc1x5 = vacc0x5; int32x4_t vacc1x6 = vacc0x6; int32x4_t vacc1x7 = vacc0x7; 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); } a += 2; size_t k = kc; // 2x partial unrolled loop to load 16 bytes at a time using MLA. while (k >= 16 * sizeof(int8_t)) { const int8x8_t va0x0 = vld1_s8(a0); a0 += 8; const int8x8_t va0x1 = vld1_s8(a0); a0 += 8; const int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb4x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb5x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb6x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb7x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x0 = vmull_s8(vb0x0, va0x0); int16x8_t vprod1x0 = vmull_s8(vb0x0, va1x0); vprod0x0 = vmlal_s8(vprod0x0, vb0x1, va0x1); vprod1x0 = vmlal_s8(vprod1x0, vb0x1, va1x1); vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0); vacc1x0 = vpadalq_s16(vacc1x0, vprod1x0); const int8x8_t vb1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x1 = vmull_s8(vb1x0, va0x0); int16x8_t vprod1x1 = vmull_s8(vb1x0, va1x0); vprod0x1 = vmlal_s8(vprod0x1, vb1x1, va0x1); vprod1x1 = vmlal_s8(vprod1x1, vb1x1, va1x1); vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1); vacc1x1 = vpadalq_s16(vacc1x1, vprod1x1); const int8x8_t vb2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x2 = vmull_s8(vb2x0, va0x0); int16x8_t vprod1x2 = vmull_s8(vb2x0, va1x0); vprod0x2 = vmlal_s8(vprod0x2, vb2x1, va0x1); vprod1x2 = vmlal_s8(vprod1x2, vb2x1, va1x1); vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2); vacc1x2 = vpadalq_s16(vacc1x2, vprod1x2); const int8x8_t vb3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x3 = vmull_s8(vb3x0, va0x0); int16x8_t vprod1x3 = vmull_s8(vb3x0, va1x0); vprod0x3 = vmlal_s8(vprod0x3, vb3x1, va0x1); vprod1x3 = vmlal_s8(vprod1x3, vb3x1, va1x1); vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3); vacc1x3 = vpadalq_s16(vacc1x3, vprod1x3); const int8x8_t vb4x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x4 = vmull_s8(vb4x0, va0x0); int16x8_t vprod1x4 = vmull_s8(vb4x0, va1x0); vprod0x4 = vmlal_s8(vprod0x4, vb4x1, va0x1); vprod1x4 = vmlal_s8(vprod1x4, vb4x1, va1x1); vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4); vacc1x4 = vpadalq_s16(vacc1x4, vprod1x4); const int8x8_t vb5x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x5 = vmull_s8(vb5x0, va0x0); int16x8_t vprod1x5 = vmull_s8(vb5x0, va1x0); vprod0x5 = vmlal_s8(vprod0x5, vb5x1, va0x1); vprod1x5 = vmlal_s8(vprod1x5, vb5x1, va1x1); vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5); vacc1x5 = vpadalq_s16(vacc1x5, vprod1x5); const int8x8_t vb6x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x6 = vmull_s8(vb6x0, va0x0); int16x8_t vprod1x6 = vmull_s8(vb6x0, va1x0); vprod0x6 = vmlal_s8(vprod0x6, vb6x1, va0x1); vprod1x6 = vmlal_s8(vprod1x6, vb6x1, va1x1); vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6); vacc1x6 = vpadalq_s16(vacc1x6, vprod1x6); const int8x8_t vb7x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x7 = vmull_s8(vb7x0, va0x0); int16x8_t vprod1x7 = vmull_s8(vb7x0, va1x0); vprod0x7 = vmlal_s8(vprod0x7, vb7x1, va0x1); vprod1x7 = vmlal_s8(vprod1x7, vb7x1, va1x1); vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7); vacc1x7 = vpadalq_s16(vacc1x7, vprod1x7); k -= 16 * sizeof(int8_t); } // Handle 8 bytes at a time using MUL. if (k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x0 = vmull_s8(vb0, va0); const int16x8_t vprod1x0 = vmull_s8(vb0, va1); vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0); vacc1x0 = vpadalq_s16(vacc1x0, vprod1x0); const int8x8_t vb1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x1 = vmull_s8(vb1, va0); const int16x8_t vprod1x1 = vmull_s8(vb1, va1); vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1); vacc1x1 = vpadalq_s16(vacc1x1, vprod1x1); const int8x8_t vb2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x2 = vmull_s8(vb2, va0); const int16x8_t vprod1x2 = vmull_s8(vb2, va1); vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2); vacc1x2 = vpadalq_s16(vacc1x2, vprod1x2); const int8x8_t vb3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x3 = vmull_s8(vb3, va0); const int16x8_t vprod1x3 = vmull_s8(vb3, va1); vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3); vacc1x3 = vpadalq_s16(vacc1x3, vprod1x3); const int8x8_t vb4 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x4 = vmull_s8(vb4, va0); const int16x8_t vprod1x4 = vmull_s8(vb4, va1); vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4); vacc1x4 = vpadalq_s16(vacc1x4, vprod1x4); const int8x8_t vb5 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x5 = vmull_s8(vb5, va0); const int16x8_t vprod1x5 = vmull_s8(vb5, va1); vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5); vacc1x5 = vpadalq_s16(vacc1x5, vprod1x5); const int8x8_t vb6 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x6 = vmull_s8(vb6, va0); const int16x8_t vprod1x6 = vmull_s8(vb6, va1); vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6); vacc1x6 = vpadalq_s16(vacc1x6, vprod1x6); const int8x8_t vb7 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x7 = vmull_s8(vb7, va0); const int16x8_t vprod1x7 = vmull_s8(vb7, va1); vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7); vacc1x7 = vpadalq_s16(vacc1x7, vprod1x7); k -= 8 * sizeof(int8_t); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 const int32x4_t vsum0x01 = vpaddq_s32(vacc0x0, vacc0x1); const int32x4_t vsum0x23 = vpaddq_s32(vacc0x2, vacc0x3); const int32x4_t vsum0x45 = vpaddq_s32(vacc0x4, vacc0x5); const int32x4_t vsum0x67 = vpaddq_s32(vacc0x6, vacc0x7); const int32x4_t vsum1x01 = vpaddq_s32(vacc1x0, vacc1x1); const int32x4_t vsum1x23 = vpaddq_s32(vacc1x2, vacc1x3); const int32x4_t vsum1x45 = vpaddq_s32(vacc1x4, vacc1x5); const int32x4_t vsum1x67 = vpaddq_s32(vacc1x6, vacc1x7); int32x4_t vacc0x0123 = vpaddq_s32(vsum0x01, vsum0x23); int32x4_t vacc0x4567 = vpaddq_s32(vsum0x45, vsum0x67); int32x4_t vacc1x0123 = vpaddq_s32(vsum1x01, vsum1x23); int32x4_t vacc1x4567 = vpaddq_s32(vsum1x45, vsum1x67); #else const int32x2_t vpsum0x0 = vadd_s32(vget_low_s32(vacc0x0), vget_high_s32(vacc0x0)); const int32x2_t vpsum0x1 = vadd_s32(vget_low_s32(vacc0x1), vget_high_s32(vacc0x1)); const int32x2_t vpsum0x2 = vadd_s32(vget_low_s32(vacc0x2), vget_high_s32(vacc0x2)); const int32x2_t vpsum0x3 = vadd_s32(vget_low_s32(vacc0x3), vget_high_s32(vacc0x3)); const int32x2_t vsum0x01 = vpadd_s32(vpsum0x0, vpsum0x1); const int32x2_t vsum0x23 = vpadd_s32(vpsum0x2, vpsum0x3); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23 ); const int32x2_t vpsum0x4 = vadd_s32(vget_low_s32(vacc0x4), vget_high_s32(vacc0x4)); const int32x2_t vpsum0x5 = vadd_s32(vget_low_s32(vacc0x5), vget_high_s32(vacc0x5)); const int32x2_t vpsum0x6 = vadd_s32(vget_low_s32(vacc0x6), vget_high_s32(vacc0x6)); const int32x2_t vpsum0x7 = vadd_s32(vget_low_s32(vacc0x7), vget_high_s32(vacc0x7)); const int32x2_t vsum0x45 = vpadd_s32(vpsum0x4, vpsum0x5); const int32x2_t vsum0x67 = vpadd_s32(vpsum0x6, vpsum0x7); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67 ); const int32x2_t vpsum1x0 = vadd_s32(vget_low_s32(vacc1x0), vget_high_s32(vacc1x0)); const int32x2_t vpsum1x1 = vadd_s32(vget_low_s32(vacc1x1), vget_high_s32(vacc1x1)); const int32x2_t vpsum1x2 = vadd_s32(vget_low_s32(vacc1x2), vget_high_s32(vacc1x2)); const int32x2_t vpsum1x3 = vadd_s32(vget_low_s32(vacc1x3), vget_high_s32(vacc1x3)); const int32x2_t vsum1x01 = vpadd_s32(vpsum1x0, vpsum1x1); const int32x2_t vsum1x23 = vpadd_s32(vpsum1x2, vpsum1x3); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23 ); const int32x2_t vpsum1x4 = vadd_s32(vget_low_s32(vacc1x4), vget_high_s32(vacc1x4)); const int32x2_t vpsum1x5 = vadd_s32(vget_low_s32(vacc1x5), vget_high_s32(vacc1x5)); const int32x2_t vpsum1x6 = vadd_s32(vget_low_s32(vacc1x6), vget_high_s32(vacc1x6)); const int32x2_t vpsum1x7 = vadd_s32(vget_low_s32(vacc1x7), vget_high_s32(vacc1x7)); const int32x2_t vsum1x45 = vpadd_s32(vpsum1x4, vpsum1x5); const int32x2_t vsum1x67 = vpadd_s32(vpsum1x6, vpsum1x7); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67 ); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
16,451
49.158537
125
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-2x8c8-minmax-fp32-neonv8-mlal.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c8-neon-mull.c.in // Generator: tools/xngen // // 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 <assert.h> #include <arm_neon.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_2x8c8__neonv8_mlal( 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 <= 2); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (2 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * sizeof(int8_t)); int8_t* c0 = c; int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride); if XNN_UNPREDICTABLE(mr != 2) { c1 = c0; } do { int32x4_t vacc0x0 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x1 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x2 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x3 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x4 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x5 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x6 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc0x7 = vld1q_lane_s32(w, vmovq_n_s32(0), 0); w = (const void*) ((uintptr_t) w + sizeof(int32_t)); int32x4_t vacc1x0 = vacc0x0; int32x4_t vacc1x1 = vacc0x1; int32x4_t vacc1x2 = vacc0x2; int32x4_t vacc1x3 = vacc0x3; int32x4_t vacc1x4 = vacc0x4; int32x4_t vacc1x5 = vacc0x5; int32x4_t vacc1x6 = vacc0x6; int32x4_t vacc1x7 = vacc0x7; 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); } a += 2; size_t k = kc; // 2x partial unrolled loop to load 16 bytes at a time using MLA. while (k >= 16 * sizeof(int8_t)) { const int8x8_t va0x0 = vld1_s8(a0); a0 += 8; const int8x8_t va0x1 = vld1_s8(a0); a0 += 8; const int8x8_t va1x0 = vld1_s8(a1); a1 += 8; const int8x8_t va1x1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb1x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb2x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb3x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb4x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb5x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb6x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb7x0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); const int8x8_t vb0x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x0 = vmull_s8(vb0x0, va0x0); int16x8_t vprod1x0 = vmull_s8(vb0x0, va1x0); vprod0x0 = vmlal_s8(vprod0x0, vb0x1, va0x1); vprod1x0 = vmlal_s8(vprod1x0, vb0x1, va1x1); vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0); vacc1x0 = vpadalq_s16(vacc1x0, vprod1x0); const int8x8_t vb1x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x1 = vmull_s8(vb1x0, va0x0); int16x8_t vprod1x1 = vmull_s8(vb1x0, va1x0); vprod0x1 = vmlal_s8(vprod0x1, vb1x1, va0x1); vprod1x1 = vmlal_s8(vprod1x1, vb1x1, va1x1); vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1); vacc1x1 = vpadalq_s16(vacc1x1, vprod1x1); const int8x8_t vb2x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x2 = vmull_s8(vb2x0, va0x0); int16x8_t vprod1x2 = vmull_s8(vb2x0, va1x0); vprod0x2 = vmlal_s8(vprod0x2, vb2x1, va0x1); vprod1x2 = vmlal_s8(vprod1x2, vb2x1, va1x1); vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2); vacc1x2 = vpadalq_s16(vacc1x2, vprod1x2); const int8x8_t vb3x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x3 = vmull_s8(vb3x0, va0x0); int16x8_t vprod1x3 = vmull_s8(vb3x0, va1x0); vprod0x3 = vmlal_s8(vprod0x3, vb3x1, va0x1); vprod1x3 = vmlal_s8(vprod1x3, vb3x1, va1x1); vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3); vacc1x3 = vpadalq_s16(vacc1x3, vprod1x3); const int8x8_t vb4x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x4 = vmull_s8(vb4x0, va0x0); int16x8_t vprod1x4 = vmull_s8(vb4x0, va1x0); vprod0x4 = vmlal_s8(vprod0x4, vb4x1, va0x1); vprod1x4 = vmlal_s8(vprod1x4, vb4x1, va1x1); vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4); vacc1x4 = vpadalq_s16(vacc1x4, vprod1x4); const int8x8_t vb5x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x5 = vmull_s8(vb5x0, va0x0); int16x8_t vprod1x5 = vmull_s8(vb5x0, va1x0); vprod0x5 = vmlal_s8(vprod0x5, vb5x1, va0x1); vprod1x5 = vmlal_s8(vprod1x5, vb5x1, va1x1); vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5); vacc1x5 = vpadalq_s16(vacc1x5, vprod1x5); const int8x8_t vb6x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x6 = vmull_s8(vb6x0, va0x0); int16x8_t vprod1x6 = vmull_s8(vb6x0, va1x0); vprod0x6 = vmlal_s8(vprod0x6, vb6x1, va0x1); vprod1x6 = vmlal_s8(vprod1x6, vb6x1, va1x1); vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6); vacc1x6 = vpadalq_s16(vacc1x6, vprod1x6); const int8x8_t vb7x1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof( int8_t)); int16x8_t vprod0x7 = vmull_s8(vb7x0, va0x0); int16x8_t vprod1x7 = vmull_s8(vb7x0, va1x0); vprod0x7 = vmlal_s8(vprod0x7, vb7x1, va0x1); vprod1x7 = vmlal_s8(vprod1x7, vb7x1, va1x1); vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7); vacc1x7 = vpadalq_s16(vacc1x7, vprod1x7); k -= 16 * sizeof(int8_t); } // Handle 8 bytes at a time using MUL. if (k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int8x8_t vb0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x0 = vmull_s8(vb0, va0); const int16x8_t vprod1x0 = vmull_s8(vb0, va1); vacc0x0 = vpadalq_s16(vacc0x0, vprod0x0); vacc1x0 = vpadalq_s16(vacc1x0, vprod1x0); const int8x8_t vb1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x1 = vmull_s8(vb1, va0); const int16x8_t vprod1x1 = vmull_s8(vb1, va1); vacc0x1 = vpadalq_s16(vacc0x1, vprod0x1); vacc1x1 = vpadalq_s16(vacc1x1, vprod1x1); const int8x8_t vb2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x2 = vmull_s8(vb2, va0); const int16x8_t vprod1x2 = vmull_s8(vb2, va1); vacc0x2 = vpadalq_s16(vacc0x2, vprod0x2); vacc1x2 = vpadalq_s16(vacc1x2, vprod1x2); const int8x8_t vb3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x3 = vmull_s8(vb3, va0); const int16x8_t vprod1x3 = vmull_s8(vb3, va1); vacc0x3 = vpadalq_s16(vacc0x3, vprod0x3); vacc1x3 = vpadalq_s16(vacc1x3, vprod1x3); const int8x8_t vb4 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x4 = vmull_s8(vb4, va0); const int16x8_t vprod1x4 = vmull_s8(vb4, va1); vacc0x4 = vpadalq_s16(vacc0x4, vprod0x4); vacc1x4 = vpadalq_s16(vacc1x4, vprod1x4); const int8x8_t vb5 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x5 = vmull_s8(vb5, va0); const int16x8_t vprod1x5 = vmull_s8(vb5, va1); vacc0x5 = vpadalq_s16(vacc0x5, vprod0x5); vacc1x5 = vpadalq_s16(vacc1x5, vprod1x5); const int8x8_t vb6 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x6 = vmull_s8(vb6, va0); const int16x8_t vprod1x6 = vmull_s8(vb6, va1); vacc0x6 = vpadalq_s16(vacc0x6, vprod0x6); vacc1x6 = vpadalq_s16(vacc1x6, vprod1x6); const int8x8_t vb7 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t)); const int16x8_t vprod0x7 = vmull_s8(vb7, va0); const int16x8_t vprod1x7 = vmull_s8(vb7, va1); vacc0x7 = vpadalq_s16(vacc0x7, vprod0x7); vacc1x7 = vpadalq_s16(vacc1x7, vprod1x7); k -= 8 * sizeof(int8_t); } p -= 2 * sizeof(void*); } while (p != 0); #if XNN_ARCH_ARM64 const int32x4_t vsum0x01 = vpaddq_s32(vacc0x0, vacc0x1); const int32x4_t vsum0x23 = vpaddq_s32(vacc0x2, vacc0x3); const int32x4_t vsum0x45 = vpaddq_s32(vacc0x4, vacc0x5); const int32x4_t vsum0x67 = vpaddq_s32(vacc0x6, vacc0x7); const int32x4_t vsum1x01 = vpaddq_s32(vacc1x0, vacc1x1); const int32x4_t vsum1x23 = vpaddq_s32(vacc1x2, vacc1x3); const int32x4_t vsum1x45 = vpaddq_s32(vacc1x4, vacc1x5); const int32x4_t vsum1x67 = vpaddq_s32(vacc1x6, vacc1x7); int32x4_t vacc0x0123 = vpaddq_s32(vsum0x01, vsum0x23); int32x4_t vacc0x4567 = vpaddq_s32(vsum0x45, vsum0x67); int32x4_t vacc1x0123 = vpaddq_s32(vsum1x01, vsum1x23); int32x4_t vacc1x4567 = vpaddq_s32(vsum1x45, vsum1x67); #else const int32x2_t vpsum0x0 = vadd_s32(vget_low_s32(vacc0x0), vget_high_s32(vacc0x0)); const int32x2_t vpsum0x1 = vadd_s32(vget_low_s32(vacc0x1), vget_high_s32(vacc0x1)); const int32x2_t vpsum0x2 = vadd_s32(vget_low_s32(vacc0x2), vget_high_s32(vacc0x2)); const int32x2_t vpsum0x3 = vadd_s32(vget_low_s32(vacc0x3), vget_high_s32(vacc0x3)); const int32x2_t vsum0x01 = vpadd_s32(vpsum0x0, vpsum0x1); const int32x2_t vsum0x23 = vpadd_s32(vpsum0x2, vpsum0x3); int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23 ); const int32x2_t vpsum0x4 = vadd_s32(vget_low_s32(vacc0x4), vget_high_s32(vacc0x4)); const int32x2_t vpsum0x5 = vadd_s32(vget_low_s32(vacc0x5), vget_high_s32(vacc0x5)); const int32x2_t vpsum0x6 = vadd_s32(vget_low_s32(vacc0x6), vget_high_s32(vacc0x6)); const int32x2_t vpsum0x7 = vadd_s32(vget_low_s32(vacc0x7), vget_high_s32(vacc0x7)); const int32x2_t vsum0x45 = vpadd_s32(vpsum0x4, vpsum0x5); const int32x2_t vsum0x67 = vpadd_s32(vpsum0x6, vpsum0x7); int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67 ); const int32x2_t vpsum1x0 = vadd_s32(vget_low_s32(vacc1x0), vget_high_s32(vacc1x0)); const int32x2_t vpsum1x1 = vadd_s32(vget_low_s32(vacc1x1), vget_high_s32(vacc1x1)); const int32x2_t vpsum1x2 = vadd_s32(vget_low_s32(vacc1x2), vget_high_s32(vacc1x2)); const int32x2_t vpsum1x3 = vadd_s32(vget_low_s32(vacc1x3), vget_high_s32(vacc1x3)); const int32x2_t vsum1x01 = vpadd_s32(vpsum1x0, vpsum1x1); const int32x2_t vsum1x23 = vpadd_s32(vpsum1x2, vpsum1x3); int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23 ); const int32x2_t vpsum1x4 = vadd_s32(vget_low_s32(vacc1x4), vget_high_s32(vacc1x4)); const int32x2_t vpsum1x5 = vadd_s32(vget_low_s32(vacc1x5), vget_high_s32(vacc1x5)); const int32x2_t vpsum1x6 = vadd_s32(vget_low_s32(vacc1x6), vget_high_s32(vacc1x6)); const int32x2_t vpsum1x7 = vadd_s32(vget_low_s32(vacc1x7), vget_high_s32(vacc1x7)); const int32x2_t vsum1x45 = vpadd_s32(vpsum1x4, vpsum1x5); const int32x2_t vsum1x67 = vpadd_s32(vpsum1x6, vpsum1x7); int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67 ); #endif 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vacc0x0123 = vcvtnq_s32_f32(vfpacc0x0123); vacc0x4567 = vcvtnq_s32_f32(vfpacc0x4567); vacc1x0123 = vcvtnq_s32_f32(vfpacc1x0123); vacc1x4567 = vcvtnq_s32_f32(vfpacc1x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4; vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 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; vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
16,229
48.633028
114
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x2-minmax-fp32-scalar-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x2__scalar_fmagic( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
5,866
32.525714
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x2-minmax-fp32-scalar-imagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x2__scalar_imagic( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float vmagic_bias = params->fp32_scalar_imagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0); int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1); int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0); int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1); int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0); int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1); const int32_t vmagic_min = params->fp32_scalar_imagic.magic_min; vout0x0 = math_max_s32(vout0x0, vmagic_min); vout0x1 = math_max_s32(vout0x1, vmagic_min); vout1x0 = math_max_s32(vout1x0, vmagic_min); vout1x1 = math_max_s32(vout1x1, vmagic_min); vout2x0 = math_max_s32(vout2x0, vmagic_min); vout2x1 = math_max_s32(vout2x1, vmagic_min); const int32_t vmagic_max = params->fp32_scalar_imagic.magic_max; vout0x0 = math_min_s32(vout0x0, vmagic_max); vout0x1 = math_min_s32(vout0x1, vmagic_max); vout1x0 = math_min_s32(vout1x0, vmagic_max); vout1x1 = math_min_s32(vout1x1, vmagic_max); vout2x0 = math_min_s32(vout2x0, vmagic_max); vout2x1 = math_min_s32(vout2x1, vmagic_max); const int32_t vmagic_bias_less_zero_point = params->fp32_scalar_imagic.magic_bias_less_zero_point; vout0x0 -= vmagic_bias_less_zero_point; vout0x1 -= vmagic_bias_less_zero_point; vout1x0 -= vmagic_bias_less_zero_point; vout1x1 -= vmagic_bias_less_zero_point; vout2x0 -= vmagic_bias_less_zero_point; vout2x1 -= vmagic_bias_less_zero_point; if XNN_LIKELY(nc >= 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
5,579
29.659341
102
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x2-minmax-fp32-scalar-lrintf.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <math.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x2__scalar_lrintf( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float voutput_min_less_zero_point = params->fp32_scalar_lrintf.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_lrintf.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); const int32_t vrndacc0x0 = (int32_t) lrintf(vfpacc0x0); const int32_t vrndacc0x1 = (int32_t) lrintf(vfpacc0x1); const int32_t vrndacc1x0 = (int32_t) lrintf(vfpacc1x0); const int32_t vrndacc1x1 = (int32_t) lrintf(vfpacc1x1); const int32_t vrndacc2x0 = (int32_t) lrintf(vfpacc2x0); const int32_t vrndacc2x1 = (int32_t) lrintf(vfpacc2x1); const int32_t voutput_zero_point = params->fp32_scalar_lrintf.output_zero_point; int32_t vout0x0 = vrndacc0x0 + voutput_zero_point; int32_t vout0x1 = vrndacc0x1 + voutput_zero_point; int32_t vout1x0 = vrndacc1x0 + voutput_zero_point; int32_t vout1x1 = vrndacc1x1 + voutput_zero_point; int32_t vout2x0 = vrndacc2x0 + voutput_zero_point; int32_t vout2x1 = vrndacc2x1 + voutput_zero_point; if XNN_LIKELY(nc >= 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
5,711
31.64
100
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x2-minmax-fp32-wasm-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x2__wasm_fmagic( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = __builtin_wasm_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = __builtin_wasm_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc1x0 = __builtin_wasm_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = __builtin_wasm_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc2x0 = __builtin_wasm_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = __builtin_wasm_max_f32(vfpacc2x1, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = __builtin_wasm_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = __builtin_wasm_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc1x0 = __builtin_wasm_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = __builtin_wasm_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc2x0 = __builtin_wasm_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = __builtin_wasm_min_f32(vfpacc2x1, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
5,984
33.2
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-scalar-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4__scalar_fmagic( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc0x2 = math_max_f32(vfpacc0x2, voutput_min_less_zero_point); vfpacc0x3 = math_max_f32(vfpacc0x3, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc1x2 = math_max_f32(vfpacc1x2, voutput_min_less_zero_point); vfpacc1x3 = math_max_f32(vfpacc1x3, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc2x2 = math_max_f32(vfpacc2x2, voutput_min_less_zero_point); vfpacc2x3 = math_max_f32(vfpacc2x3, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc0x2 = math_min_f32(vfpacc0x2, voutput_max_less_zero_point); vfpacc0x3 = math_min_f32(vfpacc0x3, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc1x2 = math_min_f32(vfpacc1x2, voutput_max_less_zero_point); vfpacc1x3 = math_min_f32(vfpacc1x3, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc2x2 = math_min_f32(vfpacc2x2, voutput_max_less_zero_point); vfpacc2x3 = math_min_f32(vfpacc2x3, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc0x2 += vmagic_bias; vfpacc0x3 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc1x2 += vmagic_bias; vfpacc1x3 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc2x2 += vmagic_bias; vfpacc2x3 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point; int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point; int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2) - vmagic_bias_less_output_zero_point; int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 4) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
8,963
35.439024
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-scalar-imagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4__scalar_imagic( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float vmagic_bias = params->fp32_scalar_imagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc0x2 += vmagic_bias; vfpacc0x3 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc1x2 += vmagic_bias; vfpacc1x3 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc2x2 += vmagic_bias; vfpacc2x3 += vmagic_bias; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0); int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1); int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2); int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3); int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0); int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1); int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2); int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3); int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0); int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1); int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2); int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3); const int32_t vmagic_min = params->fp32_scalar_imagic.magic_min; vout0x0 = math_max_s32(vout0x0, vmagic_min); vout0x1 = math_max_s32(vout0x1, vmagic_min); vout0x2 = math_max_s32(vout0x2, vmagic_min); vout0x3 = math_max_s32(vout0x3, vmagic_min); vout1x0 = math_max_s32(vout1x0, vmagic_min); vout1x1 = math_max_s32(vout1x1, vmagic_min); vout1x2 = math_max_s32(vout1x2, vmagic_min); vout1x3 = math_max_s32(vout1x3, vmagic_min); vout2x0 = math_max_s32(vout2x0, vmagic_min); vout2x1 = math_max_s32(vout2x1, vmagic_min); vout2x2 = math_max_s32(vout2x2, vmagic_min); vout2x3 = math_max_s32(vout2x3, vmagic_min); const int32_t vmagic_max = params->fp32_scalar_imagic.magic_max; vout0x0 = math_min_s32(vout0x0, vmagic_max); vout0x1 = math_min_s32(vout0x1, vmagic_max); vout0x2 = math_min_s32(vout0x2, vmagic_max); vout0x3 = math_min_s32(vout0x3, vmagic_max); vout1x0 = math_min_s32(vout1x0, vmagic_max); vout1x1 = math_min_s32(vout1x1, vmagic_max); vout1x2 = math_min_s32(vout1x2, vmagic_max); vout1x3 = math_min_s32(vout1x3, vmagic_max); vout2x0 = math_min_s32(vout2x0, vmagic_max); vout2x1 = math_min_s32(vout2x1, vmagic_max); vout2x2 = math_min_s32(vout2x2, vmagic_max); vout2x3 = math_min_s32(vout2x3, vmagic_max); const int32_t vmagic_bias_less_zero_point = params->fp32_scalar_imagic.magic_bias_less_zero_point; vout0x0 -= vmagic_bias_less_zero_point; vout0x1 -= vmagic_bias_less_zero_point; vout0x2 -= vmagic_bias_less_zero_point; vout0x3 -= vmagic_bias_less_zero_point; vout1x0 -= vmagic_bias_less_zero_point; vout1x1 -= vmagic_bias_less_zero_point; vout1x2 -= vmagic_bias_less_zero_point; vout1x3 -= vmagic_bias_less_zero_point; vout2x0 -= vmagic_bias_less_zero_point; vout2x1 -= vmagic_bias_less_zero_point; vout2x2 -= vmagic_bias_less_zero_point; vout2x3 -= vmagic_bias_less_zero_point; if XNN_LIKELY(nc >= 4) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
8,466
31.69112
102
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-scalar-lrintf.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <math.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4__scalar_lrintf( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float voutput_min_less_zero_point = params->fp32_scalar_lrintf.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc0x2 = math_max_f32(vfpacc0x2, voutput_min_less_zero_point); vfpacc0x3 = math_max_f32(vfpacc0x3, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc1x2 = math_max_f32(vfpacc1x2, voutput_min_less_zero_point); vfpacc1x3 = math_max_f32(vfpacc1x3, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc2x2 = math_max_f32(vfpacc2x2, voutput_min_less_zero_point); vfpacc2x3 = math_max_f32(vfpacc2x3, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_lrintf.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc0x2 = math_min_f32(vfpacc0x2, voutput_max_less_zero_point); vfpacc0x3 = math_min_f32(vfpacc0x3, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc1x2 = math_min_f32(vfpacc1x2, voutput_max_less_zero_point); vfpacc1x3 = math_min_f32(vfpacc1x3, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc2x2 = math_min_f32(vfpacc2x2, voutput_max_less_zero_point); vfpacc2x3 = math_min_f32(vfpacc2x3, voutput_max_less_zero_point); const int32_t vrndacc0x0 = (int32_t) lrintf(vfpacc0x0); const int32_t vrndacc0x1 = (int32_t) lrintf(vfpacc0x1); const int32_t vrndacc0x2 = (int32_t) lrintf(vfpacc0x2); const int32_t vrndacc0x3 = (int32_t) lrintf(vfpacc0x3); const int32_t vrndacc1x0 = (int32_t) lrintf(vfpacc1x0); const int32_t vrndacc1x1 = (int32_t) lrintf(vfpacc1x1); const int32_t vrndacc1x2 = (int32_t) lrintf(vfpacc1x2); const int32_t vrndacc1x3 = (int32_t) lrintf(vfpacc1x3); const int32_t vrndacc2x0 = (int32_t) lrintf(vfpacc2x0); const int32_t vrndacc2x1 = (int32_t) lrintf(vfpacc2x1); const int32_t vrndacc2x2 = (int32_t) lrintf(vfpacc2x2); const int32_t vrndacc2x3 = (int32_t) lrintf(vfpacc2x3); const int32_t voutput_zero_point = params->fp32_scalar_lrintf.output_zero_point; int32_t vout0x0 = vrndacc0x0 + voutput_zero_point; int32_t vout0x1 = vrndacc0x1 + voutput_zero_point; int32_t vout0x2 = vrndacc0x2 + voutput_zero_point; int32_t vout0x3 = vrndacc0x3 + voutput_zero_point; int32_t vout1x0 = vrndacc1x0 + voutput_zero_point; int32_t vout1x1 = vrndacc1x1 + voutput_zero_point; int32_t vout1x2 = vrndacc1x2 + voutput_zero_point; int32_t vout1x3 = vrndacc1x3 + voutput_zero_point; int32_t vout2x0 = vrndacc2x0 + voutput_zero_point; int32_t vout2x1 = vrndacc2x1 + voutput_zero_point; int32_t vout2x2 = vrndacc2x2 + voutput_zero_point; int32_t vout2x3 = vrndacc2x3 + voutput_zero_point; if XNN_LIKELY(nc >= 4) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
8,736
34.51626
100
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-wasm-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4__wasm_fmagic( 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)]) { assert(mr != 0); assert(mr <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } a += 3; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = __builtin_wasm_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = __builtin_wasm_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc0x2 = __builtin_wasm_max_f32(vfpacc0x2, voutput_min_less_zero_point); vfpacc0x3 = __builtin_wasm_max_f32(vfpacc0x3, voutput_min_less_zero_point); vfpacc1x0 = __builtin_wasm_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = __builtin_wasm_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc1x2 = __builtin_wasm_max_f32(vfpacc1x2, voutput_min_less_zero_point); vfpacc1x3 = __builtin_wasm_max_f32(vfpacc1x3, voutput_min_less_zero_point); vfpacc2x0 = __builtin_wasm_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = __builtin_wasm_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc2x2 = __builtin_wasm_max_f32(vfpacc2x2, voutput_min_less_zero_point); vfpacc2x3 = __builtin_wasm_max_f32(vfpacc2x3, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = __builtin_wasm_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = __builtin_wasm_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc0x2 = __builtin_wasm_min_f32(vfpacc0x2, voutput_max_less_zero_point); vfpacc0x3 = __builtin_wasm_min_f32(vfpacc0x3, voutput_max_less_zero_point); vfpacc1x0 = __builtin_wasm_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = __builtin_wasm_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc1x2 = __builtin_wasm_min_f32(vfpacc1x2, voutput_max_less_zero_point); vfpacc1x3 = __builtin_wasm_min_f32(vfpacc1x3, voutput_max_less_zero_point); vfpacc2x0 = __builtin_wasm_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = __builtin_wasm_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc2x2 = __builtin_wasm_min_f32(vfpacc2x2, voutput_max_less_zero_point); vfpacc2x3 = __builtin_wasm_min_f32(vfpacc2x3, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc0x2 += vmagic_bias; vfpacc0x3 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc1x2 += vmagic_bias; vfpacc1x3 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc2x2 += vmagic_bias; vfpacc2x3 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point; int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point; int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2) - vmagic_bias_less_output_zero_point; int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 4) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
9,201
36.406504
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-avx-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__avx_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
9,412
38.7173
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-avx-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__avx_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
9,530
38.878661
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-sse2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__sse2_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vsb01 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb01); const __m128i vxb0 = _mm_unpacklo_epi8(vb01, vsb01); const __m128i vxb1 = _mm_unpackhi_epi8(vb01, vsb01); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vsb23 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb23); const __m128i vxb2 = _mm_unpacklo_epi8(vb23, vsb23); const __m128i vxb3 = _mm_unpackhi_epi8(vb23, vsb23); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc22x0123 = _mm_max_epi16(vacc22x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
9,954
40.307054
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-sse2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__sse2_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_srai_epi16(_mm_unpacklo_epi8(vb3, vb3), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc22x0123 = _mm_max_epi16(vacc22x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
10,044
40.680498
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-sse41-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__sse41_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
9,414
38.725738
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-sse41-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__sse41_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
9,532
38.887029
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-wasmsimd-dot16x2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__wasmsimd_dot16x2_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; const v128_t vb01 = wasm_v128_load(w); const v128_t vxb0 = wasm_i16x8_extend_low_i8x16(vb01); const v128_t vxb1 = wasm_i16x8_extend_high_i8x16(vb01); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); const v128_t vb23 = wasm_v128_load((const int8_t*) w + 16); const v128_t vxb2 = wasm_i16x8_extend_low_i8x16(vb23); const v128_t vxb3 = wasm_i16x8_extend_high_i8x16(vb23); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 3, 3, 3, 3), vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 3, 3, 3, 3), vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 3, 3, 3, 3), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const v128_t vxb0 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); if (k > 2 * sizeof(int8_t)) { const v128_t vxb1 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); if (k > 4 * sizeof(int8_t)) { const v128_t vxb2 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc22x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc2x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc22x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
8,851
36.82906
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-wasmsimd-dot16x2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__wasmsimd_dot16x2_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; const v128_t vxb0 = wasm_i16x8_load8x8(w); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 3, 3, 3, 3), vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 3, 3, 3, 3), vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 3, 3, 3, 3), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const v128_t vxb0 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); if (k > 2 * sizeof(int8_t)) { const v128_t vxb1 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); if (k > 4 * sizeof(int8_t)) { const v128_t vxb2 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); } } } p -= 3 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc22x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc2x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc22x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
8,747
36.706897
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-xop-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__xop_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc2x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
9,192
37.145228
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2-minmax-fp32-xop-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2__xop_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 2 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc2x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); } } } p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
9,310
37.316872
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-avx-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__avx_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
6,947
36.354839
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-avx-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__avx_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,065
36.585106
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-sse2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__sse2_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vsb01 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb01); const __m128i vxb0 = _mm_unpacklo_epi8(vb01, vsb01); const __m128i vxb1 = _mm_unpackhi_epi8(vb01, vsb01); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vsb23 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb23); const __m128i vxb2 = _mm_unpacklo_epi8(vb23, vsb23); const __m128i vxb3 = _mm_unpackhi_epi8(vb23, vsb23); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc22x0123 = _mm_max_epi16(vacc22x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
7,345
37.663158
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-sse2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__sse2_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_srai_epi16(_mm_unpacklo_epi8(vb3, vb3), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc22x0123 = _mm_max_epi16(vacc22x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
7,435
38.136842
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-sse41-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__sse41_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
6,949
36.365591
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-sse41-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__sse41_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,067
36.595745
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-wasmsimd-dot16x2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__wasmsimd_dot16x2_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); do { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; const v128_t vb01 = wasm_v128_load(w); const v128_t vxb0 = wasm_i16x8_extend_low_i8x16(vb01); const v128_t vxb1 = wasm_i16x8_extend_high_i8x16(vb01); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb0)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb0)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb0)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb1)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb1)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); const v128_t vb23 = wasm_v128_load((const int8_t*) w + 16); const v128_t vxb2 = wasm_i16x8_extend_low_i8x16(vb23); const v128_t vxb3 = wasm_i16x8_extend_high_i8x16(vb23); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb2)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb2)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb2)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb3)); w = (const int8_t*) w + 32; k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc22x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc2x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc22x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
6,787
34.915344
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-wasmsimd-dot16x2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__wasmsimd_dot16x2_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); do { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; const v128_t vxb0 = wasm_i16x8_load8x8(w); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb0)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb0)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb0)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb1)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb1)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb2)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb2)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb2)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb3)); w = (const int8_t*) w + 32; k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc22x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc2x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc22x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
6,683
34.743316
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-xop-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__xop_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb0, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb0, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb0, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb1, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb1, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb1, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb2, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb2, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb2, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb3, vacc2x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
6,832
34.963158
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c2s4-minmax-fp32-xop-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c2s4__xop_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; w = (const void*) ((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); } 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); } a += 3; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb0, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb0, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb0, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb1, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb1, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb1, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb2, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb2, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb2, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb3, vacc2x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 3 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
6,950
35.203125
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-avx-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__avx_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_load_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0)); vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1)); vacc2x0 = _mm_add_epi32(vacc2x0, _mm_madd_epi16(vxa2, vxb0)); vacc2x1 = _mm_add_epi32(vacc2x1, _mm_madd_epi16(vxa2, vxb1)); const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2)); vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3)); vacc2x2 = _mm_add_epi32(vacc2x2, _mm_madd_epi16(vxa2, vxb2)); vacc2x3 = _mm_add_epi32(vacc2x3, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1); const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3); const __m128i vacc2x01 = _mm_hadd_epi32(vacc2x0, vacc2x1); const __m128i vacc2x23 = _mm_hadd_epi32(vacc2x2, vacc2x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23); __m128i vacc2x0123 = _mm_hadd_epi32(vacc2x01, vacc2x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,201
35.933333
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-avx-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__avx_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0)); vacc2x0 = _mm_add_epi32(vacc2x0, _mm_madd_epi16(vxa2, vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1)); vacc2x1 = _mm_add_epi32(vacc2x1, _mm_madd_epi16(vxa2, vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2)); vacc2x2 = _mm_add_epi32(vacc2x2, _mm_madd_epi16(vxa2, vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3)); vacc2x3 = _mm_add_epi32(vacc2x3, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1); const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3); const __m128i vacc2x01 = _mm_hadd_epi32(vacc2x0, vacc2x1); const __m128i vacc2x23 = _mm_hadd_epi32(vacc2x2, vacc2x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23); __m128i vacc2x0123 = _mm_hadd_epi32(vacc2x01, vacc2x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,323
35.80402
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-sse2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__sse2_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i vb01 = _mm_load_si128((const __m128i*) w); const __m128i vsb01 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb01); const __m128i vxb0 = _mm_unpacklo_epi8(vb01, vsb01); const __m128i vxb1 = _mm_unpackhi_epi8(vb01, vsb01); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0)); vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1)); vacc2x0 = _mm_add_epi32(vacc2x0, _mm_madd_epi16(vxa2, vxb0)); vacc2x1 = _mm_add_epi32(vacc2x1, _mm_madd_epi16(vxa2, vxb1)); const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vsb23 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb23); const __m128i vxb2 = _mm_unpacklo_epi8(vb23, vsb23); const __m128i vxb3 = _mm_unpackhi_epi8(vb23, vsb23); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2)); vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3)); vacc2x2 = _mm_add_epi32(vacc2x2, _mm_madd_epi16(vxa2, vxb2)); vacc2x3 = _mm_add_epi32(vacc2x3, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc0x0, vacc0x2), _mm_unpackhi_epi32(vacc0x0, vacc0x2)); const __m128i vacc0x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc0x1, vacc0x3), _mm_unpackhi_epi32(vacc0x1, vacc0x3)); const __m128i vacc1x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc1x0, vacc1x2), _mm_unpackhi_epi32(vacc1x0, vacc1x2)); const __m128i vacc1x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc1x1, vacc1x3), _mm_unpackhi_epi32(vacc1x1, vacc1x3)); const __m128i vacc2x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc2x0, vacc2x2), _mm_unpackhi_epi32(vacc2x0, vacc2x2)); const __m128i vacc2x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc2x1, vacc2x3), _mm_unpackhi_epi32(vacc2x1, vacc2x3)); __m128i vacc0x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc0x02, vacc0x13), _mm_unpackhi_epi32(vacc0x02, vacc0x13)); __m128i vacc1x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc1x02, vacc1x13), _mm_unpackhi_epi32(vacc1x02, vacc1x13)); __m128i vacc2x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc2x02, vacc2x13), _mm_unpackhi_epi32(vacc2x02, vacc2x13)); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc22x0123 = _mm_max_epi16(vacc22x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
8,118
39.798995
119
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-sse2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__sse2_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0)); vacc2x0 = _mm_add_epi32(vacc2x0, _mm_madd_epi16(vxa2, vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1)); vacc2x1 = _mm_add_epi32(vacc2x1, _mm_madd_epi16(vxa2, vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2)); vacc2x2 = _mm_add_epi32(vacc2x2, _mm_madd_epi16(vxa2, vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_srai_epi16(_mm_unpacklo_epi8(vb3, vb3), 8); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3)); vacc2x3 = _mm_add_epi32(vacc2x3, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc0x0, vacc0x2), _mm_unpackhi_epi32(vacc0x0, vacc0x2)); const __m128i vacc0x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc0x1, vacc0x3), _mm_unpackhi_epi32(vacc0x1, vacc0x3)); const __m128i vacc1x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc1x0, vacc1x2), _mm_unpackhi_epi32(vacc1x0, vacc1x2)); const __m128i vacc1x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc1x1, vacc1x3), _mm_unpackhi_epi32(vacc1x1, vacc1x3)); const __m128i vacc2x02 = _mm_add_epi32(_mm_unpacklo_epi32(vacc2x0, vacc2x2), _mm_unpackhi_epi32(vacc2x0, vacc2x2)); const __m128i vacc2x13 = _mm_add_epi32(_mm_unpacklo_epi32(vacc2x1, vacc2x3), _mm_unpackhi_epi32(vacc2x1, vacc2x3)); __m128i vacc0x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc0x02, vacc0x13), _mm_unpackhi_epi32(vacc0x02, vacc0x13)); __m128i vacc1x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc1x02, vacc1x13), _mm_unpackhi_epi32(vacc1x02, vacc1x13)); __m128i vacc2x0123 = _mm_add_epi32(_mm_unpacklo_epi32(vacc2x02, vacc2x13), _mm_unpackhi_epi32(vacc2x02, vacc2x13)); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc22x0123 = _mm_max_epi16(vacc22x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
8,212
39.860697
119
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-sse41-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__sse41_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_load_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0)); vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1)); vacc2x0 = _mm_add_epi32(vacc2x0, _mm_madd_epi16(vxa2, vxb0)); vacc2x1 = _mm_add_epi32(vacc2x1, _mm_madd_epi16(vxa2, vxb1)); const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2)); vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3)); vacc2x2 = _mm_add_epi32(vacc2x2, _mm_madd_epi16(vxa2, vxb2)); vacc2x3 = _mm_add_epi32(vacc2x3, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1); const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3); const __m128i vacc2x01 = _mm_hadd_epi32(vacc2x0, vacc2x1); const __m128i vacc2x23 = _mm_hadd_epi32(vacc2x2, vacc2x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23); __m128i vacc2x0123 = _mm_hadd_epi32(vacc2x01, vacc2x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,203
35.94359
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-sse41-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__sse41_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0 = _mm_add_epi32(vacc0x0, _mm_madd_epi16(vxa0, vxb0)); vacc1x0 = _mm_add_epi32(vacc1x0, _mm_madd_epi16(vxa1, vxb0)); vacc2x0 = _mm_add_epi32(vacc2x0, _mm_madd_epi16(vxa2, vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x1 = _mm_add_epi32(vacc0x1, _mm_madd_epi16(vxa0, vxb1)); vacc1x1 = _mm_add_epi32(vacc1x1, _mm_madd_epi16(vxa1, vxb1)); vacc2x1 = _mm_add_epi32(vacc2x1, _mm_madd_epi16(vxa2, vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x2 = _mm_add_epi32(vacc0x2, _mm_madd_epi16(vxa0, vxb2)); vacc1x2 = _mm_add_epi32(vacc1x2, _mm_madd_epi16(vxa1, vxb2)); vacc2x2 = _mm_add_epi32(vacc2x2, _mm_madd_epi16(vxa2, vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x3 = _mm_add_epi32(vacc0x3, _mm_madd_epi16(vxa0, vxb3)); vacc1x3 = _mm_add_epi32(vacc1x3, _mm_madd_epi16(vxa1, vxb3)); vacc2x3 = _mm_add_epi32(vacc2x3, _mm_madd_epi16(vxa2, vxb3)); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1); const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3); const __m128i vacc2x01 = _mm_hadd_epi32(vacc2x0, vacc2x1); const __m128i vacc2x23 = _mm_hadd_epi32(vacc2x2, vacc2x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23); __m128i vacc2x0123 = _mm_hadd_epi32(vacc2x01, vacc2x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,325
35.81407
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-xop-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__xop_ld128( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_load_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0 = _mm_maddd_epi16(vxa0, vxb0, vacc0x0); vacc0x1 = _mm_maddd_epi16(vxa0, vxb1, vacc0x1); vacc1x0 = _mm_maddd_epi16(vxa1, vxb0, vacc1x0); vacc1x1 = _mm_maddd_epi16(vxa1, vxb1, vacc1x1); vacc2x0 = _mm_maddd_epi16(vxa2, vxb0, vacc2x0); vacc2x1 = _mm_maddd_epi16(vxa2, vxb1, vacc2x1); const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x2 = _mm_maddd_epi16(vxa0, vxb2, vacc0x2); vacc0x3 = _mm_maddd_epi16(vxa0, vxb3, vacc0x3); vacc1x2 = _mm_maddd_epi16(vxa1, vxb2, vacc1x2); vacc1x3 = _mm_maddd_epi16(vxa1, vxb3, vacc1x3); vacc2x2 = _mm_maddd_epi16(vxa2, vxb2, vacc2x2); vacc2x3 = _mm_maddd_epi16(vxa2, vxb3, vacc2x3); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1); const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3); const __m128i vacc2x01 = _mm_hadd_epi32(vacc2x0, vacc2x1); const __m128i vacc2x23 = _mm_hadd_epi32(vacc2x2, vacc2x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23); __m128i vacc2x0123 = _mm_hadd_epi32(vacc2x01, vacc2x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,086
34.613065
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4c8-minmax-fp32-xop-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c8-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4c8__xop_ld64( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { __m128i vacc0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); __m128i vacc0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m128i vacc0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); __m128i vacc0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m128i vacc1x0 = vacc0x0; __m128i vacc1x1 = vacc0x1; __m128i vacc1x2 = vacc0x2; __m128i vacc1x3 = vacc0x3; __m128i vacc2x0 = vacc0x0; __m128i vacc2x1 = vacc0x1; __m128i vacc2x2 = vacc0x2; __m128i vacc2x3 = vacc0x3; 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); } 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0 = _mm_maddd_epi16(vxa0, vxb0, vacc0x0); vacc1x0 = _mm_maddd_epi16(vxa1, vxb0, vacc1x0); vacc2x0 = _mm_maddd_epi16(vxa2, vxb0, vacc2x0); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x1 = _mm_maddd_epi16(vxa0, vxb1, vacc0x1); vacc1x1 = _mm_maddd_epi16(vxa1, vxb1, vacc1x1); vacc2x1 = _mm_maddd_epi16(vxa2, vxb1, vacc2x1); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x2 = _mm_maddd_epi16(vxa0, vxb2, vacc0x2); vacc1x2 = _mm_maddd_epi16(vxa1, vxb2, vacc1x2); vacc2x2 = _mm_maddd_epi16(vxa2, vxb2, vacc2x2); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x3 = _mm_maddd_epi16(vxa0, vxb3, vacc0x3); vacc1x3 = _mm_maddd_epi16(vxa1, vxb3, vacc1x3); vacc2x3 = _mm_maddd_epi16(vxa2, vxb3, vacc2x3); w = (const void*) ((const int8_t*) w + 32); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m128i vacc0x01 = _mm_hadd_epi32(vacc0x0, vacc0x1); const __m128i vacc0x23 = _mm_hadd_epi32(vacc0x2, vacc0x3); const __m128i vacc1x01 = _mm_hadd_epi32(vacc1x0, vacc1x1); const __m128i vacc1x23 = _mm_hadd_epi32(vacc1x2, vacc1x3); const __m128i vacc2x01 = _mm_hadd_epi32(vacc2x0, vacc2x1); const __m128i vacc2x23 = _mm_hadd_epi32(vacc2x2, vacc2x3); __m128i vacc0x0123 = _mm_hadd_epi32(vacc0x01, vacc0x23); __m128i vacc1x0123 = _mm_hadd_epi32(vacc1x01, vacc1x23); __m128i vacc2x0123 = _mm_hadd_epi32(vacc2x01, vacc2x23); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); const __m128 vscale0123 = _mm_load_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc22x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc2x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc22x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
7,208
34.512315
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x8-minmax-fp32-neon-mlal-lane-prfm.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/neon-mlal-lane.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/igemm.h> #include <xnnpack/prefetch.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x8__neon_mlal_lane_prfm( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 += 8; const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); xnn_prefetch_to_l1((const int8_t*) w + 448); const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa2), 3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); if (k >= 2 * sizeof(int8_t)) { const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); if (k >= 4 * sizeof(int8_t)) { const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); if (k >= 6 * sizeof(int8_t)) { const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); if (k > 6 * sizeof(int8_t)) { const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); } } } } } } } p -= 3 * sizeof(void*); } while (p != 0); // Post-accumulation work 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); vacc2x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc2x0123, vmagic_bias)); vacc2x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc2x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); vacc2x0123 = vqsubq_s32(vacc2x0123, vmagic_bias_less_output_zero_point); vacc2x4567 = vqsubq_s32(vacc2x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min)); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max)); if (nc >= 8) { vst1_s8(c2 + 0, vout2x01234567); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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) { vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1_lane_s8(c2, vout2x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
20,331
56.435028
125
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x8-minmax-fp32-neon-mlal-lane.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/neon-mlal-lane.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/igemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x8__neon_mlal_lane( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 += 8; const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa2), 3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); if (k >= 2 * sizeof(int8_t)) { const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); if (k >= 4 * sizeof(int8_t)) { const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); if (k >= 6 * sizeof(int8_t)) { const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); if (k > 6 * sizeof(int8_t)) { const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); } } } } } } } p -= 3 * sizeof(void*); } while (p != 0); // Post-accumulation work 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, vscale4567); const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias); vacc0x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x0123, vmagic_bias)); vacc0x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0x4567, vmagic_bias)); vacc1x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x0123, vmagic_bias)); vacc1x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc1x4567, vmagic_bias)); vacc2x0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc2x0123, vmagic_bias)); vacc2x4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc2x4567, vmagic_bias)); const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point); vacc0x0123 = vqsubq_s32(vacc0x0123, vmagic_bias_less_output_zero_point); vacc0x4567 = vqsubq_s32(vacc0x4567, vmagic_bias_less_output_zero_point); vacc1x0123 = vqsubq_s32(vacc1x0123, vmagic_bias_less_output_zero_point); vacc1x4567 = vqsubq_s32(vacc1x4567, vmagic_bias_less_output_zero_point); vacc2x0123 = vqsubq_s32(vacc2x0123, vmagic_bias_less_output_zero_point); vacc2x4567 = vqsubq_s32(vacc2x4567, vmagic_bias_less_output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neon.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min)); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neon.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max)); if (nc >= 8) { vst1_s8(c2 + 0, vout2x01234567); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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) { vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1_lane_s8(c2, vout2x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
20,243
56.511364
125
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x8-minmax-fp32-neonv8-mlal-lane-prfm.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/neon-mlal-lane.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/prefetch.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x8__neonv8_mlal_lane_prfm( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 += 8; const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); xnn_prefetch_to_l1((const int8_t*) w + 448); const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa2), 3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); if (k >= 2 * sizeof(int8_t)) { const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); if (k >= 4 * sizeof(int8_t)) { const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); if (k >= 6 * sizeof(int8_t)) { const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); if (k > 6 * sizeof(int8_t)) { const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); } } } } } } } p -= 3 * sizeof(void*); } while (p != 0); // Post-accumulation work 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, 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); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min)); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max)); if (nc >= 8) { vst1_s8(c2 + 0, vout2x01234567); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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) { vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1_lane_s8(c2, vout2x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
20,031
55.747875
114
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x8-minmax-fp32-neonv8-mlal-lane.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/neon-mlal-lane.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x8__neonv8_mlal_lane( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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; } do { int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4); int32x4_t vacc1x0123 = vacc0x0123; int32x4_t vacc1x4567 = vacc0x4567; int32x4_t vacc2x0123 = vacc0x0123; int32x4_t vacc2x4567 = 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); } a += 3; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 += 8; const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa2), 3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); if (k >= 2 * sizeof(int8_t)) { const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); if (k >= 4 * sizeof(int8_t)) { const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); if (k >= 6 * sizeof(int8_t)) { const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); if (k > 6 * sizeof(int8_t)) { const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); } } } } } } } p -= 3 * sizeof(void*); } while (p != 0); // Post-accumulation work 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); const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x0123 = vmulq_f32(vfpacc0x0123, vscale0123); vfpacc1x0123 = vmulq_f32(vfpacc1x0123, vscale0123); vfpacc2x0123 = vmulq_f32(vfpacc2x0123, vscale0123); const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4); vfpacc0x4567 = vmulq_f32(vfpacc0x4567, vscale4567); vfpacc1x4567 = vmulq_f32(vfpacc1x4567, vscale4567); vfpacc2x4567 = vmulq_f32(vfpacc2x4567, 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); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #else int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567)); int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min)); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max)); if (nc >= 8) { vst1_s8(c2 + 0, vout2x01234567); vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567)); vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567)); 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) { vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 4); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4); } if (nc & 2) { vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 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 = vext_s8(vout2x01234567, vout2x01234567, 2); vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2); } if (nc & 1) { vst1_lane_s8(c2, vout2x01234567, 0); vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8); vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0); } nc = 0; } } while (nc != 0); }
19,943
55.820513
114
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x8c8-minmax-fp32-avx2.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx8c8-avx2.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <immintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x8c8__avx2( 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 <= 3); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (3 * sizeof(void*)) == 0); assert(a_offset % sizeof(int8_t) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); kc = round_up_po2(kc, 8 * 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; } do { const __m128i vbias0x0 = _mm_cvtsi32_si128(((const int*) w)[0]); const __m128i vbias0x1 = _mm_cvtsi32_si128(((const int*) w)[1]); __m256i vacc0x01 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x0), vbias0x1, 1); const __m128i vbias0x2 = _mm_cvtsi32_si128(((const int*) w)[2]); const __m128i vbias0x3 = _mm_cvtsi32_si128(((const int*) w)[3]); __m256i vacc0x23 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x2), vbias0x3, 1); const __m128i vbias0x4 = _mm_cvtsi32_si128(((const int*) w)[4]); const __m128i vbias0x5 = _mm_cvtsi32_si128(((const int*) w)[5]); __m256i vacc0x45 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x4), vbias0x5, 1); const __m128i vbias0x6 = _mm_cvtsi32_si128(((const int*) w)[6]); const __m128i vbias0x7 = _mm_cvtsi32_si128(((const int*) w)[7]); __m256i vacc0x67 = _mm256_inserti128_si256(_mm256_castsi128_si256(vbias0x6), vbias0x7, 1); __m256i vacc1x01 = vacc0x01; __m256i vacc1x23 = vacc0x23; __m256i vacc1x45 = vacc0x45; __m256i vacc1x67 = vacc0x67; __m256i vacc2x01 = vacc0x01; __m256i vacc2x23 = vacc0x23; __m256i vacc2x45 = vacc0x45; __m256i vacc2x67 = vacc0x67; w = (const int32_t*) w + 8; 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); } a += 3; size_t k = 0; while (k < kc) { const __m128i va0 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a0)); const __m256i vxa0 = _mm256_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a1)); const __m256i vxa1 = _mm256_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_broadcastq_epi64(_mm_loadl_epi64((const __m128i*) a2)); const __m256i vxa2 = _mm256_cvtepi8_epi16(va2); a2 += 8; const __m128i vb01 = _mm_load_si128((const __m128i*) w); const __m256i vxb01 = _mm256_cvtepi8_epi16(vb01); vacc0x01 = _mm256_add_epi32(vacc0x01, _mm256_madd_epi16(vxa0, vxb01)); vacc1x01 = _mm256_add_epi32(vacc1x01, _mm256_madd_epi16(vxa1, vxb01)); vacc2x01 = _mm256_add_epi32(vacc2x01, _mm256_madd_epi16(vxa2, vxb01)); const __m128i vb23 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 16)); const __m256i vxb23 = _mm256_cvtepi8_epi16(vb23); vacc0x23 = _mm256_add_epi32(vacc0x23, _mm256_madd_epi16(vxa0, vxb23)); vacc1x23 = _mm256_add_epi32(vacc1x23, _mm256_madd_epi16(vxa1, vxb23)); vacc2x23 = _mm256_add_epi32(vacc2x23, _mm256_madd_epi16(vxa2, vxb23)); const __m128i vb45 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 32)); const __m256i vxb45 = _mm256_cvtepi8_epi16(vb45); vacc0x45 = _mm256_add_epi32(vacc0x45, _mm256_madd_epi16(vxa0, vxb45)); vacc1x45 = _mm256_add_epi32(vacc1x45, _mm256_madd_epi16(vxa1, vxb45)); vacc2x45 = _mm256_add_epi32(vacc2x45, _mm256_madd_epi16(vxa2, vxb45)); const __m128i vb67 = _mm_load_si128((const __m128i*) ((const int8_t*) w + 48)); const __m256i vxb67 = _mm256_cvtepi8_epi16(vb67); vacc0x67 = _mm256_add_epi32(vacc0x67, _mm256_madd_epi16(vxa0, vxb67)); vacc1x67 = _mm256_add_epi32(vacc1x67, _mm256_madd_epi16(vxa1, vxb67)); vacc2x67 = _mm256_add_epi32(vacc2x67, _mm256_madd_epi16(vxa2, vxb67)); w = (const void*) ((const int8_t*) w + 64); k += 8 * sizeof(int8_t); } p -= 3 * sizeof(void*); } while (p != 0); const __m256i vacc0x0213 = _mm256_hadd_epi32(vacc0x01, vacc0x23); const __m256i vacc0x4657 = _mm256_hadd_epi32(vacc0x45, vacc0x67); const __m256i vacc1x0213 = _mm256_hadd_epi32(vacc1x01, vacc1x23); const __m256i vacc1x4657 = _mm256_hadd_epi32(vacc1x45, vacc1x67); const __m256i vacc2x0213 = _mm256_hadd_epi32(vacc2x01, vacc2x23); const __m256i vacc2x4657 = _mm256_hadd_epi32(vacc2x45, vacc2x67); const __m256i vacc0x02461357 = _mm256_hadd_epi32(vacc0x0213, vacc0x4657); const __m256i vacc1x02461357 = _mm256_hadd_epi32(vacc1x0213, vacc1x4657); const __m256i vacc2x02461357 = _mm256_hadd_epi32(vacc2x0213, vacc2x4657); const __m256i vpermute_mask = _mm256_set_epi32(7, 3, 6, 2, 5, 1, 4, 0); __m256i vacc0x01234567 = _mm256_permutevar8x32_epi32(vacc0x02461357, vpermute_mask); __m256i vacc1x01234567 = _mm256_permutevar8x32_epi32(vacc1x02461357, vpermute_mask); __m256i vacc2x01234567 = _mm256_permutevar8x32_epi32(vacc2x02461357, vpermute_mask); __m256 vscaled0x01234567 = _mm256_cvtepi32_ps(vacc0x01234567); __m256 vscaled1x01234567 = _mm256_cvtepi32_ps(vacc1x01234567); __m256 vscaled2x01234567 = _mm256_cvtepi32_ps(vacc2x01234567); const __m256 vscale01234567 = _mm256_load_ps(w); w = (const void*) ((const float*) w + 8); vscaled0x01234567 = _mm256_mul_ps(vscaled0x01234567, vscale01234567); vscaled1x01234567 = _mm256_mul_ps(vscaled1x01234567, vscale01234567); vscaled2x01234567 = _mm256_mul_ps(vscaled2x01234567, vscale01234567); const __m256 voutput_max_less_zero_point = _mm256_load_ps(params->fp32_avx2.output_max_less_zero_point); vscaled0x01234567 = _mm256_min_ps(vscaled0x01234567, voutput_max_less_zero_point); vscaled1x01234567 = _mm256_min_ps(vscaled1x01234567, voutput_max_less_zero_point); vscaled2x01234567 = _mm256_min_ps(vscaled2x01234567, voutput_max_less_zero_point); vacc0x01234567 = _mm256_cvtps_epi32(vscaled0x01234567); vacc1x01234567 = _mm256_cvtps_epi32(vscaled1x01234567); vacc2x01234567 = _mm256_cvtps_epi32(vscaled2x01234567); const __m256i voutput_zero_point = _mm256_load_si256((const __m256i*) params->fp32_avx2.output_zero_point); __m256i vacc01x01234567 = _mm256_adds_epi16(_mm256_packs_epi32(vacc0x01234567, vacc1x01234567), voutput_zero_point); __m256i vacc22x01234567 = _mm256_adds_epi16(_mm256_packs_epi32(vacc2x01234567, vacc2x01234567), voutput_zero_point); vacc01x01234567 = _mm256_permute4x64_epi64(vacc01x01234567, _MM_SHUFFLE(3, 1, 2, 0)); vacc22x01234567 = _mm256_permute4x64_epi64(vacc22x01234567, _MM_SHUFFLE(3, 1, 2, 0)); __m256i vout = _mm256_packs_epi16(vacc01x01234567, vacc22x01234567); vout = _mm256_max_epi8(vout, _mm256_load_si256((const __m256i*) params->fp32_avx2.output_min)); __m128i vout_lo = _mm256_castsi256_si128(vout); __m128i vout_hi = _mm256_extracti128_si256(vout, 1); if (nc >= 8) { _mm_storeh_pi((__m64*) c2, _mm_castsi128_ps(vout_lo)); _mm_storel_epi64((__m128i*) c1, vout_hi); _mm_storel_epi64((__m128i*) c0, vout_lo); 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) { unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout_lo, 2)); _mm_storeu_si32(c1, vout_hi); _mm_storeu_si32(c0, vout_lo); c2 += 4; c1 += 4; c0 += 4; vout_lo = _mm_srli_epi64(vout_lo, 32); vout_hi = _mm_srli_epi64(vout_hi, 32); } if (nc & 2) { unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout_lo, 4)); unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout_hi, 0)); unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout_lo, 0)); c2 += 2; c1 += 2; c0 += 2; vout_lo = _mm_srli_epi32(vout_lo, 16); vout_hi = _mm_srli_epi32(vout_hi, 16); } if (nc & 1) { *c2 = (int8_t) _mm_extract_epi8(vout_lo, 8); *c1 = (int8_t) _mm_extract_epi8(vout_hi, 0); *c0 = (int8_t) _mm_extract_epi8(vout_lo, 0); } nc = 0; } } while (nc != 0); }
9,537
39.760684
120
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x16c4-minmax-fp32-neondot.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neondot.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> 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(&params->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(&params->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->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); }
18,211
52.881657
130
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x2-minmax-fp32-scalar-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x2__scalar_fmagic( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc3x0 = math_max_f32(vfpacc3x0, voutput_min_less_zero_point); vfpacc3x1 = math_max_f32(vfpacc3x1, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc3x0 = math_min_f32(vfpacc3x0, voutput_max_less_zero_point); vfpacc3x1 = math_min_f32(vfpacc3x1, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc3x0 += vmagic_bias; vfpacc3x1 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0) - vmagic_bias_less_output_zero_point; int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
7,125
33.760976
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x2-minmax-fp32-scalar-imagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x2__scalar_imagic( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float vmagic_bias = params->fp32_scalar_imagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc3x0 += vmagic_bias; vfpacc3x1 += vmagic_bias; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0); int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1); int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0); int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1); int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0); int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1); int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0); int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1); const int32_t vmagic_min = params->fp32_scalar_imagic.magic_min; vout0x0 = math_max_s32(vout0x0, vmagic_min); vout0x1 = math_max_s32(vout0x1, vmagic_min); vout1x0 = math_max_s32(vout1x0, vmagic_min); vout1x1 = math_max_s32(vout1x1, vmagic_min); vout2x0 = math_max_s32(vout2x0, vmagic_min); vout2x1 = math_max_s32(vout2x1, vmagic_min); vout3x0 = math_max_s32(vout3x0, vmagic_min); vout3x1 = math_max_s32(vout3x1, vmagic_min); const int32_t vmagic_max = params->fp32_scalar_imagic.magic_max; vout0x0 = math_min_s32(vout0x0, vmagic_max); vout0x1 = math_min_s32(vout0x1, vmagic_max); vout1x0 = math_min_s32(vout1x0, vmagic_max); vout1x1 = math_min_s32(vout1x1, vmagic_max); vout2x0 = math_min_s32(vout2x0, vmagic_max); vout2x1 = math_min_s32(vout2x1, vmagic_max); vout3x0 = math_min_s32(vout3x0, vmagic_max); vout3x1 = math_min_s32(vout3x1, vmagic_max); const int32_t vmagic_bias_less_zero_point = params->fp32_scalar_imagic.magic_bias_less_zero_point; vout0x0 -= vmagic_bias_less_zero_point; vout0x1 -= vmagic_bias_less_zero_point; vout1x0 -= vmagic_bias_less_zero_point; vout1x1 -= vmagic_bias_less_zero_point; vout2x0 -= vmagic_bias_less_zero_point; vout2x1 -= vmagic_bias_less_zero_point; vout3x0 -= vmagic_bias_less_zero_point; vout3x1 -= vmagic_bias_less_zero_point; if XNN_LIKELY(nc >= 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
6,768
30.630841
102
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x2-minmax-fp32-scalar-lrintf.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <math.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x2__scalar_lrintf( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float voutput_min_less_zero_point = params->fp32_scalar_lrintf.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc3x0 = math_max_f32(vfpacc3x0, voutput_min_less_zero_point); vfpacc3x1 = math_max_f32(vfpacc3x1, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_lrintf.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc3x0 = math_min_f32(vfpacc3x0, voutput_max_less_zero_point); vfpacc3x1 = math_min_f32(vfpacc3x1, voutput_max_less_zero_point); const int32_t vrndacc0x0 = (int32_t) lrintf(vfpacc0x0); const int32_t vrndacc0x1 = (int32_t) lrintf(vfpacc0x1); const int32_t vrndacc1x0 = (int32_t) lrintf(vfpacc1x0); const int32_t vrndacc1x1 = (int32_t) lrintf(vfpacc1x1); const int32_t vrndacc2x0 = (int32_t) lrintf(vfpacc2x0); const int32_t vrndacc2x1 = (int32_t) lrintf(vfpacc2x1); const int32_t vrndacc3x0 = (int32_t) lrintf(vfpacc3x0); const int32_t vrndacc3x1 = (int32_t) lrintf(vfpacc3x1); const int32_t voutput_zero_point = params->fp32_scalar_lrintf.output_zero_point; int32_t vout0x0 = vrndacc0x0 + voutput_zero_point; int32_t vout0x1 = vrndacc0x1 + voutput_zero_point; int32_t vout1x0 = vrndacc1x0 + voutput_zero_point; int32_t vout1x1 = vrndacc1x1 + voutput_zero_point; int32_t vout2x0 = vrndacc2x0 + voutput_zero_point; int32_t vout2x1 = vrndacc2x1 + voutput_zero_point; int32_t vout3x0 = vrndacc3x0 + voutput_zero_point; int32_t vout3x1 = vrndacc3x1 + voutput_zero_point; if XNN_LIKELY(nc >= 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
6,946
32.887805
100
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x2-minmax-fp32-wasm-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x2__wasm_fmagic( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = unaligned_indexed_load_s32(w, 0); int32_t vacc0x1 = unaligned_indexed_load_s32(w, 1); int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; w = (const void*) ((const int32_t*) w + 2); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; w = (const void*) ((const int8_t*) w + 2); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; const float vscale0 = unaligned_indexed_load_f32(w, 0); vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = unaligned_indexed_load_f32(w, 1); vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; w = (const void*) ((const float*) w + 2); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = __builtin_wasm_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = __builtin_wasm_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc1x0 = __builtin_wasm_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = __builtin_wasm_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc2x0 = __builtin_wasm_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = __builtin_wasm_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc3x0 = __builtin_wasm_max_f32(vfpacc3x0, voutput_min_less_zero_point); vfpacc3x1 = __builtin_wasm_max_f32(vfpacc3x1, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = __builtin_wasm_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = __builtin_wasm_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc1x0 = __builtin_wasm_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = __builtin_wasm_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc2x0 = __builtin_wasm_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = __builtin_wasm_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc3x0 = __builtin_wasm_min_f32(vfpacc3x0, voutput_max_less_zero_point); vfpacc3x1 = __builtin_wasm_min_f32(vfpacc3x1, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc3x0 += vmagic_bias; vfpacc3x1 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0) - vmagic_bias_less_output_zero_point; int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; 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 -= 2; } else { if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
7,283
34.531707
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4-minmax-fp32-scalar-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4__scalar_fmagic( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; int32_t vacc3x2 = vacc0x2; int32_t vacc3x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; vacc3x2 += va3 * vb2; vacc3x3 += va3 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; float vfpacc3x2 = (float) vacc3x2; float vfpacc3x3 = (float) vacc3x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; vfpacc3x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; vfpacc3x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc0x2 = math_max_f32(vfpacc0x2, voutput_min_less_zero_point); vfpacc0x3 = math_max_f32(vfpacc0x3, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc1x2 = math_max_f32(vfpacc1x2, voutput_min_less_zero_point); vfpacc1x3 = math_max_f32(vfpacc1x3, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc2x2 = math_max_f32(vfpacc2x2, voutput_min_less_zero_point); vfpacc2x3 = math_max_f32(vfpacc2x3, voutput_min_less_zero_point); vfpacc3x0 = math_max_f32(vfpacc3x0, voutput_min_less_zero_point); vfpacc3x1 = math_max_f32(vfpacc3x1, voutput_min_less_zero_point); vfpacc3x2 = math_max_f32(vfpacc3x2, voutput_min_less_zero_point); vfpacc3x3 = math_max_f32(vfpacc3x3, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc0x2 = math_min_f32(vfpacc0x2, voutput_max_less_zero_point); vfpacc0x3 = math_min_f32(vfpacc0x3, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc1x2 = math_min_f32(vfpacc1x2, voutput_max_less_zero_point); vfpacc1x3 = math_min_f32(vfpacc1x3, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc2x2 = math_min_f32(vfpacc2x2, voutput_max_less_zero_point); vfpacc2x3 = math_min_f32(vfpacc2x3, voutput_max_less_zero_point); vfpacc3x0 = math_min_f32(vfpacc3x0, voutput_max_less_zero_point); vfpacc3x1 = math_min_f32(vfpacc3x1, voutput_max_less_zero_point); vfpacc3x2 = math_min_f32(vfpacc3x2, voutput_max_less_zero_point); vfpacc3x3 = math_min_f32(vfpacc3x3, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc0x2 += vmagic_bias; vfpacc0x3 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc1x2 += vmagic_bias; vfpacc1x3 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc2x2 += vmagic_bias; vfpacc2x3 += vmagic_bias; vfpacc3x0 += vmagic_bias; vfpacc3x1 += vmagic_bias; vfpacc3x2 += vmagic_bias; vfpacc3x3 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point; int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point; int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2) - vmagic_bias_less_output_zero_point; int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3) - vmagic_bias_less_output_zero_point; int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0) - vmagic_bias_less_output_zero_point; int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1) - vmagic_bias_less_output_zero_point; int32_t vout3x2 = (int32_t) float_as_uint32(vfpacc3x2) - vmagic_bias_less_output_zero_point; int32_t vout3x3 = (int32_t) float_as_uint32(vfpacc3x3) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 4) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c3[2] = (int8_t) vout3x2; c3[3] = (int8_t) vout3x3; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; vout3x0 = vout3x2; c3 += 2; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
11,184
36.533557
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4-minmax-fp32-scalar-imagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4__scalar_imagic( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; int32_t vacc3x2 = vacc0x2; int32_t vacc3x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; vacc3x2 += va3 * vb2; vacc3x3 += va3 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; float vfpacc3x2 = (float) vacc3x2; float vfpacc3x3 = (float) vacc3x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; vfpacc3x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; vfpacc3x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float vmagic_bias = params->fp32_scalar_imagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc0x2 += vmagic_bias; vfpacc0x3 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc1x2 += vmagic_bias; vfpacc1x3 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc2x2 += vmagic_bias; vfpacc2x3 += vmagic_bias; vfpacc3x0 += vmagic_bias; vfpacc3x1 += vmagic_bias; vfpacc3x2 += vmagic_bias; vfpacc3x3 += vmagic_bias; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0); int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1); int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2); int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3); int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0); int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1); int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2); int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3); int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0); int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1); int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2); int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3); int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0); int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1); int32_t vout3x2 = (int32_t) float_as_uint32(vfpacc3x2); int32_t vout3x3 = (int32_t) float_as_uint32(vfpacc3x3); const int32_t vmagic_min = params->fp32_scalar_imagic.magic_min; vout0x0 = math_max_s32(vout0x0, vmagic_min); vout0x1 = math_max_s32(vout0x1, vmagic_min); vout0x2 = math_max_s32(vout0x2, vmagic_min); vout0x3 = math_max_s32(vout0x3, vmagic_min); vout1x0 = math_max_s32(vout1x0, vmagic_min); vout1x1 = math_max_s32(vout1x1, vmagic_min); vout1x2 = math_max_s32(vout1x2, vmagic_min); vout1x3 = math_max_s32(vout1x3, vmagic_min); vout2x0 = math_max_s32(vout2x0, vmagic_min); vout2x1 = math_max_s32(vout2x1, vmagic_min); vout2x2 = math_max_s32(vout2x2, vmagic_min); vout2x3 = math_max_s32(vout2x3, vmagic_min); vout3x0 = math_max_s32(vout3x0, vmagic_min); vout3x1 = math_max_s32(vout3x1, vmagic_min); vout3x2 = math_max_s32(vout3x2, vmagic_min); vout3x3 = math_max_s32(vout3x3, vmagic_min); const int32_t vmagic_max = params->fp32_scalar_imagic.magic_max; vout0x0 = math_min_s32(vout0x0, vmagic_max); vout0x1 = math_min_s32(vout0x1, vmagic_max); vout0x2 = math_min_s32(vout0x2, vmagic_max); vout0x3 = math_min_s32(vout0x3, vmagic_max); vout1x0 = math_min_s32(vout1x0, vmagic_max); vout1x1 = math_min_s32(vout1x1, vmagic_max); vout1x2 = math_min_s32(vout1x2, vmagic_max); vout1x3 = math_min_s32(vout1x3, vmagic_max); vout2x0 = math_min_s32(vout2x0, vmagic_max); vout2x1 = math_min_s32(vout2x1, vmagic_max); vout2x2 = math_min_s32(vout2x2, vmagic_max); vout2x3 = math_min_s32(vout2x3, vmagic_max); vout3x0 = math_min_s32(vout3x0, vmagic_max); vout3x1 = math_min_s32(vout3x1, vmagic_max); vout3x2 = math_min_s32(vout3x2, vmagic_max); vout3x3 = math_min_s32(vout3x3, vmagic_max); const int32_t vmagic_bias_less_zero_point = params->fp32_scalar_imagic.magic_bias_less_zero_point; vout0x0 -= vmagic_bias_less_zero_point; vout0x1 -= vmagic_bias_less_zero_point; vout0x2 -= vmagic_bias_less_zero_point; vout0x3 -= vmagic_bias_less_zero_point; vout1x0 -= vmagic_bias_less_zero_point; vout1x1 -= vmagic_bias_less_zero_point; vout1x2 -= vmagic_bias_less_zero_point; vout1x3 -= vmagic_bias_less_zero_point; vout2x0 -= vmagic_bias_less_zero_point; vout2x1 -= vmagic_bias_less_zero_point; vout2x2 -= vmagic_bias_less_zero_point; vout2x3 -= vmagic_bias_less_zero_point; vout3x0 -= vmagic_bias_less_zero_point; vout3x1 -= vmagic_bias_less_zero_point; vout3x2 -= vmagic_bias_less_zero_point; vout3x3 -= vmagic_bias_less_zero_point; if XNN_LIKELY(nc >= 4) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c3[2] = (int8_t) vout3x2; c3[3] = (int8_t) vout3x3; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; vout3x0 = vout3x2; c3 += 2; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
10,547
32.485714
102
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4-minmax-fp32-scalar-lrintf.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <math.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4__scalar_lrintf( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; int32_t vacc3x2 = vacc0x2; int32_t vacc3x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; vacc3x2 += va3 * vb2; vacc3x3 += va3 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; float vfpacc3x2 = (float) vacc3x2; float vfpacc3x3 = (float) vacc3x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; vfpacc3x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; vfpacc3x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float voutput_min_less_zero_point = params->fp32_scalar_lrintf.output_min_less_zero_point; vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc0x2 = math_max_f32(vfpacc0x2, voutput_min_less_zero_point); vfpacc0x3 = math_max_f32(vfpacc0x3, voutput_min_less_zero_point); vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc1x2 = math_max_f32(vfpacc1x2, voutput_min_less_zero_point); vfpacc1x3 = math_max_f32(vfpacc1x3, voutput_min_less_zero_point); vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc2x2 = math_max_f32(vfpacc2x2, voutput_min_less_zero_point); vfpacc2x3 = math_max_f32(vfpacc2x3, voutput_min_less_zero_point); vfpacc3x0 = math_max_f32(vfpacc3x0, voutput_min_less_zero_point); vfpacc3x1 = math_max_f32(vfpacc3x1, voutput_min_less_zero_point); vfpacc3x2 = math_max_f32(vfpacc3x2, voutput_min_less_zero_point); vfpacc3x3 = math_max_f32(vfpacc3x3, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_lrintf.output_max_less_zero_point; vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc0x2 = math_min_f32(vfpacc0x2, voutput_max_less_zero_point); vfpacc0x3 = math_min_f32(vfpacc0x3, voutput_max_less_zero_point); vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc1x2 = math_min_f32(vfpacc1x2, voutput_max_less_zero_point); vfpacc1x3 = math_min_f32(vfpacc1x3, voutput_max_less_zero_point); vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc2x2 = math_min_f32(vfpacc2x2, voutput_max_less_zero_point); vfpacc2x3 = math_min_f32(vfpacc2x3, voutput_max_less_zero_point); vfpacc3x0 = math_min_f32(vfpacc3x0, voutput_max_less_zero_point); vfpacc3x1 = math_min_f32(vfpacc3x1, voutput_max_less_zero_point); vfpacc3x2 = math_min_f32(vfpacc3x2, voutput_max_less_zero_point); vfpacc3x3 = math_min_f32(vfpacc3x3, voutput_max_less_zero_point); const int32_t vrndacc0x0 = (int32_t) lrintf(vfpacc0x0); const int32_t vrndacc0x1 = (int32_t) lrintf(vfpacc0x1); const int32_t vrndacc0x2 = (int32_t) lrintf(vfpacc0x2); const int32_t vrndacc0x3 = (int32_t) lrintf(vfpacc0x3); const int32_t vrndacc1x0 = (int32_t) lrintf(vfpacc1x0); const int32_t vrndacc1x1 = (int32_t) lrintf(vfpacc1x1); const int32_t vrndacc1x2 = (int32_t) lrintf(vfpacc1x2); const int32_t vrndacc1x3 = (int32_t) lrintf(vfpacc1x3); const int32_t vrndacc2x0 = (int32_t) lrintf(vfpacc2x0); const int32_t vrndacc2x1 = (int32_t) lrintf(vfpacc2x1); const int32_t vrndacc2x2 = (int32_t) lrintf(vfpacc2x2); const int32_t vrndacc2x3 = (int32_t) lrintf(vfpacc2x3); const int32_t vrndacc3x0 = (int32_t) lrintf(vfpacc3x0); const int32_t vrndacc3x1 = (int32_t) lrintf(vfpacc3x1); const int32_t vrndacc3x2 = (int32_t) lrintf(vfpacc3x2); const int32_t vrndacc3x3 = (int32_t) lrintf(vfpacc3x3); const int32_t voutput_zero_point = params->fp32_scalar_lrintf.output_zero_point; int32_t vout0x0 = vrndacc0x0 + voutput_zero_point; int32_t vout0x1 = vrndacc0x1 + voutput_zero_point; int32_t vout0x2 = vrndacc0x2 + voutput_zero_point; int32_t vout0x3 = vrndacc0x3 + voutput_zero_point; int32_t vout1x0 = vrndacc1x0 + voutput_zero_point; int32_t vout1x1 = vrndacc1x1 + voutput_zero_point; int32_t vout1x2 = vrndacc1x2 + voutput_zero_point; int32_t vout1x3 = vrndacc1x3 + voutput_zero_point; int32_t vout2x0 = vrndacc2x0 + voutput_zero_point; int32_t vout2x1 = vrndacc2x1 + voutput_zero_point; int32_t vout2x2 = vrndacc2x2 + voutput_zero_point; int32_t vout2x3 = vrndacc2x3 + voutput_zero_point; int32_t vout3x0 = vrndacc3x0 + voutput_zero_point; int32_t vout3x1 = vrndacc3x1 + voutput_zero_point; int32_t vout3x2 = vrndacc3x2 + voutput_zero_point; int32_t vout3x3 = vrndacc3x3 + voutput_zero_point; if XNN_LIKELY(nc >= 4) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c3[2] = (int8_t) vout3x2; c3[3] = (int8_t) vout3x3; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; vout3x0 = vout3x2; c3 += 2; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
10,909
35.610738
100
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4-minmax-fp32-wasm-fmagic.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/scalar.c.in // Generator: tools/xngen // // 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 <assert.h> #include <xnnpack/math.h> #include <xnnpack/gemm.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4__wasm_fmagic( 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)]) { assert(mr != 0); assert(mr <= 4); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (4 * sizeof(void*)) == 0); assert(a != NULL); assert(w != NULL); assert(c != NULL); 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 { int32_t vacc0x0 = ((const int32_t*) w)[0]; int32_t vacc0x1 = ((const int32_t*) w)[1]; int32_t vacc0x2 = ((const int32_t*) w)[2]; int32_t vacc0x3 = ((const int32_t*) w)[3]; int32_t vacc1x0 = vacc0x0; int32_t vacc1x1 = vacc0x1; int32_t vacc1x2 = vacc0x2; int32_t vacc1x3 = vacc0x3; int32_t vacc2x0 = vacc0x0; int32_t vacc2x1 = vacc0x1; int32_t vacc2x2 = vacc0x2; int32_t vacc2x3 = vacc0x3; int32_t vacc3x0 = vacc0x0; int32_t vacc3x1 = vacc0x1; int32_t vacc3x2 = vacc0x2; int32_t vacc3x3 = vacc0x3; w = (const void*) ((const int32_t*) w + 4); size_t p = ks; do { const int8_t* restrict a0 = a[0]; assert(a0 != NULL); if XNN_UNPREDICTABLE(a0 != zero) { a0 = (const int8_t*) ((uintptr_t) a0 + a_offset); } const int8_t* restrict a1 = a[1]; assert(a1 != NULL); if XNN_UNPREDICTABLE(a1 != zero) { a1 = (const int8_t*) ((uintptr_t) a1 + a_offset); } const int8_t* restrict a2 = a[2]; assert(a2 != NULL); if XNN_UNPREDICTABLE(a2 != zero) { a2 = (const int8_t*) ((uintptr_t) a2 + a_offset); } const int8_t* restrict a3 = a[3]; assert(a3 != NULL); if XNN_UNPREDICTABLE(a3 != zero) { a3 = (const int8_t*) ((uintptr_t) a3 + a_offset); } a += 4; size_t k = kc; do { const int32_t va0 = (int32_t) *a0++; const int32_t va1 = (int32_t) *a1++; const int32_t va2 = (int32_t) *a2++; const int32_t va3 = (int32_t) *a3++; const int32_t vb0 = (int32_t) ((const int8_t*) w)[0]; const int32_t vb1 = (int32_t) ((const int8_t*) w)[1]; const int32_t vb2 = (int32_t) ((const int8_t*) w)[2]; const int32_t vb3 = (int32_t) ((const int8_t*) w)[3]; w = (const void*) ((const int8_t*) w + 4); vacc0x0 += va0 * vb0; vacc0x1 += va0 * vb1; vacc0x2 += va0 * vb2; vacc0x3 += va0 * vb3; vacc1x0 += va1 * vb0; vacc1x1 += va1 * vb1; vacc1x2 += va1 * vb2; vacc1x3 += va1 * vb3; vacc2x0 += va2 * vb0; vacc2x1 += va2 * vb1; vacc2x2 += va2 * vb2; vacc2x3 += va2 * vb3; vacc3x0 += va3 * vb0; vacc3x1 += va3 * vb1; vacc3x2 += va3 * vb2; vacc3x3 += va3 * vb3; k -= sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); float vfpacc0x0 = (float) vacc0x0; float vfpacc0x1 = (float) vacc0x1; float vfpacc0x2 = (float) vacc0x2; float vfpacc0x3 = (float) vacc0x3; float vfpacc1x0 = (float) vacc1x0; float vfpacc1x1 = (float) vacc1x1; float vfpacc1x2 = (float) vacc1x2; float vfpacc1x3 = (float) vacc1x3; float vfpacc2x0 = (float) vacc2x0; float vfpacc2x1 = (float) vacc2x1; float vfpacc2x2 = (float) vacc2x2; float vfpacc2x3 = (float) vacc2x3; float vfpacc3x0 = (float) vacc3x0; float vfpacc3x1 = (float) vacc3x1; float vfpacc3x2 = (float) vacc3x2; float vfpacc3x3 = (float) vacc3x3; const float vscale0 = ((const float*) w)[0]; vfpacc0x0 *= vscale0; vfpacc1x0 *= vscale0; vfpacc2x0 *= vscale0; vfpacc3x0 *= vscale0; const float vscale1 = ((const float*) w)[1]; vfpacc0x1 *= vscale1; vfpacc1x1 *= vscale1; vfpacc2x1 *= vscale1; vfpacc3x1 *= vscale1; const float vscale2 = ((const float*) w)[2]; vfpacc0x2 *= vscale2; vfpacc1x2 *= vscale2; vfpacc2x2 *= vscale2; vfpacc3x2 *= vscale2; const float vscale3 = ((const float*) w)[3]; vfpacc0x3 *= vscale3; vfpacc1x3 *= vscale3; vfpacc2x3 *= vscale3; vfpacc3x3 *= vscale3; w = (const void*) ((const float*) w + 4); const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point; vfpacc0x0 = __builtin_wasm_max_f32(vfpacc0x0, voutput_min_less_zero_point); vfpacc0x1 = __builtin_wasm_max_f32(vfpacc0x1, voutput_min_less_zero_point); vfpacc0x2 = __builtin_wasm_max_f32(vfpacc0x2, voutput_min_less_zero_point); vfpacc0x3 = __builtin_wasm_max_f32(vfpacc0x3, voutput_min_less_zero_point); vfpacc1x0 = __builtin_wasm_max_f32(vfpacc1x0, voutput_min_less_zero_point); vfpacc1x1 = __builtin_wasm_max_f32(vfpacc1x1, voutput_min_less_zero_point); vfpacc1x2 = __builtin_wasm_max_f32(vfpacc1x2, voutput_min_less_zero_point); vfpacc1x3 = __builtin_wasm_max_f32(vfpacc1x3, voutput_min_less_zero_point); vfpacc2x0 = __builtin_wasm_max_f32(vfpacc2x0, voutput_min_less_zero_point); vfpacc2x1 = __builtin_wasm_max_f32(vfpacc2x1, voutput_min_less_zero_point); vfpacc2x2 = __builtin_wasm_max_f32(vfpacc2x2, voutput_min_less_zero_point); vfpacc2x3 = __builtin_wasm_max_f32(vfpacc2x3, voutput_min_less_zero_point); vfpacc3x0 = __builtin_wasm_max_f32(vfpacc3x0, voutput_min_less_zero_point); vfpacc3x1 = __builtin_wasm_max_f32(vfpacc3x1, voutput_min_less_zero_point); vfpacc3x2 = __builtin_wasm_max_f32(vfpacc3x2, voutput_min_less_zero_point); vfpacc3x3 = __builtin_wasm_max_f32(vfpacc3x3, voutput_min_less_zero_point); const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point; vfpacc0x0 = __builtin_wasm_min_f32(vfpacc0x0, voutput_max_less_zero_point); vfpacc0x1 = __builtin_wasm_min_f32(vfpacc0x1, voutput_max_less_zero_point); vfpacc0x2 = __builtin_wasm_min_f32(vfpacc0x2, voutput_max_less_zero_point); vfpacc0x3 = __builtin_wasm_min_f32(vfpacc0x3, voutput_max_less_zero_point); vfpacc1x0 = __builtin_wasm_min_f32(vfpacc1x0, voutput_max_less_zero_point); vfpacc1x1 = __builtin_wasm_min_f32(vfpacc1x1, voutput_max_less_zero_point); vfpacc1x2 = __builtin_wasm_min_f32(vfpacc1x2, voutput_max_less_zero_point); vfpacc1x3 = __builtin_wasm_min_f32(vfpacc1x3, voutput_max_less_zero_point); vfpacc2x0 = __builtin_wasm_min_f32(vfpacc2x0, voutput_max_less_zero_point); vfpacc2x1 = __builtin_wasm_min_f32(vfpacc2x1, voutput_max_less_zero_point); vfpacc2x2 = __builtin_wasm_min_f32(vfpacc2x2, voutput_max_less_zero_point); vfpacc2x3 = __builtin_wasm_min_f32(vfpacc2x3, voutput_max_less_zero_point); vfpacc3x0 = __builtin_wasm_min_f32(vfpacc3x0, voutput_max_less_zero_point); vfpacc3x1 = __builtin_wasm_min_f32(vfpacc3x1, voutput_max_less_zero_point); vfpacc3x2 = __builtin_wasm_min_f32(vfpacc3x2, voutput_max_less_zero_point); vfpacc3x3 = __builtin_wasm_min_f32(vfpacc3x3, voutput_max_less_zero_point); const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias; vfpacc0x0 += vmagic_bias; vfpacc0x1 += vmagic_bias; vfpacc0x2 += vmagic_bias; vfpacc0x3 += vmagic_bias; vfpacc1x0 += vmagic_bias; vfpacc1x1 += vmagic_bias; vfpacc1x2 += vmagic_bias; vfpacc1x3 += vmagic_bias; vfpacc2x0 += vmagic_bias; vfpacc2x1 += vmagic_bias; vfpacc2x2 += vmagic_bias; vfpacc2x3 += vmagic_bias; vfpacc3x0 += vmagic_bias; vfpacc3x1 += vmagic_bias; vfpacc3x2 += vmagic_bias; vfpacc3x3 += vmagic_bias; const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_output_zero_point; int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point; int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point; int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point; int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point; int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point; int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point; int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point; int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point; int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point; int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point; int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2) - vmagic_bias_less_output_zero_point; int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3) - vmagic_bias_less_output_zero_point; int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0) - vmagic_bias_less_output_zero_point; int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1) - vmagic_bias_less_output_zero_point; int32_t vout3x2 = (int32_t) float_as_uint32(vfpacc3x2) - vmagic_bias_less_output_zero_point; int32_t vout3x3 = (int32_t) float_as_uint32(vfpacc3x3) - vmagic_bias_less_output_zero_point; if XNN_LIKELY(nc >= 4) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; c3[2] = (int8_t) vout3x2; c3[3] = (int8_t) vout3x3; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; c2[2] = (int8_t) vout2x2; c2[3] = (int8_t) vout2x3; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; c1[2] = (int8_t) vout1x2; c1[3] = (int8_t) vout1x3; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; c0[2] = (int8_t) vout0x2; c0[3] = (int8_t) vout0x3; 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 -= 4; } else { if (nc & 2) { c3[0] = (int8_t) vout3x0; c3[1] = (int8_t) vout3x1; vout3x0 = vout3x2; c3 += 2; c2[0] = (int8_t) vout2x0; c2[1] = (int8_t) vout2x1; vout2x0 = vout2x2; c2 += 2; c1[0] = (int8_t) vout1x0; c1[1] = (int8_t) vout1x1; vout1x0 = vout1x2; c1 += 2; c0[0] = (int8_t) vout0x0; c0[1] = (int8_t) vout0x1; vout0x0 = vout0x2; c0 += 2; } if (nc & 1) { c3[0] = (int8_t) vout3x0; c2[0] = (int8_t) vout2x0; c1[0] = (int8_t) vout1x0; c0[0] = (int8_t) vout0x0; } nc = 0; } } while (nc != 0); }
11,502
37.600671
116
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-avx-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__avx_ld128( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
11,431
40.570909
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-avx-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__avx_ld64( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
11,549
40.696751
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-sse2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__sse2_ld128( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_srai_epi16(_mm_unpacklo_epi8(va3, va3), 8); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vsb01 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb01); const __m128i vxb0 = _mm_unpacklo_epi8(vb01, vsb01); const __m128i vxb1 = _mm_unpackhi_epi8(vb01, vsb01); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vsb23 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb23); const __m128i vxb2 = _mm_unpacklo_epi8(vb23, vsb23); const __m128i vxb3 = _mm_unpackhi_epi8(vb23, vsb23); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_srai_epi16(_mm_unpacklo_epi8(va3, va3), 8); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc23x0123 = _mm_max_epi16(vacc23x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(3, 3, 3, 3)))); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi16(vout, 6); *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
12,062
42.236559
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-sse2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__sse2_ld64( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_srai_epi16(_mm_unpacklo_epi8(va3, va3), 8); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_srai_epi16(_mm_unpacklo_epi8(vb3, vb3), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_srai_epi16(_mm_unpacklo_epi8(va3, va3), 8); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc23x0123 = _mm_max_epi16(vacc23x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(3, 3, 3, 3)))); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi16(vout, 6); *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
12,152
42.55914
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-sse41-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__sse41_ld128( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
11,433
40.578182
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-sse41-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__sse41_ld64( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0)); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1)); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(_mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
11,551
40.703971
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-wasmsimd-dot16x2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__wasmsimd_dot16x2_ld128( 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, 2 * 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 { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; v128_t vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; const v128_t vxa3 = wasm_i16x8_load8x8(a3); a3 += 8; const v128_t vb01 = wasm_v128_load(w); const v128_t vxb0 = wasm_i16x8_extend_low_i8x16(vb01); const v128_t vxb1 = wasm_i16x8_extend_high_i8x16(vb01); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 0, 0, 0, 0), vxb0)); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 1, 1, 1, 1), vxb1)); const v128_t vb23 = wasm_v128_load((const int8_t*) w + 16); const v128_t vxb2 = wasm_i16x8_extend_low_i8x16(vb23); const v128_t vxb3 = wasm_i16x8_extend_high_i8x16(vb23); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 2, 2, 2, 2), vxb2)); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 3, 3, 3, 3), vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 3, 3, 3, 3), vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 3, 3, 3, 3), vxb3)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 3, 3, 3, 3), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const v128_t vxa3 = wasm_i16x8_load8x8(a3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const v128_t vxb0 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 0, 0, 0, 0), vxb0)); if (k > 2 * sizeof(int8_t)) { const v128_t vxb1 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 1, 1, 1, 1), vxb1)); if (k > 4 * sizeof(int8_t)) { const v128_t vxb2 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 2, 2, 2, 2), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); vacc3x0123 = wasm_f32x4_convert_i32x4(vacc3x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); vacc3x0123 = wasm_f32x4_mul(vacc3x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); vacc3x0123 = wasm_f32x4_add(vacc3x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); vacc3x0123 = wasm_i32x4_max(vacc3x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); vacc3x0123 = wasm_i32x4_sub(vacc3x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc23x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc3x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc23x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c3, vout, 3); wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c3, vout, 6); c3 += 2; wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c3, vout, 12); wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
10,750
38.671587
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-wasmsimd-dot16x2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__wasmsimd_dot16x2_ld64( 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, 2 * 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 { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; v128_t vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; const v128_t vxa3 = wasm_i16x8_load8x8(a3); a3 += 8; const v128_t vxb0 = wasm_i16x8_load8x8(w); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 0, 0, 0, 0), vxb0)); const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 1, 1, 1, 1), vxb1)); const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 2, 2, 2, 2), vxb2)); const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 3, 3, 3, 3), vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 3, 3, 3, 3), vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 3, 3, 3, 3), vxb3)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 3, 3, 3, 3), vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const v128_t vxa3 = wasm_i16x8_load8x8(a3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const v128_t vxb0 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 0, 0, 0, 0), vxb0)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 0, 0, 0, 0), vxb0)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 0, 0, 0, 0), vxb0)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 0, 0, 0, 0), vxb0)); if (k > 2 * sizeof(int8_t)) { const v128_t vxb1 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 1, 1, 1, 1), vxb1)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 1, 1, 1, 1), vxb1)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 1, 1, 1, 1), vxb1)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 1, 1, 1, 1), vxb1)); if (k > 4 * sizeof(int8_t)) { const v128_t vxb2 = wasm_i16x8_load8x8(w); w = (const void*) ((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa0, vxa0, 2, 2, 2, 2), vxb2)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa1, vxa1, 2, 2, 2, 2), vxb2)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa2, vxa2, 2, 2, 2, 2), vxb2)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(wasm_v32x4_shuffle(vxa3, vxa3, 2, 2, 2, 2), vxb2)); } } } p -= 4 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); vacc3x0123 = wasm_f32x4_convert_i32x4(vacc3x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); vacc3x0123 = wasm_f32x4_mul(vacc3x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); vacc3x0123 = wasm_f32x4_add(vacc3x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); vacc3x0123 = wasm_i32x4_max(vacc3x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); vacc3x0123 = wasm_i32x4_sub(vacc3x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc23x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc3x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc23x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c3, vout, 3); wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c3, vout, 6); c3 += 2; wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c3, vout, 12); wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
10,646
38.579926
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-xop-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__xop_ld128( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc3x0123); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc3x0123); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc3x0123); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc3x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc3x0123); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc3x0123); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc3x0123); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
11,120
38.860215
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2-minmax-fp32-xop-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2-sse.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2__xop_ld64( 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, 2 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc3x0123); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc3x0123); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc3x0123); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(3, 3, 3, 3)), vxb3, vacc3x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } if (k != 0) { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); const __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); const __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); const __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); const __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 0, 0, 0)), vxb0, vacc3x0123); if (k > 2 * sizeof(int8_t)) { const __m128i vb1 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(1, 1, 1, 1)), vxb1, vacc3x0123); if (k > 4 * sizeof(int8_t)) { const __m128i vb2 = _mm_loadl_epi64((const __m128i*) w); w = (const void*) ((const int8_t*) w + 8); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc0x0123); vacc1x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc1x0123); vacc2x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc2x0123); vacc3x0123 = _mm_maddd_epi16( _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(2, 2, 2, 2)), vxb2, vacc3x0123); } } } p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
11,238
38.996441
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-avx-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__avx_ld128( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb0)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb1)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb2)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
8,367
38.102804
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-avx-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__avx_ld64( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb0)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb1)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb2)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
8,485
38.287037
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-sse2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__sse2_ld128( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_srai_epi16(_mm_unpacklo_epi8(va3, va3), 8); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vsb01 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb01); const __m128i vxb0 = _mm_unpacklo_epi8(vb01, vsb01); const __m128i vxb1 = _mm_unpackhi_epi8(vb01, vsb01); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb0)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb1)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vsb23 = _mm_cmpgt_epi8(_mm_setzero_si128(), vb23); const __m128i vxb2 = _mm_unpacklo_epi8(vb23, vsb23); const __m128i vxb3 = _mm_unpackhi_epi8(vb23, vsb23); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb2)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc23x0123 = _mm_max_epi16(vacc23x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(3, 3, 3, 3)))); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi16(vout, 6); *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
8,830
39.509174
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-sse2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <emmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__sse2_ld64( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_srai_epi16(_mm_unpacklo_epi8(va0, va0), 8); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_srai_epi16(_mm_unpacklo_epi8(va1, va1), 8); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_srai_epi16(_mm_unpacklo_epi8(va2, va2), 8); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_srai_epi16(_mm_unpacklo_epi8(va3, va3), 8); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_srai_epi16(_mm_unpacklo_epi8(vb0, vb0), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb0)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_srai_epi16(_mm_unpacklo_epi8(vb1, vb1), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb1)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_srai_epi16(_mm_unpacklo_epi8(vb2, vb2), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb2)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_srai_epi16(_mm_unpacklo_epi8(vb3, vb3), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse2.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse2.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); const __m128i voutput_min = _mm_load_si128((const __m128i*) params->fp32_sse2.output_min); vacc01x0123 = _mm_max_epi16(vacc01x0123, voutput_min); vacc23x0123 = _mm_max_epi16(vacc23x0123, voutput_min); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(3, 3, 3, 3)))); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(2, 2, 2, 2)))); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_cvtsi128_si32(_mm_shuffle_epi32(vout, _MM_SHUFFLE(1, 1, 1, 1)))); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi16(vout, 6); *c2 = (int8_t) _mm_extract_epi16(vout, 4); *c1 = (int8_t) _mm_extract_epi16(vout, 2); *c0 = (int8_t) _mm_cvtsi128_si32(vout); } nc = 0; } } while (nc != 0); }
8,920
39.922018
110
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-sse41-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__sse41_ld128( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb0)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb1)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb2)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
8,369
38.11215
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-sse41-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #include <smmintrin.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__sse41_ld64( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb0)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb0)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb0)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb0)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb1)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb1)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb1)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb1)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb2)); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb2)); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb2)); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb2)); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_add_epi32(vacc0x0123, _mm_madd_epi16(vxa0, vxb3)); vacc1x0123 = _mm_add_epi32(vacc1x0123, _mm_madd_epi16(vxa1, vxb3)); vacc2x0123 = _mm_add_epi32(vacc2x0123, _mm_madd_epi16(vxa2, vxb3)); vacc3x0123 = _mm_add_epi32(vacc3x0123, _mm_madd_epi16(vxa3, vxb3)); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
8,487
38.296296
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-wasmsimd-dot16x2-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__wasmsimd_dot16x2_ld128( 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); 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; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); do { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; v128_t vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; v128_t vxa3 = wasm_i16x8_load8x8(a3); a3 += 8; const v128_t vb01 = wasm_v128_load(w); const v128_t vxb0 = wasm_i16x8_extend_low_i8x16(vb01); const v128_t vxb1 = wasm_i16x8_extend_high_i8x16(vb01); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb0)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb0)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb0)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb0)); vxa3 = wasm_v32x4_shuffle(vxa3, vxa3, 1, 2, 3, 4); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb1)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb1)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb1)); vxa3 = wasm_v32x4_shuffle(vxa3, vxa3, 1, 2, 3, 4); const v128_t vb23 = wasm_v128_load((const int8_t*) w + 16); const v128_t vxb2 = wasm_i16x8_extend_low_i8x16(vb23); const v128_t vxb3 = wasm_i16x8_extend_high_i8x16(vb23); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb2)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb2)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb2)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb2)); vxa3 = wasm_v32x4_shuffle(vxa3, vxa3, 1, 2, 3, 4); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb3)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb3)); w = (const int8_t*) w + 32; k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); vacc3x0123 = wasm_f32x4_convert_i32x4(vacc3x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); vacc3x0123 = wasm_f32x4_mul(vacc3x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); vacc3x0123 = wasm_f32x4_add(vacc3x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); vacc3x0123 = wasm_i32x4_max(vacc3x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); vacc3x0123 = wasm_i32x4_sub(vacc3x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc23x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc3x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc23x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c3, vout, 3); wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c3, vout, 6); c3 += 2; wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c3, vout, 12); wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
8,157
36.59447
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-wasmsimd-dot16x2-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-wasmsimd-dot16x2.c.in // Generator: tools/xngen // // 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 <assert.h> #include <wasm_simd128.h> #include <xnnpack/igemm.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__wasmsimd_dot16x2_ld64( 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); 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; } kc = round_up_po2(kc, 8 * sizeof(int8_t)); do { v128_t vacc0x0123 = wasm_v128_load(w); v128_t vacc1x0123 = vacc0x0123; v128_t vacc2x0123 = vacc0x0123; v128_t vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { v128_t vxa0 = wasm_i16x8_load8x8(a0); a0 += 8; v128_t vxa1 = wasm_i16x8_load8x8(a1); a1 += 8; v128_t vxa2 = wasm_i16x8_load8x8(a2); a2 += 8; v128_t vxa3 = wasm_i16x8_load8x8(a3); a3 += 8; const v128_t vxb0 = wasm_i16x8_load8x8(w); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb0)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb0)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb0)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb0)); vxa3 = wasm_v32x4_shuffle(vxa3, vxa3, 1, 2, 3, 4); const v128_t vxb1 = wasm_i16x8_load8x8((const int8_t*) w + 8); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb1)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb1)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb1)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb1)); vxa3 = wasm_v32x4_shuffle(vxa3, vxa3, 1, 2, 3, 4); const v128_t vxb2 = wasm_i16x8_load8x8((const int8_t*) w + 16); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb2)); vxa0 = wasm_v32x4_shuffle(vxa0, vxa0, 1, 2, 3, 4); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb2)); vxa1 = wasm_v32x4_shuffle(vxa1, vxa1, 1, 2, 3, 4); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb2)); vxa2 = wasm_v32x4_shuffle(vxa2, vxa2, 1, 2, 3, 4); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb2)); vxa3 = wasm_v32x4_shuffle(vxa3, vxa3, 1, 2, 3, 4); const v128_t vxb3 = wasm_i16x8_load8x8((const int8_t*) w + 24); vacc0x0123 = wasm_i32x4_add(vacc0x0123, wasm_i32x4_dot_i16x8(vxa0, vxb3)); vacc1x0123 = wasm_i32x4_add(vacc1x0123, wasm_i32x4_dot_i16x8(vxa1, vxb3)); vacc2x0123 = wasm_i32x4_add(vacc2x0123, wasm_i32x4_dot_i16x8(vxa2, vxb3)); vacc3x0123 = wasm_i32x4_add(vacc3x0123, wasm_i32x4_dot_i16x8(vxa3, vxb3)); w = (const int8_t*) w + 32; k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); vacc0x0123 = wasm_f32x4_convert_i32x4(vacc0x0123); vacc1x0123 = wasm_f32x4_convert_i32x4(vacc1x0123); vacc2x0123 = wasm_f32x4_convert_i32x4(vacc2x0123); vacc3x0123 = wasm_f32x4_convert_i32x4(vacc3x0123); const v128_t vscale0123 = wasm_v128_load(w); w = (const void*) ((const float*) w + 4); vacc0x0123 = wasm_f32x4_mul(vacc0x0123, vscale0123); vacc1x0123 = wasm_f32x4_mul(vacc1x0123, vscale0123); vacc2x0123 = wasm_f32x4_mul(vacc2x0123, vscale0123); vacc3x0123 = wasm_f32x4_mul(vacc3x0123, vscale0123); const v128_t vmagic_bias = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias); vacc0x0123 = wasm_f32x4_add(vacc0x0123, vmagic_bias); vacc1x0123 = wasm_f32x4_add(vacc1x0123, vmagic_bias); vacc2x0123 = wasm_f32x4_add(vacc2x0123, vmagic_bias); vacc3x0123 = wasm_f32x4_add(vacc3x0123, vmagic_bias); const v128_t vmagic_min = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_min); vacc0x0123 = wasm_i32x4_max(vacc0x0123, vmagic_min); vacc1x0123 = wasm_i32x4_max(vacc1x0123, vmagic_min); vacc2x0123 = wasm_i32x4_max(vacc2x0123, vmagic_min); vacc3x0123 = wasm_i32x4_max(vacc3x0123, vmagic_min); const v128_t vmagic_bias_less_output_zero_point = wasm_v128_load64_splat(params->fp32_wasmsimd.magic_bias_less_output_zero_point); vacc0x0123 = wasm_i32x4_sub(vacc0x0123, vmagic_bias_less_output_zero_point); vacc1x0123 = wasm_i32x4_sub(vacc1x0123, vmagic_bias_less_output_zero_point); vacc2x0123 = wasm_i32x4_sub(vacc2x0123, vmagic_bias_less_output_zero_point); vacc3x0123 = wasm_i32x4_sub(vacc3x0123, vmagic_bias_less_output_zero_point); v128_t vacc01x0123 = wasm_i16x8_narrow_i32x4(vacc0x0123, vacc1x0123); v128_t vacc23x0123 = wasm_i16x8_narrow_i32x4(vacc2x0123, vacc3x0123); v128_t vout = wasm_i8x16_narrow_i16x8(vacc01x0123, vacc23x0123); const v128_t voutput_max = wasm_v128_load64_splat(params->fp32_wasmsimd.output_max); vout = wasm_i8x16_min(vout, voutput_max); if (nc >= 4) { wasm_v128_store32_lane(c3, vout, 3); wasm_v128_store32_lane(c2, vout, 2); wasm_v128_store32_lane(c1, vout, 1); wasm_v128_store32_lane(c0, vout, 0); 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 -= 4; } else { if (nc & 2) { wasm_v128_store16_lane(c3, vout, 6); c3 += 2; wasm_v128_store16_lane(c2, vout, 4); c2 += 2; wasm_v128_store16_lane(c1, vout, 2); c1 += 2; wasm_v128_store16_lane(c0, vout, 0); c0 += 2; vout = wasm_u32x4_shr(vout, 16); } if (nc & 1) { wasm_v128_store8_lane(c3, vout, 12); wasm_v128_store8_lane(c2, vout, 8); wasm_v128_store8_lane(c1, vout, 4); wasm_v128_store8_lane(c0, vout, 0); } nc = 0; } } while (nc != 0); }
8,053
36.460465
134
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-xop-ld128.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__xop_ld128( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb01 = _mm_loadu_si128((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb01); const __m128i vxb1 = _mm_srai_epi16(_mm_unpackhi_epi8(vb01, vb01), 8); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb0, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb0, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb0, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb0, vacc3x0123); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb1, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb1, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb1, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb1, vacc3x0123); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb23 = _mm_loadu_si128((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb23); const __m128i vxb3 = _mm_srai_epi16(_mm_unpackhi_epi8(vb23, vb23), 8); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb2, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb2, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb2, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb2, vacc3x0123); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb3, vacc2x0123); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb3, vacc3x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
8,196
36.600917
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x4c2s4-minmax-fp32-xop-ld64.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/MRx4c2s4-sse.c.in // Generator: tools/xngen // // Copyright 2022 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 <assert.h> #ifdef _MSC_VER #include <intrin.h> #else #include <x86intrin.h> #endif #include <xnnpack/igemm.h> #include <xnnpack/math.h> #include <xnnpack/unaligned.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x4c2s4__xop_ld64( 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, 8 * 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 { __m128i vacc0x0123 = _mm_loadu_si128((const __m128i*) w); __m128i vacc1x0123 = vacc0x0123; __m128i vacc2x0123 = vacc0x0123; __m128i vacc3x0123 = vacc0x0123; w = (const void*) ((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); } 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; size_t k = kc; do { const __m128i va0 = _mm_loadl_epi64((const __m128i*) a0); __m128i vxa0 = _mm_cvtepi8_epi16(va0); a0 += 8; const __m128i va1 = _mm_loadl_epi64((const __m128i*) a1); __m128i vxa1 = _mm_cvtepi8_epi16(va1); a1 += 8; const __m128i va2 = _mm_loadl_epi64((const __m128i*) a2); __m128i vxa2 = _mm_cvtepi8_epi16(va2); a2 += 8; const __m128i va3 = _mm_loadl_epi64((const __m128i*) a3); __m128i vxa3 = _mm_cvtepi8_epi16(va3); a3 += 8; const __m128i vb0 = _mm_loadl_epi64((const __m128i*) w); const __m128i vxb0 = _mm_cvtepi8_epi16(vb0); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb0, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb0, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb0, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb0, vacc3x0123); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb1 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 8)); const __m128i vxb1 = _mm_cvtepi8_epi16(vb1); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb1, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb1, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb1, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb1, vacc3x0123); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb2 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 16)); const __m128i vxb2 = _mm_cvtepi8_epi16(vb2); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb2, vacc0x0123); vxa0 = _mm_shuffle_epi32(vxa0, _MM_SHUFFLE(0, 3, 2, 1)); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb2, vacc1x0123); vxa1 = _mm_shuffle_epi32(vxa1, _MM_SHUFFLE(0, 3, 2, 1)); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb2, vacc2x0123); vxa2 = _mm_shuffle_epi32(vxa2, _MM_SHUFFLE(0, 3, 2, 1)); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb2, vacc3x0123); vxa3 = _mm_shuffle_epi32(vxa3, _MM_SHUFFLE(0, 3, 2, 1)); const __m128i vb3 = _mm_loadl_epi64((const __m128i*) ((const int8_t*) w + 24)); const __m128i vxb3 = _mm_cvtepi8_epi16(vb3); vacc0x0123 = _mm_maddd_epi16(vxa0, vxb3, vacc0x0123); vacc1x0123 = _mm_maddd_epi16(vxa1, vxb3, vacc1x0123); vacc2x0123 = _mm_maddd_epi16(vxa2, vxb3, vacc2x0123); vacc3x0123 = _mm_maddd_epi16(vxa3, vxb3, vacc3x0123); w = (const void*) ((const int8_t*) w + 32); k -= 8 * sizeof(int8_t); } while (k != 0); p -= 4 * sizeof(void*); } while (p != 0); __m128 vscaled0x0123 = _mm_cvtepi32_ps(vacc0x0123); __m128 vscaled1x0123 = _mm_cvtepi32_ps(vacc1x0123); __m128 vscaled2x0123 = _mm_cvtepi32_ps(vacc2x0123); __m128 vscaled3x0123 = _mm_cvtepi32_ps(vacc3x0123); const __m128 vscale0123 = _mm_loadu_ps((const float*) w); w = (const void*) ((const float*) w + 4); vscaled0x0123 = _mm_mul_ps(vscaled0x0123, vscale0123); vscaled1x0123 = _mm_mul_ps(vscaled1x0123, vscale0123); vscaled2x0123 = _mm_mul_ps(vscaled2x0123, vscale0123); vscaled3x0123 = _mm_mul_ps(vscaled3x0123, vscale0123); const __m128 voutput_max_less_zero_point = _mm_load_ps(params->fp32_sse4.output_max_less_zero_point); vscaled0x0123 = _mm_min_ps(vscaled0x0123, voutput_max_less_zero_point); vscaled1x0123 = _mm_min_ps(vscaled1x0123, voutput_max_less_zero_point); vscaled2x0123 = _mm_min_ps(vscaled2x0123, voutput_max_less_zero_point); vscaled3x0123 = _mm_min_ps(vscaled3x0123, voutput_max_less_zero_point); vacc0x0123 = _mm_cvtps_epi32(vscaled0x0123); vacc1x0123 = _mm_cvtps_epi32(vscaled1x0123); vacc2x0123 = _mm_cvtps_epi32(vscaled2x0123); vacc3x0123 = _mm_cvtps_epi32(vscaled3x0123); const __m128i voutput_zero_point = _mm_load_si128((const __m128i*) params->fp32_sse4.output_zero_point); __m128i vacc01x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc0x0123, vacc1x0123), voutput_zero_point); __m128i vacc23x0123 = _mm_adds_epi16(_mm_packs_epi32(vacc2x0123, vacc3x0123), voutput_zero_point); __m128i vout = _mm_packs_epi16(vacc01x0123, vacc23x0123); vout = _mm_max_epi8(vout, _mm_load_si128((const __m128i*) params->fp32_sse4.output_min)); if (nc >= 4) { unaligned_store_u32(c3, (uint32_t) _mm_extract_epi32(vout, 3)); c3 = (int8_t*) ((uintptr_t) c3 + cn_stride); unaligned_store_u32(c2, (uint32_t) _mm_extract_epi32(vout, 2)); c2 = (int8_t*) ((uintptr_t) c2 + cn_stride); unaligned_store_u32(c1, (uint32_t) _mm_extract_epi32(vout, 1)); c1 = (int8_t*) ((uintptr_t) c1 + cn_stride); unaligned_store_u32(c0, (uint32_t) _mm_cvtsi128_si32(vout)); c0 = (int8_t*) ((uintptr_t) c0 + cn_stride); a = (const int8_t**restrict) ((uintptr_t) a - ks); nc -= 4; } else { if (nc & 2) { unaligned_store_u16(c3, (uint16_t) _mm_extract_epi16(vout, 6)); c3 += 2; unaligned_store_u16(c2, (uint16_t) _mm_extract_epi16(vout, 4)); c2 += 2; unaligned_store_u16(c1, (uint16_t) _mm_extract_epi16(vout, 2)); c1 += 2; unaligned_store_u16(c0, (uint16_t) _mm_extract_epi16(vout, 0)); c0 += 2; vout = _mm_srli_epi32(vout, 16); } if (nc & 1) { *c3 = (int8_t) _mm_extract_epi8(vout, 12); *c2 = (int8_t) _mm_extract_epi8(vout, 8); *c1 = (int8_t) _mm_extract_epi8(vout, 4); *c0 = (int8_t) _mm_extract_epi8(vout, 0); } nc = 0; } } while (nc != 0); }
8,314
36.795455
108
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x8-minmax-fp32-neonv8-mlal-lane-prfm.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/neon-mlal-lane.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/prefetch.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x8__neonv8_mlal_lane_prfm( 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); 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 void*) ((const int32_t*) w + 4); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 += 8; const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t va3 = vld1_s8(a3); a3 += 8; const int16x8_t vxa3 = vmovl_s8(va3); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa3), 0); const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa3), 1); const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa3), 2); const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa3), 3); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa3), 3); xnn_prefetch_to_l1((const int8_t*) w + 448); const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa3), 0); const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa3), 1); const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa3), 2); const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa3), 3); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa3), 3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t va3 = vld1_s8(a3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const int16x8_t vxa3 = vmovl_s8(va3); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa3), 0); if (k >= 2 * sizeof(int8_t)) { const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa3), 1); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa3), 2); if (k >= 4 * sizeof(int8_t)) { const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa3), 3); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa3), 3); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa3), 0); if (k >= 6 * sizeof(int8_t)) { const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa3), 1); if (k > 6 * sizeof(int8_t)) { const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa3), 2); } } } } } } } p -= 4 * sizeof(void*); } while (p != 0); // Post-accumulation work 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 void*) ((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 void*) ((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(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567); int16x8_t vacc3x01234567 = vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); vacc3x01234567 = vqaddq_s16(vacc3x01234567, 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 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)); int16x8_t vacc3x01234567 = vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); vacc3x01234567 = vqaddq_s16(vacc3x01234567, 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(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, 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); }
24,984
59.643204
114
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x8-minmax-fp32-neonv8-mlal-lane.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/neon-mlal-lane.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_4x8__neonv8_mlal_lane( 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); 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 void*) ((const int32_t*) w + 4); int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((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; size_t k = kc; while (k >= 8 * sizeof(int8_t)) { const int8x8_t va0 = vld1_s8(a0); a0 += 8; const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 += 8; const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 += 8; const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t va3 = vld1_s8(a3); a3 += 8; const int16x8_t vxa3 = vmovl_s8(va3); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa3), 0); const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa3), 1); const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa3), 2); const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa3), 3); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa3), 3); const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa3), 0); const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa3), 1); const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa3), 2); const int8x8_t vb01234567c7 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c7 = vmovl_s8(vb01234567c7); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa2), 3); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c7), vget_high_s16(vxa3), 3); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c7), vget_high_s16(vxa3), 3); k -= 8 * sizeof(int8_t); } if XNN_UNLIKELY(k != 0) { const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k); const int16x8_t vxa0 = vmovl_s8(va0); const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k); const int16x8_t vxa1 = vmovl_s8(va1); const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k); const int16x8_t vxa2 = vmovl_s8(va2); const int8x8_t va3 = vld1_s8(a3); a3 = (const int8_t*) ((uintptr_t) a3 + k); const int16x8_t vxa3 = vmovl_s8(va3); const int8x8_t vb01234567c0 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c0 = vmovl_s8(vb01234567c0); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c0), vget_low_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c0), vget_low_s16(vxa3), 0); if (k >= 2 * sizeof(int8_t)) { const int8x8_t vb01234567c1 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c1 = vmovl_s8(vb01234567c1); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c1), vget_low_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c1), vget_low_s16(vxa3), 1); if (k > 2 * sizeof(int8_t)) { const int8x8_t vb01234567c2 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c2 = vmovl_s8(vb01234567c2); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c2), vget_low_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c2), vget_low_s16(vxa3), 2); if (k >= 4 * sizeof(int8_t)) { const int8x8_t vb01234567c3 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c3 = vmovl_s8(vb01234567c3); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa0), 3); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa1), 3); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa2), 3); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c3), vget_low_s16(vxa3), 3); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c3), vget_low_s16(vxa3), 3); if (k > 4 * sizeof(int8_t)) { const int8x8_t vb01234567c4 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c4 = vmovl_s8(vb01234567c4); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa0), 0); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa1), 0); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa2), 0); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c4), vget_high_s16(vxa3), 0); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c4), vget_high_s16(vxa3), 0); if (k >= 6 * sizeof(int8_t)) { const int8x8_t vb01234567c5 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c5 = vmovl_s8(vb01234567c5); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa0), 1); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa1), 1); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa2), 1); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c5), vget_high_s16(vxa3), 1); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c5), vget_high_s16(vxa3), 1); if (k > 6 * sizeof(int8_t)) { const int8x8_t vb01234567c6 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8); const int16x8_t vxb01234567c6 = vmovl_s8(vb01234567c6); vacc0x0123 = vmlal_lane_s16(vacc0x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc0x4567 = vmlal_lane_s16(vacc0x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa0), 2); vacc1x0123 = vmlal_lane_s16(vacc1x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc1x4567 = vmlal_lane_s16(vacc1x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa1), 2); vacc2x0123 = vmlal_lane_s16(vacc2x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc2x4567 = vmlal_lane_s16(vacc2x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa2), 2); vacc3x0123 = vmlal_lane_s16(vacc3x0123, vget_low_s16(vxb01234567c6), vget_high_s16(vxa3), 2); vacc3x4567 = vmlal_lane_s16(vacc3x4567, vget_high_s16(vxb01234567c6), vget_high_s16(vxa3), 2); } } } } } } } p -= 4 * sizeof(void*); } while (p != 0); // Post-accumulation work 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 void*) ((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 void*) ((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(&params->fp32_neonv8.output_zero_point); #if XNN_ARCH_ARM64 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567); int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567); int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567); int16x8_t vacc3x01234567 = vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); vacc3x01234567 = vqaddq_s16(vacc3x01234567, 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 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)); int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)); int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)); int16x8_t vacc3x01234567 = vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)); vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point); vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point); vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point); vacc3x01234567 = vqaddq_s16(vacc3x01234567, 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(&params->fp32_neonv8.output_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, 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); }
24,896
59.72439
114
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-4x8c4-minmax-fp32-neondot.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neondot.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> 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(&params->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(&params->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->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); }
11,535
45.516129
130
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-6x8c4-minmax-fp32-neondot.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neondot.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_6x8c4__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 <= 6); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (6 * 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; } int8_t* c4 = (int8_t*) ((uintptr_t) c3 + cm_stride); if XNN_UNPREDICTABLE(mr <= 4) { c4 = c3; } int8_t* c5 = (int8_t*) ((uintptr_t) c4 + cm_stride); if XNN_UNPREDICTABLE(mr != 6) { c5 = c4; } 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; int32x4_t vacc4x0123 = vacc0x0123; int32x4_t vacc4x4567 = vacc0x4567; int32x4_t vacc5x0123 = vacc0x0123; int32x4_t vacc5x4567 = 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); } const int8_t* restrict a4 = a[4]; if XNN_UNPREDICTABLE(a4 != zero) { a4 = (const int8_t*) ((uintptr_t) a4 + a_offset); } const int8_t* restrict a5 = a[5]; if XNN_UNPREDICTABLE(a5 != zero) { a5 = (const int8_t*) ((uintptr_t) a5 + a_offset); } a += 6; // 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 6x8 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; const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8; const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 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: 6x8 * 8x8 --> 6x8. 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); vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0); vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0); vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0); vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 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); vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1); vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1); vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb4567x0123, va5x01234567, 1); vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb4567x4567, va5x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 6x4 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); const int8x8_t va4x01234567 = vld1_s8(a4); const int8x8_t va5x01234567 = vld1_s8(a5); // 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: 6x4 * 4x8 --> 6x8. 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); vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0); vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0); vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0); vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0); } p -= 6 * 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); float32x4_t vfpacc4x0123 = vcvtq_f32_s32(vacc4x0123); float32x4_t vfpacc4x4567 = vcvtq_f32_s32(vacc4x4567); float32x4_t vfpacc5x0123 = vcvtq_f32_s32(vacc5x0123); float32x4_t vfpacc5x4567 = vcvtq_f32_s32(vacc5x4567); 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); vfpacc4x0123 = vmulq_f32(vfpacc4x0123, vscale0123); vfpacc5x0123 = vmulq_f32(vfpacc5x0123, 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); vfpacc4x4567 = vmulq_f32(vfpacc4x4567, vscale4567); vfpacc5x4567 = vmulq_f32(vfpacc5x4567, 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); vacc4x0123 = vcvtnq_s32_f32(vfpacc4x0123); vacc4x4567 = vcvtnq_s32_f32(vfpacc4x4567); vacc5x0123 = vcvtnq_s32_f32(vfpacc5x0123); vacc5x4567 = vcvtnq_s32_f32(vfpacc5x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->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); const int16x8_t vacc4x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc4x0123), vacc4x4567), voutput_zero_point); const int16x8_t vacc5x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc5x0123), vacc5x4567), 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); int8x16_t vout4x01234567_5x01234567 = vqmovn_high_s16(vqmovn_s16(vacc4x01234567), vacc5x01234567); #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); const int16x8_t vacc4x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc4x0123), vqmovn_s32(vacc4x4567)), voutput_zero_point); const int16x8_t vacc5x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc5x0123), vqmovn_s32(vacc5x4567)), 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)); int8x16_t vout4x01234567_5x01234567 = vcombine_s8(vqmovn_s16(vacc4x01234567), vqmovn_s16(vacc5x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout4x01234567_5x01234567 = vmaxq_s8(vout4x01234567_5x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout4x01234567_5x01234567 = vminq_s8(vout4x01234567_5x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c5 + 0, vget_high_s8(vout4x01234567_5x01234567)); vst1_s8(c4 + 0, vget_low_s8(vout4x01234567_5x01234567)); 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)); c5 = (int8_t*) ((uintptr_t) c5 + cn_stride); c4 = (int8_t*) ((uintptr_t) c4 + cn_stride); 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*) c5, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 2); c5 += 4; vst1q_lane_u32((void*) c4, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 0); c4 += 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; vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 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*) c5, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 4); c5 += 2; vst1q_lane_u16((void*) c4, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 0); c4 += 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; vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 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(c5, vout4x01234567_5x01234567, 8); vst1q_lane_s8(c4, vout4x01234567_5x01234567, 0); 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); }
15,831
49.101266
130
c
XNNPACK
XNNPACK-master/src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-8x8c4-minmax-fp32-neondot.c
// Auto-generated file. Do not edit! // Template: src/qs8-igemm/c4-neondot.c.in // Generator: tools/xngen // // Copyright 2020 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 <assert.h> #include <arm_neon.h> #include <xnnpack/igemm.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/math.h> void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_8x8c4__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 <= 8); assert(nc != 0); assert(kc != 0); assert(ks != 0); assert(ks % (8 * 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; } int8_t* c4 = (int8_t*) ((uintptr_t) c3 + cm_stride); if XNN_UNPREDICTABLE(mr <= 4) { c4 = c3; } int8_t* c5 = (int8_t*) ((uintptr_t) c4 + cm_stride); if XNN_UNPREDICTABLE(mr < 6) { c5 = c4; } int8_t* c6 = (int8_t*) ((uintptr_t) c5 + cm_stride); if XNN_UNPREDICTABLE(mr <= 6) { c6 = c5; } int8_t* c7 = (int8_t*) ((uintptr_t) c6 + cm_stride); if XNN_UNPREDICTABLE(mr != 8) { c7 = c6; } 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; int32x4_t vacc4x0123 = vacc0x0123; int32x4_t vacc4x4567 = vacc0x4567; int32x4_t vacc5x0123 = vacc0x0123; int32x4_t vacc5x4567 = vacc0x4567; int32x4_t vacc6x0123 = vacc0x0123; int32x4_t vacc6x4567 = vacc0x4567; int32x4_t vacc7x0123 = vacc0x0123; int32x4_t vacc7x4567 = 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); } const int8_t* restrict a4 = a[4]; if XNN_UNPREDICTABLE(a4 != zero) { a4 = (const int8_t*) ((uintptr_t) a4 + a_offset); } const int8_t* restrict a5 = a[5]; if XNN_UNPREDICTABLE(a5 != zero) { a5 = (const int8_t*) ((uintptr_t) a5 + a_offset); } const int8_t* restrict a6 = a[6]; if XNN_UNPREDICTABLE(a6 != zero) { a6 = (const int8_t*) ((uintptr_t) a6 + a_offset); } const int8_t* restrict a7 = a[7]; if XNN_UNPREDICTABLE(a7 != zero) { a7 = (const int8_t*) ((uintptr_t) a7 + a_offset); } a += 8; // 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 8x8 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; const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8; const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 8; const int8x8_t va6x01234567 = vld1_s8(a6); a6 += 8; const int8x8_t va7x01234567 = vld1_s8(a7); a7 += 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: 8x8 * 8x8 --> 8x8. 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); vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0); vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0); vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0); vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0); vacc6x0123 = vdotq_lane_s32(vacc6x0123, vb0123x0123, va6x01234567, 0); vacc6x4567 = vdotq_lane_s32(vacc6x4567, vb0123x4567, va6x01234567, 0); vacc7x0123 = vdotq_lane_s32(vacc7x0123, vb0123x0123, va7x01234567, 0); vacc7x4567 = vdotq_lane_s32(vacc7x4567, vb0123x4567, va7x01234567, 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); vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1); vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1); vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb4567x0123, va5x01234567, 1); vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb4567x4567, va5x01234567, 1); vacc6x0123 = vdotq_lane_s32(vacc6x0123, vb4567x0123, va6x01234567, 1); vacc6x4567 = vdotq_lane_s32(vacc6x4567, vb4567x4567, va6x01234567, 1); vacc7x0123 = vdotq_lane_s32(vacc7x0123, vb4567x0123, va7x01234567, 1); vacc7x4567 = vdotq_lane_s32(vacc7x4567, vb4567x4567, va7x01234567, 1); k -= 8 * sizeof(int8_t); } // Handle up to 4 final positions of `k` if XNN_UNLIKELY(k != 0) { // Load a 8x4 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); const int8x8_t va4x01234567 = vld1_s8(a4); const int8x8_t va5x01234567 = vld1_s8(a5); const int8x8_t va6x01234567 = vld1_s8(a6); const int8x8_t va7x01234567 = vld1_s8(a7); // 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: 8x4 * 4x8 --> 8x8. 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); vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0); vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0); vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0); vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0); vacc6x0123 = vdotq_lane_s32(vacc6x0123, vb0123x0123, va6x01234567, 0); vacc6x4567 = vdotq_lane_s32(vacc6x4567, vb0123x4567, va6x01234567, 0); vacc7x0123 = vdotq_lane_s32(vacc7x0123, vb0123x0123, va7x01234567, 0); vacc7x4567 = vdotq_lane_s32(vacc7x4567, vb0123x4567, va7x01234567, 0); } p -= 8 * 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); float32x4_t vfpacc4x0123 = vcvtq_f32_s32(vacc4x0123); float32x4_t vfpacc4x4567 = vcvtq_f32_s32(vacc4x4567); float32x4_t vfpacc5x0123 = vcvtq_f32_s32(vacc5x0123); float32x4_t vfpacc5x4567 = vcvtq_f32_s32(vacc5x4567); float32x4_t vfpacc6x0123 = vcvtq_f32_s32(vacc6x0123); float32x4_t vfpacc6x4567 = vcvtq_f32_s32(vacc6x4567); float32x4_t vfpacc7x0123 = vcvtq_f32_s32(vacc7x0123); float32x4_t vfpacc7x4567 = vcvtq_f32_s32(vacc7x4567); 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); vfpacc4x0123 = vmulq_f32(vfpacc4x0123, vscale0123); vfpacc5x0123 = vmulq_f32(vfpacc5x0123, vscale0123); vfpacc6x0123 = vmulq_f32(vfpacc6x0123, vscale0123); vfpacc7x0123 = vmulq_f32(vfpacc7x0123, 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); vfpacc4x4567 = vmulq_f32(vfpacc4x4567, vscale4567); vfpacc5x4567 = vmulq_f32(vfpacc5x4567, vscale4567); vfpacc6x4567 = vmulq_f32(vfpacc6x4567, vscale4567); vfpacc7x4567 = vmulq_f32(vfpacc7x4567, 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); vacc4x0123 = vcvtnq_s32_f32(vfpacc4x0123); vacc4x4567 = vcvtnq_s32_f32(vfpacc4x4567); vacc5x0123 = vcvtnq_s32_f32(vfpacc5x0123); vacc5x4567 = vcvtnq_s32_f32(vfpacc5x4567); vacc6x0123 = vcvtnq_s32_f32(vfpacc6x0123); vacc6x4567 = vcvtnq_s32_f32(vfpacc6x4567); vacc7x0123 = vcvtnq_s32_f32(vfpacc7x0123); vacc7x4567 = vcvtnq_s32_f32(vfpacc7x4567); const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->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); const int16x8_t vacc4x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc4x0123), vacc4x4567), voutput_zero_point); const int16x8_t vacc5x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc5x0123), vacc5x4567), voutput_zero_point); const int16x8_t vacc6x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc6x0123), vacc6x4567), voutput_zero_point); const int16x8_t vacc7x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc7x0123), vacc7x4567), 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); int8x16_t vout4x01234567_5x01234567 = vqmovn_high_s16(vqmovn_s16(vacc4x01234567), vacc5x01234567); int8x16_t vout6x01234567_7x01234567 = vqmovn_high_s16(vqmovn_s16(vacc6x01234567), vacc7x01234567); #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); const int16x8_t vacc4x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc4x0123), vqmovn_s32(vacc4x4567)), voutput_zero_point); const int16x8_t vacc5x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc5x0123), vqmovn_s32(vacc5x4567)), voutput_zero_point); const int16x8_t vacc6x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc6x0123), vqmovn_s32(vacc6x4567)), voutput_zero_point); const int16x8_t vacc7x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc7x0123), vqmovn_s32(vacc7x4567)), 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)); int8x16_t vout4x01234567_5x01234567 = vcombine_s8(vqmovn_s16(vacc4x01234567), vqmovn_s16(vacc5x01234567)); int8x16_t vout6x01234567_7x01234567 = vcombine_s8(vqmovn_s16(vacc6x01234567), vqmovn_s16(vacc7x01234567)); #endif const int8x16_t voutput_min = vld1q_dup_s8(&params->fp32_neonv8.output_min); const int8x16_t voutput_max = vld1q_dup_s8(&params->fp32_neonv8.output_max); vout6x01234567_7x01234567 = vmaxq_s8(vout6x01234567_7x01234567, voutput_min); vout4x01234567_5x01234567 = vmaxq_s8(vout4x01234567_5x01234567, voutput_min); vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min); vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min); vout6x01234567_7x01234567 = vminq_s8(vout6x01234567_7x01234567, voutput_max); vout4x01234567_5x01234567 = vminq_s8(vout4x01234567_5x01234567, voutput_max); vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max); vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max); if (nc >= 8) { vst1_s8(c7 + 0, vget_high_s8(vout6x01234567_7x01234567)); vst1_s8(c6 + 0, vget_low_s8(vout6x01234567_7x01234567)); vst1_s8(c5 + 0, vget_high_s8(vout4x01234567_5x01234567)); vst1_s8(c4 + 0, vget_low_s8(vout4x01234567_5x01234567)); 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)); c7 = (int8_t*) ((uintptr_t) c7 + cn_stride); c6 = (int8_t*) ((uintptr_t) c6 + cn_stride); c5 = (int8_t*) ((uintptr_t) c5 + cn_stride); c4 = (int8_t*) ((uintptr_t) c4 + cn_stride); 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*) c7, vreinterpretq_u32_s8(vout6x01234567_7x01234567), 2); c7 += 4; vst1q_lane_u32((void*) c6, vreinterpretq_u32_s8(vout6x01234567_7x01234567), 0); c6 += 4; vst1q_lane_u32((void*) c5, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 2); c5 += 4; vst1q_lane_u32((void*) c4, vreinterpretq_u32_s8(vout4x01234567_5x01234567), 0); c4 += 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; vout6x01234567_7x01234567 = vextq_s8(vout6x01234567_7x01234567, vout6x01234567_7x01234567, 4); vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 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*) c7, vreinterpretq_u16_s8(vout6x01234567_7x01234567), 4); c7 += 2; vst1q_lane_u16((void*) c6, vreinterpretq_u16_s8(vout6x01234567_7x01234567), 0); c6 += 2; vst1q_lane_u16((void*) c5, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 4); c5 += 2; vst1q_lane_u16((void*) c4, vreinterpretq_u16_s8(vout4x01234567_5x01234567), 0); c4 += 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; vout6x01234567_7x01234567 = vextq_s8(vout6x01234567_7x01234567, vout6x01234567_7x01234567, 2); vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 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(c7, vout6x01234567_7x01234567, 8); vst1q_lane_s8(c6, vout6x01234567_7x01234567, 0); vst1q_lane_s8(c5, vout4x01234567_5x01234567, 8); vst1q_lane_s8(c4, vout4x01234567_5x01234567, 0); 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); }
20,127
51.416667
130
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-fp32-neon.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <stdint.h> #include <stddef.h> #include <arm_neon.h> #include <xnnpack/intrinsics-polyfill.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_fp32__neon( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 16 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); const float32x4_t vscale = vdupq_n_f32(scale); #ifdef __aarch64__ const int16x8_t vzero_point = vdupq_n_s16((int16_t) zero_point); const int8x16_t vqmin = vdupq_n_s8(qmin); const int8x16_t vqmax = vdupq_n_s8(qmax); #else const float32x4_t vfmin = vdupq_n_f32((float) ((int32_t) qmin - (int32_t) zero_point)); const float32x4_t vfmax = vdupq_n_f32((float) ((int32_t) qmax - (int32_t) zero_point)); const float32x4_t vfmagic = vdupq_n_f32(12582912.0f); const int32x4_t vimagic = vdupq_n_s32(INT32_C(0x4B400000) - (int32_t) zero_point); #endif for (; n != 0; n -= 16) { const int32x4_t x = vld1q_s32(input); const int32x4_t y = vld1q_s32(input + 4); const int32x4_t z = vld1q_s32(input + 8); const int32x4_t w = vld1q_s32(input + 12); input += 16; // Convert int32_t input to FP32 and multiply by FP32 scale. // Both operations involve statistically unbiased roundings: // - Large int32_t values can't be exactly represented as FP32. The conversion instruction in ARM NEON would // round it to nearest FP32 value with ties to even. // - Product of two FP32 values is generally not exactly representation as an FP32 value, and will be rounded // to nearest FP32 value with ties to even. const float32x4_t x_scaled = vmulq_f32(vcvtq_f32_s32(x), vscale); const float32x4_t y_scaled = vmulq_f32(vcvtq_f32_s32(y), vscale); const float32x4_t z_scaled = vmulq_f32(vcvtq_f32_s32(z), vscale); const float32x4_t w_scaled = vmulq_f32(vcvtq_f32_s32(w), vscale); #ifdef __aarch64__ // Leverage "Floating-point Convert to Signed integer, rounding to nearest with ties to even" instruction. // This is an ARMv8 instruction (always available in AArch64), which saturates result on overflow. // We don't need to specifically consider saturated results, they will be clamped at the last stage. const int32x4_t x_rounded = vcvtnq_s32_f32(x_scaled); const int32x4_t y_rounded = vcvtnq_s32_f32(y_scaled); const int32x4_t z_rounded = vcvtnq_s32_f32(z_scaled); const int32x4_t w_rounded = vcvtnq_s32_f32(w_scaled); // Standard final sequence on ARM NEON: // - Pack to int16_t and saturate // - Add zero point // - Pack to uint8_t and saturate // - Clamp between qmin and qmax const int16x8_t xy_packed = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(x_rounded), y_rounded), vzero_point); const int16x8_t zw_packed = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(z_rounded), w_rounded), vzero_point); const int8x16_t xyzw_packed = vqmovn_high_s16(vqmovn_s16(xy_packed), zw_packed); const int8x16_t xyzw_clamped = vmaxq_s8(vminq_s8(xyzw_packed, vqmax), vqmin); // AArch32 version: // 4x VCVT.F32.S32 Qd, Qm // 4x VMUL.F32 Qd, Qm, Qn // 4x VMIN.F32 Qd, Qm, Qn // 4x VMAX.F32 Qd, Qm, Qn // 4x VADD.F32 Qd, Qm, Qn // 4x VSUB.S32 Qd, Qm, Qn // 4x VMOVN.I32 Dd, Qm // 2x VMOVN.I16 Dd, Qm // --------------------- // 30 instructions total vst1q_s8(output, xyzw_clamped); output += 16; #else // AArch64 version: // 4x SCVTF Vd.4S, Vn.4S // 4x FMUL Vd.4S, Vn.4S, Vm.4S // 4x FCVTNS Vd.4S, Vn.4S // 2x SQXTN Vd.4H, Vn.4S // 2x SQXTN2 Vd.8H, Vn.4S // 2x SQADD Vd.8H, Vn.8H, Vm.8H // 1x SQXTN Vd.8B, Vn.8H // 1x SQXTN2 Vd.16B, Vn.8H // 1x SMIN Vd.16B, Vn.16B, Vm.16B // 1x SMAX Vd.16B, Vn.16B, Vm.16B // --------------------- // 22 instructions total // ARMv7 NEON offers only a floating-point to integer conversion instruction with rounding towards zero. // In lieu of conversion instruction with rounding-to-nearest-even, we use a magic trick of adding a large // number (1.5 * 2**23) to scaled value to cause rounding to integer, and then substracing this magic number as // integer. This trick works only in a limited range (absolute value of input must be less than 2**22), so // generally we have to clamp input to this range before using the magic. However, clamping to any smaller range // works just as well, and thus we clamp to [qmin - zero point, qmax - zero point] range so that after we add // zero point to the result, it gets into target [qmin, qmax] range. const float32x4_t x_clamped = vminq_f32(vmaxq_f32(x_scaled, vfmin), vfmax); const float32x4_t y_clamped = vminq_f32(vmaxq_f32(y_scaled, vfmin), vfmax); const float32x4_t z_clamped = vminq_f32(vmaxq_f32(z_scaled, vfmin), vfmax); const float32x4_t w_clamped = vminq_f32(vmaxq_f32(w_scaled, vfmin), vfmax); // Conversion to integer using the "magic trick". Rounding is performed in the output of addition operation, // and result is rounded to nearest even integer with ties to even. const int32x4_t x_biased = vsubq_s32(vreinterpretq_s32_f32(vaddq_f32(x_clamped, vfmagic)), vimagic); const int32x4_t y_biased = vsubq_s32(vreinterpretq_s32_f32(vaddq_f32(y_clamped, vfmagic)), vimagic); const int32x4_t z_biased = vsubq_s32(vreinterpretq_s32_f32(vaddq_f32(z_clamped, vfmagic)), vimagic); const int32x4_t w_biased = vsubq_s32(vreinterpretq_s32_f32(vaddq_f32(w_clamped, vfmagic)), vimagic); // Select low 8 bits of each 32-bit integer in the vectors for the output. // Since result is already clamped to [qmin, qmax] subrange of [0, 255], saturation is not needed. const int16x8_t xy_packed = vcombine_s16(vmovn_s32(x_biased), vmovn_s32(y_biased)); const int16x8_t zw_packed = vcombine_s16(vmovn_s32(z_biased), vmovn_s32(w_biased)); const int8x16_t xyzw_packed = vcombine_s8(vmovn_s16(xy_packed), vmovn_s16(zw_packed)); vst1q_s8(output, xyzw_packed); output += 16; #endif } }
6,337
45.602941
116
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-fp32-scalar-fmagic.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <math.h> #include <stdint.h> #include <stddef.h> #include <xnnpack/math.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_fp32__scalar_fmagic( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 4 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); const float fmin = (float) ((int32_t) qmin - (int32_t) zero_point); const float fmax = (float) ((int32_t) qmax - (int32_t) zero_point); const float fmagic = 12582912.0f; const int32_t imagic = INT32_C(0x4B400000) - (int32_t) zero_point; for (; n != 0; n -= 4) { const int32_t x = input[0]; const int32_t y = input[1]; const int32_t z = input[2]; const int32_t w = input[3]; input += 4; const float x_scaled = (float) x * scale; const float y_scaled = (float) y * scale; const float z_scaled = (float) z * scale; const float w_scaled = (float) w * scale; const float x_clamped = math_min_f32(math_max_f32(x_scaled, fmin), fmax); const float y_clamped = math_min_f32(math_max_f32(y_scaled, fmin), fmax); const float z_clamped = math_min_f32(math_max_f32(z_scaled, fmin), fmax); const float w_clamped = math_min_f32(math_max_f32(w_scaled, fmin), fmax); const int32_t x_biased = (int32_t) float_as_uint32(x_clamped + fmagic) - imagic; const int32_t y_biased = (int32_t) float_as_uint32(y_clamped + fmagic) - imagic; const int32_t z_biased = (int32_t) float_as_uint32(z_clamped + fmagic) - imagic; const int32_t w_biased = (int32_t) float_as_uint32(w_clamped + fmagic) - imagic; output[0] = (int8_t) x_biased; output[1] = (int8_t) y_biased; output[2] = (int8_t) z_biased; output[3] = (int8_t) w_biased; output += 4; } }
2,071
31.375
84
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-fp32-scalar-lrintf.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <math.h> #include <stdint.h> #include <stddef.h> #include <xnnpack/math.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_fp32__scalar_lrintf( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 4 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); const float fmin = (float) ((int32_t) qmin - (int32_t) zero_point); const float fmax = (float) ((int32_t) qmax - (int32_t) zero_point); for (; n != 0; n -= 4) { const int32_t x = input[0]; const int32_t y = input[1]; const int32_t z = input[2]; const int32_t w = input[3]; input += 4; const float x_scaled = (float) x * scale; const float y_scaled = (float) y * scale; const float z_scaled = (float) z * scale; const float w_scaled = (float) w * scale; const float x_clamped = math_min_f32(math_max_f32(x_scaled, fmin), fmax); const float y_clamped = math_min_f32(math_max_f32(y_scaled, fmin), fmax); const float z_clamped = math_min_f32(math_max_f32(z_scaled, fmin), fmax); const float w_clamped = math_min_f32(math_max_f32(w_scaled, fmin), fmax); const int32_t x_rounded = (int32_t) lrintf(x_clamped); const int32_t y_rounded = (int32_t) lrintf(y_clamped); const int32_t z_rounded = (int32_t) lrintf(z_clamped); const int32_t w_rounded = (int32_t) lrintf(w_clamped); const int32_t x_biased = x_rounded + (int32_t) zero_point; const int32_t y_biased = y_rounded + (int32_t) zero_point; const int32_t z_biased = z_rounded + (int32_t) zero_point; const int32_t w_biased = w_rounded + (int32_t) zero_point; output[0] = (int8_t) x_biased; output[1] = (int8_t) y_biased; output[2] = (int8_t) z_biased; output[3] = (int8_t) w_biased; output += 4; } }
2,115
30.58209
77
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-fp32-sse2.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <stdint.h> #include <stddef.h> #include <emmintrin.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_fp32__sse2( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 16 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); const __m128 vscale = _mm_set1_ps(scale); const __m128i vzero_point = _mm_set1_epi16((short) (uint16_t) zero_point); const __m128i vqmin = _mm_set1_epi8((char) qmin); const __m128i vqmax = _mm_set1_epi8((char) qmax); for (; n != 0; n -= 16) { const __m128i x = _mm_loadu_si128((const __m128i*) input); const __m128i y = _mm_loadu_si128((const __m128i*) (input + 4)); const __m128i z = _mm_loadu_si128((const __m128i*) (input + 8)); const __m128i w = _mm_loadu_si128((const __m128i*) (input + 12)); input += 16; // Convert int32_t input to FP32 and multiply by FP32 scale. // Both operations involve statistically unbiased roundings (with default MXCSR rounding mode): // - Large int32_t values can't be exactly represented as FP32. CVTDQ2PS instruction on x86 would round it // according to nearest FP32 value with ties to even (assuming default MXCSR rounding mode). // - Product of two FP32 values is generally not exactly representation as an FP32 value, and will be rounded // to nearest FP32 value with ties to even with default MXCSR rounding mode. const __m128 x_scaled = _mm_mul_ps(_mm_cvtepi32_ps(x), vscale); const __m128 y_scaled = _mm_mul_ps(_mm_cvtepi32_ps(y), vscale); const __m128 z_scaled = _mm_mul_ps(_mm_cvtepi32_ps(z), vscale); const __m128 w_scaled = _mm_mul_ps(_mm_cvtepi32_ps(w), vscale); // Convert scaled FP32 result to int32_t using CVTPS2DQ instruction from x86 SSE2. CVTPS2DQ instruction rounds // result according to nearest FP32 value with ties to even (assuming default MXCSR rounding mode). // However, when conversion overflows, it produces INT32_MIN as a result. For large positive inputs the result // of conversion can become negative, which affects the final requantization result. Note that on x86 SSE2 we // have e.g. int32_t(float(INT32_MAX)) == INT32_MIN! This happens because float(INT32_MAX) rounds to 2**31, // which overflows int32_t when it is converted back to integer. // // Thankfully, we can prove that overflow never happens in this requantization scheme. The largest positive // input is INT32_MAX (2**31 - 1), which turns into 2**31 when converted to float. The largest scale value // is 0x1.FFFFFEp-1. When multiplied together, the result is 2147483520 (compare to INT32_MAX = 2147483647), // which fits into int32_t without overflow. const __m128i x_rounded = _mm_cvtps_epi32(x_scaled); const __m128i y_rounded = _mm_cvtps_epi32(y_scaled); const __m128i z_rounded = _mm_cvtps_epi32(z_scaled); const __m128i w_rounded = _mm_cvtps_epi32(w_scaled); // Standard final sequence on x86 SSE2: // - Pack to int16_t and saturate // - Add zero point // - Clamp between qmin and qmax // - Pack to int8_t and saturate const __m128i xy_packed = _mm_adds_epi16(_mm_packs_epi32(x_rounded, y_rounded), vzero_point); const __m128i zw_packed = _mm_adds_epi16(_mm_packs_epi32(z_rounded, w_rounded), vzero_point); const __m128i xy_clamped = _mm_max_epi16(_mm_min_epi16(xy_packed, vqmax), vqmin); const __m128i zw_clamped = _mm_max_epi16(_mm_min_epi16(zw_packed, vqmax), vqmin); const __m128i xyzw_clamped = _mm_packs_epi16(xy_clamped, zw_clamped); // 4x CVTDQ2PS // 4x MULPS // 4x CVTPS2DQ // 2x PACKSSDW // 2x PADDSW // 2x PMAXSW // 2x PMINSW // 1x PACKSSWB // --------------------- // 21 instructions total _mm_storeu_si128((__m128i*) output, xyzw_clamped); output += 16; } }
4,165
42.852632
114
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-fp32-sse41.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <stdint.h> #include <stddef.h> #include <nmmintrin.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_fp32__sse41( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 16 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); const __m128 vscale = _mm_set1_ps(scale); const __m128i vzero_point = _mm_set1_epi16((short) zero_point); const __m128i vqmin = _mm_set1_epi8((char) qmin); const __m128i vqmax = _mm_set1_epi8((char) qmax); for (; n != 0; n -= 16) { const __m128i x = _mm_loadu_si128((const __m128i*) input); const __m128i y = _mm_loadu_si128((const __m128i*) (input + 4)); const __m128i z = _mm_loadu_si128((const __m128i*) (input + 8)); const __m128i w = _mm_loadu_si128((const __m128i*) (input + 12)); input += 16; // Convert int32_t input to FP32 and multiply by FP32 scale. // Both operations involve statistically unbiased roundings (with default MXCSR rounding mode): // - Large int32_t values can't be exactly represented as FP32. CVTDQ2PS instruction on x86 would round it // according to nearest FP32 value with ties to even (assuming default MXCSR rounding mode). // - Product of two FP32 values is generally not exactly representation as an FP32 value, and will be rounded // to nearest FP32 value with ties to even with default MXCSR rounding mode. const __m128 x_scaled = _mm_mul_ps(_mm_cvtepi32_ps(x), vscale); const __m128 y_scaled = _mm_mul_ps(_mm_cvtepi32_ps(y), vscale); const __m128 z_scaled = _mm_mul_ps(_mm_cvtepi32_ps(z), vscale); const __m128 w_scaled = _mm_mul_ps(_mm_cvtepi32_ps(w), vscale); // Convert scaled FP32 result to int32_t using CVTPS2DQ instruction from x86 SSE2. CVTPS2DQ instruction rounds // result according to nearest FP32 value with ties to even (assuming default MXCSR rounding mode). // However, when conversion overflows, it produces INT32_MIN as a result. For large positive inputs the result // of conversion can become negative, which affects the final requantization result. Note that on x86 SSE2 we // have e.g. int32_t(float(INT32_MAX)) == INT32_MIN! This happens because float(INT32_MAX) rounds to 2**31, // which overflows int32_t when it is converted back to integer. // // Thankfully, we can prove that overflow never happens in this requantization scheme. The largest positive // input is INT32_MAX (2**31 - 1), which turns into 2**31 when converted to float. The largest scale value // is 0x1.FFFFFEp-1. When multiplied together, the result is 2147483520 (compare to INT32_MAX = 2147483647), // which fits into int32_t without overflow. const __m128i x_rounded = _mm_cvtps_epi32(x_scaled); const __m128i y_rounded = _mm_cvtps_epi32(y_scaled); const __m128i z_rounded = _mm_cvtps_epi32(z_scaled); const __m128i w_rounded = _mm_cvtps_epi32(w_scaled); // Standard final sequence on x86 SSE2: // - Pack to int16_t and saturate // - Add zero point // - Pack to int8_t and saturate // - Clamp between qmin and qmax const __m128i xy_packed = _mm_adds_epi16(_mm_packs_epi32(x_rounded, y_rounded), vzero_point); const __m128i zw_packed = _mm_adds_epi16(_mm_packs_epi32(z_rounded, w_rounded), vzero_point); const __m128i xyzw_packed = _mm_packs_epi16(xy_packed, zw_packed); const __m128i xyzw_clamped = _mm_max_epi8(_mm_min_epi8(xyzw_packed, vqmax), vqmin); // 4x CVTDQ2PS // 4x MULPS // 4x CVTPS2DQ // 2x PACKSSDW // 2x PADDSW // 1x PACKSSWB // 1x PMAXSB // 1x PMINSB // --------------------- // 19 instructions total _mm_storeu_si128((__m128i*) output, xyzw_clamped); output += 16; } }
4,068
42.287234
114
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-fp32-wasmsimd.c
// Copyright 2020 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 <assert.h> #include <stdint.h> #include <stddef.h> #include <wasm_simd128.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_fp32__wasmsimd( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 16 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); const v128_t vscale = wasm_f32x4_splat(scale); const v128_t vfmin = wasm_f32x4_splat((float) ((int32_t) qmin - (int32_t) zero_point)); const v128_t vfmax = wasm_f32x4_splat((float) ((int32_t) qmax - (int32_t) zero_point)); const v128_t vfmagic = wasm_f32x4_const_splat(12582912.0f); const v128_t vimagic = wasm_i32x4_splat(INT32_C(0x4B400000) - (int32_t) zero_point); for (; n != 0; n -= 16) { const v128_t x = wasm_v128_load(input); const v128_t y = wasm_v128_load(input + 4); const v128_t z = wasm_v128_load(input + 8); const v128_t w = wasm_v128_load(input + 12); input += 16; // Convert int32_t input to FP32 and multiply by FP32 scale. // Both operations involve statistically unbiased roundings: // - Large int32_t values can't be exactly represented as FP32. The conversion instruction in WAsm SIMD would // round it to nearest FP32 value with ties to even. // - Product of two FP32 values is generally not exactly representation as an FP32 value, and will be rounded // to nearest FP32 value with ties to even. const v128_t x_scaled = wasm_f32x4_mul(wasm_f32x4_convert_i32x4(x), vscale); const v128_t y_scaled = wasm_f32x4_mul(wasm_f32x4_convert_i32x4(y), vscale); const v128_t z_scaled = wasm_f32x4_mul(wasm_f32x4_convert_i32x4(z), vscale); const v128_t w_scaled = wasm_f32x4_mul(wasm_f32x4_convert_i32x4(w), vscale); // WAsm SIMD offers only a floating-point to integer conversion instruction with rounding towards zero. // In lieu of conversion instruction with rounding-to-nearest-even, we use a magic trick of adding a large // number (1.5 * 2**23) to scaled value to cause rounding to integer, and then substracing this magic number as // integer. This trick works only in a limited range (absolute value of input must be less than 2**22), so // generally we have to clamp input to this range before using the magic. However, clamping to any smaller range // works just as well, and thus we clamp to [qmin - zero point, qmax - zero point] range so that after we add // zero point to the result, it gets into target [qmin, qmax] range. const v128_t x_clamped = wasm_f32x4_min(wasm_f32x4_max(x_scaled, vfmin), vfmax); const v128_t y_clamped = wasm_f32x4_min(wasm_f32x4_max(y_scaled, vfmin), vfmax); const v128_t z_clamped = wasm_f32x4_min(wasm_f32x4_max(z_scaled, vfmin), vfmax); const v128_t w_clamped = wasm_f32x4_min(wasm_f32x4_max(w_scaled, vfmin), vfmax); // Conversion to integer using the "magic trick". Rounding is performed in the output of addition operation, // and result is rounded to nearest even integer with ties to even. const v128_t x_biased = wasm_i32x4_sub(wasm_f32x4_add(x_clamped, vfmagic), vimagic); const v128_t y_biased = wasm_i32x4_sub(wasm_f32x4_add(y_clamped, vfmagic), vimagic); const v128_t z_biased = wasm_i32x4_sub(wasm_f32x4_add(z_clamped, vfmagic), vimagic); const v128_t w_biased = wasm_i32x4_sub(wasm_f32x4_add(w_clamped, vfmagic), vimagic); // Select low 8 bits of each 32-bit integer in the vectors for the output. // Since result is already clamped to [qmin, qmax] subrange of [0, 255], saturation is not needed. const v128_t xy_packed = wasm_v16x8_shuffle(x_biased, y_biased, 0, 2, 4, 6, 8, 10, 12, 14); const v128_t zw_packed = wasm_v16x8_shuffle(z_biased, w_biased, 0, 2, 4, 6, 8, 10, 12, 14); const v128_t xyzw_packed = wasm_v8x16_shuffle(xy_packed, zw_packed, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30); // 4x f32x4.convert_i32x4_s // 4x f32x4.mul // 4x f32x4.max // 4x f32x4.min // 4x f32x4.add // 4x i32x4.sub // 3x v8x16.shuffle // --------------------- // 29 instructions total wasm_v128_store(output, xyzw_packed); output += 16; } }
4,378
47.655556
131
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-gemmlowp-neon.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <stdint.h> #include <stddef.h> #include <arm_neon.h> #include <xnnpack/math.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_gemmlowp__neon( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 16 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); // Compute requantization parameters. const uint32_t scale_bits = float_as_uint32(scale); // Multiplier is in [0x40000000, 0x7FFFFF80] range. const int32_t multiplier = (int32_t) (((scale_bits & UINT32_C(0x007FFFFF)) | UINT32_C(0x00800000)) << 7); assert(multiplier >= INT32_C(0x40000000)); assert(multiplier <= INT32_C(0x7FFFFF80)); // Shift is in [0, 31] range. const int32_t shift = 127 + 31 - 32 - (float_as_uint32(scale) >> 23); assert(shift >= 0); assert(shift < 32); const int32x4_t vmultiplier = vdupq_n_s32(multiplier); const int16x8_t vzero_point = vdupq_n_s16((int16_t) zero_point); const int32x4_t vshift = vdupq_n_s32(-shift); const int32x4_t vshift_eq_0_mask = vreinterpretq_s32_u32(vceqq_s32(vshift, vmovq_n_s32(0))); const int8x16_t vqmin = vdupq_n_s8(qmin); const int8x16_t vqmax = vdupq_n_s8(qmax); for (; n != 0; n -= 16) { const int32x4_t x = vld1q_s32(input); const int32x4_t y = vld1q_s32(input + 4); const int32x4_t z = vld1q_s32(input + 8); const int32x4_t w = vld1q_s32(input + 12); input += 16; // Directly use VQRDMULH/SQRDMULH instruction for Q31 multiplication with rounding. // Although these instruction saturate out-of-range outputs, we never hit this case in requantization. const int32x4_t x_product = vqrdmulhq_s32(x, vmultiplier); const int32x4_t y_product = vqrdmulhq_s32(y, vmultiplier); const int32x4_t z_product = vqrdmulhq_s32(z, vmultiplier); const int32x4_t w_product = vqrdmulhq_s32(w, vmultiplier); // Shift the 32-bit product right with rounding. // Rounding is performed towards closest integer, with midpoints rounded away from zero. // // We leverage the "right shift with rounding" instruction (VRSHL.S32 on ARM NEON, SRSHL in ARM64 Advanced SIMD) to // do the shift. However, as this instruction rounds midpoints up, rather than away from zero, we adjust the input // by subtracting 1 from negative values, but only if shift is non-zero. const int32x4_t x_adjusted_product = vsraq_n_s32(x_product, vbicq_s32(x, vshift_eq_0_mask), 31); const int32x4_t y_adjusted_product = vsraq_n_s32(y_product, vbicq_s32(y, vshift_eq_0_mask), 31); const int32x4_t z_adjusted_product = vsraq_n_s32(z_product, vbicq_s32(z, vshift_eq_0_mask), 31); const int32x4_t w_adjusted_product = vsraq_n_s32(w_product, vbicq_s32(w, vshift_eq_0_mask), 31); const int32x4_t x_scaled = vrshlq_s32(x_adjusted_product, vshift); const int32x4_t y_scaled = vrshlq_s32(y_adjusted_product, vshift); const int32x4_t z_scaled = vrshlq_s32(z_adjusted_product, vshift); const int32x4_t w_scaled = vrshlq_s32(w_adjusted_product, vshift); #ifdef __aarch64__ const int16x8_t xy_packed = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(x_scaled), y_scaled), vzero_point); const int16x8_t zw_packed = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(z_scaled), w_scaled), vzero_point); const int8x16_t xyzw_packed = vqmovn_high_s16(vqmovn_s16(xy_packed), zw_packed); #else const int16x8_t xy_packed = vqaddq_s16(vcombine_s16(vqmovn_s32(x_scaled), vqmovn_s32(y_scaled)), vzero_point); const int16x8_t zw_packed = vqaddq_s16(vcombine_s16(vqmovn_s32(z_scaled), vqmovn_s32(w_scaled)), vzero_point); const int8x16_t xyzw_packed = vcombine_s8(vqmovn_s16(xy_packed), vqmovn_s16(zw_packed)); #endif const int8x16_t xyzw_clamped = vmaxq_s8(vminq_s8(xyzw_packed, vqmax), vqmin); // AArch32 version: // 4x VQRDMULH.S32 Qd, Qm, Qn // 4x VAND Qd, Qm, Dn // 4x VSRA.S32 Qd, Qm, #31 // 4x VRSHL.S32 Qd, Qm, Qn // 4x VQMOVN.S32 Dd, Qm // 2x VQADD.S16 Qd, Qm, Qn // 2x VQMOVN.S16 Dd, Qm // 1x VMAX.S8 Qd, Qm, Qn // 1x VMIN.S8 Qd, Qm, Qn // --------------------- // 26 instructions total // // AArch64 version: // 4x SQRDMULH Vd.4S, Vn.4S, Vm.4S // 4x AND Vd.16B, Vn.16B, Vm.16B // 4x SSRA Vd.4S, Vn.4S, #31 // 4x SRSHL Vd.4S, Vn.4S, Vm.4S // 2x SQXTN Vd.4H, Vn.4S // 2x SQXTN2 Vd.8H, Vn.4S // 2x SQADD Vd.8H, Vn.8H, Vm.8H // 1x SQXTN Vd.8B, Vn.8H // 1x SQXTN2 Vd.16B, Vn.8H // 1x SMIN Vd.16B, Vn.16B, Vm.16B // 1x SMAX Vd.16B, Vn.16B, Vm.16B // --------------------- // 26 instructions total vst1q_s8(output, xyzw_clamped); output += 16; } }
4,990
38.928
119
c
XNNPACK
XNNPACK-master/src/qs8-requantization/qs8-requantization-gemmlowp-scalar.c
// Copyright (c) Facebook, Inc. and its affiliates. // All rights reserved. // // Copyright 2019 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 <assert.h> #include <stdint.h> #include <stddef.h> #include <xnnpack/math.h> #include <xnnpack/requantization-stubs.h> void xnn_qs8_requantize_gemmlowp__scalar( size_t n, const int32_t* input, float scale, int8_t zero_point, int8_t qmin, int8_t qmax, int8_t* output) { assert(n % 4 == 0); assert(scale < 1.0f); assert(scale >= 0x1.0p-32f); // Compute requantization parameters. const uint32_t scale_bits = float_as_uint32(scale); // Multiplier is in [0x40000000, 0x7FFFFF80] range. const int32_t multiplier = (int32_t)(((scale_bits & UINT32_C(0x007FFFFF)) | UINT32_C(0x00800000)) << 7); assert(multiplier >= INT32_C(0x40000000)); assert(multiplier <= INT32_C(0x7FFFFF80)); // Shift is in [0, 31] range. const int32_t shift = 127 + 31 - 32 - (float_as_uint32(scale) >> 23); assert(shift >= 0); assert(shift < 32); const int64_t q31rounding = INT64_C(0x40000000); const int32_t remainder_mask = (int32_t)((UINT32_C(1) << shift) - UINT32_C(1)); const int32_t threshold = (int32_t)((uint32_t) remainder_mask >> 1); const int32_t smin = (int32_t) qmin - (int32_t) zero_point; const int32_t smax = (int32_t) qmax - (int32_t) zero_point; for (; n != 0; n -= 4) { const int32_t x = input[0]; const int32_t y = input[1]; const int32_t z = input[2]; const int32_t w = input[3]; input += 4; // Compute full 64-bit product of signed 32-bit factors. // // Note: multiplier can be treated as either signed or unsigned. const int64_t x_product = (int64_t) x * (int64_t) multiplier; const int64_t y_product = (int64_t) y * (int64_t) multiplier; const int64_t z_product = (int64_t) z * (int64_t) multiplier; const int64_t w_product = (int64_t) w * (int64_t) multiplier; // Get the Q31 multiplication result by extracting bits 31-62 of the product, with rounding up. // Add rounding value (0x40000000) and then shift right by 31 bits and extract the low 32-bit word. // Note: casts to unsigned types are needed to avoid undefined behavior. // Given the multiplier range, the result of Q31 multiplication is in [-2147483520, 2147483519] range. const int32_t x_q31product = (int32_t) (uint32_t) ((uint64_t) (x_product + q31rounding) >> 31); const int32_t y_q31product = (int32_t) (uint32_t) ((uint64_t) (y_product + q31rounding) >> 31); const int32_t z_q31product = (int32_t) (uint32_t) ((uint64_t) (z_product + q31rounding) >> 31); const int32_t w_q31product = (int32_t) (uint32_t) ((uint64_t) (w_product + q31rounding) >> 31); // Arithmetically shift the adjusted product right with rounding. // Rounding is performed towards closest integer, with midpoints rounded away from zero. // // Shift with correct rounding could be efficiently implemented by pre-adding rounding constant, but with input in // [-2147483520, 2147483519] range and rounding constant up to 2**30 we can't rule out overflow. This limitation // leaves us with 3 options: // 1. Extend input to 64-bit signed integer, perform addition and shift on 64-bit integers, then truncate result // to 32 bits. // 2. Detect overflow and handle this situation separately. Note that overflow is possible only when input is // positive, and even when addition of a rounding constant overflows 32-bit signed integer, it still doesn't // overflow 32-bit unsigned integer. Thus, in case of signed overflow, we can compute the result using unsigned // arithmetics, specifically using logical shift right instead of arithmetic shift right. // 3. Performs arithmetic shift as is, which will produce division result rounded down. Then compute remainder of // this division by a power of 2, and adjust the result. Result needs adjustment (increment by 1) when // - input is positive, shift is non-zero, and remainder >= 2**(shift - 1), e.g. 10 >> 2 needs adjustment // - input is negative, shift is non-zero, and remainder > 2**(shift - 1), e.g. -10 >> 2 doesn't need adjustment // These conditions can be generalized as // remainder + (input <= 0) > 2**(shift - 1) // or equivalently // remainder - (input < 0) > ((2**shift - 1) >> 1) // When shift is 0, remainder is 0 as well, the last condition is always false, and no adjustment is done. // // Among these options, option 3 is the most performant across the board, although option 1 is promising for 64-bit // instruction sets. const int32_t x_remainder = (x_q31product & remainder_mask) - (int32_t) (x_q31product < 0); const int32_t y_remainder = (y_q31product & remainder_mask) - (int32_t) (y_q31product < 0); const int32_t z_remainder = (z_q31product & remainder_mask) - (int32_t) (z_q31product < 0); const int32_t w_remainder = (w_q31product & remainder_mask) - (int32_t) (w_q31product < 0); const int32_t x_scaled = math_asr_s32(x_q31product, shift) + (int32_t) (x_remainder > threshold); const int32_t y_scaled = math_asr_s32(y_q31product, shift) + (int32_t) (y_remainder > threshold); const int32_t z_scaled = math_asr_s32(z_q31product, shift) + (int32_t) (z_remainder > threshold); const int32_t w_scaled = math_asr_s32(w_q31product, shift) + (int32_t) (w_remainder > threshold); // Clamp scaled value with zero point between (qmin - zero point) and (qmax - zero point). const int32_t x_clamped = math_min_s32(math_max_s32(x_scaled, smin), smax); const int32_t y_clamped = math_min_s32(math_max_s32(y_scaled, smin), smax); const int32_t z_clamped = math_min_s32(math_max_s32(z_scaled, smin), smax); const int32_t w_clamped = math_min_s32(math_max_s32(w_scaled, smin), smax); // Add zero point to clamped value. // The result is guaranteed to be in [qmin, qmax] range. // // This addition can be safely done before clamping, because scaled values are in [-2147483520, 2147483519] // range, so addition of zero point (which is in [-128, 127] range) can not overflow signed 32-bit integer. const int32_t x_biased = x_clamped + zero_point; const int32_t y_biased = y_clamped + zero_point; const int32_t z_biased = z_clamped + zero_point; const int32_t w_biased = w_clamped + zero_point; output[0] = (int8_t) x_biased; output[1] = (int8_t) y_biased; output[2] = (int8_t) z_biased; output[3] = (int8_t) w_biased; output += 4; } }
6,682
50.806202
120
c