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
57 #elif defined (CONFIG_OS2)
62 #endif /* !__MINGW32__ && CONFIG_OS2 */
64 # ifdef USE_FASTMEMCPY
65 # include "libvo/fastmemcpy.h"
68 // Use rip-relative addressing if compiling PIC code on x86-64.
69 # if defined(__MINGW32__) || defined(__CYGWIN__) || \
70 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
71 # if defined(ARCH_X86_64) && defined(PIC)
72 # define MANGLE(a) "_" #a"(%%rip)"
74 # define MANGLE(a) "_" #a
77 # if defined(ARCH_X86_64) && defined(PIC)
78 # define MANGLE(a) #a"(%%rip)"
79 # elif defined(CONFIG_DARWIN)
80 # define MANGLE(a) "_" #a
88 # if !defined(DEBUG) && !defined(NDEBUG)
95 # define dprintf(fmt,...) av_log(NULL, AV_LOG_DEBUG, fmt, __VA_ARGS__)
97 # define dprintf(fmt,...)
104 # define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
106 extern const uint32_t inverse[256];
108 #if defined(ARCH_X86) || defined(ARCH_X86_64)
109 # define FASTDIV(a,b) \
114 :"=d"(ret),"=a"(dmy)\
115 :"1"(a),"g"(inverse[b])\
119 #elif defined(ARCH_ARMV4L)
120 # define FASTDIV(a,b) \
124 "umull %1, %0, %2, %3"\
125 :"=&r"(ret),"=&r"(dmy)\
126 :"r"(a),"r"(inverse[b])\
130 #elif defined(CONFIG_FASTDIV)
131 # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
133 # define FASTDIV(a,b) ((a)/(b))
137 extern FF_IMPORT_ATTR const uint8_t ff_sqrt_tab[128];
139 static inline int ff_sqrt(int a)
145 if(a<128) return ff_sqrt_tab[a];
147 for(s=15; s>=0; s--){
148 int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
157 #if defined(ARCH_X86) || defined(ARCH_X86_64)
158 #define MASK_ABS(mask, level)\
163 : "+a" (level), "=&d" (mask)\
166 #define MASK_ABS(mask, level)\
168 level= (level^mask)-mask;
171 #if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
172 #define COPY3_IF_LT(x,y,a,b,c,d)\
178 : "+r" (x), "+r" (a), "+r" (c)\
179 : "r" (y), "r" (b), "r" (d)\
182 #define COPY3_IF_LT(x,y,a,b,c,d)\
190 /* avoid usage of various functions */
191 #define malloc please_use_av_malloc
192 #define free please_use_av_free
193 #define realloc please_use_av_realloc
194 #define time time_is_forbidden_due_to_security_issues
195 #define rand rand_is_forbidden_due_to_state_trashing
196 #define srand srand_is_forbidden_due_to_state_trashing
197 #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
198 #define strcat strcat_is_forbidden_due_to_security_issues_use_pstrcat
199 #if !(defined(LIBAVFORMAT_BUILD) || defined(_FRAMEHOOK_H))
200 #define printf please_use_av_log
201 #define fprintf please_use_av_log
204 #define CHECKED_ALLOCZ(p, size)\
206 p= av_mallocz(size);\
207 if(p==NULL && (size)!=0){\
214 /* XXX: add ISOC specific test to avoid specific BSD testing. */
215 /* better than nothing implementation. */
216 /* btw, rintf() is existing on fbsd too -- alex */
217 static always_inline long int lrintf(float x)
224 : "=m" (i) : "t" (x) : "st"
228 /* XXX: incorrect, but make it compile */
229 return (int)(x + (x < 0 ? -0.5 : 0.5));
230 # endif /* ARCH_X86 */
232 return (int)(rint(x));
233 #endif /* __MINGW32__ */
235 #endif /* HAVE_LRINTF */
237 #endif /* INTERNAL_H */