Statistics
| Branch: | Revision:

ffmpeg / libavcodec / i386 / mpegvideo_mmx_template.c @ c4ff7c53

History | View | Annotate | Download (17.1 KB)

1 2f349de2 Michael Niedermayer
/*
2 ff4ec49e Fabrice Bellard
 * MPEG video MMX templates
3
 *
4
 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
5
 *
6 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9 ff4ec49e Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
12 ff4ec49e Fabrice Bellard
 *
13 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
14 ff4ec49e Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
20 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 ff4ec49e Fabrice Bellard
 */
22 ff506a90 Loren Merritt
23
#undef MMREG_WIDTH
24
#undef MM
25
#undef MOVQ
26 2f349de2 Michael Niedermayer
#undef SPREADW
27
#undef PMAXW
28 8fb0d073 Måns Rullgård
#undef PMAX
29 ff506a90 Loren Merritt
#undef SAVE_SIGN
30
#undef RESTORE_SIGN
31
32
#if defined(HAVE_SSE2)
33
#define MMREG_WIDTH "16"
34
#define MM "%%xmm"
35
#define MOVQ "movdqa"
36
#define SPREADW(a) \
37
            "pshuflw $0, "a", "a"       \n\t"\
38
            "punpcklwd "a", "a"         \n\t"
39
#define PMAXW(a,b) "pmaxsw "a", "b"     \n\t"
40 12e96681 Michael Niedermayer
#define PMAX(a,b) \
41 ff506a90 Loren Merritt
            "movhlps "a", "b"           \n\t"\
42 bb270c08 Diego Biurrun
            PMAXW(b, a)\
43 ff506a90 Loren Merritt
            "pshuflw $0x0E, "a", "b"    \n\t"\
44
            PMAXW(b, a)\
45
            "pshuflw $0x01, "a", "b"    \n\t"\
46
            PMAXW(b, a)
47
#else
48
#define MMREG_WIDTH "8"
49
#define MM "%%mm"
50
#define MOVQ "movq"
51
#if defined(HAVE_MMX2)
52
#define SPREADW(a) "pshufw $0, "a", "a" \n\t"
53
#define PMAXW(a,b) "pmaxsw "a", "b"     \n\t"
54
#define PMAX(a,b) \
55
            "pshufw $0x0E, "a", "b"     \n\t"\
56
            PMAXW(b, a)\
57
            "pshufw $0x01, "a", "b"     \n\t"\
58 bb270c08 Diego Biurrun
            PMAXW(b, a)
59 2f349de2 Michael Niedermayer
#else
60
#define SPREADW(a) \
61 ff506a90 Loren Merritt
            "punpcklwd "a", "a"         \n\t"\
62
            "punpcklwd "a", "a"         \n\t"
63 2f349de2 Michael Niedermayer
#define PMAXW(a,b) \
64 ff506a90 Loren Merritt
            "psubusw "a", "b"           \n\t"\
65
            "paddw "a", "b"             \n\t"
66 12e96681 Michael Niedermayer
#define PMAX(a,b)  \
67 ff506a90 Loren Merritt
            "movq "a", "b"              \n\t"\
68
            "psrlq $32, "a"             \n\t"\
69 bb270c08 Diego Biurrun
            PMAXW(b, a)\
70 ff506a90 Loren Merritt
            "movq "a", "b"              \n\t"\
71
            "psrlq $16, "a"             \n\t"\
72 bb270c08 Diego Biurrun
            PMAXW(b, a)
73 12e96681 Michael Niedermayer
74 2f349de2 Michael Niedermayer
#endif
75 ff506a90 Loren Merritt
#endif
76
77
#ifdef HAVE_SSSE3
78
#define SAVE_SIGN(a,b) \
79
            "movdqa "b", "a"            \n\t"\
80
            "pabsw  "b", "b"            \n\t"
81
#define RESTORE_SIGN(a,b) \
82
            "psignw "a", "b"            \n\t"
