| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | static void resize_bilinear_image_packn(const Mat& src, Mat& dst, float* alpha, int* xofs, float* beta, int* yofs) |
| 16 | { |
| 17 | const int packn = csrr_vlenb() / 4; |
| 18 | const size_t vl = vsetvl_e32m1(packn); |
| 19 | |
| 20 | int w = dst.w; |
| 21 | int h = dst.h; |
| 22 | |
| 23 | // loop body |
| 24 | Mat rowsbuf0(w, (size_t)packn * 4u, packn); |
| 25 | Mat rowsbuf1(w, (size_t)packn * 4u, packn); |
| 26 | float* rows0 = rowsbuf0; |
| 27 | float* rows1 = rowsbuf1; |
| 28 | |
| 29 | int prev_sy1 = -2; |
| 30 | |
| 31 | for (int dy = 0; dy < h; dy++) |
| 32 | { |
| 33 | int sy = yofs[dy]; |
| 34 | |
| 35 | if (sy == prev_sy1) |
| 36 | { |
| 37 | // reuse all rows |
| 38 | } |
| 39 | else if (sy == prev_sy1 + 1) |
| 40 | { |
| 41 | // hresize one row |
| 42 | float* rows0_old = rows0; |
| 43 | rows0 = rows1; |
| 44 | rows1 = rows0_old; |
| 45 | const float* S1 = src.row(sy + 1); |
| 46 | |
| 47 | const float* alphap = alpha; |
| 48 | float* rows1p = rows1; |
| 49 | int dx = 0; |
| 50 | for (; dx < w; dx++) |
| 51 | { |
| 52 | int sx = xofs[dx] * packn; |
| 53 | const float* S1p = S1 + sx; |
| 54 | |
| 55 | vfloat32m1_t _S10 = vle32_v_f32m1(S1p, vl); |
| 56 | vfloat32m1_t _S11 = vle32_v_f32m1(S1p + packn, vl); |
| 57 | vfloat32m1_t _rows1 = vfmacc_vf_f32m1(vfmul_vf_f32m1(_S10, alphap[0], vl), alphap[1], _S11, vl); |
| 58 | |
| 59 | vse32_v_f32m1(rows1p + dx * packn, _rows1, vl); |
| 60 | |
| 61 | alphap += 2; |
| 62 | } |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | // hresize two rows |
| 67 | const float* S0 = src.row(sy); |
| 68 | const float* S1 = src.row(sy + 1); |
| 69 | |
| 70 | const float* alphap = alpha; |
| 71 | float* rows0p = rows0; |
| 72 | float* rows1p = rows1; |
| 73 | int dx = 0; |
| 74 | for (; dx < w; dx++) |
| 75 | { |
| 76 | int sx = xofs[dx] * packn; |
| 77 | const float* S0p = S0 + sx; |
| 78 | const float* S1p = S1 + sx; |
| 79 | |
| 80 | vfloat32m1_t _S00 = vle32_v_f32m1(S0p, vl); |
| 81 | vfloat32m1_t _S01 = vle32_v_f32m1(S0p + packn, vl); |
| 82 | vfloat32m1_t _S10 = vle32_v_f32m1(S1p, vl); |
| 83 | vfloat32m1_t _S11 = vle32_v_f32m1(S1p + packn, vl); |
| 84 | vfloat32m1_t _rows0 = vfmacc_vf_f32m1(vfmul_vf_f32m1(_S00, alphap[0], vl), alphap[1], _S01, vl); |
| 85 | vfloat32m1_t _rows1 = vfmacc_vf_f32m1(vfmul_vf_f32m1(_S10, alphap[0], vl), alphap[1], _S11, vl); |
| 86 | |
| 87 | vse32_v_f32m1(rows0p + dx * packn, _rows0, vl); |
| 88 | vse32_v_f32m1(rows1p + dx * packn, _rows1, vl); |
| 89 | |
| 90 | alphap += 2; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | prev_sy1 = sy; |
| 95 | |
| 96 | // vresize |
| 97 | float b0 = beta[0]; |
| 98 | float b1 = beta[1]; |
| 99 | |
| 100 | float* rows0p = rows0; |
| 101 | float* rows1p = rows1; |
| 102 | float* Dp = dst.row(dy); |
| 103 | |
| 104 | for (int dx = 0; dx < w; dx++) |
| 105 | { |
| 106 | vfloat32m1_t _rows0 = vle32_v_f32m1(rows0p, vl); |
| 107 | vfloat32m1_t _rows1 = vle32_v_f32m1(rows1p, vl); |
| 108 | |
| 109 | vfloat32m1_t _Dp = vfmacc_vf_f32m1(vfmul_vf_f32m1(_rows0, b0, vl), b1, _rows1, vl); |
| 110 | |
| 111 | vse32_v_f32m1(Dp, _Dp, vl); |
| 112 | |
| 113 | Dp += packn; |
| 114 | rows0p += packn; |
| 115 | rows1p += packn; |
| 116 | } |
| 117 | |
| 118 | beta += 2; |
| 119 | } |
| 120 | } |