FFmpeg
Data Structures | Macros | Functions
uops_tmpl.c File Reference
#include <libavutil/bswap.h>
#include "uops_tmpl.h"

Go to the source code of this file.

Data Structures

struct  fn
 

Macros

#define BIT_DEPTH   8
 Copyright (C) 2026 Niklas Haas. More...
 
#define PIXEL_MAX   0xFFu
 
#define pixel_t   uint8_t
 
#define inter_t   int32_t
 
#define PX   U8
 
#define px   u8
 
#define DECL_PERMUTE(DUMMY, NAME, TYPE, UOP, MASK, IDX0, IDX1, IDX2, IDX3)
 
#define DECL_COPY(DUMMY, NAME, TYPE, UOP, MASK, IDX0, IDX1, IDX2, IDX3)
 
#define DECL_CAST(DST, dst)
 
#define ONE(N)   SWS_COMP_TEST(one, N)
 
#define ZERO(N)   SWS_COMP_TEST(zero, N)
 
#define LIN_VAL(I, J, val)   ((one & SWS_MASK(I, J)) ? (val) : c.m[I][J] * (val))
 
#define LIN_ROW(I, var)
 

Functions

 DECL_READ (read_planar, const SwsCompMask mask)
 
 DECL_READ (read_packed, const SwsCompMask mask)
 
 DECL_WRITE (write_planar, const SwsCompMask mask)
 
 DECL_WRITE (write_packed, const SwsCompMask mask)
 
 DECL_READ (read_bit, const SwsCompMask mask)
 
 DECL_READ (read_nibble, const SwsCompMask mask)
 
 DECL_WRITE (write_bit, const SwsCompMask mask)
 
 DECL_WRITE (write_nibble, const SwsCompMask mask)
 
 DECL_SETUP (setup_filter_v, params, out)
 
 DECL_READ (read_planar_fv, const SwsCompMask mask, const SwsPixelType type)
 
 DECL_SETUP (setup_filter_h, params, out)
 
 DECL_READ (read_planar_fh, const SwsCompMask mask, const SwsPixelType type)
 
 DECL_FUNC (lshift, const SwsCompMask mask, const uint8_t amount)
 
 DECL_FUNC (rshift, const SwsCompMask mask, const uint8_t amount)
 
 DECL_FUNC (expand_bit, const SwsCompMask mask)
 
 DECL_FUNC (expand_pair, const SwsCompMask mask)
 
 DECL_FUNC (expand_quad, const SwsCompMask mask)
 
 DECL_FUNC (unpack, const SwsCompMask mask, const uint8_t bx, const uint8_t by, const uint8_t bz, const uint8_t bw)
 
 DECL_FUNC (pack, const SwsCompMask mask, const uint8_t bx, const uint8_t by, const uint8_t bz, const uint8_t bw)
 
 DECL_FUNC (clear, const SwsCompMask mask, const SwsCompMask one, const SwsCompMask zero)
 
 DECL_FUNC (scale, const SwsCompMask mask)
 
 DECL_FUNC (add, const SwsCompMask mask)
 
 DECL_FUNC (min, const SwsCompMask mask)
 
 DECL_FUNC (max, const SwsCompMask mask)
 
 DECL_SETUP (setup_dither, params, out)
 
 DECL_FUNC (dither, const SwsCompMask mask, const uint8_t off0, const uint8_t off1, const uint8_t off2, const uint8_t off3, const uint8_t size_log2)
 
 DECL_SETUP (setup_linear, params, out)
 
 DECL_FUNC (linear, const SwsCompMask mask, const uint32_t one, const uint32_t zero)
 Fully general case for a 5x5 linear affine transformation. More...
 

Macro Definition Documentation

◆ BIT_DEPTH

#define BIT_DEPTH   8

Copyright (C) 2026 Niklas Haas.

This file is part of FFmpeg.

FFmpeg is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

