1/*
2 * Alpha optimized DSP utils
3 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
4 *
5 * This file is part of FFmpeg.
6 *
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.
11 *
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.
16 *
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
20 */
21
22#include "libavutil/attributes.h"
23#include "libavcodec/dsputil.h"
24#include "dsputil_alpha.h"
25#include "asm.h"
26
27#if 0
28/* These functions were the base for the optimized assembler routines,
29   and remain here for documentation purposes.  */
30static void put_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
31                                   ptrdiff_t line_size)
32{
33    int i = 8;
34    uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
35
36    do {
37        uint64_t shorts0, shorts1;
38
39        shorts0 = ldq(block);
40        shorts0 = maxsw4(shorts0, 0);
41        shorts0 = minsw4(shorts0, clampmask);
42        stl(pkwb(shorts0), pixels);
43
44        shorts1 = ldq(block + 4);
45        shorts1 = maxsw4(shorts1, 0);
46        shorts1 = minsw4(shorts1, clampmask);
47        stl(pkwb(shorts1), pixels + 4);
48
49        pixels += line_size;
50        block += 8;
51    } while (--i);
52}
53
54void add_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
55                            ptrdiff_t line_size)
56{
57    int h = 8;
58    /* Keep this function a leaf function by generating the constants
59       manually (mainly for the hack value ;-).  */
60    uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
61    uint64_t signmask  = zap(-1, 0x33);
62    signmask ^= signmask >> 1;  /* 0x8000800080008000 */
63
64    do {
65        uint64_t shorts0, pix0, signs0;
66        uint64_t shorts1, pix1, signs1;
67
68        shorts0 = ldq(block);
69        shorts1 = ldq(block + 4);
70
71        pix0    = unpkbw(ldl(pixels));
72        /* Signed subword add (MMX paddw).  */
73        signs0  = shorts0 & signmask;
74        shorts0 &= ~signmask;
75        shorts0 += pix0;
76        shorts0 ^= signs0;
77        /* Clamp. */
78        shorts0 = maxsw4(shorts0, 0);
79        shorts0 = minsw4(shorts0, clampmask);
80
81        /* Next 4.  */
82        pix1    = unpkbw(ldl(pixels + 4));
83        signs1  = shorts1 & signmask;
84        shorts1 &= ~signmask;
85        shorts1 += pix1;
86        shorts1 ^= signs1;
87        shorts1 = maxsw4(shorts1, 0);
88        shorts1 = minsw4(shorts1, clampmask);
89
90        stl(pkwb(shorts0), pixels);
91        stl(pkwb(shorts1), pixels + 4);
92
93        pixels += line_size;
94        block += 8;
95    } while (--h);
96}
97#endif
98
99av_cold void ff_dsputil_init_alpha(DSPContext *c, AVCodecContext *avctx)
100{
101    /* amask clears all bits that correspond to present features.  */
102    if (amask(AMASK_MVI) == 0) {
103        c->sad[0]           = pix_abs16x16_mvi_asm;
104        c->sad[1]           = pix_abs8x8_mvi;
105        c->pix_abs[0][0]    = pix_abs16x16_mvi_asm;
106        c->pix_abs[1][0]    = pix_abs8x8_mvi;
107        c->pix_abs[0][1]    = pix_abs16x16_x2_mvi;
108        c->pix_abs[0][2]    = pix_abs16x16_y2_mvi;
109        c->pix_abs[0][3]    = pix_abs16x16_xy2_mvi;
110    }
111
112}
113