~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_libraries/ADM_libmpeg2enc/altivec/sumsq_sub22.c

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* sumsq_sub22.c, this file is part of the
 
2
 * AltiVec optimized library for MJPEG tools MPEG-1/2 Video Encoder
 
3
 * Copyright (C) 2002  James Klicman <james@klicman.org>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program 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
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include <config.h>
 
22
#endif
 
23
 
 
24
#include "altivec_motion.h"
 
25
#include "vectorize.h"
 
26
#include "../mjpeg_logging.h"
 
27
 
 
28
/* #define AMBER_ENABLE */
 
29
#include "amber.h"
 
30
 
 
31
#ifdef HAVE_ALTIVEC_H
 
32
/* include last to ensure AltiVec type semantics, especially for bool. */
 
33
#include <altivec.h>
 
34
#endif
 
35
 
 
36
 
 
37
/*
 
38
 * Total squared difference between bidriection prediction of (8*h)
 
39
 * blocks of 2*2 subsampled pels.
 
40
 *
 
41
 * Iterate through all rows 2 at a time.
 
42
 *
 
43
 * Hints regarding input:
 
44
 *   b) blk2 is about 50% vector aligned and 50% 8 byte aligned
 
45
 *   c) rowstride is always a multiple of 16
 
46
 *   d) h == 4 or 8
 
47
 *
 
48
 * for (j = 0; j < h; j++) {
 
49
 *     for (i = 0; i < 8; i++) {
 
50
 *         d = p1[i] - p2[i];
 
51
 *         sum += d * d;
 
52
 *     }
 
53
 *     p1 += rowstride;
 
54
 *     p2 += rowstride;
 
55
 * }
 
56
 */
 
57
 
 
58
 
 
59
#define SUMSQ_SUB22_PDECL                                                    \
 
60
  uint8_t *blk1,                                                             \
 
61
  uint8_t *blk2,                                                             \
 
62
  int rowstride,                                                             \
 
63
  int h                                                                      \
 
64
 
 
65
#define SUMSQ_SUB22_ARGS blk1, blk2, rowstride, h
 
66
 
 
67
int sumsq_sub22_altivec(SUMSQ_SUB22_PDECL)
 
