1/* 2 * Loongson SIMD optimized simple idct 3 * 4 * Copyright (c) 2015 Loongson Technology Corporation Limited 5 * Copyright (c) 2015 Zhou Xiaoyong <zhouxiaoyong@loongson.cn> 6 * Zhang Shuangshuang <zhangshuangshuang@ict.ac.cn> 7 * 8 * This file is part of FFmpeg. 9 * 10 * FFmpeg is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; either 13 * version 2.1 of the License, or (at your option) any later version. 14 * 15 * FFmpeg is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with FFmpeg; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 25#include "idctdsp_mips.h" 26#include "constants.h" 27#include "libavutil/mips/asmdefs.h" 28#include "libavutil/mips/mmiutils.h" 29#include "libavutil/mem_internal.h" 30 31#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 32#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 33#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 34#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 35#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 36#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 37#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 38 39#define ROW_SHIFT 11 40#define COL_SHIFT 20 41#define DC_SHIFT 3 42 43DECLARE_ALIGNED(16, const int16_t, W_arr)[46] = { 44 W4, W2, W4, W6, 45 W1, W3, W5, W7, 46 W4, W6, -W4, -W2, 47 W3, -W7, -W1, -W5, 48 W4, -W6, -W4, W2, 49 W5, -W1, W7, W3, 50 W4, -W2, W4, -W6, 51 W7, -W5, W3, -W1, 52 1024, 0, 1024, 0, //ff_p32_1024 = 0x0000040000000400ULL 53 0, -1, -1, -1, //mask = 0xffffffffffff0000ULL 54 32, 32, 32, 32 //ff_p16_32 = 0x0020002000200020ULL 55}; 56 57void ff_simple_idct_8_mmi(int16_t *block) 58{ 59 DECLARE_VAR_ALL64; 60 61 BACKUP_REG 62 __asm__ volatile ( 63 64#define IDCT_ROW_COND_DC(src1, src2) \ 65 "dmfc1 $11, "#src1" \n\t" \ 66 "dmfc1 $12, "#src2" \n\t" \ 67 "and $11, $11, $9 \n\t" \ 68 "or $10, $11, $12 \n\t" \ 69 "beqz $10, 1f \n\t" \ 70 \ 71 "punpcklhw $f30, "#src1", "#src2" \n\t" \ 72 "punpckhhw $f31, "#src1", "#src2" \n\t" \ 73 /* s6, s4, s2, s0 */ \ 74 "punpcklhw "#src1", $f30, $f31 \n\t" \ 75 /* s7, s5, s3, s1 */ \ 76 "punpckhhw "#src2", $f30, $f31 \n\t" \ 77 \ 78 "pmaddhw $f30, "#src1", $f18 \n\t" \ 79 "pmaddhw $f31, "#src2", $f19 \n\t" \ 80 "paddw $f28, $f30, $f31 \n\t" \ 81 "psubw $f29, $f30, $f31 \n\t" \ 82 "punpcklwd $f30, $f28, $f29 \n\t" \ 83 "punpckhwd $f31, $f28, $f29 \n\t" \ 84 "paddw $f26, $f30, $f31 \n\t" \ 85 "paddw $f26, $f26, $f16 \n\t" \ 86 /* $f26: src[7], src[0] */ \ 87 "psraw $f26, $f26, $f17 \n\t" \ 88 \ 89 "pmaddhw $f30, "#src1", $f20 \n\t" \ 90 "pmaddhw $f31, "#src2", $f21 \n\t" \ 91 "paddw $f28, $f30, $f31 \n\t" \ 92 "psubw $f29, $f30, $f31 \n\t" \ 93 "punpcklwd $f30, $f28, $f29 \n\t" \ 94 "punpckhwd $f31, $f28, $f29 \n\t" \ 95 "paddw $f27, $f30, $f31 \n\t" \ 96 "paddw $f27, $f27, $f16 \n\t" \ 97 /* $f27: src[6], src[1] */ \ 98 "psraw $f27, $f27, $f17 \n\t" \ 99 \ 100 "pmaddhw $f30, "#src1", $f22 \n\t" \ 101 "pmaddhw $f31, "#src2", $f23 \n\t" \ 102 "paddw $f28, $f30, $f31 \n\t" \ 103 "psubw $f29, $f30, $f31 \n\t" \ 104 "punpcklwd $f30, $f28, $f29 \n\t" \ 105 "punpckhwd $f31, $f28, $f29 \n\t" \ 106 "paddw $f28, $f30, $f31 \n\t" \ 107 "paddw $f28, $f28, $f16 \n\t" \ 108 /* $f28: src[5], src[2] */ \ 109 "psraw $f28, $f28, $f17 \n\t" \ 110 \ 111 "pmaddhw $f30, "#src1", $f24 \n\t" \ 112 "pmaddhw $f31, "#src2", $f25 \n\t" \ 113 "paddw "#src1", $f30, $f31 \n\t" \ 114 "psubw "#src2", $f30, $f31 \n\t" \ 115 "punpcklwd $f30, "#src1", "#src2" \n\t" \ 116 "punpckhwd $f31, "#src1", "#src2" \n\t" \ 117 "paddw $f29, $f30, $f31 \n\t" \ 118 "paddw $f29, $f29, $f16 \n\t" \ 119 /* $f29: src[4], src[3] */ \ 120 "psraw $f29, $f29, $f17 \n\t" \ 121 \ 122 "punpcklhw "#src1", $f26, $f27 \n\t" \ 123 "punpckhhw $f30, $f27, $f26 \n\t" \ 124 "punpcklhw $f31, $f28, $f29 \n\t" \ 125 "punpckhhw "#src2", $f29, $f28 \n\t" \ 126 /* src[3], src[2], src[1], src[0] */ \ 127 "punpcklwd "#src1", "#src1", $f31 \n\t" \ 128 /* src[7], src[6], src[5], src[4] */ \ 129 "punpcklwd "#src2", "#src2", $f30 \n\t" \ 130 "j 2f \n\t" \ 131 \ 132 "1: \n\t" \ 133 "li $10, 3 \n\t" \ 134 "dmtc1 $10, $f30 \n\t" \ 135 "psllh $f28, "#src1", $f30 \n\t" \ 136 "dmtc1 $9, $f31 \n\t" \ 137 "punpcklhw $f29, $f28, $f28 \n\t" \ 138 "pand $f29, $f29, $f31 \n\t" \ 139 "paddw $f28, $f28, $f29 \n\t" \ 140 "punpcklwd "#src1", $f28, $f28 \n\t" \ 141 "punpcklwd "#src2", $f28, $f28 \n\t" \ 142 "2: \n\t" \ 143 144 /* idctRowCondDC row0~8 */ 145 146 /* load W */ 147 MMI_LQC1($f19, $f18, %[w_arr], 0x00) 148 MMI_LQC1($f21, $f20, %[w_arr], 0x10) 149 MMI_LQC1($f23, $f22, %[w_arr], 0x20) 150 MMI_LQC1($f25, $f24, %[w_arr], 0x30) 151 MMI_LQC1($f17, $f16, %[w_arr], 0x40) 152 /* load source in block */ 153 MMI_LQC1($f1, $f0, %[block], 0x00) 154 MMI_LQC1($f3, $f2, %[block], 0x10) 155 MMI_LQC1($f5, $f4, %[block], 0x20) 156 MMI_LQC1($f7, $f6, %[block], 0x30) 157 MMI_LQC1($f9, $f8, %[block], 0x40) 158 MMI_LQC1($f11, $f10, %[block], 0x50) 159 MMI_LQC1($f13, $f12, %[block], 0x60) 160 MMI_LQC1($f15, $f14, %[block], 0x70) 161 162 /* $9: mask ; $f17: ROW_SHIFT */ 163 "dmfc1 $9, $f17 \n\t" 164 "li $10, 11 \n\t" 165 "mtc1 $10, $f17 \n\t" 166 IDCT_ROW_COND_DC($f0,$f1) 167 IDCT_ROW_COND_DC($f2,$f3) 168 IDCT_ROW_COND_DC($f4,$f5) 169 IDCT_ROW_COND_DC($f6,$f7) 170 IDCT_ROW_COND_DC($f8,$f9) 171 IDCT_ROW_COND_DC($f10,$f11) 172 IDCT_ROW_COND_DC($f12,$f13) 173 IDCT_ROW_COND_DC($f14,$f15) 174 175#define IDCT_COL_CASE1(src, out1, out2) \ 176 "pmaddhw $f26, "#src", $f18 \n\t" \ 177 "pmaddhw $f27, "#src", $f20 \n\t" \ 178 "pmaddhw $f28, "#src", $f22 \n\t" \ 179 "pmaddhw $f29, "#src", $f24 \n\t" \ 180 \ 181 "punpcklwd $f30, $f26, $f26 \n\t" \ 182 "punpckhwd $f31, $f26, $f26 \n\t" \ 183 /* $f26: src[0], src[56] */ \ 184 "paddw $f26, $f30, $f31 \n\t" \ 185 "punpcklwd $f30, $f27, $f27 \n\t" \ 186 "punpckhwd $f31, $f27, $f27 \n\t" \ 187 /* $f27: src[8], src[48] */ \ 188 "paddw $f27, $f30, $f31 \n\t" \ 189 "punpcklwd $f30, $f28, $f28 \n\t" \ 190 "punpckhwd $f31, $f28, $f28 \n\t" \ 191 /* $f28: src[16], src[40] */ \ 192 "paddw $f28, $f30, $f31 \n\t" \ 193 "punpcklwd $f30, $f29, $f29 \n\t" \ 194 "punpckhwd $f31, $f29, $f29 \n\t" \ 195 /* $f29: src[24], src[32] */ \ 196 "paddw $f29, $f30, $f31 \n\t" \ 197 \ 198 /* out1: src[24], src[16], src[8], src[0] */ \ 199 /* out2: src[56], src[48], src[40], src[32] */ \ 200 "punpcklhw $f30, $f26, $f27 \n\t" \ 201 "punpcklhw $f31, $f28, $f29 \n\t" \ 202 "punpckhwd "#out1", $f30, $f31 \n\t" \ 203 "psrah "#out1", "#out1", $f16 \n\t" \ 204 "punpcklhw $f30, $f27, $f26 \n\t" \ 205 "punpcklhw $f31, $f29, $f28 \n\t" \ 206 "punpckhwd "#out2", $f31, $f30 \n\t" \ 207 "psrah "#out2", "#out2", $f16 \n\t" 208 209#define IDCT_COL_CASE2(src1, src2, out1, out2) \ 210 "pmaddhw $f28, "#src1", $f18 \n\t" \ 211 "pmaddhw $f29, "#src2", $f19 \n\t" \ 212 "paddw $f30, $f28, $f29 \n\t" \ 213 "psubw $f31, $f28, $f29 \n\t" \ 214 "punpcklwd $f28, $f30, $f31 \n\t" \ 215 "punpckhwd $f29, $f30, $f31 \n\t" \ 216 "pmaddhw $f30, "#src1", $f20 \n\t" \ 217 "pmaddhw $f31, "#src2", $f21 \n\t" \ 218 /* $f26: src[0], src[56] */ \ 219 "paddw $f26, $f28, $f29 \n\t" \ 220 "paddw $f28, $f30, $f31 \n\t" \ 221 "psubw $f29, $f30, $f31 \n\t" \ 222 "punpcklwd $f30, $f28, $f29 \n\t" \ 223 "punpckhwd $f31, $f28, $f29 \n\t" \ 224 "pmaddhw $f28, "#src1", $f22 \n\t" \ 225 "pmaddhw $f29, "#src2", $f23 \n\t" \ 226 /* $f27: src[8], src[48] */ \ 227 "paddw $f27, $f30, $f31 \n\t" \ 228 "paddw $f30, $f28, $f29 \n\t" \ 229 "psubw $f31, $f28, $f29 \n\t" \ 230 "punpcklwd $f28, $f30, $f31 \n\t" \ 231 "punpckhwd $f29, $f30, $f31 \n\t" \ 232 "pmaddhw $f30, "#src1", $f24 \n\t" \ 233 "pmaddhw $f31, "#src2", $f25 \n\t" \ 234 /* $f28: src[16], src[40] */ \ 235 "paddw $f28, $f28, $f29 \n\t" \ 236 "paddw "#out1", $f30, $f31 \n\t" \ 237 "psubw "#out2", $f30, $f31 \n\t" \ 238 "punpcklwd $f30, "#out1", "#out2" \n\t" \ 239 "punpckhwd $f31, "#out1", "#out2" \n\t" \ 240 /* $f29: src[24], src[32] */ \ 241 "paddw $f29, $f30, $f31 \n\t" \ 242 \ 243 /* out1: src[24], src[16], src[8], src[0] */ \ 244 /* out2: src[56], src[48], src[40], src[32] */ \ 245 "punpcklhw "#out1", $f26, $f27 \n\t" \ 246 "punpckhhw "#out2", $f27, $f26 \n\t" \ 247 "punpcklhw $f30, $f28, $f29 \n\t" \ 248 "punpckhhw $f31, $f29, $f28 \n\t" \ 249 "punpckhwd "#out1", "#out1", $f30 \n\t" \ 250 "punpckhwd "#out2", $f31, "#out2" \n\t" \ 251 "psrah "#out1", "#out1", $f16 \n\t" \ 252 "psrah "#out2", "#out2", $f16 \n\t" 253 254 255 /* idctSparseCol col0~3 */ 256 257 /* $f17: ff_p16_32; $f16: COL_SHIFT-16 */ 258 MMI_ULDC1($f17, %[w_arr], 0x50) 259 "li $10, 4 \n\t" 260 "dmtc1 $10, $f16 \n\t" 261 "paddh $f0, $f0, $f17 \n\t" 262 /* Transpose row[0,2,4,6] */ 263 "punpcklhw $f26, $f0, $f4 \n\t" 264 "punpckhhw $f27, $f0, $f4 \n\t" 265 "punpcklhw $f28, $f8, $f12 \n\t" 266 "punpckhhw $f29, $f8, $f12 \n\t" 267 "punpcklwd $f0, $f26, $f28 \n\t" 268 "punpckhwd $f4, $f26, $f28 \n\t" 269 "punpcklwd $f8, $f27, $f29 \n\t" 270 "punpckhwd $f12, $f27, $f29 \n\t" 271 272 "por $f26, $f2, $f6 \n\t" 273 "por $f26, $f26, $f10 \n\t" 274 "por $f26, $f26, $f14 \n\t" 275 "dmfc1 $10, $f26 \n\t" 276 "bnez $10, 1f \n\t" 277 /* case1: In this case, row[1,3,5,7] are all zero */ 278 /* col0: $f0: col[24,16,8,0]; $f2: col[56,48,40,32] */ 279 IDCT_COL_CASE1($f0, $f0, $f2) 280 /* col1: $f4: col[25,17,9,1]; $f6: col[57,49,41,33] */ 281 IDCT_COL_CASE1($f4, $f4, $f6) 282 /* col2: $f8: col[26,18,10,2]; $f10: col[58,50,42,34] */ 283 IDCT_COL_CASE1($f8, $f8, $f10) 284 /* col3: $f12: col[27,19,11,3]; $f14: col[59,51,43,35] */ 285 IDCT_COL_CASE1($f12, $f12, $f14) 286 "j 2f \n\t" 287 288 "1: \n\t" 289 /* case2: row[1,3,5,7] are not all zero */ 290 /* Transpose */ 291 "punpcklhw $f26, $f2, $f6 \n\t" 292 "punpckhhw $f27, $f2, $f6 \n\t" 293 "punpcklhw $f28, $f10, $f14 \n\t" 294 "punpckhhw $f29, $f10, $f14 \n\t" 295 "punpcklwd $f2, $f26, $f28 \n\t" 296 "punpckhwd $f6, $f26, $f28 \n\t" 297 "punpcklwd $f10, $f27, $f29 \n\t" 298 "punpckhwd $f14, $f27, $f29 \n\t" 299 300 /* col0: $f0: col[24,16,8,0]; $f2: col[56,48,40,32] */ 301 IDCT_COL_CASE2($f0, $f2, $f0, $f2) 302 /* col1: $f4: col[25,17,9,1]; $f6: col[57,49,41,33] */ 303 IDCT_COL_CASE2($f4, $f6, $f4, $f6) 304 /* col2: $f8: col[26,18,10,2]; $f10: col[58,50,42,34] */ 305 IDCT_COL_CASE2($f8, $f10, $f8, $f10) 306 /* col3: $f12: col[27,19,11,3]; $f14: col[59,51,43,35] */ 307 IDCT_COL_CASE2($f12, $f14, $f12, $f14) 308 309 "2: \n\t" 310 /* Transpose */ 311 "punpcklhw $f26, $f0, $f4 \n\t" 312 "punpckhhw $f27, $f0, $f4 \n\t" 313 "punpcklhw $f28, $f8, $f12 \n\t" 314 "punpckhhw $f29, $f8, $f12 \n\t" 315 "punpcklwd $f0, $f26, $f28 \n\t" 316 "punpckhwd $f4, $f26, $f28 \n\t" 317 "punpcklwd $f8, $f27, $f29 \n\t" 318 "punpckhwd $f12, $f27, $f29 \n\t" 319 /* Transpose */ 320 "punpcklhw $f26, $f2, $f6 \n\t" 321 "punpckhhw $f27, $f2, $f6 \n\t" 322 "punpcklhw $f28, $f10, $f14 \n\t" 323 "punpckhhw $f29, $f10, $f14 \n\t" 324 "punpcklwd $f2, $f26, $f28 \n\t" 325 "punpckhwd $f6, $f26, $f28 \n\t" 326 "punpcklwd $f10, $f27, $f29 \n\t" 327 "punpckhwd $f14, $f27, $f29 \n\t" 328 329 /* idctSparseCol col4~7 */ 330 331 "paddh $f1, $f1, $f17 \n\t" 332 /* Transpose */ 333 "punpcklhw $f26, $f1, $f5 \n\t" 334 "punpckhhw $f27, $f1, $f5 \n\t" 335 "punpcklhw $f28, $f9, $f13 \n\t" 336 "punpckhhw $f29, $f9, $f13 \n\t" 337 "punpcklwd $f1, $f26, $f28 \n\t" 338 "punpckhwd $f5, $f26, $f28 \n\t" 339 "punpcklwd $f9, $f27, $f29 \n\t" 340 "punpckhwd $f13, $f27, $f29 \n\t" 341 342 "por $f26, $f3, $f7 \n\t" 343 "por $f26, $f26, $f11 \n\t" 344 "por $f26, $f26, $f15 \n\t" 345 "dmfc1 $10, $f26 \n\t" 346 "bnez $10, 1f \n\t" 347 /* case1: In this case, row[1,3,5,7] are all zero */ 348 /* col4: $f1: col[24,16,8,0]; $f3: col[56,48,40,32] */ 349 IDCT_COL_CASE1($f1, $f1, $f3) 350 /* col5: $f5: col[25,17,9,1]; $f7: col[57,49,41,33] */ 351 IDCT_COL_CASE1($f5, $f5, $f7) 352 /* col6: $f9: col[26,18,10,2]; $f11: col[58,50,42,34] */ 353 IDCT_COL_CASE1($f9, $f9, $f11) 354 /* col7: $f13: col[27,19,11,3]; $f15: col[59,51,43,35] */ 355 IDCT_COL_CASE1($f13, $f13, $f15) 356 "j 2f \n\t" 357 358 "1: \n\t" 359 /* case2: row[1,3,5,7] are not all zero */ 360 /* Transpose */ 361 "punpcklhw $f26, $f3, $f7 \n\t" 362 "punpckhhw $f27, $f3, $f7 \n\t" 363 "punpcklhw $f28, $f11, $f15 \n\t" 364 "punpckhhw $f29, $f11, $f15 \n\t" 365 "punpcklwd $f3, $f26, $f28 \n\t" 366 "punpckhwd $f7, $f26, $f28 \n\t" 367 "punpcklwd $f11, $f27, $f29 \n\t" 368 "punpckhwd $f15, $f27, $f29 \n\t" 369 370 /* col4: $f1: col[24,16,8,0]; $f3: col[56,48,40,32] */ 371 IDCT_COL_CASE2($f1, $f3, $f1, $f3) 372 /* col5: $f5: col[25,17,9,1]; $f7: col[57,49,41,33] */ 373 IDCT_COL_CASE2($f5, $f7, $f5, $f7) 374 /* col6: $f9: col[26,18,10,2]; $f11: col[58,50,42,34] */ 375 IDCT_COL_CASE2($f9, $f11, $f9, $f11) 376 /* col7: $f13: col[27,19,11,3]; $f15: col[59,51,43,35] */ 377 IDCT_COL_CASE2($f13, $f15, $f13, $f15) 378 379 "2: \n\t" 380 /* Transpose */ 381 "punpcklhw $f26, $f1, $f5 \n\t" 382 "punpckhhw $f27, $f1, $f5 \n\t" 383 "punpcklhw $f28, $f9, $f13 \n\t" 384 "punpckhhw $f29, $f9, $f13 \n\t" 385 "punpcklwd $f1, $f26, $f28 \n\t" 386 "punpckhwd $f5, $f26, $f28 \n\t" 387 "punpcklwd $f9, $f27, $f29 \n\t" 388 "punpckhwd $f13, $f27, $f29 \n\t" 389 /* Transpose */ 390 "punpcklhw $f26, $f3, $f7 \n\t" 391 "punpckhhw $f27, $f3, $f7 \n\t" 392 "punpcklhw $f28, $f11, $f15 \n\t" 393 "punpckhhw $f29, $f11, $f15 \n\t" 394 "punpcklwd $f3, $f26, $f28 \n\t" 395 "punpckhwd $f7, $f26, $f28 \n\t" 396 "punpcklwd $f11, $f27, $f29 \n\t" 397 "punpckhwd $f15, $f27, $f29 \n\t" 398 /* Store */ 399 MMI_SQC1($f1, $f0, %[block], 0x00) 400 MMI_SQC1($f5, $f4, %[block], 0x10) 401 MMI_SQC1($f9, $f8, %[block], 0x20) 402 MMI_SQC1($f13, $f12, %[block], 0x30) 403 MMI_SQC1($f3, $f2, %[block], 0x40) 404 MMI_SQC1($f7, $f6, %[block], 0x50) 405 MMI_SQC1($f11, $f10, %[block], 0x60) 406 MMI_SQC1($f15, $f14, %[block], 0x70) 407 408 : RESTRICT_ASM_ALL64 [block]"+&r"(block) 409 : [w_arr]"r"(W_arr) 410 : "memory" 411 ); 412 413 RECOVER_REG 414} 415 416void ff_simple_idct_put_8_mmi(uint8_t *dest, ptrdiff_t line_size, int16_t *block) 417{ 418 ff_simple_idct_8_mmi(block); 419 ff_put_pixels_clamped_mmi(block, dest, line_size); 420} 421void ff_simple_idct_add_8_mmi(uint8_t *dest, ptrdiff_t line_size, int16_t *block) 422{ 423 ff_simple_idct_8_mmi(block); 424 ff_add_pixels_clamped_mmi(block, dest, line_size); 425} 426