FFmpeg
intmath.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVUTIL_RISCV_INTMATH_H
20 #define AVUTIL_RISCV_INTMATH_H
21 
22 #include <stdint.h>
23 
24 #include "config.h"
25 #include "libavutil/attributes.h"
26 
27 /*
28  * The compiler is forced to sign-extend the result anyhow, so it is faster to
29  * compute it explicitly and use it.
30  */
31 #define av_clip_int8 av_clip_int8_rvi
33 {
34  union { uint8_t u; int8_t s; } u = { .u = a };
35 
36  if (a != u.s)
37  a = ((a >> 31) ^ 0x7F);
38  return a;
39 }
40 
41 #define av_clip_int16 av_clip_int16_rvi
43 {
44  union { uint16_t u; int16_t s; } u = { .u = a };
45 
46  if (a != u.s)
47  a = ((a >> 31) ^ 0x7FFF);
48  return a;
49 }
50 
51 #define av_clipl_int32 av_clipl_int32_rvi
53 {
54  union { uint32_t u; int32_t s; } u = { .u = a };
55 
56  if (a != u.s)
57  a = ((a >> 63) ^ 0x7FFFFFFF);
58  return a;
59 }
60 
61 #define av_clip_intp2 av_clip_intp2_rvi
63 {
64  const int shift = 31 - p;
65  int b = ((int)(((unsigned)a) << shift)) >> shift;
66 
67  if (a != b)
68  b = (a >> 31) ^ ((1 << p) - 1);
69  return b;
70 }
71 
72 #if defined (__GNUC__) || defined (__clang__)
73 #define av_popcount __builtin_popcount
74 #if (__riscv_xlen >= 64)
75 #define av_popcount64 __builtin_popcountl
76 #else
77 #define av_popcount64 __builtin_popcountll
78 #endif
79 #endif
80 
81 #endif /* AVUTIL_RISCV_INTMATH_H */
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:250
int64_t
long long int64_t
Definition: coverity.c:34
av_const
#define av_const
Definition: attributes.h:84
b
#define b
Definition: input.c:41
av_clipl_int32_rvi
static av_always_inline av_const int32_t av_clipl_int32_rvi(int64_t a)
Definition: intmath.h:52
av_clip_int8_rvi
static av_always_inline av_const int8_t av_clip_int8_rvi(int a)
Definition: intmath.h:32
s
#define s(width, name)
Definition: cbs_vp9.c:198
shift
static int shift(int a, int b)
Definition: bonk.c:262
av_clip_intp2_rvi
static av_always_inline av_const int av_clip_intp2_rvi(int a, int p)
Definition: intmath.h:62
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
attributes.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
av_clip_int16_rvi
static av_always_inline av_const int16_t av_clip_int16_rvi(int a)
Definition: intmath.h:42
int32_t
int32_t
Definition: audioconvert.c:56
int
int
Definition: ffmpeg_filter.c:409