68
{
 
69
    int i;
 
70
    unsigned char *pB, *pR;
 
71
    vector unsigned char align8x2;
 
72
    vector unsigned char lB0, lB1, lB2, lB3, lR0, lR1;
 
73
    vector unsigned char B, R;
 
74
    vector unsigned char min;
 
75
    vector unsigned char max;
 
76
    vector unsigned char dif;
 
77
    vector unsigned int sum;
 
78
    vector signed int zero;
 
79
    vector unsigned char perm1, perm2;
 
80
    union {
 
81
        vector signed int v;
 
82
        struct {
 
83
            signed int pad[3];
 
84
            signed int sum;
 
85
        } s;
 
86
    } vo;
 
87
 
 
88
#ifdef ALTIVEC_VERIFY
 
89
    if (((unsigned long)blk2 % 8) != 0)
 
90
        mjpeg_error_exit1("sumsq_sub22: blk2 %% 8 != 0, (0x%X)", blk2);
 
91
 
 
92
    if (NOT_VECTOR_ALIGNED(rowstride))
 
93
        mjpeg_error_exit1("sumsq_sub22: rowstride %% 16 != 0, (%d)", rowstride);
 
94
 
 
95
    if (h != 4 && h != 8)
 
96
        mjpeg_error_exit1("sumsq_sub22: h != [4|8], (%d)", h);
 
97
#endif
 
98
 
 
99
    /* 8*h blocks calculated in 8*2 chunks */
 
100
    /* align8x2 = 0x( 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 ) {{{ */
 
101
    align8x2 = vec_lvsl(0, (unsigned char*)0);
 
102
    align8x2 = vec_sld(align8x2, align8x2, 8);
 
103
    perm1 = vec_lvsr(0, (unsigned char*)0);
 
104
    align8x2 = vec_sld(align8x2, perm1, 8);
 
105
    /* }}} */
 
106
 
 
107
 
 
108
    pB = blk1;
 
109
    pR = blk2;
 
110
    i = (h >> 1) - 1;
 
111
 
 
112
    zero = vec_splat_s32(0);
 
113
    sum = vec_splat_u32(0);
 
114
 
 
115
    perm1 = vec_lvsl(0, pB);
 
116
 
 
117
    perm2 = vec_lvsl(0, pR);
 
118
    perm2 = vec_splat(perm2, 0);
 
119
    perm2 = vec_add(perm2, align8x2);
 
120
 
 
121
 
 
122
    if (((unsigned long)pB & 0xf) <= 8) {
 
123
 
 
124
        perm1 = vec_splat(perm1, 0);
 
125
        perm1 = vec_add(perm1, align8x2);
 
126
 
 
127
        lB0 = vec_ld(0, pB);
 
128
        pB += rowstride;
 
129
        lB1 = vec_ld(0, pB);
 
130
 
 
131
        lR0 = vec_ld(0, pR);
 
132
        pR += rowstride;
 
133
        lR1 = vec_ld(0, pR);
 
134
 
 
135
        B = vec_perm(lB0, lB1, perm1);
 
136
        R = vec_perm(lR0, lR1, perm2);
 
137
 
 
138
        do {
 
139
            pB += rowstride;
 
140
            lB0 = vec_ld(0, pB);
 
141
            pB += rowstride;
 
142
            lB1 = vec_ld(0, pB);
 
143
 
 
144
            pR += rowstride;
 
145
            lR0 = vec_ld(0, pR);
 
146
            pR += rowstride;
 
147
            lR1 = vec_ld(0, pR);
 
148
 
 
149
 
 
150
            max = vec_max(B, R);
 
151
            min = vec_min(B, R);
 
152
            dif = vec_sub(max, min);
 
153
            sum = vec_msum(dif, dif, sum);
 
154
 
 
155
 
 
156
            B = vec_perm(lB0, lB1, perm1);
 
157
 
 
158
            R = vec_perm(lR0, lR1, perm2);
 
159
        } while (--i);
 
160
 
 
161
    } else {
 
162
 
 
163
        lB0 = vec_ld(0, pB);
 
164
        lB1 = vec_ld(16, pB);
 
165
        pB += rowstride;
 
166
        lB2 = vec_ld(0, pB);
 
167
        lB3 = vec_ld(16, pB);
 
168
 
 
169
        lR0 = vec_ld(0, pR);
 
170
        pR += rowstride;
 
171
        lR1 = vec_ld(0, pR);
 
172
 
 
173
        lB0 = vec_perm(lB0, lB1, perm1);
 
174
        lB2 = vec_perm(lB2, lB3, perm1);
 
175
        B = vec_perm(lB0, lB2, align8x2);
 
176
 
 
177
        R = vec_perm(lR0, lR1, perm2);
 
178
 
 
179
 
 
180
        do {
 
181
            pB += rowstride;
 
182
            lB0 = vec_ld(0, pB);
 
183
            lB1 = vec_ld(16, pB);
 
184
            pB += rowstride;
 
185
            lB2 = vec_ld(0, pB);
 
186
            lB3 = vec_ld(16, pB);
 
187
 
 
188
            pR += rowstride;
 
189
            lR0 = vec_ld(0, pR);
 
190
            pR += rowstride;
 
191
            lR1 = vec_ld(0, pR);
 
192
 
 
193
 
 
194
            max = vec_max(B, R);
 
195
            min = vec_min(B, R);
 
196
            dif = vec_sub(max, min);
 
197
            sum = vec_msum(dif, dif, sum);
 
198
 
 
199
 
 
200
            lB0 = vec_perm(lB0, lB1, perm1);
 
201
            lB2 = vec_perm(lB2, lB3, perm1);
 
202
            B = vec_perm(lB0, lB2, align8x2);
 
203
 
 
204
            R = vec_perm(lR0, lR1, perm2);
 
205
        } while (--i);
 
206
    }
 
207
 
 
208
    max = vec_max(B, R);
 
209
    min = vec_min(B, R);
 
210
    dif = vec_sub(max, min);
 
211
    sum = vec_msum(dif, dif, sum);
 
212
 
 
213
 
 
214
    vo.v = vec_sums(vs32(sum), zero);
 
215
 
 
216
    AMBER_STOP;
 
217
 
 
218
    return vo.s.sum;
 
219
}
 
220
 
 
221
 
 
222
#if ALTIVEC_TEST_FUNCTION(sumsq_sub22)
 
223
ALTIVEC_TEST(sumsq_sub22, int, (SUMSQ_SUB22_PDECL),
 
224
  "blk1=0x%X, blk2=0x%X, rowstride=%d, h=%d",
 
225
  SUMSQ_SUB22_ARGS);
 
226
#endif
 
227
/* vim:set foldmethod=marker foldlevel=0: */