Go to the documentation of this file.
21 #ifndef AVUTIL_RISCV_INTMATH_H
22 #define AVUTIL_RISCV_INTMATH_H
35 #define av_clip_int8 av_clip_int8_rvi
38 union { uint8_t
u; int8_t
s; }
u = { .u =
a };
41 a = ((
a >> 31) ^ 0x7F);
45 #define av_clip_int16 av_clip_int16_rvi
48 union { uint16_t
u; int16_t
s; }
u = { .u =
a };
51 a = ((
a >> 31) ^ 0x7FFF);
55 #define av_clipl_int32 av_clipl_int32_rvi
61 a = ((
a >> 63) ^ 0x7FFFFFFF);
65 #define av_clip_intp2 av_clip_intp2_rvi
68 const int shift = 31 - p;
72 b = (
a >> 31) ^ ((1 << p) - 1);
76 #if defined (__riscv_f) || defined (__riscv_zfinx)
77 #define av_clipf av_clipf_rvf
85 #if defined (__riscv_d) || defined (__riscv_zdinx)
86 #define av_clipd av_clipd_rvd
94 #if defined (__GNUC__) || defined (__clang__)
97 #if HAVE_RV && !defined(__riscv_zbb)
98 if (!__builtin_constant_p(x) &&
104 ".option arch, +zbb\n"
105 #
if __riscv_xlen >= 64
110 ".option pop" :
"=r" (y) :
"r" (x));
112 __builtin_unreachable();
116 return __builtin_ctz(x);
118 #define ff_ctz ff_ctz_rv
122 #if HAVE_RV && !defined(__riscv_zbb) && __riscv_xlen == 64
123 if (!__builtin_constant_p(x) &&
129 ".option arch, +zbb\n"
131 ".option pop" :
"=r" (y) :
"r" (x));
133 __builtin_unreachable();
137 return __builtin_ctzll(x);
139 #define ff_ctzll ff_ctzll_rv
143 #if HAVE_RV && !defined(__riscv_zbb)
144 if (!__builtin_constant_p(x) &&
150 ".option arch, +zbb\n"
151 #
if __riscv_xlen >= 64
156 ".option pop" :
"=r" (y) :
"r" (x));
158 __builtin_unreachable();
162 return __builtin_clz(x);
164 #define ff_clz ff_clz_rv
166 #if __riscv_xlen == 64
167 static inline av_const int ff_clzll_rv(
long long x)
169 #if HAVE_RV && !defined(__riscv_zbb)
170 if (!__builtin_constant_p(x) &&
176 ".option arch, +zbb\n"
178 ".option pop" :
"=r" (y) :
"r" (x));
180 __builtin_unreachable();
184 return __builtin_clzll(x);
186 #define ff_clz ff_clz_rv
193 #define ff_log2 ff_log2_rv
194 #define ff_log2_16bit ff_log2_rv
198 #if HAVE_RV && !defined(__riscv_zbb)
199 if (!__builtin_constant_p(x) &&
205 ".option arch, +zbb\n"
206 #
if __riscv_xlen >= 64
211 ".option pop" :
"=r" (y) :
"r" (x));
213 __builtin_unreachable();
217 return __builtin_popcount(x);
219 #define av_popcount av_popcount_rv
223 #if HAVE_RV && !defined(__riscv_zbb) && __riscv_xlen >= 64
224 if (!__builtin_constant_p(x) &&
230 ".option arch, +zbb\n"
232 ".option pop" :
"=r" (y) :
"r" (x));
234 __builtin_unreachable();
238 return __builtin_popcountl(x);
240 #define av_popcount64 av_popcount64_rv
244 #if HAVE_RV && !defined(__riscv_zbb)
245 if (!__builtin_constant_p(x) &&
251 ".option arch, +zbb\n"
252 #
if __riscv_xlen >= 64
257 ".option pop" :
"=r" (y) :
"r" (x));
261 return __builtin_parity(x);
263 #define av_parity av_parity_rv
#define u(width, name, range_min, range_max)
static av_always_inline av_const int32_t av_clipl_int32_rvi(int64_t a)
static av_always_inline av_const int8_t av_clip_int8_rvi(int a)
static av_const int ff_clz_rv(int x)
static av_const bool ff_rv_zbb_support(void)
float fminf(float, float)
static av_const int ff_ctzll_rv(long long x)
static av_const int av_popcount_rv(unsigned int x)
static av_const int ff_ctz_rv(int x)
static int shift(int a, int b)
static av_const int ff_log2_rv(unsigned int x)
float fmaxf(float, float)
double fmin(double, double)
static av_always_inline av_const int av_clip_intp2_rvi(int a, int p)
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
static av_const int av_parity_rv(unsigned int x)
__asm__(".macro parse_r var r\n\t" "\\var = -1\n\t" _IFC_REG(0) _IFC_REG(1) _IFC_REG(2) _IFC_REG(3) _IFC_REG(4) _IFC_REG(5) _IFC_REG(6) _IFC_REG(7) _IFC_REG(8) _IFC_REG(9) _IFC_REG(10) _IFC_REG(11) _IFC_REG(12) _IFC_REG(13) _IFC_REG(14) _IFC_REG(15) _IFC_REG(16) _IFC_REG(17) _IFC_REG(18) _IFC_REG(19) _IFC_REG(20) _IFC_REG(21) _IFC_REG(22) _IFC_REG(23) _IFC_REG(24) _IFC_REG(25) _IFC_REG(26) _IFC_REG(27) _IFC_REG(28) _IFC_REG(29) _IFC_REG(30) _IFC_REG(31) ".iflt \\var\n\t" ".error \"Unable to parse register name \\r\"\n\t" ".endif\n\t" ".endm")
double fmax(double, double)
static av_always_inline av_const int16_t av_clip_int16_rvi(int a)
static av_const int av_popcount64_rv(uint64_t x)