clear_blocks_mmi() optimization by BroadQ (and patch by Leon van Stuivenberg <leonvs...
[libav.git] / libavcodec / ps2 / dsputil_mmi.c
1 /*
2 * MMI optimized DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * MMI optimization by Leon van Stuivenberg <leonvs@iae.nl>
20 * clear_blocks_mmi() by BroadQ
21 */
22
23 #include "../dsputil.h"
24 #include "mmi.h"
25
26 void ff_mmi_idct_put(uint8_t *dest, int line_size, DCTELEM *block);
27 void ff_mmi_idct_add(uint8_t *dest, int line_size, DCTELEM *block);
28
29
30 static void clear_blocks_mmi(DCTELEM * blocks)
31 {
32 asm volatile(
33 ".set noreorder \n"
34 "addiu $9, %0, 768 \n"
35 "nop \n"
36 "1: \n"
37 "sq $0, 0(%0) \n"
38 "move $8, %0 \n"
39 "addi %0, %0, 64 \n"
40 "sq $0, 16($8) \n"
41 "slt $10, %0, $9 \n"
42 "sq $0, 32($8) \n"
43 "bnez $10, 1b \n"
44 "sq $0, 48($8) \n"
45 ".set reorder \n"
46 : "+r" (blocks) :: "$8", "$9", "memory" );
47 }
48
49
50 static void get_pixels_mmi(DCTELEM *block, const uint8_t *pixels, int line_size)
51 {
52 int i;
53 for(i=0;i<8;i++) {
54 asm volatile(
55 ".set push \n\t"
56 ".set mips3 \n\t"
57 "ld $8, 0(%1) \n\t"
58 "add %1, %1, %2 \n\t"
59 "pextlb $8, $0, $8 \n\t"
60 "sq $8, 0(%0) \n\t"
61 ".set pop \n\t"
62 :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "memory" );
63 block += 8;
64 }
65 }
66
67
68 static void put_pixels8_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
69 {
70 int i;
71 for(i=0; i<h; i++) {
72 asm volatile(
73 ".set push \n\t"
74 ".set mips3 \n\t"
75 "ldr $8, 0(%1) \n\t"
76 "ldl $8, 7(%1) \n\t"
77 "add %1, %1, %2 \n\t"
78 "sd $8, 0(%0) \n\t"
79 "add %0, %0, %2 \n\t"
80 ".set pop \n\t"
81 :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "memory" );
82 }
83 }
84
85
86 static void put_pixels16_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
87 {
88 int i;
89 for(i=0; i<(h>>2); i++) {
90 asm volatile (
91 ".set push \n\t"
92 ".set mips3 \n\t"
93 #define PUTPIX16 \
94 "ldr $8, 0(%1) \n\t" \
95 "ldl $8, 7(%1) \n\t" \
96 "ldr $9, 8(%1) \n\t" \
97 "ldl $9, 15(%1) \n\t" \
98 "add %1, %1, %2 \n\t" \
99 "pcpyld $8, $9, $8 \n\t" \
100 "sq $8, 0(%0) \n\t" \
101 "add %0, %0, %2 \n\t"
102 PUTPIX16
103 PUTPIX16
104 PUTPIX16
105 PUTPIX16
106 ".set pop \n\t"
107 :: "r" (block), "r" (pixels), "r" (line_size) : "$8", "$9", "memory" );
108 }
109 }
110
111
112 void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx)
113 {
114 const int idct_algo= avctx->idct_algo;
115
116 c->clear_blocks = clear_blocks_mmi;
117
118 c->put_pixels_tab[1][0] = put_pixels8_mmi;
119 c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmi;
120
121 c->put_pixels_tab[0][0] = put_pixels16_mmi;
122 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmi;
123
124 c->get_pixels = get_pixels_mmi;
125
126 if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_PS2){
127 c->idct_put= ff_mmi_idct_put;
128 c->idct_add= ff_mmi_idct_add;
129 c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
130 }
131 }
132