FFmpeg
intmath.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Mans Rullgard <mans@mansr.com>
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 #ifndef AVUTIL_ARM_INTMATH_H
22 #define AVUTIL_ARM_INTMATH_H
23 
24 #include <stdint.h>
25 
26 #include "config.h"
27 #include "libavutil/attributes.h"
28 
29 #if HAVE_INLINE_ASM
30 
31 #if HAVE_ARMV6_INLINE
32 
33 #define av_clip_uint8 av_clip_uint8_arm
34 static av_always_inline av_const int av_clip_uint8_arm(int a)
35 {
36  int x;
37  __asm__ ("usat %0, #8, %1" : "=r"(x) : "r"(a));
38  return x;
39 }
40 
41 #define av_clip_int8 av_clip_int8_arm
42 static av_always_inline av_const int av_clip_int8_arm(int a)
43 {
44  int x;
45  __asm__ ("ssat %0, #8, %1" : "=r"(x) : "r"(a));
46  return x;
47 }
48 
49 #define av_clip_uint16 av_clip_uint16_arm
50 static av_always_inline av_const int av_clip_uint16_arm(int a)
51 {
52  int x;
53  __asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a));
54  return x;
55 }
56 
57 #define av_clip_int16 av_clip_int16_arm
58 static av_always_inline av_const int av_clip_int16_arm(int a)
59 {
60  int x;
61  __asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
62  return x;
63 }
64 
65 #define av_clip_intp2 av_clip_intp2_arm
66 static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
67 {
68  if (av_builtin_constant_p(p)) {
69  unsigned x;
70  __asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
71  return x;
72  } else {
73  if (((unsigned)a + (1 << p)) & ~((2 << p) - 1))
74  return (a >> 31) ^ ((1 << p) - 1);
75  else
76  return a;
77  }
78 }
79 
80 #define av_clip_uintp2 av_clip_uintp2_arm
81 static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
82 {
83  if (av_builtin_constant_p(p)) {
84  unsigned x;
85  __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
86  return x;
87  } else {
88  if (a & ~((1<<p) - 1)) return (~a) >> 31 & ((1<<p) - 1);
89  else return a;
90  }
91 }
92 
93 #define av_sat_add32 av_sat_add32_arm
94 static av_always_inline int av_sat_add32_arm(int a, int b)
95 {
96  int r;
97  __asm__ ("qadd %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
98  return r;
99 }
100 
101 #define av_sat_dadd32 av_sat_dadd32_arm
102 static av_always_inline int av_sat_dadd32_arm(int a, int b)
103 {
104  int r;
105  __asm__ ("qdadd %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
106  return r;
107 }
108 
109 #define av_sat_sub32 av_sat_sub32_arm
110 static av_always_inline int av_sat_sub32_arm(int a, int b)
111 {
112  int r;
113  __asm__ ("qsub %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
114  return r;
115 }
116 
117 #define av_sat_dsub32 av_sat_dsub32_arm
118 static av_always_inline int av_sat_dsub32_arm(int a, int b)
119 {
120  int r;
121  __asm__ ("qdsub %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));
122  return r;
123 }
124 
125 #endif /* HAVE_ARMV6_INLINE */
126 
127 #if HAVE_ASM_MOD_Q
128 
129 #define av_clipl_int32 av_clipl_int32_arm
130 static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a)
131 {
132  int x, y;
133  __asm__ ("adds %1, %R2, %Q2, lsr #31 \n\t"
134  "itet ne \n\t"
135  "mvnne %1, #1<<31 \n\t"
136  "moveq %0, %Q2 \n\t"
137  "eorne %0, %1, %R2, asr #31 \n\t"
138  : "=r"(x), "=&r"(y) : "r"(a) : "cc");
139  return x;
140 }
141 
142 #endif /* HAVE_ASM_MOD_Q */
143 
144 #endif /* HAVE_INLINE_ASM */
145 
146 #endif /* AVUTIL_ARM_INTMATH_H */
r
const char * r
Definition: vf_curves.c:127
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
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_builtin_constant_p
#define av_builtin_constant_p
Definition: attributes.h:160
av_always_inline
#define av_always_inline
Definition: attributes.h:49
__asm__
__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")
int32_t
int32_t
Definition: audioconvert.c:56