83
#else
84
#define SAVE_SIGN(a,b) \
85
            "pxor "a", "a"              \n\t"\
86
            "pcmpgtw "b", "a"           \n\t" /* block[i] <= 0 ? 0xFF : 0x00 */\
87
            "pxor "a", "b"              \n\t"\
88
            "psubw "a", "b"             \n\t" /* ABS(block[i]) */
89
#define RESTORE_SIGN(a,b) \
90
            "pxor "a", "b"              \n\t"\
91
            "psubw "a", "b"             \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
92
#endif
93 2f349de2 Michael Niedermayer
94
static int RENAME(dct_quantize)(MpegEncContext *s,
95
                            DCTELEM *block, int n,
96 d7e9533a Michael Niedermayer
                            int qscale, int *overflow)
97 2f349de2 Michael Niedermayer
{
98 40d0e665 Ramiro Polla
    x86_reg last_non_zero_p1;
99 04932b0d Diego Biurrun
    int level=0, q; //=0 is because gcc says uninitialized ...
100 0c1a9eda Zdenek Kabelac
    const uint16_t *qmat, *bias;
101 ff506a90 Loren Merritt
    DECLARE_ALIGNED_16(int16_t, temp_block[64]);
102 115329f1 Diego Biurrun
103 f8188626 Michael Niedermayer
    assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly?
104 2f349de2 Michael Niedermayer
105 28db7fce Michael Niedermayer
    //s->fdct (block);
106 755bfeab Diego Biurrun
    RENAMEl(ff_fdct) (block); //cannot be anything else ...
107 d7e9533a Michael Niedermayer
108 821cb11f Michael Niedermayer
    if(s->dct_error_sum)
109 783df5f3 Michael Niedermayer
        s->denoise_dct(s, block);
110 821cb11f Michael Niedermayer
111 2f349de2 Michael Niedermayer
    if (s->mb_intra) {
112
        int dummy;
113
        if (n < 4)
114 1a684b3d Michael Niedermayer
            q = s->y_dc_scale;
115 2f349de2 Michael Niedermayer
        else
116 1a684b3d Michael Niedermayer
            q = s->c_dc_scale;
117 2f349de2 Michael Niedermayer
        /* note: block[0] is assumed to be positive */
118 ef5b1b5a Juanjo
        if (!s->h263_aic) {
119 2f349de2 Michael Niedermayer
#if 1
120 be449fca Diego Pettenò
        __asm__ volatile (
121 bb270c08 Diego Biurrun
                "mul %%ecx                \n\t"
122
                : "=d" (level), "=a"(dummy)
123 36cd3069 Måns Rullgård
                : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1])
124 d7e9533a Michael Niedermayer
        );
125 2f349de2 Michael Niedermayer
#else
126 be449fca Diego Pettenò
        __asm__ volatile (
127 bb270c08 Diego Biurrun
                "xorl %%edx, %%edx        \n\t"
128
                "divw %%cx                \n\t"
129
                "movzwl %%ax, %%eax       \n\t"
130
                : "=a" (level)
131
                : "a" ((block[0]>>2) + q), "c" (q<<1)
132
                : "%edx"
133 d7e9533a Michael Niedermayer
        );
134 2f349de2 Michael Niedermayer
#endif
135 ef5b1b5a Juanjo
        } else
136
            /* For AIC we skip quant/dequant of INTRADC */
137 1a684b3d Michael Niedermayer
            level = (block[0] + 4)>>3;
138 115329f1 Diego Biurrun
139 d7e9533a Michael Niedermayer
        block[0]=0; //avoid fake overflow
140 2f349de2 Michael Niedermayer
//        temp_block[0] = (block[0] + (q >> 1)) / q;
141
        last_non_zero_p1 = 1;
142 642ccefb Michael Niedermayer
        bias = s->q_intra_matrix16[qscale][1];
