2 * Alpha optimized DSP utils
3 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/attributes.h"
23 #include "libavcodec/dsputil.h"
24 #include "dsputil_alpha.h"
27 void (*put_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels,
29 void (*add_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels,
33 /* These functions were the base for the optimized assembler routines,
34 and remain here for documentation purposes. */
35 static void put_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
39 uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
42 uint64_t shorts0, shorts1;
45 shorts0 = maxsw4(shorts0, 0);
46 shorts0 = minsw4(shorts0, clampmask);
47 stl(pkwb(shorts0), pixels);
49 shorts1 = ldq(block + 4);
50 shorts1 = maxsw4(shorts1, 0);
51 shorts1 = minsw4(shorts1, clampmask);
52 stl(pkwb(shorts1), pixels + 4);
59 void add_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
63 /* Keep this function a leaf function by generating the constants
64 manually (mainly for the hack value ;-). */
65 uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
66 uint64_t signmask = zap(-1, 0x33);
67 signmask ^= signmask >> 1; /* 0x8000800080008000 */
70 uint64_t shorts0, pix0, signs0;
71 uint64_t shorts1, pix1, signs1;
74 shorts1 = ldq(block + 4);
76 pix0 = unpkbw(ldl(pixels));
77 /* Signed subword add (MMX paddw). */
78 signs0 = shorts0 & signmask;
83 shorts0 = maxsw4(shorts0, 0);
84 shorts0 = minsw4(shorts0, clampmask);
87 pix1 = unpkbw(ldl(pixels + 4));
88 signs1 = shorts1 & signmask;
92 shorts1 = maxsw4(shorts1, 0);
93 shorts1 = minsw4(shorts1, clampmask);
95 stl(pkwb(shorts0), pixels);
96 stl(pkwb(shorts1), pixels + 4);
104 av_cold void ff_dsputil_init_alpha(DSPContext *c, AVCodecContext *avctx)
106 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
108 /* amask clears all bits that correspond to present features. */
109 if (amask(AMASK_MVI) == 0) {
110 c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
111 c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
114 c->get_pixels = get_pixels_mvi;
115 c->diff_pixels = diff_pixels_mvi;
116 c->sad[0] = pix_abs16x16_mvi_asm;
117 c->sad[1] = pix_abs8x8_mvi;
118 c->pix_abs[0][0] = pix_abs16x16_mvi_asm;
119 c->pix_abs[1][0] = pix_abs8x8_mvi;
120 c->pix_abs[0][1] = pix_abs16x16_x2_mvi;
121 c->pix_abs[0][2] = pix_abs16x16_y2_mvi;
122 c->pix_abs[0][3] = pix_abs16x16_xy2_mvi;
125 put_pixels_clamped_axp_p = c->put_pixels_clamped;
126 add_pixels_clamped_axp_p = c->add_pixels_clamped;
128 if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 &&
129 (avctx->idct_algo == FF_IDCT_AUTO ||
130 avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) {
131 c->idct_put = ff_simple_idct_put_axp;
132 c->idct_add = ff_simple_idct_add_axp;
133 c->idct = ff_simple_idct_axp;