special handling for vp3 idct, use the c reference
[libav.git] / libavutil / internal.h
CommitLineData
04d7f601
DB
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
b78e7197
DB
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
04d7f601
DB
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
04d7f601 10 *
b78e7197 11 * FFmpeg is distributed in the hope that it will be useful,
04d7f601
DB
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
b78e7197 17 * License along with FFmpeg; if not, write to the Free Software
04d7f601
DB
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
05020c89
RD
21/**
22 * @file internal.h
23 * common internal api header.
24 */
25
26#ifndef INTERNAL_H
27#define INTERNAL_H
28
318049b8
MR
29#if !defined(DEBUG) && !defined(NDEBUG)
30# define NDEBUG
31#endif
32
99545457 33#include <stdint.h>
318049b8
MR
34#include <stddef.h>
35#include <assert.h>
99545457 36
5403f857
MR
37#ifndef attribute_used
38#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
39# define attribute_used __attribute__((used))
40#else
41# define attribute_used
42#endif
43#endif
44
cd107896
MR
45#ifndef M_PI
46#define M_PI 3.14159265358979323846
47#endif
48
cd107896
MR
49#ifndef INT16_MIN
50#define INT16_MIN (-0x7fff-1)
51#endif
52
53#ifndef INT16_MAX
54#define INT16_MAX 0x7fff
55#endif
56
57#ifndef INT32_MIN
58#define INT32_MIN (-0x7fffffff-1)
59#endif
60
61#ifndef INT32_MAX
62#define INT32_MAX 0x7fffffff
63#endif
64
65#ifndef UINT32_MAX
66#define UINT32_MAX 0xffffffff
67#endif
68
69#ifndef INT64_MIN
70#define INT64_MIN (-0x7fffffffffffffffLL-1)
71#endif
72
73#ifndef INT64_MAX
8da9266c 74#define INT64_MAX INT64_C(9223372036854775807)
cd107896
MR
75#endif
76
77#ifndef UINT64_MAX
8da9266c 78#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
cd107896
MR
79#endif
80
81#ifndef INT_BIT
82# if INT_MAX != 2147483647
83# define INT_BIT 64
84# else
85# define INT_BIT 32
86# endif
87#endif
88
05020c89
RD
89#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC)
90# define PIC
91#endif
92
cf1e119b 93#include "intreadwrite.h"
aab77159
RD
94#include "bswap.h"
95
05020c89 96#ifndef offsetof
635eb0cc 97# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
05020c89
RD
98#endif
99
635eb0cc
MR
100#ifdef USE_FASTMEMCPY
101# include "libvo/fastmemcpy.h"
6f74b71e 102# define memcpy(a,b,c) fast_memcpy(a,b,c)
635eb0cc 103#endif
05020c89
RD
104
105// Use rip-relative addressing if compiling PIC code on x86-64.
635eb0cc
MR
106#if defined(__MINGW32__) || defined(__CYGWIN__) || \
107 defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
108# if defined(ARCH_X86_64) && defined(PIC)
109# define MANGLE(a) "_" #a"(%%rip)"
05020c89 110# else
635eb0cc 111# define MANGLE(a) "_" #a
05020c89 112# endif
635eb0cc
MR
113#else
114# if defined(ARCH_X86_64) && defined(PIC)
115# define MANGLE(a) #a"(%%rip)"
116# elif defined(CONFIG_DARWIN)
117# define MANGLE(a) "_" #a
118# else
119# define MANGLE(a) #a
120# endif
121#endif
05020c89
RD
122
123/* debug stuff */
124
05020c89 125/* dprintf macros */
635eb0cc 126#ifdef DEBUG
318c5e05 127# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
635eb0cc 128#else
318c5e05 129# define dprintf(pctx, ...)
635eb0cc 130#endif
05020c89 131
635eb0cc 132#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
05020c89 133
7e5f82dc
MR
134/* math */
135
36cd3069 136extern const uint32_t ff_inverse[256];
05020c89 137
3cd52279 138#if defined(ARCH_X86)
05020c89
RD
139# define FASTDIV(a,b) \
140 ({\
141 int ret,dmy;\
142 asm volatile(\
143 "mull %3"\
144 :"=d"(ret),"=a"(dmy)\
36cd3069 145 :"1"(a),"g"(ff_inverse[b])\
05020c89
RD
146 );\
147 ret;\
148 })
eeebe6ad
SS
149#elif defined(ARCH_ARMV4L)
150# define FASTDIV(a,b) \
151 ({\
152 int ret,dmy;\
153 asm volatile(\
154 "umull %1, %0, %2, %3"\
155 :"=&r"(ret),"=&r"(dmy)\
36cd3069 156 :"r"(a),"r"(ff_inverse[b])\
eeebe6ad
SS
157 );\
158 ret;\
159 })
05020c89 160#elif defined(CONFIG_FASTDIV)
36cd3069 161# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32))
05020c89
RD
162#else
163# define FASTDIV(a,b) ((a)/(b))
164#endif
165
a77caa4d 166extern const uint8_t ff_sqrt_tab[128];
05020c89
RD
167
168static inline int ff_sqrt(int a)
169{
170 int ret=0;
45221f7f 171 int s, b;
05020c89
RD
172
173 if(a<128) return ff_sqrt_tab[a];
174
45221f7f
MN
175 for(s=30; s>=0; s-=2){
176 ret+=ret;
177 b= (1+2*ret)<<s;
05020c89 178 if(b<=a){
fd735e4b 179 a-=b;
45221f7f 180 ret++;
05020c89
RD
181 }
182 }
183 return ret;
184}
185
3cd52279 186#if defined(ARCH_X86)
05020c89
RD
187#define MASK_ABS(mask, level)\
188 asm volatile(\
189 "cdq \n\t"\
190 "xorl %1, %0 \n\t"\
191 "subl %1, %0 \n\t"\
192 : "+a" (level), "=&d" (mask)\
193 );
194#else
195#define MASK_ABS(mask, level)\
196 mask= level>>31;\
197 level= (level^mask)-mask;
198#endif
199
94e4c3a3 200#ifdef HAVE_CMOV
05020c89
RD
201#define COPY3_IF_LT(x,y,a,b,c,d)\
202asm volatile (\
203 "cmpl %0, %3 \n\t"\
204 "cmovl %3, %0 \n\t"\
205 "cmovl %4, %1 \n\t"\
206 "cmovl %5, %2 \n\t"\
8c2e2040 207 : "+&r" (x), "+&r" (a), "+r" (c)\
05020c89
RD
208 : "r" (y), "r" (b), "r" (d)\
209);
210#else
211#define COPY3_IF_LT(x,y,a,b,c,d)\
212if((y)<(x)){\
213 (x)=(y);\
214 (a)=(b);\
215 (c)=(d);\
216}
217#endif
218
219/* avoid usage of various functions */
84662c01 220#undef malloc
05020c89 221#define malloc please_use_av_malloc
84662c01 222#undef free
05020c89 223#define free please_use_av_free
84662c01 224#undef realloc
05020c89 225#define realloc please_use_av_realloc
84662c01 226#undef time
05020c89 227#define time time_is_forbidden_due_to_security_issues
84662c01 228#undef rand
3299fb45 229#define rand rand_is_forbidden_due_to_state_trashing_use_av_random
84662c01 230#undef srand
3299fb45 231#define srand srand_is_forbidden_due_to_state_trashing_use_av_init_random
84662c01 232#undef random
3299fb45 233#define random random_is_forbidden_due_to_state_trashing_use_av_random
84662c01 234#undef sprintf
05020c89 235#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
84662c01 236#undef strcat
272605c7 237#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
84662c01 238#undef exit
c367d067 239#define exit exit_is_forbidden
22490641 240#if !(defined(LIBAVFORMAT_BUILD) || defined(FRAMEHOOK_H))
84662c01 241#undef printf
05020c89 242#define printf please_use_av_log
84662c01 243#undef fprintf
05020c89
RD
244#define fprintf please_use_av_log
245#endif
246
247#define CHECKED_ALLOCZ(p, size)\
248{\
249 p= av_mallocz(size);\
250 if(p==NULL && (size)!=0){\
251 perror("malloc");\
252 goto fail;\
253 }\
254}
255
256#ifndef HAVE_LRINTF
257/* XXX: add ISOC specific test to avoid specific BSD testing. */
258/* better than nothing implementation. */
259/* btw, rintf() is existing on fbsd too -- alex */
849f1035 260static av_always_inline long int lrintf(float x)
05020c89 261{
05020c89 262 return (int)(rint(x));
05020c89
RD
263}
264#endif /* HAVE_LRINTF */
265
266#endif /* INTERNAL_H */