]> git.sesse.net Git - ffmpeg/blob - libavcodec/mips/dsputil_mmi.c
avcodec: Drop long-deprecated imgconvert.h header
[ffmpeg] / libavcodec / mips / dsputil_mmi.c
1 /*
2  * MMI optimized DSP utils
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  *
5  * MMI optimization by Leon van Stuivenberg
6  * clear_blocks_mmi() by BroadQ
7  *
8  * This file is part of Libav.
9  *
10  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24
25 #include "libavcodec/dsputil.h"
26 #include "mmi.h"
27
28 static void clear_blocks_mmi(DCTELEM * blocks)
29 {
30         __asm__ volatile(
31         ".set noreorder    \n"
32         "addiu $9, %0, 768 \n"
33         "nop               \n"
34         "1:                \n"
35         "sq $0, 0(%0)      \n"
36         "move $8, %0       \n"
37         "addi %0, %0, 64   \n"
38         "sq $0, 16($8)     \n"
39         "slt $10, %0, $9   \n"
40         "sq $0, 32($8)     \n"
41         "bnez $10, 1b      \n"
42         "sq $0, 48($8)     \n"
43         ".set reorder      \n"
44         : "+r" (blocks) ::  "$8", "$9", "memory" );
45 }
46
47
48 static void get_pixels_mmi(DCTELEM *block, const uint8_t *pixels, int line_size)
49 {
50         __asm__ volatile(
51         ".set   push            \n\t"
52         ".set   mips3           \n\t"
53         "ld     $8, 0(%0)       \n\t"
54         "add    %0, %0, %2      \n\t"
55         "ld     $9, 0(%0)       \n\t"
56         "add    %0, %0, %2      \n\t"
57         "ld     $10, 0(%0)      \n\t"
58         "pextlb $8, $0, $8      \n\t"
59         "sq     $8, 0(%1)       \n\t"
60         "add    %0, %0, %2      \n\t"
61         "ld     $8, 0(%0)       \n\t"
62         "pextlb $9, $0, $9      \n\t"
63         "sq     $9, 16(%1)      \n\t"
64         "add    %0, %0, %2      \n\t"
65         "ld     $9, 0(%0)       \n\t"
66         "pextlb $10, $0, $10    \n\t"
67         "sq     $10, 32(%1)     \n\t"
68         "add    %0, %0, %2      \n\t"
69         "ld     $10, 0(%0)      \n\t"
70         "pextlb $8, $0, $8      \n\t"
71         "sq     $8, 48(%1)      \n\t"
72         "add    %0, %0, %2      \n\t"
73         "ld     $8, 0(%0)       \n\t"
74         "pextlb $9, $0, $9      \n\t"
75         "sq     $9, 64(%1)      \n\t"
76         "add    %0, %0, %2      \n\t"
77         "ld     $9, 0(%0)       \n\t"
78         "pextlb $10, $0, $10    \n\t"
79         "sq     $10, 80(%1)     \n\t"
80         "pextlb $8, $0, $8      \n\t"
81         "sq     $8, 96(%1)      \n\t"
82         "pextlb $9, $0, $9      \n\t"
83         "sq     $9, 112(%1)     \n\t"
84         ".set   pop             \n\t"
85         : "+r" (pixels) : "r" (block), "r" (line_size) : "$8", "$9", "$10", "memory" );
86 }
87
88
89 static void put_pixels8_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
90 {
91         __asm__ volatile(
92         ".set   push            \n\t"
93         ".set   mips3           \n\t"
94         "1:                     \n\t"
95         "ldr    $8, 0(%1)       \n\t"
96         "addiu  %2, %2, -1      \n\t"
97         "ldl    $8, 7(%1)       \n\t"
98         "add    %1, %1, %3      \n\t"
99         "sd     $8, 0(%0)       \n\t"
100         "add    %0, %0, %3      \n\t"
101         "bgtz   %2, 1b          \n\t"
102         ".set   pop             \n\t"
103         : "+r" (block), "+r" (pixels), "+r" (h) : "r" (line_size)
104         : "$8", "memory" );
105 }
106
107
108 static void put_pixels16_mmi(uint8_t *block, const uint8_t *pixels, int line_size, int h)
109 {
110         __asm__ volatile (
111         ".set   push            \n\t"
112         ".set   mips3           \n\t"
113         "1:                     \n\t"
114         "ldr    $8, 0(%1)       \n\t"
115         "add    $11, %1, %3     \n\t"
116         "ldl    $8, 7(%1)       \n\t"
117         "add    $10, %0, %3     \n\t"
118         "ldr    $9, 8(%1)       \n\t"
119         "ldl    $9, 15(%1)      \n\t"
120         "ldr    $12, 0($11)     \n\t"
121         "add    %1, $11, %3     \n\t"
122         "ldl    $12, 7($11)     \n\t"
123         "pcpyld $8, $9, $8      \n\t"
124         "sq     $8, 0(%0)       \n\t"
125         "ldr    $13, 8($11)     \n\t"
126         "addiu  %2, %2, -2      \n\t"
127         "ldl    $13, 15($11)    \n\t"
128         "add    %0, $10, %3     \n\t"
129         "pcpyld $12, $13, $12   \n\t"
130         "sq     $12, 0($10)     \n\t"
131         "bgtz   %2, 1b          \n\t"
132         ".set   pop             \n\t"
133         : "+r" (block), "+r" (pixels), "+r" (h) : "r" (line_size)
134         : "$8", "$9", "$10", "$11", "$12", "$13", "memory" );
135 }
136
137
138 void ff_dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx)
139 {
140     const int idct_algo= avctx->idct_algo;
141     const int high_bit_depth = avctx->bits_per_raw_sample > 8;
142
143     if (!high_bit_depth) {
144     c->clear_blocks = clear_blocks_mmi;
145
146     c->put_pixels_tab[1][0] = put_pixels8_mmi;
147     c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmi;
148
149     c->put_pixels_tab[0][0] = put_pixels16_mmi;
150     c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmi;
151
152     c->get_pixels = get_pixels_mmi;
153     }
154
155     if (avctx->bits_per_raw_sample <= 8 &&
156         (idct_algo == FF_IDCT_AUTO || idct_algo == FF_IDCT_MMI)) {
157         c->idct_put= ff_mmi_idct_put;
158         c->idct_add= ff_mmi_idct_add;
159         c->idct    = ff_mmi_idct;
160         c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
161     }
162 }