| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-rsum/wasmsimd.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2024 Google LLC |
| 6 |
// |
| 7 |
// This source code is licensed under the BSD-style license found in the |
| 8 |
// LICENSE file in the root directory of this source tree. |
| 9 |
|
| 10 |
|
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
#include <wasm_simd128.h> |
| 14 |
|
| 15 |
#include "xnnpack/common.h" |
| 16 |
#include "xnnpack/reduce.h" |
| 17 |
|
| 18 |
void xnn_qu8_rsum_ukernel__wasmsimd_u8( |
| 19 |
size_t batch, |
| 20 |
const uint8_t* input, |
| 21 |
uint32_t* output, |
| 22 |
const struct xnn_qs8_rsum_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(input != NULL); |
| 26 |
assert(output != NULL); |
| 27 |
assert(params != NULL); |
| 28 |
|
| 29 |
XNN_ALIGN(16) static const int16_t mask_table[16] = { |
| 30 |
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, |
| 31 |
0, 0, 0, 0, 0, 0, 0, 0 |
| 32 |
}; |
| 33 |
|
| 34 |
v128_t vacc0 = wasm_i32x4_const_splat(0); |
| 35 |
|
| 36 |
// 256 int8s may be summed into an int16 before overflowing. |
| 37 |
// Each register has 8 lanes and there are 1 accumulators so batch size is 2048 |
| 38 |
for (; batch >= 2048; batch -= 2048) { |
| 39 |
v128_t vacc16_0 = wasm_i16x8_const_splat(0); |
| 40 |
for (size_t current_batch = 2048; current_batch > 0; current_batch -= 8) { |
| 41 |
const v128_t vt0 = wasm_u16x8_load8x8(input); input += 8; |
| 42 |
vacc16_0 = wasm_i16x8_add(vacc16_0, vt0); |
| 43 |
} |
| 44 |
vacc0 = wasm_i32x4_add(vacc0, wasm_u32x4_extend_low_u16x8(vacc16_0)); |
| 45 |
vacc0 = wasm_i32x4_add(vacc0, wasm_u32x4_extend_high_u16x8(vacc16_0)); |
| 46 |
} |
| 47 |
|
| 48 |
if (XNN_UNLIKELY(batch != 0)) { |
| 49 |
assert(batch >= 1 && batch < 2048); |
| 50 |
v128_t vacc16 = wasm_i16x8_const_splat(0); |
| 51 |
for (; batch >= 8; batch -= 8) { |
| 52 |
const v128_t vt = wasm_u16x8_load8x8(input); input += 8; |
| 53 |
vacc16 = wasm_i16x8_add(vacc16, vt); |
| 54 |
} |
| 55 |
if (XNN_UNLIKELY(batch != 0)) { |
| 56 |
assert(batch >= 1 && batch <= 7); |
| 57 |
const v128_t mask = wasm_v128_load(&mask_table[8 - batch]); |
| 58 |
const v128_t vt = wasm_v128_bitselect(wasm_u16x8_load8x8(input), wasm_i16x8_const_splat(0), mask); |
| 59 |
vacc16 = wasm_i16x8_add(vacc16, vt); |
| 60 |
} |
| 61 |
vacc0 = wasm_i32x4_add(vacc0, wasm_u32x4_extend_low_u16x8(vacc16)); |
| 62 |
vacc0 = wasm_i32x4_add(vacc0, wasm_u32x4_extend_high_u16x8(vacc16)); |
| 63 |
} |
| 64 |
|
| 65 |
v128_t vacc_shifted = wasm_i32x4_shuffle(vacc0, vacc0, 1, 0, 3, 2); |
| 66 |
v128_t vacc_lo = wasm_i32x4_add(vacc0, vacc_shifted); |
| 67 |
|
| 68 |
v128_t vacc_final_shifted = wasm_i32x4_shuffle(vacc_lo, vacc_lo, 2, 3, 0, 1); |
| 69 |
v128_t vacc_final = wasm_i32x4_add(vacc_lo, vacc_final_shifted); |
| 70 |
const int32_t vacc = wasm_u32x4_extract_lane(vacc_final, 0); |
| 71 |
|
| 72 |
*output += vacc; |
| 73 |
} |