FFmpeg
idctdsp_alpha.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/attributes.h"
22 #include "libavcodec/avcodec.h"
23 #include "libavcodec/idctdsp.h"
24 #include "idctdsp_alpha.h"
25 #include "asm.h"
26 
27 void put_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels,
28  ptrdiff_t line_size);
29 void add_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels,
30  ptrdiff_t line_size);
31 
32 void (*put_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels,
33  ptrdiff_t line_size);
34 void (*add_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels,
35  ptrdiff_t line_size);
36 
37 #if 0
38 /* These functions were the base for the optimized assembler routines,
39  and remain here for documentation purposes. */
40 static void put_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
41  ptrdiff_t line_size)
42 {
43  int i = 8;
44  uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
45 
46  do {
47  uint64_t shorts0, shorts1;
48 
49  shorts0 = ldq(block);
50  shorts0 = maxsw4(shorts0, 0);
51  shorts0 = minsw4(shorts0, clampmask);
52  stl(pkwb(shorts0), pixels);
53 
54  shorts1 = ldq(block + 4);
55  shorts1 = maxsw4(shorts1, 0);
56  shorts1 = minsw4(shorts1, clampmask);
57  stl(pkwb(shorts1), pixels + 4);
58 
59  pixels += line_size;
60  block += 8;
61  } while (--i);
62 }
63 
64 void add_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
65  ptrdiff_t line_size)
66 {
67  int h = 8;
68  /* Keep this function a leaf function by generating the constants
69  manually (mainly for the hack value ;-). */
70  uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
71  uint64_t signmask = zap(-1, 0x33);
72  signmask ^= signmask >> 1; /* 0x8000800080008000 */
73 
74  do {
75  uint64_t shorts0, pix0, signs0;
76  uint64_t shorts1, pix1, signs1;
77 
78  shorts0 = ldq(block);
79  shorts1 = ldq(block + 4);
80 
81  pix0 = unpkbw(ldl(pixels));
82  /* Signed subword add (MMX paddw). */
83  signs0 = shorts0 & signmask;
84  shorts0 &= ~signmask;
85  shorts0 += pix0;
86  shorts0 ^= signs0;
87  /* Clamp. */
88  shorts0 = maxsw4(shorts0, 0);
89  shorts0 = minsw4(shorts0, clampmask);
90 
91  /* Next 4. */
92  pix1 = unpkbw(ldl(pixels + 4));
93  signs1 = shorts1 & signmask;
94  shorts1 &= ~signmask;
95  shorts1 += pix1;
96  shorts1 ^= signs1;
97  shorts1 = maxsw4(shorts1, 0);
98  shorts1 = minsw4(shorts1, clampmask);
99 
100  stl(pkwb(shorts0), pixels);
101  stl(pkwb(shorts1), pixels + 4);
102 
103  pixels += line_size;
104  block += 8;
105  } while (--h);
106 }
107 #endif
108 
110  unsigned high_bit_depth)
111 {
112  /* amask clears all bits that correspond to present features. */
113  if (amask(AMASK_MVI) == 0) {
114  c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
115  c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
116  }
117 
118  put_pixels_clamped_axp_p = c->put_pixels_clamped;
119  add_pixels_clamped_axp_p = c->add_pixels_clamped;
120 
121  if (!high_bit_depth && !avctx->lowres &&
122  (avctx->idct_algo == FF_IDCT_AUTO)) {
123  c->idct_put = ff_simple_idct_put_axp;
124  c->idct_add = ff_simple_idct_add_axp;
125  c->idct = ff_simple_idct_axp;
126  }
127 }
put_pixels_clamped_mvi_asm
void put_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size)
ff_simple_idct_axp
void ff_simple_idct_axp(int16_t *block)
Definition: simple_idct_alpha.c:253
ldq
#define ldq(p)
Definition: asm.h:59
FF_IDCT_AUTO
#define FF_IDCT_AUTO
Definition: avcodec.h:1548
AMASK_MVI
#define AMASK_MVI
Definition: asm.h:40
asm.h
add_pixels_clamped_mvi_asm
void add_pixels_clamped_mvi_asm(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size)
av_cold
#define av_cold
Definition: attributes.h:90
pkwb
#define pkwb(a)
Definition: asm.h:144
zap
#define zap(a, b)
Definition: asm.h:111
ff_simple_idct_put_axp
void ff_simple_idct_put_axp(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: simple_idct_alpha.c:293
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ldl
#define ldl(p)
Definition: asm.h:64
AVCodecContext::lowres
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:1854
stl
#define stl(l, p)
Definition: asm.h:76
attributes.h
amask
#define amask(a)
Definition: asm.h:113
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
add_pixels_clamped_axp_p
void(* add_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size)
Definition: idctdsp_alpha.c:34
maxsw4
#define maxsw4(a, b)
Definition: asm.h:141
AVCodecContext::idct_algo
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
Definition: avcodec.h:1547
idctdsp.h
avcodec.h
IDCTDSPContext
Definition: idctdsp.h:43
unpkbw
#define unpkbw(a)
Definition: asm.h:146
ff_simple_idct_add_axp
void ff_simple_idct_add_axp(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
Definition: simple_idct_alpha.c:299
AVCodecContext
main external API structure.
Definition: avcodec.h:445
minsw4
#define minsw4(a, b)
Definition: asm.h:137
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
put_pixels_clamped_axp_p
void(* put_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels, ptrdiff_t line_size)
Definition: idctdsp_alpha.c:32
h
h
Definition: vp9dsp_template.c:2038
ff_idctdsp_init_alpha
av_cold void ff_idctdsp_init_alpha(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
Definition: idctdsp_alpha.c:109
idctdsp_alpha.h