| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/x32-transposec/rvv.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2023 SiFive, Inc. |
| 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 |
#include <riscv_vector.h> |
| 11 |
|
| 12 |
#include <assert.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/math.h" |
| 16 |
#include "xnnpack/transpose.h" |
| 17 |
|
| 18 |
void xnn_x32_transposec_ukernel__4x4_rvv( |
| 19 |
const uint32_t* input, |
| 20 |
uint32_t* output, |
| 21 |
size_t input_stride, |
| 22 |
size_t output_stride, |
| 23 |
size_t block_width, |
| 24 |
size_t block_height) XNN_OOB_READS |
| 25 |
{ |
| 26 |
assert(block_width == 1 || output_stride >= block_height * sizeof(uint32_t)); |
| 27 |
assert(block_height == 1 || input_stride >= block_width * sizeof(uint32_t)); |
| 28 |
|
| 29 |
const size_t tile_height = 4; |
| 30 |
const size_t tile_width = 4; |
| 31 |
const size_t tile_hbytes = tile_height * sizeof(uint32_t); |
| 32 |
const size_t tile_wbytes = tile_width * sizeof(uint32_t); |
| 33 |
const size_t input_reset = tile_wbytes - round_down_po2(block_height, tile_height) * input_stride; |
| 34 |
const size_t input_offset = tile_height * input_stride; |
| 35 |
const size_t output_reset = tile_width * output_stride - round_down_po2(block_height, 2) * sizeof(uint32_t); |
| 36 |
|
| 37 |
const uint32_t* i0 = input; |
| 38 |
|
| 39 |
uint32_t* o0 = (uint32_t*) output; |
| 40 |
uint32_t* o1 = (uint32_t*) ((uintptr_t) o0 + output_stride); |
| 41 |
uint32_t* o2 = (uint32_t*) ((uintptr_t) o1 + output_stride); |
| 42 |
uint32_t* o3 = (uint32_t*) ((uintptr_t) o2 + output_stride); |
| 43 |
|
| 44 |
do { |
| 45 |
size_t bh = block_height; |
| 46 |
size_t vl = __riscv_vsetvl_e32m1(tile_height); |
| 47 |
for (; bh >= 4; bh -= 4) { |
| 48 |
if (block_width >= tile_width) { |
| 49 |
vuint32m1x4_t tuple = __riscv_vlsseg4e32_v_u32m1x4(i0, input_stride, vl); |
| 50 |
|
| 51 |
vuint32m1_t v_d0 = __riscv_vget_v_u32m1x4_u32m1(tuple, 0); |
| 52 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 53 |
vuint32m1_t v_d1 = __riscv_vget_v_u32m1x4_u32m1(tuple, 1); |
| 54 |
__riscv_vse32_v_u32m1(o1, v_d1, vl); |
| 55 |
vuint32m1_t v_d2 = __riscv_vget_v_u32m1x4_u32m1(tuple, 2); |
| 56 |
__riscv_vse32_v_u32m1(o2, v_d2, vl); |
| 57 |
vuint32m1_t v_d3 = __riscv_vget_v_u32m1x4_u32m1(tuple, 3); |
| 58 |
__riscv_vse32_v_u32m1(o3, v_d3, vl); |
| 59 |
|
| 60 |
} else { |
| 61 |
switch (block_width) { |
| 62 |
case 3: { |
| 63 |
vuint32m1x3_t tuple = __riscv_vlsseg3e32_v_u32m1x3(i0, input_stride, vl); |
| 64 |
|
| 65 |
vuint32m1_t v_d0 = __riscv_vget_v_u32m1x3_u32m1(tuple, 0); |
| 66 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 67 |
vuint32m1_t v_d1 = __riscv_vget_v_u32m1x3_u32m1(tuple, 1); |
| 68 |
__riscv_vse32_v_u32m1(o1, v_d1, vl); |
| 69 |
vuint32m1_t v_d2 = __riscv_vget_v_u32m1x3_u32m1(tuple, 2); |
| 70 |
__riscv_vse32_v_u32m1(o2, v_d2, vl); |
| 71 |
break; |
| 72 |
} |
| 73 |
|
| 74 |
case 2: { |
| 75 |
vuint32m1x2_t tuple = __riscv_vlsseg2e32_v_u32m1x2(i0, input_stride, vl); |
| 76 |
|
| 77 |
vuint32m1_t v_d0 = __riscv_vget_v_u32m1x2_u32m1(tuple, 0); |
| 78 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 79 |
vuint32m1_t v_d1 = __riscv_vget_v_u32m1x2_u32m1(tuple, 1); |
| 80 |
__riscv_vse32_v_u32m1(o1, v_d1, vl); |
| 81 |
break; |
| 82 |
} |
| 83 |
|
| 84 |
case 1: { |
| 85 |
vuint32m1_t v_d0 = __riscv_vlse32_v_u32m1(i0, input_stride, vl); |
| 86 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 87 |
break; |
| 88 |
} |
| 89 |
|
| 90 |
default: |
| 91 |
XNN_UNREACHABLE; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
i0 = (uint32_t*) ((uintptr_t) i0 + input_offset); |
| 96 |
o3 = (uint32_t*) ((uintptr_t) o3 + tile_hbytes); |
| 97 |
o2 = (uint32_t*) ((uintptr_t) o2 + tile_hbytes); |
| 98 |
o1 = (uint32_t*) ((uintptr_t) o1 + tile_hbytes); |
| 99 |
o0 = (uint32_t*) ((uintptr_t) o0 + tile_hbytes); |
| 100 |
} |
| 101 |
|
| 102 |
if (bh != 0) { |
| 103 |
const uint32_t* i = i0; |
| 104 |
vl = __riscv_vsetvl_e32m1(bh); |
| 105 |
if (block_width >= tile_width) { |
| 106 |
vuint32m1x4_t tuple = __riscv_vlsseg4e32_v_u32m1x4(i, input_stride, vl); |
| 107 |
|
| 108 |
vuint32m1_t v_d0 = __riscv_vget_v_u32m1x4_u32m1(tuple, 0); |
| 109 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 110 |
vuint32m1_t v_d1 = __riscv_vget_v_u32m1x4_u32m1(tuple, 1); |
| 111 |
__riscv_vse32_v_u32m1(o1, v_d1, vl); |
| 112 |
vuint32m1_t v_d2 = __riscv_vget_v_u32m1x4_u32m1(tuple, 2); |
| 113 |
__riscv_vse32_v_u32m1(o2, v_d2, vl); |
| 114 |
vuint32m1_t v_d3 = __riscv_vget_v_u32m1x4_u32m1(tuple, 3); |
| 115 |
__riscv_vse32_v_u32m1(o3, v_d3, vl); |
| 116 |
} else { |
| 117 |
switch(block_width) { |
| 118 |
case 3: { |
| 119 |
vuint32m1x3_t tuple = __riscv_vlsseg3e32_v_u32m1x3(i, input_stride, vl); |
| 120 |
|
| 121 |
vuint32m1_t v_d0 = __riscv_vget_v_u32m1x3_u32m1(tuple, 0); |
| 122 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 123 |
vuint32m1_t v_d1 = __riscv_vget_v_u32m1x3_u32m1(tuple, 1); |
| 124 |
__riscv_vse32_v_u32m1(o1, v_d1, vl); |
| 125 |
vuint32m1_t v_d2 = __riscv_vget_v_u32m1x3_u32m1(tuple, 2); |
| 126 |
__riscv_vse32_v_u32m1(o2, v_d2, vl); |
| 127 |
break; |
| 128 |
} |
| 129 |
case 2: { |
| 130 |
vuint32m1x2_t tuple = __riscv_vlsseg2e32_v_u32m1x2(i, input_stride, vl); |
| 131 |
|
| 132 |
vuint32m1_t v_d0 = __riscv_vget_v_u32m1x2_u32m1(tuple, 0); |
| 133 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 134 |
vuint32m1_t v_d1 = __riscv_vget_v_u32m1x2_u32m1(tuple, 1); |
| 135 |
__riscv_vse32_v_u32m1(o1, v_d1, vl); |
| 136 |
break; |
| 137 |
} |
| 138 |
|
| 139 |
case 1: { |
| 140 |
vuint32m1_t v_d0 = __riscv_vlse32_v_u32m1(i, input_stride, vl); |
| 141 |
__riscv_vse32_v_u32m1(o0, v_d0, vl); |
| 142 |
break; |
| 143 |
} |
| 144 |
|
| 145 |
default: |
| 146 |
XNN_UNREACHABLE; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
if (bh & 2) { |
| 151 |
o3 += 2; |
| 152 |
o2 += 2; |
| 153 |
o1 += 2; |
| 154 |
o0 += 2; |
| 155 |
i = (uint32_t*) ((uintptr_t) i + input_stride * 2); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
i0 = (const uint32_t*) ((uintptr_t) i0 + input_reset); |
| 160 |
|
| 161 |
o0 = (uint32_t*) ((uintptr_t) o0 + output_reset); |
| 162 |
o1 = (uint32_t*) ((uintptr_t) o1 + output_reset); |
| 163 |
o2 = (uint32_t*) ((uintptr_t) o2 + output_reset); |
| 164 |
o3 = (uint32_t*) ((uintptr_t) o3 + output_reset); |
| 165 |
|
| 166 |
block_width = doz(block_width, tile_width); |
| 167 |
} while (block_width != 0); |
| 168 |
} |