2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
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.
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.
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
23 * common internal api header.
29 #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
41 # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
49 # define snprintf _snprintf
50 # define vsnprintf _vsnprintf
58 #elif defined (CONFIG_OS2)
63 #endif /* !__MINGW32__ && CONFIG_OS2 */
66 # include "libvo/fastmemcpy.h"
69 // Use rip-relative addressing if compiling PIC code on x86-64.
70 #if defined(__MINGW32__) || defined(__CYGWIN__) || \
71 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
72 # if defined(ARCH_X86_64) && defined(PIC)
73 # define MANGLE(a) "_" #a"(%%rip)"
75 # define MANGLE(a) "_" #a
78 # if defined(ARCH_X86_64) && defined(PIC)
79 # define MANGLE(a) #a"(%%rip)"
80 # elif defined(CONFIG_DARWIN)
81 # define MANGLE(a) "_" #a
89 #if !defined(DEBUG) && !defined(NDEBUG)
96 # define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
98 # define dprintf(fmt,...)
101 #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
105 extern const uint32_t ff_inverse[256];
107 #if defined(ARCH_X86)
108 # define FASTDIV(a,b) \
113 :"=d"(ret),"=a"(dmy)\
114 :"1"(a),"g"(ff_inverse[b])\
118 #elif defined(ARCH_ARMV4L)
119 # define FASTDIV(a,b) \
123 "umull %1, %0, %2, %3"\
124 :"=&r"(ret),"=&r"(dmy)\
125 :"r"(a),"r"(ff_inverse[b])\
129 #elif defined(CONFIG_FASTDIV)
130 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
132 # define FASTDIV(a,b) ((a)/(b))
135 extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128];
137 static inline int ff_sqrt(int a)
143 if(a<128) return ff_sqrt_tab[a];
145 for(s=15; s>=0; s--){
146 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
155 #if defined(ARCH_X86)
156 #define MASK_ABS(mask, level)\
161 : "+a" (level), "=&d" (mask)\
164 #define MASK_ABS(mask, level)\
166 level= (level^mask)-mask;
170 #define COPY3_IF_LT(x,y,a,b,c,d)\
176 : "+r" (x), "+r" (a), "+r" (c)\
177 : "r" (y), "r" (b), "r" (d)\
180 #define COPY3_IF_LT(x,y,a,b,c,d)\
188 /* avoid usage of various functions */
189 #define malloc please_use_av_malloc
190 #define free please_use_av_free
191 #define realloc please_use_av_realloc
192 #define time time_is_forbidden_due_to_security_issues
193 #define rand rand_is_forbidden_due_to_state_trashing
194 #define srand srand_is_forbidden_due_to_state_trashing
195 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
196 #define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
197 #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
198 #define printf please_use_av_log
199 #define fprintf please_use_av_log
202 #define CHECKED_ALLOCZ(p, size)\
204 p= av_mallocz(size);\
205 if(p==NULL && (size)!=0){\
212 /* XXX: add ISOC specific test to avoid specific BSD testing. */
213 /* better than nothing implementation. */
214 /* btw, rintf() is existing on fbsd too -- alex */
215 static always_inline long int lrintf(float x)
222 : "=m" (i) : "t" (x) : "st"
226 /* XXX: incorrect, but make it compile */
227 return (int)(x + (x < 0 ? -0.5 : 0.5));
228 # endif /* ARCH_X86_32 */
230 return (int)(rint(x));
231 #endif /* __MINGW32__ */
233 #endif /* HAVE_LRINTF */
235 #endif /* INTERNAL_H */