rotate_msa.cc 9.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *  Copyright 2016 The LibYuv Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS. All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "libyuv/rotate_row.h"

// This module is for GCC MSA
#if !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa)
#include "libyuv/macros_msa.h"

#ifdef __cplusplus
namespace libyuv {
extern "C" {
#endif

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#define ILVRL_B(in0, in1, in2, in3, out0, out1, out2, out3) \
  {                                                         \
    out0 = (v16u8)__msa_ilvr_b((v16i8)in1, (v16i8)in0);     \
    out1 = (v16u8)__msa_ilvl_b((v16i8)in1, (v16i8)in0);     \
    out2 = (v16u8)__msa_ilvr_b((v16i8)in3, (v16i8)in2);     \
    out3 = (v16u8)__msa_ilvl_b((v16i8)in3, (v16i8)in2);     \
  }

#define ILVRL_H(in0, in1, in2, in3, out0, out1, out2, out3) \
  {                                                         \
    out0 = (v16u8)__msa_ilvr_h((v8i16)in1, (v8i16)in0);     \
    out1 = (v16u8)__msa_ilvl_h((v8i16)in1, (v8i16)in0);     \
    out2 = (v16u8)__msa_ilvr_h((v8i16)in3, (v8i16)in2);     \
    out3 = (v16u8)__msa_ilvl_h((v8i16)in3, (v8i16)in2);     \
  }

#define ILVRL_W(in0, in1, in2, in3, out0, out1, out2, out3) \
  {                                                         \
    out0 = (v16u8)__msa_ilvr_w((v4i32)in1, (v4i32)in0);     \
    out1 = (v16u8)__msa_ilvl_w((v4i32)in1, (v4i32)in0);     \
    out2 = (v16u8)__msa_ilvr_w((v4i32)in3, (v4i32)in2);     \
    out3 = (v16u8)__msa_ilvl_w((v4i32)in3, (v4i32)in2);     \
  }

#define ILVRL_D(in0, in1, in2, in3, out0, out1, out2, out3) \
  {                                                         \
    out0 = (v16u8)__msa_ilvr_d((v2i64)in1, (v2i64)in0);     \
    out1 = (v16u8)__msa_ilvl_d((v2i64)in1, (v2i64)in0);     \
    out2 = (v16u8)__msa_ilvr_d((v2i64)in3, (v2i64)in2);     \
    out3 = (v16u8)__msa_ilvl_d((v2i64)in3, (v2i64)in2);     \
  }

Frank Barchard's avatar
Frank Barchard committed
54
void TransposeWx16_C(const uint8_t* src,
55
                     int src_stride,
Frank Barchard's avatar
Frank Barchard committed
56
                     uint8_t* dst,
57 58 59 60 61 62 63
                     int dst_stride,
                     int width) {
  TransposeWx8_C(src, src_stride, dst, dst_stride, width);
  TransposeWx8_C((src + 8 * src_stride), src_stride, (dst + 8), dst_stride,
                 width);
}

Frank Barchard's avatar
Frank Barchard committed
64
void TransposeUVWx16_C(const uint8_t* src,
65
                       int src_stride,
Frank Barchard's avatar
Frank Barchard committed
66
                       uint8_t* dst_a,
67
                       int dst_stride_a,
Frank Barchard's avatar
Frank Barchard committed
68
                       uint8_t* dst_b,
69 70 71 72 73 74 75 76
                       int dst_stride_b,
                       int width) {
  TransposeUVWx8_C(src, src_stride, dst_a, dst_stride_a, dst_b, dst_stride_b,
                   width);
  TransposeUVWx8_C((src + 8 * src_stride), src_stride, (dst_a + 8),
                   dst_stride_a, (dst_b + 8), dst_stride_b, width);
}

Frank Barchard's avatar
Frank Barchard committed
77
void TransposeWx16_MSA(const uint8_t* src,
78
                       int src_stride,
Frank Barchard's avatar
Frank Barchard committed
79
                       uint8_t* dst,
80 81
                       int dst_stride,
                       int width) {
82
  int x;
Frank Barchard's avatar
Frank Barchard committed
83
  const uint8_t* s;
84
  v16u8 src0, src1, src2, src3, dst0, dst1, dst2, dst3, vec0, vec1, vec2, vec3;
85
  v16u8 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7;
86
  v16u8 res0, res1, res2, res3, res4, res5, res6, res7, res8, res9;
87 88

  for (x = 0; x < width; x += 16) {
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    s = src;
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3);
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7);
    ILVRL_W(reg0, reg4, reg1, reg5, res0, res1, res2, res3);
    ILVRL_W(reg2, reg6, reg3, reg7, res4, res5, res6, res7);
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3);
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7);
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg4, (v4i32)reg0);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg4, (v4i32)reg0);
    ILVRL_D(res0, res8, res1, res9, dst0, dst1, dst2, dst3);
    ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride);
