| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
|
| 12 |
#include <wasm_simd128.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/ibilinear.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_s8_ibilinear_ukernel__wasmsimd_mul32_c8( |
| 19 |
size_t output_pixels, |
| 20 |
size_t channels, |
| 21 |
const int8_t** restrict input, |
| 22 |
size_t input_offset, |
| 23 |
const int16_t* restrict weights, |
| 24 |
int8_t* restrict output, |
| 25 |
size_t output_increment) XNN_OOB_READS |
| 26 |
{ |
| 27 |
assert(output_pixels != 0); |
| 28 |
assert(channels != 0); |
| 29 |
|
| 30 |
do { |
| 31 |
const int8_t* i0 = (const int8_t*) ((uintptr_t) input[0] + input_offset); |
| 32 |
const int8_t* i1 = (const int8_t*) ((uintptr_t) input[1] + input_offset); |
| 33 |
const int8_t* i2 = (const int8_t*) ((uintptr_t) input[2] + input_offset); |
| 34 |
const int8_t* i3 = (const int8_t*) ((uintptr_t) input[3] + input_offset); |
| 35 |
input += 4; |
| 36 |
|
| 37 |
const v128_t valphah = wasm_i32x4_extend_low_i16x8(wasm_v128_load16_splat(weights)); |
| 38 |
const v128_t valphav = wasm_i32x4_extend_low_i16x8(wasm_v128_load16_splat(weights + 1)); |
| 39 |
weights += 2; |
| 40 |
|
| 41 |
const v128_t vrounding = wasm_i32x4_const_splat(0x00200000); |
| 42 |
|
| 43 |
size_t c = channels; |
| 44 |
for (; c >= 8 * sizeof(int8_t); c -= 8 * sizeof(int8_t)) { |
| 45 |
const v128_t vtl01234567 = wasm_i16x8_load8x8(i0); |
| 46 |
i0 += 8; |
| 47 |
const v128_t vtr01234567 = wasm_i16x8_load8x8(i1); |
| 48 |
i1 += 8; |
| 49 |
const v128_t vbl01234567 = wasm_i16x8_load8x8(i2); |
| 50 |
i2 += 8; |
| 51 |
const v128_t vbr01234567 = wasm_i16x8_load8x8(i3); |
| 52 |
i3 += 8; |
| 53 |
|
| 54 |
const v128_t vtd01234567 = wasm_i16x8_sub(vtr01234567, vtl01234567); |
| 55 |
const v128_t vbd01234567 = wasm_i16x8_sub(vbr01234567, vbl01234567); |
| 56 |
const v128_t vdl01234567 = wasm_i16x8_sub(vbl01234567, vtl01234567); |
| 57 |
const v128_t vdd01234567 = wasm_i16x8_sub(vbd01234567, vtd01234567); |
| 58 |
|
| 59 |
const v128_t vt0123 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_low_i16x8(vtl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_low_i16x8(vtd01234567), valphah)); |
| 60 |
const v128_t vt4567 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_high_i16x8(vtl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_high_i16x8(vtd01234567), valphah)); |
| 61 |
const v128_t vd0123 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_low_i16x8(vdl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_low_i16x8(vdd01234567), valphah)); |
| 62 |
const v128_t vd4567 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_high_i16x8(vdl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_high_i16x8(vdd01234567), valphah)); |
| 63 |
|
| 64 |
v128_t vacc0123 = wasm_i32x4_mul(vd0123, valphav); |
| 65 |
v128_t vacc4567 = wasm_i32x4_mul(vd4567, valphav); |
| 66 |
|
| 67 |
vacc0123 = wasm_i32x4_add(wasm_i32x4_shl(vt0123, 11), vacc0123); |
| 68 |
vacc4567 = wasm_i32x4_add(wasm_i32x4_shl(vt4567, 11), vacc4567); |
| 69 |
|
| 70 |
vacc0123 = wasm_i32x4_shr(wasm_i16x8_add(vacc0123, vrounding), 22); |
| 71 |
vacc4567 = wasm_i32x4_shr(wasm_i16x8_add(vacc4567, vrounding), 22); |
| 72 |
|
| 73 |
const v128_t vacc01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567); |
| 74 |
|
| 75 |
const v128_t vo01234567 = wasm_i8x16_narrow_i16x8(vacc01234567, vacc01234567); |
| 76 |
|
| 77 |
wasm_v128_store64_lane(output, vo01234567, 0); |
| 78 |
output += 8; |
| 79 |
} |
| 80 |
if XNN_UNLIKELY(c != 0) { |
| 81 |
const v128_t vtl01234567 = wasm_i16x8_load8x8(i0); |
| 82 |
const v128_t vtr01234567 = wasm_i16x8_load8x8(i1); |
| 83 |
const v128_t vbl01234567 = wasm_i16x8_load8x8(i2); |
| 84 |
const v128_t vbr01234567 = wasm_i16x8_load8x8(i3); |
| 85 |
|
| 86 |
const v128_t vtd01234567 = wasm_i16x8_sub(vtr01234567, vtl01234567); |
| 87 |
const v128_t vbd01234567 = wasm_i16x8_sub(vbr01234567, vbl01234567); |
| 88 |
const v128_t vdl01234567 = wasm_i16x8_sub(vbl01234567, vtl01234567); |
| 89 |
const v128_t vdd01234567 = wasm_i16x8_sub(vbd01234567, vtd01234567); |
| 90 |
|
| 91 |
const v128_t vt0123 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_low_i16x8(vtl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_low_i16x8(vtd01234567), valphah)); |
| 92 |
const v128_t vt4567 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_high_i16x8(vtl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_high_i16x8(vtd01234567), valphah)); |
| 93 |
const v128_t vd0123 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_low_i16x8(vdl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_low_i16x8(vdd01234567), valphah)); |
| 94 |
const v128_t vd4567 = wasm_i32x4_add(wasm_i32x4_shl(wasm_i32x4_extend_high_i16x8(vdl01234567), 11), wasm_i32x4_mul(wasm_i32x4_extend_high_i16x8(vdd01234567), valphah)); |
| 95 |
|
| 96 |
v128_t vacc0123 = wasm_i32x4_mul(vd0123, valphav); |
| 97 |
v128_t vacc4567 = wasm_i32x4_mul(vd4567, valphav); |
| 98 |
|
| 99 |
vacc0123 = wasm_i32x4_add(wasm_i32x4_shl(vt0123, 11), vacc0123); |
| 100 |
vacc4567 = wasm_i32x4_add(wasm_i32x4_shl(vt4567, 11), vacc4567); |
| 101 |
|
| 102 |
vacc0123 = wasm_i32x4_shr(wasm_i16x8_add(vacc0123, vrounding), 22); |
| 103 |
vacc4567 = wasm_i32x4_shr(wasm_i16x8_add(vacc4567, vrounding), 22); |
| 104 |
|
| 105 |
const v128_t vacc01234567 = wasm_i16x8_narrow_i32x4(vacc0123, vacc4567); |
| 106 |
|
| 107 |
v128_t vo01234567 = wasm_i8x16_narrow_i16x8(vacc01234567, vacc01234567); |
| 108 |
|
| 109 |
if (c & (4 * sizeof(int8_t))) { |
| 110 |
wasm_v128_store32_lane(output, vo01234567, 0); |
| 111 |
vo01234567 = wasm_u64x2_shr(vo01234567, 32); |
| 112 |
output += 4; |
| 113 |
} |
| 114 |
if (c & (2 * sizeof(int8_t))) { |
| 115 |
wasm_v128_store16_lane(output, vo01234567, 0); |
| 116 |
vo01234567 = wasm_u32x4_shr(vo01234567, 16); |
| 117 |
output += 2; |
| 118 |
} |
| 119 |
if (c & (1 * sizeof(int8_t))) { |
| 120 |
wasm_v128_store8_lane(output, vo01234567, 0); |
| 121 |
output += 1; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
output = (int8_t*) ((uintptr_t) output + output_increment); |
| 126 |
} while (--output_pixels != 0); |
| 127 |
} |