143
        qmat = s->q_intra_matrix16[qscale][0];
144 2f349de2 Michael Niedermayer
    } else {
145
        last_non_zero_p1 = 0;
146 642ccefb Michael Niedermayer
        bias = s->q_inter_matrix16[qscale][1];
147
        qmat = s->q_inter_matrix16[qscale][0];
148 2f349de2 Michael Niedermayer
    }
149
150 1c3990db Michael Niedermayer
    if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){
151 115329f1 Diego Biurrun
152 be449fca Diego Pettenò
        __asm__ volatile(
153 ff506a90 Loren Merritt
            "movd %%"REG_a", "MM"3              \n\t" // last_non_zero_p1
154
            SPREADW(MM"3")
155
            "pxor "MM"7, "MM"7                  \n\t" // 0
156
            "pxor "MM"4, "MM"4                  \n\t" // 0
157
            MOVQ" (%2), "MM"5                   \n\t" // qmat[0]
158
            "pxor "MM"6, "MM"6                  \n\t"
159
            "psubw (%3), "MM"6                  \n\t" // -bias[0]
160 bb270c08 Diego Biurrun
            "mov $-128, %%"REG_a"               \n\t"
161 4454dc1b John Dalgliesh
            ASMALIGN(4)
162 bb270c08 Diego Biurrun
            "1:                                 \n\t"
163 ff506a90 Loren Merritt
            MOVQ" (%1, %%"REG_a"), "MM"0        \n\t" // block[i]
164
            SAVE_SIGN(MM"1", MM"0")                   // ABS(block[i])
165
            "psubusw "MM"6, "MM"0               \n\t" // ABS(block[i]) + bias[0]
166
            "pmulhw "MM"5, "MM"0                \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16
167
            "por "MM"0, "MM"4                   \n\t"
168
            RESTORE_SIGN(MM"1", MM"0")                // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
169
            MOVQ" "MM"0, (%5, %%"REG_a")        \n\t"
170
            "pcmpeqw "MM"7, "MM"0               \n\t" // out==0 ? 0xFF : 0x00
171
            MOVQ" (%4, %%"REG_a"), "MM"1        \n\t"
172
            MOVQ" "MM"7, (%1, %%"REG_a")        \n\t" // 0
173
            "pandn "MM"1, "MM"0                 \n\t"
174
            PMAXW(MM"0", MM"3")
175
            "add $"MMREG_WIDTH", %%"REG_a"      \n\t"
176 bb270c08 Diego Biurrun
            " js 1b                             \n\t"
177 ff506a90 Loren Merritt
            PMAX(MM"3", MM"0")
178
            "movd "MM"3, %%"REG_a"              \n\t"
179 bb270c08 Diego Biurrun
            "movzb %%al, %%"REG_a"              \n\t" // last_non_zero_p1
180
            : "+a" (last_non_zero_p1)
181 d04fdff1 Zdenek Kabelac
            : "r" (block+64), "r" (qmat), "r" (bias),
182 486497e0 Måns Rullgård
              "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
183 d04fdff1 Zdenek Kabelac
        );
184 d7e9533a Michael Niedermayer
    }else{ // FMT_H263
185 be449fca Diego Pettenò
        __asm__ volatile(
186 ff506a90 Loren Merritt
            "movd %%"REG_a", "MM"3              \n\t" // last_non_zero_p1
187
            SPREADW(MM"3")
188
            "pxor "MM"7, "MM"7                  \n\t" // 0
189
            "pxor "MM"4, "MM"4                  \n\t" // 0
190 bb270c08 Diego Biurrun
            "mov $-128, %%"REG_a"               \n\t"
191 4454dc1b John Dalgliesh
            ASMALIGN(4)
192 bb270c08 Diego Biurrun
            "1:                                 \n\t"
193 ff506a90 Loren Merritt
            MOVQ" (%1, %%"REG_a"), "MM"0        \n\t" // block[i]
194
            SAVE_SIGN(MM"1", MM"0")                   // ABS(block[i])
195
            MOVQ" (%3, %%"REG_a"), "MM"6        \n\t" // bias[0]
196
            "paddusw "MM"6, "MM"0               \n\t" // ABS(block[i]) + bias[0]
197
            MOVQ" (%2, %%"REG_a"), "MM"5        \n\t" // qmat[i]
198
            "pmulhw "MM"5, "MM"0                \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16
199
            "por "MM"0, "MM"4                   \n\t"
200
            RESTORE_SIGN(MM"1", MM"0")                // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
201
            MOVQ" "MM"0, (%5, %%"REG_a")        \n\t"
202
            "pcmpeqw "MM"7, "MM"0               \n\t" // out==0 ? 0xFF : 0x00
203
            MOVQ" (%4, %%"REG_a"), "MM"1        \n\t"
204
            MOVQ" "MM"7, (%1, %%"REG_a")        \n\t" // 0
205
            "pandn "MM"1, "MM"0                 \n\t"
206
            PMAXW(MM"0", MM"3")
207
            "add $"MMREG_WIDTH", %%"REG_a"      \n\t"
208 bb270c08 Diego Biurrun
            " js 1b                             \n\t"
209 ff506a90 Loren Merritt
            PMAX(MM"3", MM"0")
210
            "movd "MM"3, %%"REG_a"              \n\t"
211 bb270c08 Diego Biurrun
            "movzb %%al, %%"REG_a"              \n\t" // last_non_zero_p1
212
            : "+a" (last_non_zero_p1)
213 d04fdff1 Zdenek Kabelac
            : "r" (block+64), "r" (qmat+64), "r" (bias+64),
214 486497e0 Måns Rullgård
              "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
215 d7e9533a Michael Niedermayer
        );
216 ff506a90 Loren Merritt
    }