136
    dst += dst_stride * 4;
137 138 139 140
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg5, (v4i32)reg1);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg5, (v4i32)reg1);
    ILVRL_D(res2, res8, res3, res9, dst0, dst1, dst2, dst3);
    ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride);
141
    dst += dst_stride * 4;
142 143 144 145
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg6, (v4i32)reg2);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg6, (v4i32)reg2);
    ILVRL_D(res4, res8, res5, res9, dst0, dst1, dst2, dst3);
    ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride);
146
    dst += dst_stride * 4;
147 148 149 150
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg7, (v4i32)reg3);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg7, (v4i32)reg3);
    ILVRL_D(res6, res8, res7, res9, dst0, dst1, dst2, dst3);
    ST_UB4(dst0, dst1, dst2, dst3, dst, dst_stride);
151
    src += 16;
152
    dst += dst_stride * 4;
153 154 155
  }
}

Frank Barchard's avatar
Frank Barchard committed
156
void TransposeUVWx16_MSA(const uint8_t* src,
157
                         int src_stride,
Frank Barchard's avatar
Frank Barchard committed
158
                         uint8_t* dst_a,
159
                         int dst_stride_a,
Frank Barchard's avatar
Frank Barchard committed
160
                         uint8_t* dst_b,
161 162
                         int dst_stride_b,
                         int width) {
163
  int x;
Frank Barchard's avatar
Frank Barchard committed
164
  const uint8_t* s;
165
  v16u8 src0, src1, src2, src3, dst0, dst1, dst2, dst3, vec0, vec1, vec2, vec3;
166
  v16u8 reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7;
167
  v16u8 res0, res1, res2, res3, res4, res5, res6, res7, res8, res9;
168 169

  for (x = 0; x < width; x += 8) {
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    s = src;
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3);
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7);
    ILVRL_W(reg0, reg4, reg1, reg5, res0, res1, res2, res3);
    ILVRL_W(reg2, reg6, reg3, reg7, res4, res5, res6, res7);
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg0, reg1, reg2, reg3);
    src0 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src1 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src2 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    src3 = (v16u8)__msa_ld_b((v16i8*)s, 0);
    s += src_stride;
    ILVRL_B(src0, src1, src2, src3, vec0, vec1, vec2, vec3);
    ILVRL_H(vec0, vec2, vec1, vec3, reg4, reg5, reg6, reg7);
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg4, (v4i32)reg0);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg4, (v4i32)reg0);
    ILVRL_D(res0, res8, res1, res9, dst0, dst1, dst2, dst3);
    ST_UB2(dst0, dst2, dst_a, dst_stride_a);
    ST_UB2(dst1, dst3, dst_b, dst_stride_b);
218 219
    dst_a += dst_stride_a * 2;
    dst_b += dst_stride_b * 2;
220 221 222 223 224
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg5, (v4i32)reg1);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg5, (v4i32)reg1);
    ILVRL_D(res2, res8, res3, res9, dst0, dst1, dst2, dst3);
    ST_UB2(dst0, dst2, dst_a, dst_stride_a);
    ST_UB2(dst1, dst3, dst_b, dst_stride_b);
225 226
    dst_a += dst_stride_a * 2;
    dst_b += dst_stride_b * 2;
227 228 229 230 231
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg6, (v4i32)reg2);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg6, (v4i32)reg2);
    ILVRL_D(res4, res8, res5, res9, dst0, dst1, dst2, dst3);
    ST_UB2(dst0, dst2, dst_a, dst_stride_a);
    ST_UB2(dst1, dst3, dst_b, dst_stride_b);
232 233
    dst_a += dst_stride_a * 2;
    dst_b += dst_stride_b * 2;
234 235 236 237 238 239
    res8 = (v16u8)__msa_ilvr_w((v4i32)reg7, (v4i32)reg3);
    res9 = (v16u8)__msa_ilvl_w((v4i32)reg7, (v4i32)reg3);
    ILVRL_D(res6, res8, res7, res9, dst0, dst1, dst2, dst3);
    ST_UB2(dst0, dst2, dst_a, dst_stride_a);
    ST_UB2(dst1, dst3, dst_b, dst_stride_b);
    src += 16;
240 241 242 243 244 245 246 247 248 249 250
    dst_a += dst_stride_a * 2;
    dst_b += dst_stride_b * 2;
  }
}

#ifdef __cplusplus
}  // extern "C"
}  // namespace libyuv
#endif

#endif  // !defined(LIBYUV_DISABLE_MSA) && defined(__mips_msa)