FFmpeg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FFmpeg; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Definition at line 26 of file uops_tmpl.c.

◆ PIXEL_MAX

#define PIXEL_MAX   0xFFu

Definition at line 50 of file uops_tmpl.c.

◆ pixel_t

#define pixel_t   uint8_t

Definition at line 51 of file uops_tmpl.c.

◆ inter_t

#define inter_t   int32_t

Definition at line 52 of file uops_tmpl.c.

◆ PX

#define PX   U8

Definition at line 53 of file uops_tmpl.c.

◆ px

#define px   u8

Definition at line 54 of file uops_tmpl.c.

◆ DECL_PERMUTE

#define DECL_PERMUTE (   DUMMY,
  NAME,
  TYPE,
  UOP,
  MASK,
  IDX0,
  IDX1,
  IDX2,
  IDX3 
)
Value:
static void NAME##_c(SwsOpIter *restrict iter, \
const SwsOpImpl *restrict impl, \
void *restrict in0, void *restrict in1, \
void *restrict in2, void *restrict in3) \
{ \
CONTINUE(in##IDX0, in##IDX1, in##IDX2, in##IDX3); \
}

Definition at line 344 of file uops_tmpl.c.

◆ DECL_COPY

#define DECL_COPY (   DUMMY,
  NAME,
  TYPE,
  UOP,
  MASK,
  IDX0,
  IDX1,
  IDX2,
  IDX3 
)
Value:
static void NAME##_c(SwsOpIter *restrict iter, \
const SwsOpImpl *restrict impl, \
void *restrict in0, void *restrict in1, \
void *restrict in2, void *restrict in3) \
{ \
const SwsCompMask mask = (MASK); \
block_t x, y, z, w; \
if (X) memcpy(&x.px, in##IDX0, SIZEOF_BLOCK); \
if (Y) memcpy(&y.px, in##IDX1, SIZEOF_BLOCK); \
if (Z) memcpy(&z.px, in##IDX2, SIZEOF_BLOCK); \
if (W) memcpy(&w.px, in##IDX3, SIZEOF_BLOCK); \
CONTINUE(X ? &x : in0, Y ? &y : in1, Z ? &z : in2, W ? &w : in3); \
}

Definition at line 353 of file uops_tmpl.c.

◆ DECL_CAST

#define DECL_CAST (   DST,
  dst 
)
Value:
DECL_FUNC(to_##dst, const SwsCompMask mask) \
{ \
block_t xx, yy, zz, ww; \
for (int i = 0; i < SWS_BLOCK_SIZE; i++) { \
if (X) xx.dst[i] = x[i]; \
if (Y) yy.dst[i] = y[i]; \
if (Z) zz.dst[i] = z[i]; \
if (W) ww.dst[i] = w[i]; \
} \
CONTINUE(&xx, &yy, &zz, &ww); \
} \
SWS_FOR(PX, TO_##DST, DECL_IMPL, to_##dst) \
SWS_FOR_STRUCT(PX, TO_##DST, DECL_ENTRY)

Definition at line 379 of file uops_tmpl.c.

◆ ONE

#define ONE (   N)    SWS_COMP_TEST(one, N)

◆ ZERO

#define ZERO (   N)    SWS_COMP_TEST(zero, N)

◆ LIN_VAL

#define LIN_VAL (   I,
  J,
  val 
)    ((one & SWS_MASK(I, J)) ? (val) : c.m[I][J] * (val))

◆ LIN_ROW

#define LIN_ROW (   I,
  var 
)
Value:
do { \
var[i] = (zero & SWS_MASK(I, 4)) ? 0 : c.k[I]; \
if (!(zero & SWS_MASK(I, 0))) var[i] += LIN_VAL(I, 0, xx); \
if (!(zero & SWS_MASK(I, 1))) var[i] += LIN_VAL(I, 1, yy); \
if (!(zero & SWS_MASK(I, 2))) var[i] += LIN_VAL(I, 2, zz); \
if (!(zero & SWS_MASK(I, 3))) var[i] += LIN_VAL(I, 3, ww); \
} while (0)

Function Documentation

◆ DECL_READ() [1/6]

DECL_READ ( read_planar  ,
const SwsCompMask  mask 
)

Definition at line 63 of file uops_tmpl.c.

◆ DECL_READ() [2/6]

DECL_READ ( read_packed  ,
const SwsCompMask  mask 
)

Definition at line 81 of file uops_tmpl.c.

◆ DECL_WRITE() [1/4]

DECL_WRITE ( write_planar  ,
const SwsCompMask  mask 
)

Definition at line 97 of file uops_tmpl.c.

◆ DECL_WRITE() [2/4]

DECL_WRITE ( write_packed  ,
const SwsCompMask  mask 
)

Definition at line 113 of file uops_tmpl.c.

◆ DECL_READ() [3/6]

DECL_READ ( read_bit  ,
const SwsCompMask  mask 
)

Definition at line 130 of file uops_tmpl.c.

◆ DECL_READ() [4/6]

DECL_READ ( read_nibble  ,
const SwsCompMask  mask 
)

Definition at line 151 of file uops_tmpl.c.

◆ DECL_WRITE() [3/4]

DECL_WRITE ( write_bit  ,
const SwsCompMask  mask 
)

Definition at line 166 of file uops_tmpl.c.

◆ DECL_WRITE() [4/4]

DECL_WRITE ( write_nibble  ,
const SwsCompMask  mask 
)

Definition at line 185 of file uops_tmpl.c.

◆ DECL_SETUP() [1/4]

DECL_SETUP ( setup_filter_v  ,
params  ,
out   
)

Definition at line 220 of file uops_tmpl.c.

◆ DECL_READ() [5/6]

DECL_READ ( read_planar_fv  ,
const SwsCompMask  mask,
const SwsPixelType  type 
)

Definition at line 244 of file uops_tmpl.c.

◆ DECL_SETUP() [2/4]

DECL_SETUP ( setup_filter_h  ,
params  ,
out   
)

Definition at line 283 of file uops_tmpl.c.

◆ DECL_READ() [6/6]

DECL_READ ( read_planar_fh  ,
const SwsCompMask  mask,
const SwsPixelType  type 
)

Definition at line 296 of file uops_tmpl.c.

◆ DECL_FUNC() [1/14]

DECL_FUNC ( lshift  ,
const SwsCompMask  mask,
const uint8_t  amount 
)

Definition at line 408 of file uops_tmpl.c.

◆ DECL_FUNC() [2/14]

DECL_FUNC ( rshift  ,
const SwsCompMask  mask,
const uint8_t  amount 
)

Definition at line 421 of file uops_tmpl.c.

◆ DECL_FUNC() [3/14]

DECL_FUNC ( expand_bit  ,
const SwsCompMask  mask 
)

Definition at line 460 of file uops_tmpl.c.

◆ DECL_FUNC() [4/14]

DECL_FUNC ( expand_pair  ,
const SwsCompMask  mask 
)

Definition at line 475 of file uops_tmpl.c.

◆ DECL_FUNC() [5/14]

DECL_FUNC ( expand_quad  ,
const SwsCompMask  mask 
)

Definition at line 490 of file uops_tmpl.c.

◆ DECL_FUNC() [6/14]

DECL_FUNC ( unpack  ,
const SwsCompMask  mask,
const uint8_t  bx,
const uint8_t  by,
const uint8_t  bz,
const uint8_t  bw 
)

Definition at line 518 of file uops_tmpl.c.

◆ DECL_FUNC() [7/14]

DECL_FUNC ( pack  ,
const SwsCompMask  mask,
const uint8_t  bx,
const uint8_t  by,
const uint8_t  bz,
const uint8_t  bw 
)

Definition at line 544 of file uops_tmpl.c.

◆ DECL_FUNC() [8/14]

DECL_FUNC ( clear  ,
const SwsCompMask  mask,
const SwsCompMask  one,
const SwsCompMask  zero 
)

Definition at line 577 of file uops_tmpl.c.

◆ DECL_FUNC() [9/14]

DECL_FUNC ( scale  ,
const SwsCompMask  mask 
)

Definition at line 606 of file uops_tmpl.c.

◆ DECL_FUNC() [10/14]

DECL_FUNC ( add  ,
const SwsCompMask  mask 
)

Definition at line 621 of file uops_tmpl.c.

◆ DECL_FUNC() [11/14]

DECL_FUNC ( min  ,
const SwsCompMask  mask 
)

Definition at line 634 of file uops_tmpl.c.

◆ DECL_FUNC() [12/14]

DECL_FUNC ( max  ,
const SwsCompMask  mask 
)

Definition at line 647 of file uops_tmpl.c.

◆ DECL_SETUP() [3/4]

DECL_SETUP ( setup_dither  ,
params  ,
out   
)

Definition at line 673 of file uops_tmpl.c.

◆ DECL_FUNC() [13/14]

DECL_FUNC ( dither  ,
const SwsCompMask  mask,
const uint8_t  off0,
const uint8_t  off1,
const uint8_t  off2,
const uint8_t  off3,
const uint8_t  size_log2 
)

Definition at line 707 of file uops_tmpl.c.

◆ DECL_SETUP() [4/4]

DECL_SETUP ( setup_linear  ,
params  ,
out   
)

Definition at line 748 of file uops_tmpl.c.

◆ DECL_FUNC() [14/14]

DECL_FUNC ( linear  ,
const SwsCompMask  mask,
const uint32_t  one,
const uint32_t  zero 
)

Fully general case for a 5x5 linear affine transformation.

Should never be called without constant mask. This function will compile down to the appropriately optimized version for the required subset of operations when called with a constant mask.

Definition at line 770 of file uops_tmpl.c.

SIZEOF_BLOCK
#define SIZEOF_BLOCK
Definition: uops_tmpl.h:50
Z
#define Z
Definition: uops_tmpl.h:83
X
@ X
Definition: vf_addroi.c:27
DECL_ENTRY
#define DECL_ENTRY(SETUP, NAME,...)
Definition: uops_tmpl.h:139
mask
int mask
Definition: mediacodecdec_common.c:154
SwsOpIter
Internal context holding per-iter execution data.
Definition: uops_tmpl.h:56
PX
#define PX
Definition: uops_tmpl.c:53
SWS_FOR
#define SWS_FOR(TYPE, UOP, MACRO,...)
Definition: uops_macros.h:17
W
#define W(a, i, v)
Definition: jpegls.h:119
SwsOpImpl
Definition: ops_chain.h:71
SwsCompMask
uint8_t SwsCompMask
Bit-mask of components.
Definition: uops.h:61
if
if(ret)
Definition: filter_design.txt:179
MASK
#define MASK
Definition: median_template.c:42
DECL_IMPL
#define DECL_IMPL(FUNC, NAME, TYPE, UOP,...)
Definition: uops_tmpl.h:119
SWS_MASK
#define SWS_MASK(I, J)
Definition: ops.h:197
SWS_BLOCK_SIZE
#define SWS_BLOCK_SIZE
Copyright (C) 2026 Niklas Haas.
Definition: uops_tmpl.h:40
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
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
zero
static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:121
Y
#define Y
Definition: boxblur.h:37
CONTINUE
#define CONTINUE(...)
Definition: uops_tmpl.h:107
DECL_FUNC
DECL_FUNC(lshift, const SwsCompMask mask, const uint8_t amount)
Definition: uops_tmpl.c:408
DST
#define DST(x, y)
Definition: vp9dsp_template.c:813
w
uint8_t w
Definition: llvidencdsp.c:39
LIN_VAL
#define LIN_VAL(I, J, val)