217 be449fca Diego Pettenò
    __asm__ volatile(
218 ff506a90 Loren Merritt
        "movd %1, "MM"1                     \n\t" // max_qcoeff
219
        SPREADW(MM"1")
220
        "psubusw "MM"1, "MM"4               \n\t"
221
        "packuswb "MM"4, "MM"4              \n\t"
222
#ifdef HAVE_SSE2
223
        "packuswb "MM"4, "MM"4              \n\t"
224
#endif
225
        "movd "MM"4, %0                     \n\t" // *overflow
226 d04fdff1 Zdenek Kabelac
        : "=g" (*overflow)
227
        : "g" (s->max_qcoeff)
228 ff506a90 Loren Merritt
    );
229 d7e9533a Michael Niedermayer
230 2ad1516a Michael Niedermayer
    if(s->mb_intra) block[0]= level;
231
    else            block[0]= temp_block[0];
232
233 b0368839 Michael Niedermayer
    if(s->dsp.idct_permutation_type == FF_SIMPLE_IDCT_PERM){
234 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 1) goto end;
235 115329f1 Diego Biurrun
        block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08];
236
        block[0x20] = temp_block[0x10];
237 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 4) goto end;
238 115329f1 Diego Biurrun
        block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02];
239
        block[0x09] = temp_block[0x03];
240 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 7) goto end;
241 115329f1 Diego Biurrun
        block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11];
242
        block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20];
243 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 11) goto end;
244 115329f1 Diego Biurrun
        block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12];
245
        block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04];
246
        block[0x0C] = temp_block[0x05];
247 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 16) goto end;
248 115329f1 Diego Biurrun
        block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13];
249
        block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21];
250
        block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30];
251
        block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22];
252 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 24) goto end;
253 115329f1 Diego Biurrun
        block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14];
254
        block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06];
255
        block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E];
256
        block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C];
257 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 32) goto end;
258 115329f1 Diego Biurrun
        block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A];
259
        block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38];
260
        block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32];
261
        block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24];
262 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 40) goto end;
263 115329f1 Diego Biurrun
        block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16];
264
        block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17];
265
        block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25];
266
        block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33];
267 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 48) goto end;
268 115329f1 Diego Biurrun
        block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
269
        block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D];
270
        block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
271
        block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
272 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 56) goto end;
273 115329f1 Diego Biurrun
        block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C];
274
        block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36];
275
        block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37];
276 2ad1516a Michael Niedermayer
        block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
277 b0368839 Michael Niedermayer
    }else if(s->dsp.idct_permutation_type == FF_LIBMPEG2_IDCT_PERM){
278 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 1) goto end;
279 115329f1 Diego Biurrun
        block[0x04] = temp_block[0x01];
280
        block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
281 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 4) goto end;
282 115329f1 Diego Biurrun
        block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02];
283
        block[0x05] = temp_block[0x03];
284 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 7) goto end;
285 115329f1 Diego Biurrun
        block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11];
286
        block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
287 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 11) goto end;
288 115329f1 Diego Biurrun
        block[0x1C] = temp_block[0x19];
289
        block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B];
290
        block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05];
291 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 16) goto end;
292 115329f1 Diego Biurrun
        block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13];
293
        block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21];
294
        block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
295
        block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22];
296 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 24) goto end;
297 115329f1 Diego Biurrun
        block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14];
298
        block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06];
299
        block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E];
300
        block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C];
301 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 32) goto end;
302 115329f1 Diego Biurrun
        block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A];
303
        block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38];
304
        block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32];
305
        block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24];
306 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 40) goto end;
307 115329f1 Diego Biurrun
        block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16];
308
        block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
309
        block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25];
310
        block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33];
311 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 48) goto end;
312 115329f1 Diego Biurrun
        block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B];
313
        block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D];
314
            block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
315
        block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E];
316 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 56) goto end;
317 115329f1 Diego Biurrun
        block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C];
318
        block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36];
319
        block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
320 2ad1516a Michael Niedermayer
        block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
321
    }else{
322
        if(last_non_zero_p1 <= 1) goto end;
323 115329f1 Diego Biurrun
        block[0x01] = temp_block[0x01];
324
        block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
325 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 4) goto end;
326 115329f1 Diego Biurrun
        block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02];
327
        block[0x03] = temp_block[0x03];
328 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 7) goto end;
329 115329f1 Diego Biurrun
        block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11];
330
        block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
331 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 11) goto end;
332 115329f1 Diego Biurrun
        block[0x19] = temp_block[0x19];
333
        block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B];
334
        block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05];
335 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 16) goto end;
336 115329f1 Diego Biurrun
        block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13];
337
        block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21];
338
        block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
339
        block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22];
340 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 24) goto end;
341 115329f1 Diego Biurrun
        block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14];
342
        block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06];
343
        block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E];
344
        block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C];
345 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 32) goto end;
346 115329f1 Diego Biurrun
        block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A];
347
        block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38];
348
        block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32];
349
        block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
350 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 40) goto end;
351 115329f1 Diego Biurrun
        block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16];
352
        block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
353
        block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25];
354
        block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33];
355 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 48) goto end;
356 115329f1 Diego Biurrun
        block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
357
        block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
358
        block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
359
        block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E];
360 2ad1516a Michael Niedermayer
        if(last_non_zero_p1 <= 56) goto end;
361 115329f1 Diego Biurrun
        block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C];
362
        block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
363
        block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
364 2ad1516a Michael Niedermayer
        block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
365
    }
366
    end:
367 2f349de2 Michael Niedermayer
/*
368
    for(i=0; i<last_non_zero_p1; i++)
369
    {
370
       int j= zigzag_direct_noperm[i];
371
       block[block_permute_op(j)]= temp_block[j];
372
    }
373
*/
374 d7e9533a Michael Niedermayer
375 2f349de2 Michael Niedermayer
    return last_non_zero_p1 - 1;
376
}