From 4c624dccf4d1e13653be90c26dac49664c0f8241 Mon Sep 17 00:00:00 2001 From: Steven Walters Date: Mon, 28 Feb 2011 19:07:40 -0500 Subject: [PATCH] Intel Compiler support Big thanks to David Rudie, the original author of this patch. --- .gitignore | 3 + Makefile | 47 +++---- common/common.c | 4 +- common/osdep.c | 20 +-- common/osdep.h | 46 +++++-- common/set.c | 1 - common/win32thread.c | 2 +- common/x86/predict-c.c | 16 ++- common/x86/util.h | 2 +- configure | 231 ++++++++++++++++++++++++++++----- encoder/analyse.c | 2 - encoder/encoder.c | 2 - encoder/ratecontrol.c | 1 - encoder/set.c | 2 - encoder/slicetype.c | 2 - extras/inttypes.h | 285 +++++++++++++++++++++++++++++++++++++++++ extras/stdint.h | 17 +++ input/timecode.c | 1 - tools/checkasm.c | 6 +- x264.c | 10 +- 20 files changed, 585 insertions(+), 115 deletions(-) create mode 100644 extras/inttypes.h diff --git a/.gitignore b/.gitignore index 5a47b49b..682a23c1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ *.rej *.dll* *.exe +*.def +*.lib +*.pdb *.mo *.o *.patch diff --git a/Makefile b/Makefile index a66a9eef..67301fcc 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,7 @@ SRCCLI += extras/getopt.c endif ifneq ($(SONAME),) -ifeq ($(SYS),MINGW) +ifeq ($(SYS),WINDOWS) SRCSO += x264dll.c endif endif @@ -139,30 +139,30 @@ DEP = depend default: $(DEP) x264$(EXE) -libx264.a: .depend $(OBJS) $(OBJASM) - $(AR) rc libx264.a $(OBJS) $(OBJASM) - $(RANLIB) libx264.a +$(LIBX264): .depend $(OBJS) $(OBJASM) + $(AR)$@ $(OBJS) $(OBJASM) + $(if $(RANLIB), $(RANLIB) $@) $(SONAME): .depend $(OBJS) $(OBJASM) $(OBJSO) - $(CC) -shared -o $@ $(OBJS) $(OBJASM) $(OBJSO) $(SOFLAGS) $(LDFLAGS) + $(LD)$@ $(OBJS) $(OBJASM) $(OBJSO) $(SOFLAGS) $(LDFLAGS) -x264$(EXE): $(OBJCLI) libx264.a - $(CC) -o $@ $+ $(LDFLAGSCLI) $(LDFLAGS) +x264$(EXE): $(OBJCLI) $(LIBX264) + $(LD)$@ $+ $(LDFLAGSCLI) $(LDFLAGS) -checkasm: tools/checkasm.o libx264.a - $(CC) -o $@ $+ $(LDFLAGS) +checkasm: tools/checkasm.o $(LIBX264) + $(LD)$@ $+ $(LDFLAGS) %.o: %.asm $(AS) $(ASFLAGS) -o $@ $< - -@ $(STRIP) -x $@ # delete local/anonymous symbols, so they don't show up in oprofile + -@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile %.o: %.S $(AS) $(ASFLAGS) -o $@ $< - -@ $(STRIP) -x $@ # delete local/anonymous symbols, so they don't show up in oprofile + -@ $(if $(STRIP), $(STRIP) -x $@) # delete local/anonymous symbols, so they don't show up in oprofile .depend: config.mak @rm -f .depend - @$(foreach SRC, $(SRCS) $(SRCCLI) $(SRCSO), $(CC) $(CFLAGS) $(SRC) -MT $(SRC:%.c=%.o) -MM -g0 1>> .depend;) + @$(foreach SRC, $(SRCS) $(SRCCLI) $(SRCSO), $(CC) $(CFLAGS) $(SRC) $(DEPMT) $(SRC:%.c=%.o) $(DEPMM) 1>> .depend;) config.mak: ./configure @@ -191,25 +191,20 @@ fprofiled: else fprofiled: $(MAKE) clean - mv config.mak config.mak2 - sed -e 's/CFLAGS.*/& -fprofile-generate/; s/LDFLAGS.*/& -fprofile-generate/' config.mak2 > config.mak - $(MAKE) x264$(EXE) + $(MAKE) x264$(EXE) CFLAGS="$(CFLAGS) $(PROF_GEN_CC)" LDFLAGS="$(LDFLAGS) $(PROF_GEN_LD)" $(foreach V, $(VIDS), $(foreach I, 0 1 2 3 4 5 6 7, ./x264$(EXE) $(OPT$I) --threads 1 $(V) -o $(DEVNULL) ;)) rm -f $(SRC2:%.c=%.o) - sed -e 's/CFLAGS.*/& -fprofile-use/; s/LDFLAGS.*/& -fprofile-use/' config.mak2 > config.mak - $(MAKE) - rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) - mv config.mak2 config.mak + $(MAKE) CFLAGS="$(CFLAGS) $(PROF_USE_CC)" LDFLAGS="$(LDFLAGS) $(PROF_USE_LD)" + rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock endif clean: - rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a x264 x264.exe .depend TAGS + rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a *.lib *.exp *.pdb x264 x264.exe .depend TAGS rm -f checkasm checkasm.exe tools/checkasm.o tools/checkasm-a.o - rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) - - sed -e 's/ *-fprofile-\(generate\|use\)//g' config.mak > config.mak2 && mv config.mak2 config.mak + rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno) *.dyn pgopti.dpi pgopti.dpi.lock distclean: clean - rm -f config.mak x264_config.h config.h config.log x264.pc + rm -f config.mak x264_config.h config.h config.log x264.pc x264.def rm -rf test/ install: x264$(EXE) $(SONAME) @@ -219,11 +214,11 @@ install: x264$(EXE) $(SONAME) install -d $(DESTDIR)$(libdir)/pkgconfig install -m 644 x264.h $(DESTDIR)$(includedir) install -m 644 x264_config.h $(DESTDIR)$(includedir) - install -m 644 libx264.a $(DESTDIR)$(libdir) + install -m 644 $(LIBX264) $(DESTDIR)$(libdir) install -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig install x264$(EXE) $(DESTDIR)$(bindir) - $(RANLIB) $(DESTDIR)$(libdir)/libx264.a -ifeq ($(SYS),MINGW) + $(if $(RANLIB), $(RANLIB) $(DESTDIR)$(libdir)/$(LIBX264)) +ifeq ($(SYS),WINDOWS) $(if $(SONAME), install -m 755 $(SONAME) $(DESTDIR)$(bindir)) else $(if $(SONAME), ln -f -s $(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)) diff --git a/common/common.c b/common/common.c index ae503c88..69941de0 100644 --- a/common/common.c +++ b/common/common.c @@ -1095,7 +1095,7 @@ void x264_picture_clean( x264_picture_t *pic ) void *x264_malloc( int i_size ) { uint8_t *align_buf = NULL; -#if SYS_MACOSX || (SYS_MINGW && ARCH_X86_64) +#if SYS_MACOSX || (SYS_WINDOWS && ARCH_X86_64) /* Mac OS X and Win x64 always returns 16 byte aligned memory */ align_buf = malloc( i_size ); #elif HAVE_MALLOC_H @@ -1121,7 +1121,7 @@ void x264_free( void *p ) { if( p ) { -#if HAVE_MALLOC_H || SYS_MACOSX || (SYS_MINGW && ARCH_X86_64) +#if HAVE_MALLOC_H || SYS_MACOSX || (SYS_WINDOWS && ARCH_X86_64) free( p ); #else free( *( ( ( void **) p ) - 1 ) ); diff --git a/common/osdep.c b/common/osdep.c index 510d4933..fc035915 100644 --- a/common/osdep.c +++ b/common/osdep.c @@ -24,16 +24,16 @@ * For more information, contact us at licensing@x264.com. *****************************************************************************/ -#ifndef __MINGW32__ -#include -#else +#include "common.h" + +#if SYS_WINDOWS #include #include +#else +#include #endif #include -#include "common.h" - #if PTW32_STATIC_LIB #define WIN32_LEAN_AND_MEAN #include @@ -43,14 +43,14 @@ extern int ptw32_processInitialized; int64_t x264_mdate( void ) { -#ifndef __MINGW32__ - struct timeval tv_date; - gettimeofday( &tv_date, NULL ); - return (int64_t)tv_date.tv_sec * 1000000 + (int64_t)tv_date.tv_usec; -#else +#if SYS_WINDOWS struct timeb tb; ftime( &tb ); return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000; +#else + struct timeval tv_date; + gettimeofday( &tv_date, NULL ); + return (int64_t)tv_date.tv_sec * 1000000 + (int64_t)tv_date.tv_usec; #endif } diff --git a/common/osdep.h b/common/osdep.h index f56f7334..6249dbe0 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -50,6 +50,25 @@ #include // _O_BINARY #endif +#ifdef __ICL +#define inline __inline +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#define snprintf _snprintf +#define strtok_r strtok_s +#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) +#endif + +#ifdef __INTEL_COMPILER +#include +#else +#include +#endif + +#if (defined(__GNUC__) || defined(__INTEL_COMPILER)) && (ARCH_X86 || ARCH_X86_64) +#define HAVE_X86_INLINE_ASM 1 +#endif + #if !defined(isfinite) && (SYS_OPENBSD || SYS_SunOS) #define isfinite finite #endif @@ -60,7 +79,11 @@ #endif #endif +#ifdef __ICL +#define DECLARE_ALIGNED( var, n ) __declspec(align(n)) var +#else #define DECLARE_ALIGNED( var, n ) var __attribute__((aligned(n))) +#endif #define ALIGNED_16( var ) DECLARE_ALIGNED( var, 16 ) #define ALIGNED_8( var ) DECLARE_ALIGNED( var, 8 ) #define ALIGNED_4( var ) DECLARE_ALIGNED( var, 4 ) @@ -99,9 +122,14 @@ #define x264_constant_p(x) __builtin_constant_p(x) #define x264_nonconstant_p(x) (!__builtin_constant_p(x)) #else -#define UNUSED +#ifdef __ICL +#define ALWAYS_INLINE __forceinline +#define NOINLINE __declspec(noinline) +#else #define ALWAYS_INLINE inline #define NOINLINE +#endif +#define UNUSED #define MAY_ALIAS #define x264_constant_p(x) 0 #define x264_nonconstant_p(x) 0 @@ -179,19 +207,13 @@ int x264_threading_init( void ); #define asm __asm__ -#if !defined(_WIN64) && !defined(__LP64__) -#if defined(__INTEL_COMPILER) -#define BROKEN_STACK_ALIGNMENT 1 /* define it if stack is not mod16 */ -#endif -#endif - #if WORDS_BIGENDIAN #define endian_fix(x) (x) #define endian_fix64(x) (x) #define endian_fix32(x) (x) #define endian_fix16(x) (x) #else -#if defined(__GNUC__) && HAVE_MMX +#if HAVE_X86_INLINE_ASM && HAVE_MMX static ALWAYS_INLINE uint32_t endian_fix32( uint32_t x ) { asm("bswap %0":"+r"(x)); @@ -209,7 +231,7 @@ static ALWAYS_INLINE uint32_t endian_fix32( uint32_t x ) return (x<<24) + ((x<<8)&0xff0000) + ((x>>8)&0xff00) + (x>>24); } #endif -#if defined(__GNUC__) && ARCH_X86_64 +#if HAVE_X86_INLINE_ASM && ARCH_X86_64 static ALWAYS_INLINE uint64_t endian_fix64( uint64_t x ) { asm("bswap %0":"+r"(x)); @@ -260,7 +282,7 @@ static int ALWAYS_INLINE x264_ctz( uint32_t x ) } #endif -#if defined(__GNUC__) && HAVE_MMX +#if HAVE_X86_INLINE_ASM && HAVE_MMX /* Don't use __builtin_prefetch; even as recent as 4.3.4, GCC seems incapable of * using complex address modes properly unless we use inline asm. */ static ALWAYS_INLINE void x264_prefetch( void *p ) @@ -277,7 +299,7 @@ static ALWAYS_INLINE void x264_prefetch( void *p ) #endif #if HAVE_POSIXTHREAD -#if SYS_MINGW +#if SYS_WINDOWS #define x264_lower_thread_priority(p)\ {\ x264_pthread_t handle = pthread_self();\ @@ -290,7 +312,7 @@ static ALWAYS_INLINE void x264_prefetch( void *p ) #else #include #define x264_lower_thread_priority(p) { UNUSED int nice_ret = nice(p); } -#endif /* SYS_MINGW */ +#endif /* SYS_WINDOWS */ #elif HAVE_WIN32THREAD #define x264_lower_thread_priority(p) SetThreadPriority( GetCurrentThread(), X264_MAX( -2, -p ) ) #else diff --git a/common/set.c b/common/set.c index 57d68e6b..3690ed64 100644 --- a/common/set.c +++ b/common/set.c @@ -24,7 +24,6 @@ *****************************************************************************/ #define _ISOC99_SOURCE -#include #include "common.h" #define SHIFT(x,s) ((s)<=0 ? (x)<<-(s) : ((x)+(1<<((s)-1)))>>(s)) diff --git a/common/win32thread.c b/common/win32thread.c index 45dfb12d..2d981d35 100644 --- a/common/win32thread.c +++ b/common/win32thread.c @@ -59,7 +59,7 @@ typedef struct static x264_win32thread_control_t thread_control; /* _beginthreadex requires that the start routine is __stdcall */ -static __stdcall unsigned x264_win32thread_worker( void *arg ) +static unsigned __stdcall x264_win32thread_worker( void *arg ) { x264_pthread_t *h = arg; h->ret = h->func( h->arg ); diff --git a/common/x86/predict-c.c b/common/x86/predict-c.c index da87d197..24192a2c 100644 --- a/common/x86/predict-c.c +++ b/common/x86/predict-c.c @@ -180,7 +180,7 @@ PREDICT_16x16_P( sse2 ) PREDICT_16x16_P( avx ) #endif //!HIGH_BIT_DEPTH -#ifdef __GNUC__ +#if HAVE_X86_INLINE_ASM #if HIGH_BIT_DEPTH static void x264_predict_16x16_p_sse2( uint16_t *src ) #else @@ -218,7 +218,7 @@ static void x264_predict_16x16_p_ssse3( uint8_t *src ) "pshufw $1, %%mm0, %%mm1 \n" "paddw %%mm1, %%mm0 \n" "movd %%mm0, %0 \n" - "movsx %w0, %0 \n" + "movswl %w0, %0 \n" :"=r"(H) :"m"(src[-FDEC_STRIDE]), "m"(src[-FDEC_STRIDE+8]), "m"(src[-FDEC_STRIDE-8]), "m"(*pb_12345678), "m"(*pb_m87654321) @@ -271,7 +271,7 @@ PREDICT_8x8_P( sse2 ) #endif //!HIGH_BIT_DEPTH -#ifdef __GNUC__ +#if HAVE_X86_INLINE_ASM #if HIGH_BIT_DEPTH static void x264_predict_8x8c_p_sse2( uint16_t *src ) #else @@ -301,7 +301,7 @@ static void x264_predict_8x8c_p_ssse3( uint8_t *src ) "pshufw $1, %%mm0, %%mm1 \n" "paddw %%mm1, %%mm0 \n" "movd %%mm0, %0 \n" - "movsx %w0, %0 \n" + "movswl %w0, %0 \n" :"=r"(H) :"m"(src[-FDEC_STRIDE]), "m"(*pb_m32101234) ); @@ -432,7 +432,9 @@ void x264_predict_16x16_init_mmx( int cpu, x264_predict_t pf[7] ) pf[I_PRED_16x16_DC_LEFT] = x264_predict_16x16_dc_left_sse2; pf[I_PRED_16x16_V] = x264_predict_16x16_v_sse2; pf[I_PRED_16x16_H] = x264_predict_16x16_h_sse2; +#if HAVE_X86_INLINE_ASM pf[I_PRED_16x16_P] = x264_predict_16x16_p_sse2; +#endif #else #if !ARCH_X86_64 pf[I_PRED_16x16_P] = x264_predict_16x16_p_mmxext; @@ -449,7 +451,7 @@ void x264_predict_16x16_init_mmx( int cpu, x264_predict_t pf[7] ) if( !(cpu&X264_CPU_SSSE3) ) return; pf[I_PRED_16x16_H] = x264_predict_16x16_h_ssse3; -#ifdef __GNUC__ +#if HAVE_X86_INLINE_ASM pf[I_PRED_16x16_P] = x264_predict_16x16_p_ssse3; #endif if( !(cpu&X264_CPU_AVX) ) @@ -473,7 +475,9 @@ void x264_predict_8x8c_init_mmx( int cpu, x264_predict_t pf[7] ) pf[I_PRED_CHROMA_DC] = x264_predict_8x8c_dc_sse2; pf[I_PRED_CHROMA_DC_TOP] = x264_predict_8x8c_dc_top_sse2; pf[I_PRED_CHROMA_H] = x264_predict_8x8c_h_sse2; +#if HAVE_X86_INLINE_ASM pf[I_PRED_CHROMA_P] = x264_predict_8x8c_p_sse2; +#endif #else #if ARCH_X86_64 pf[I_PRED_CHROMA_DC_LEFT] = x264_predict_8x8c_dc_left; @@ -493,7 +497,7 @@ void x264_predict_8x8c_init_mmx( int cpu, x264_predict_t pf[7] ) if( !(cpu&X264_CPU_SSSE3) ) return; pf[I_PRED_CHROMA_H] = x264_predict_8x8c_h_ssse3; -#ifdef __GNUC__ +#if HAVE_X86_INLINE_ASM pf[I_PRED_CHROMA_P] = x264_predict_8x8c_p_ssse3; #endif #endif // HIGH_BIT_DEPTH diff --git a/common/x86/util.h b/common/x86/util.h index 9d71b405..445248a5 100644 --- a/common/x86/util.h +++ b/common/x86/util.h @@ -27,7 +27,7 @@ #ifndef X264_X86_UTIL_H #define X264_X86_UTIL_H -#ifdef __GNUC__ +#if HAVE_X86_INLINE_ASM #ifdef __SSE__ #include diff --git a/configure b/configure index 96544ce4..e4c77299 100755 --- a/configure +++ b/configure @@ -49,6 +49,47 @@ log_msg() { echo "$1" >> config.log } +intel_cflags() { + # Intel Compiler issues an incredibly large number of warnings on any warning level, + # suppress them by disabling all warnings rather than having to use #pragmas to disable most of them + for arg in $*; do + [ $arg = -ffast-math ] && arg= + [[ "$arg" = -falign-loops* ]] && arg= + [ "$arg" = -fno-tree-vectorize ] && arg= + [ "$arg" = -Wshadow ] && arg= + if [ $compiler = ICL ]; then + [ "$arg" = -Wall ] && arg=-W0 + [ "$arg" = -g ] && arg=-Z7 + [ "$arg" = -fomit-frame-pointer ] && arg= + [ "$arg" = -s ] && arg= + [ "$arg" = -fPIC ] && arg= + else + [ "$arg" = -Wall ] && arg=-w0 + fi + + # Intel Compiler on Mac OS X does not allow pre -msse3 + [ $SYS = MACOSX -a \( "$arg" = -mia32 -o "$arg" = -msse -o "$arg" = -msse2 \) ] && arg= + [ -n "$arg" ] && echo -n "$arg " + done +} + +icl_ldflags() { + for arg in $*; do + arg=${arg/LIBPATH/libpath} + [ ${arg#-libpath:} == $arg -a ${arg#-l} != $arg ] && arg=${arg#-l}.lib + [ ${arg#-L} != $arg ] && arg=-libpath:${arg#-L} + [ $arg = -Wl,--large-address-aware ] && arg=-largeaddressaware + [ $arg = -s ] && arg= + [ "$arg" = -Wl,-Bsymbolic ] && arg= + + arg=${arg/pthreadGC/pthreadVC} + [ "$arg" = avifil32.lib ] && arg=vfw32.lib + [ "$arg" = gpac_static.lib ] && arg=libgpac_static.lib + + [ -n "$arg" ] && echo -n "$arg " + done +} + cc_check() { if [ -z "$3" ]; then if [ -z "$1$2" ]; then @@ -66,7 +107,12 @@ cc_check() { rm -f conftest.c [ -n "$1" ] && echo "#include <$1>" > conftest.c echo "int main () { $3 return 0; }" >> conftest.c - if $CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest >conftest.log 2>&1; then + if [ $compiler = ICL ]; then + cc_cmd="$CC conftest.c $CFLAGS $2 -link $(icl_ldflags $2 $LDFLAGSCLI $LDFLAGS)" + else + cc_cmd="$CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS -o conftest" + fi + if $cc_cmd >conftest.log 2>&1; then res=$? log_ok else @@ -74,7 +120,7 @@ cc_check() { log_fail log_msg "Failed commandline was:" log_msg "--------------------------------------------------" - log_msg "$CC conftest.c $CFLAGS $2 $LDFLAGSCLI $LDFLAGS" + log_msg "$cc_cmd" cat conftest.log >> config.log log_msg "--------------------------------------------------" log_msg "Failed program was:" @@ -140,7 +186,7 @@ die() { exit 1 } -rm -f x264_config.h config.h config.mak config.log x264.pc conftest* +rm -f x264_config.h config.h config.mak config.log x264.pc x264.def conftest* prefix='/usr/local' exec_prefix='${prefix}' @@ -163,6 +209,7 @@ pic="no" vis="no" shared="no" bit_depth="8" +compiler="GNU" CFLAGS="$CFLAGS -Wall -I." LDFLAGS="$LDFLAGS" @@ -290,6 +337,28 @@ host="${host#*-}" host_vendor="${host%%-*}" host_os="${host#*-}" +# test for use of Intel Compiler +if [[ $host_os = mingw* || $host_os = cygwin* ]]; then + if [[ `basename "$CC"` = icl* ]]; then + # Windows Intel Compiler creates dependency generation with absolute Windows paths, Cygwin's make does not support Windows paths. + [[ $host_os = cygwin* ]] && die "Windows Intel Compiler support requires MSYS" + ARCHPRE="-arch:" + compiler=ICL + CFLAGS="$CFLAGS -Qstd=c99 -nologo -Qms0 -DHAVE_STRING_H -Iextras" + QPRE="-Q" + `$CC 2>&1 | grep -q IA-32` && host_cpu=i486 + `$CC 2>&1 | grep -q "Intel(R) 64"` && host_cpu=x86_64 + cpp_check "" "" "_MSC_VER >= 1400" || die "Windows Intel Compiler support requires Visual Studio 2005 or newer" + fi +else + if [[ `basename "$CC"` = icc* ]]; then + AR="xiar" + ARCHPRE="-m" + compiler=ICC + QPRE="-" + fi +fi + case $host_os in beos*) SYS="BEOS" @@ -326,7 +395,7 @@ case $host_os in LDFLAGS="$LDFLAGS -lm" ;; cygwin*) - SYS="MINGW" + SYS="WINDOWS" EXE=".exe" DEVNULL="NUL" if cc_check "" -mno-cygwin; then @@ -335,7 +404,7 @@ case $host_os in fi ;; mingw*) - SYS="MINGW" + SYS="WINDOWS" EXE=".exe" DEVNULL="NUL" ;; @@ -355,15 +424,37 @@ case $host_cpu in ARCH="X86" AS="yasm" ASFLAGS="$ASFLAGS -O2" - if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then - CFLAGS="$CFLAGS -march=i686" - fi - if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then - CFLAGS="$CFLAGS -mfpmath=sse -msse" + if [ $compiler = GNU ]; then + if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then + CFLAGS="$CFLAGS -march=i686" + fi + if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then + CFLAGS="$CFLAGS -mfpmath=sse -msse" + fi + else + # Intel Compiler >= 11 generally defaults to SSE2 optimization. -msse is also deprecated for -mia32 + if cpp_check "" "" "__INTEL_COMPILER >= 1100" \ + && ! (echo $CFLAGS | grep -Eiq "(${ARCHPRE}ia32|${ARCHPRE}sse|${ARCHPRE}ssse3|${ARCHPRE}avx)") \ + && [[ "$CFLAGS" != *${QPRE}x* ]]; then + CFLAGS="$CFLAGS ${ARCHPRE}ia32" + fi + # icc on linux has various degrees of mod16 stack support + if [ $SYS = LINUX ]; then + # < 11 is completely incapable of keeping a mod16 stack + if cpp_check "" "" "__INTEL_COMPILER < 1100" ; then + define BROKEN_STACK_ALIGNMENT + # 11 <= x < 12 is capable of keeping a mod16 stack, but defaults to not doing so. + elif cpp_check "" "" "__INTEL_COMPILER < 1200" ; then + CFLAGS="$CFLAGS -falign-stack=assume-16-byte" + fi + # >= 12 defaults to a mod16 stack + fi + # icl on windows has no mod16 stack support + [ $SYS = WINDOWS ] && define BROKEN_STACK_ALIGNMENT fi if [ "$SYS" = MACOSX ]; then ASFLAGS="$ASFLAGS -f macho -DPREFIX" - elif [ "$SYS" = MINGW ]; then + elif [ "$SYS" = WINDOWS ]; then ASFLAGS="$ASFLAGS -f win32 -DPREFIX" LDFLAGS="$LDFLAGS -Wl,--large-address-aware" else @@ -379,9 +470,10 @@ case $host_cpu in CFLAGS="$CFLAGS -arch x86_64" LDFLAGS="$LDFLAGS -arch x86_64" fi - elif [ "$SYS" = MINGW ]; then + elif [ "$SYS" = WINDOWS ]; then ASFLAGS="$ASFLAGS -f win32 -m amd64" - cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX" + # only the GNU toolchain is inconsistent in prefixing function names with _ + [ $compiler = GNU ] && cc_check "" "-S" && grep -q "_main:" conftest && ASFLAGS="$ASFLAGS -DPREFIX" else ASFLAGS="$ASFLAGS -f elf -m amd64" fi @@ -460,10 +552,12 @@ log_msg "" cc_check || die "No working C compiler found." -if cc_check '' -std=gnu99 ; then - CFLAGS="$CFLAGS -std=gnu99" -elif cc_check '' -std=c99 ; then - CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE" +if [ $compiler != ICL ]; then + if cc_check '' -std=gnu99 ; then + CFLAGS="$CFLAGS -std=gnu99" + elif cc_check '' -std=c99 ; then + CFLAGS="$CFLAGS -std=c99 -D_POSIX_C_SOURCE=200112L -D_BSD_SOURCE" + fi fi if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" \) ] ; then @@ -510,18 +604,21 @@ fi define ARCH_$ARCH define SYS_$SYS -echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c -$CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed" -if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then - define WORDS_BIGENDIAN -elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then - die "endian test failed" +# skip endianness check for Intel Compiler, as all supported platforms are little. the -ipo flag will also cause the check to fail +if [ $compiler = GNU ]; then + echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c + $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed" + if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then + define WORDS_BIGENDIAN + elif !(${cross_prefix}strings -a conftest.o | grep -q EGIB && ${cross_prefix}strings -a conftest.o | grep -q naidnePF) ; then + die "endian test failed" + fi fi # autodetect options that weren't forced nor disabled # pthread-win32 is lgpl, prevent its use if --disable-gpl is specified and targeting windows -[ "$SYS" = "MINGW" -a "$gpl" = "no" -a "$thread" = "auto" ] && thread="win32" +[ "$SYS" = "WINDOWS" -a "$gpl" = "no" -a "$thread" = "auto" ] && thread="win32" libpthread="" if [ "$thread" = "auto" ]; then @@ -531,7 +628,7 @@ if [ "$thread" = "auto" ]; then thread="beos" define HAVE_BEOSTHREAD ;; - MINGW) + WINDOWS) if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then thread="posix" libpthread="-lpthread" @@ -564,7 +661,7 @@ if [ "$thread" = "posix" ]; then define HAVE_POSIXTHREAD fi if [ "$thread" = "win32" ]; then - if [ "$SYS" = "MINGW" ]; then + if [ "$SYS" = "WINDOWS" ]; then define HAVE_WIN32THREAD else thread="no" @@ -683,7 +780,7 @@ if [ "$swscale" = "yes" ]; then fi GPAC_LIBS="-lgpac_static" -if [ $SYS = MINGW ]; then +if [ $SYS = WINDOWS ]; then GPAC_LIBS="$GPAC_LIBS -lwinmm" fi if [ "$gpac" = "auto" ] ; then @@ -706,7 +803,7 @@ fi if [ "$avs" = "auto" ] ; then avs="no" - if [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then + if [ $SYS = WINDOWS ] && cc_check extras/avisynth_c.h ; then avs="yes" define HAVE_AVS fi @@ -738,7 +835,7 @@ if cc_check '' -fno-tree-vectorize ; then CFLAGS="$CFLAGS -fno-tree-vectorize" fi -if [ $SYS = MINGW -a $ARCH = X86 ] ; then +if [ $SYS = WINDOWS -a $ARCH = X86 -a $compiler = GNU ] ; then # workaround gcc/ld bug with alignment of static variables/arrays that are initialized to zero cc_check '' -fno-zero-initialized-in-bss && CFLAGS="$CFLAGS -fno-zero-initialized-in-bss" fi @@ -749,6 +846,9 @@ if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then define fseek fseeko64 define ftell ftello64 +elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then + define fseek _fseeki64 + define ftell _ftelli64 fi if cc_check '' -Wshadow ; then @@ -769,6 +869,45 @@ for var in $CONFIG_HAVE; do grep -q "HAVE_$var 1" config.h || define HAVE_$var 0 done +if [ $compiler = ICL ]; then + AR="xilib -nologo -out:" + DEPMM=-QMM + DEPMT=-QMT + HAVE_GETOPT_LONG=0 + LD="xilink -out:" + LDFLAGS="-nologo -incremental:no $(icl_ldflags $LDFLAGS)" + LDFLAGSCLI="$(icl_ldflags $LDFLAGSCLI)" + LIBX264=libx264.lib + RANLIB= + STRIP= + if [ $debug = yes ]; then + LDFLAGS="-debug $LDFLAGS" + CFLAGS="-D_DEBUG $CFLAGS" + else + CFLAGS="-DNDEBUG $CFLAGS" + fi +else + AR="$AR rc " + DEPMM="-MM -g0" + DEPMT="-MT" + LD="$CC -o " + LIBX264=libx264.a +fi +if [ $compiler = GNU ]; then + PROF_GEN_CC="-fprofile-generate" + PROF_GEN_LD="-fprofile-generate" + PROF_USE_CC="-fprofile-use" + PROF_USE_LD="-fprofile-use" +else + CFLAGS="$(intel_cflags $CFLAGS)" + # icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP + [ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__ + PROF_GEN_CC="${QPRE}prof-gen ${QPRE}prof-dir." + PROF_GEN_LD= + PROF_USE_CC="${QPRE}prof-use ${QPRE}prof-dir." + PROF_USE_LD= +fi + rm -f conftest* # generate exported config file @@ -790,8 +929,12 @@ ARCH=$ARCH SYS=$SYS CC=$CC CFLAGS=$CFLAGS +DEPMM=$DEPMM +DEPMT=$DEPMT +LD=$LD LDFLAGS=$LDFLAGS LDFLAGSCLI=$LDFLAGSCLI +LIBX264=$LIBX264 AR=$AR RANLIB=$RANLIB STRIP=$STRIP @@ -800,26 +943,44 @@ ASFLAGS=$ASFLAGS EXE=$EXE HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG DEVNULL=$DEVNULL +PROF_GEN_CC=$PROF_GEN_CC +PROF_GEN_LD=$PROF_GEN_LD +PROF_USE_CC=$PROF_USE_CC +PROF_USE_LD=$PROF_USE_LD EOF +if [ $compiler = ICL ]; then + echo '%.o: %.c' >> config.mak + echo ' $(CC) $(CFLAGS) -c -Fo$@ $<' >> config.mak +fi + if [ "$shared" = "yes" ]; then API=$(grep '#define X264_BUILD' < x264.h | cut -f 3 -d ' ') - if [ "$SYS" = "MINGW" ]; then + if [ "$SYS" = "WINDOWS" ]; then echo "SONAME=libx264-$API.dll" >> config.mak - echo 'IMPLIBNAME=libx264.dll.a' >> config.mak - echo 'SOFLAGS=-Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak + if [ $compiler = ICL ]; then + echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak + # GNU ld on windows defaults to exporting all global functions if there are no explicit __declspec(dllexport) declarations + # MSVC link does not act similarly, so it is required to make an export definition out of x264.h and use it at link time + echo 'SOFLAGS=-dll -def:x264.def -implib:$(IMPLIBNAME)' >> config.mak + echo "EXPORTS" > x264.def + grep "^\(int\|void\|x264_t\|extern\).*x264.*[\[(;]" x264.h | sed -e "s/.*\(x264.*\)[\[(].*/\1/;s/.*\(x264.*\);/\1/;s/open/open_$API/g" >> x264.def + else + echo 'IMPLIBNAME=libx264.dll.a' >> config.mak + echo 'SOFLAGS=-shared -Wl,--out-implib,$(IMPLIBNAME) -Wl,--enable-auto-image-base' >> config.mak + fi elif [ "$SYS" = "MACOSX" ]; then echo "SOSUFFIX=dylib" >> config.mak echo "SONAME=libx264.$API.dylib" >> config.mak - echo 'SOFLAGS=-dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak + echo 'SOFLAGS=-shared -dynamiclib -Wl,-single_module -Wl,-read_only_relocs,suppress -install_name $(DESTDIR)$(libdir)/$(SONAME)' >> config.mak elif [ "$SYS" = "SunOS" ]; then echo "SOSUFFIX=so" >> config.mak echo "SONAME=libx264.so.$API" >> config.mak - echo 'SOFLAGS=-Wl,-h,$(SONAME)' >> config.mak + echo 'SOFLAGS=-shared -Wl,-h,$(SONAME)' >> config.mak else echo "SOSUFFIX=so" >> config.mak echo "SONAME=libx264.so.$API" >> config.mak - echo 'SOFLAGS=-Wl,-soname,$(SONAME)' >> config.mak + echo 'SOFLAGS=-shared -Wl,-soname,$(SONAME)' >> config.mak fi echo 'default: $(SONAME)' >> config.mak fi diff --git a/encoder/analyse.c b/encoder/analyse.c index 3c200a21..b6907200 100644 --- a/encoder/analyse.c +++ b/encoder/analyse.c @@ -26,8 +26,6 @@ *****************************************************************************/ #define _ISOC99_SOURCE -#include -#include #include "common/common.h" #include "macroblock.h" diff --git a/encoder/encoder.c b/encoder/encoder.c index ca7fc8ea..6a47acf2 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -25,8 +25,6 @@ * For more information, contact us at licensing@x264.com. *****************************************************************************/ -#include - #include "common/common.h" #include "set.h" diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 65b5f148..3e018cec 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -29,7 +29,6 @@ #define _ISOC99_SOURCE #undef NDEBUG // always check asserts, the speed effect is far too small to disable them -#include #include "common/common.h" #include "ratecontrol.h" diff --git a/encoder/set.c b/encoder/set.c index b605b742..78f1b56d 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -24,8 +24,6 @@ * For more information, contact us at licensing@x264.com. *****************************************************************************/ -#include - #include "common/common.h" #include "set.h" diff --git a/encoder/slicetype.c b/encoder/slicetype.c index 07244cc1..01dcb671 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -25,8 +25,6 @@ * For more information, contact us at licensing@x264.com. *****************************************************************************/ -#include - #include "common/common.h" #include "macroblock.h" #include "me.h" diff --git a/extras/inttypes.h b/extras/inttypes.h new file mode 100644 index 00000000..b2e3fc61 --- /dev/null +++ b/extras/inttypes.h @@ -0,0 +1,285 @@ +// ISO C9x compliant inttypes.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_INTTYPES_H_ // [ +#define _MSC_INTTYPES_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include "stdint.h" + +// 7.8 Format conversion of integer types + +typedef struct { + intmax_t quot; + intmax_t rem; +} imaxdiv_t; + +// 7.8.1 Macros for format specifiers + +#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 + +// The fprintf macros for signed integers are: +#define PRId8 "d" +#define PRIi8 "i" +#define PRIdLEAST8 "d" +#define PRIiLEAST8 "i" +#define PRIdFAST8 "d" +#define PRIiFAST8 "i" + +#define PRId16 "hd" +#define PRIi16 "hi" +#define PRIdLEAST16 "hd" +#define PRIiLEAST16 "hi" +#define PRIdFAST16 "hd" +#define PRIiFAST16 "hi" + +#define PRId32 "I32d" +#define PRIi32 "I32i" +#define PRIdLEAST32 "I32d" +#define PRIiLEAST32 "I32i" +#define PRIdFAST32 "I32d" +#define PRIiFAST32 "I32i" + +#define PRId64 "I64d" +#define PRIi64 "I64i" +#define PRIdLEAST64 "I64d" +#define PRIiLEAST64 "I64i" +#define PRIdFAST64 "I64d" +#define PRIiFAST64 "I64i" + +#define PRIdMAX "I64d" +#define PRIiMAX "I64i" + +#define PRIdPTR "Id" +#define PRIiPTR "Ii" + +// The fprintf macros for unsigned integers are: +#define PRIo8 "o" +#define PRIu8 "u" +#define PRIx8 "x" +#define PRIX8 "X" +#define PRIoLEAST8 "o" +#define PRIuLEAST8 "u" +#define PRIxLEAST8 "x" +#define PRIXLEAST8 "X" +#define PRIoFAST8 "o" +#define PRIuFAST8 "u" +#define PRIxFAST8 "x" +#define PRIXFAST8 "X" + +#define PRIo16 "ho" +#define PRIu16 "hu" +#define PRIx16 "hx" +#define PRIX16 "hX" +#define PRIoLEAST16 "ho" +#define PRIuLEAST16 "hu" +#define PRIxLEAST16 "hx" +#define PRIXLEAST16 "hX" +#define PRIoFAST16 "ho" +#define PRIuFAST16 "hu" +#define PRIxFAST16 "hx" +#define PRIXFAST16 "hX" + +#define PRIo32 "I32o" +#define PRIu32 "I32u" +#define PRIx32 "I32x" +#define PRIX32 "I32X" +#define PRIoLEAST32 "I32o" +#define PRIuLEAST32 "I32u" +#define PRIxLEAST32 "I32x" +#define PRIXLEAST32 "I32X" +#define PRIoFAST32 "I32o" +#define PRIuFAST32 "I32u" +#define PRIxFAST32 "I32x" +#define PRIXFAST32 "I32X" + +#define PRIo64 "I64o" +#define PRIu64 "I64u" +#define PRIx64 "I64x" +#define PRIX64 "I64X" +#define PRIoLEAST64 "I64o" +#define PRIuLEAST64 "I64u" +#define PRIxLEAST64 "I64x" +#define PRIXLEAST64 "I64X" +#define PRIoFAST64 "I64o" +#define PRIuFAST64 "I64u" +#define PRIxFAST64 "I64x" +#define PRIXFAST64 "I64X" + +#define PRIoMAX "I64o" +#define PRIuMAX "I64u" +#define PRIxMAX "I64x" +#define PRIXMAX "I64X" + +#define PRIoPTR "Io" +#define PRIuPTR "Iu" +#define PRIxPTR "Ix" +#define PRIXPTR "IX" + +// The fscanf macros for signed integers are: +#define SCNd16 "hd" +#define SCNi16 "hi" +#define SCNdLEAST16 "hd" +#define SCNiLEAST16 "hi" +#define SCNdFAST16 "hd" +#define SCNiFAST16 "hi" + +#define SCNd32 "ld" +#define SCNi32 "li" +#define SCNdLEAST32 "ld" +#define SCNiLEAST32 "li" +#define SCNdFAST32 "ld" +#define SCNiFAST32 "li" + +#define SCNd64 "I64d" +#define SCNi64 "I64i" +#define SCNdLEAST64 "I64d" +#define SCNiLEAST64 "I64i" +#define SCNdFAST64 "I64d" +#define SCNiFAST64 "I64i" + +#define SCNdMAX "I64d" +#define SCNiMAX "I64i" + +#ifdef _WIN64 // [ +# define SCNdPTR "I64d" +# define SCNiPTR "I64i" +#else // _WIN64 ][ +# define SCNdPTR "ld" +# define SCNiPTR "li" +#endif // _WIN64 ] + +// The fscanf macros for unsigned integers are: +#define SCNo16 "ho" +#define SCNu16 "hu" +#define SCNx16 "hx" +#define SCNX16 "hX" +#define SCNoLEAST16 "ho" +#define SCNuLEAST16 "hu" +#define SCNxLEAST16 "hx" +#define SCNXLEAST16 "hX" +#define SCNoFAST16 "ho" +#define SCNuFAST16 "hu" +#define SCNxFAST16 "hx" +#define SCNXFAST16 "hX" + +#define SCNo32 "lo" +#define SCNu32 "lu" +#define SCNx32 "lx" +#define SCNX32 "lX" +#define SCNoLEAST32 "lo" +#define SCNuLEAST32 "lu" +#define SCNxLEAST32 "lx" +#define SCNXLEAST32 "lX" +#define SCNoFAST32 "lo" +#define SCNuFAST32 "lu" +#define SCNxFAST32 "lx" +#define SCNXFAST32 "lX" + +#define SCNo64 "I64o" +#define SCNu64 "I64u" +#define SCNx64 "I64x" +#define SCNX64 "I64X" +#define SCNoLEAST64 "I64o" +#define SCNuLEAST64 "I64u" +#define SCNxLEAST64 "I64x" +#define SCNXLEAST64 "I64X" +#define SCNoFAST64 "I64o" +#define SCNuFAST64 "I64u" +#define SCNxFAST64 "I64x" +#define SCNXFAST64 "I64X" + +#define SCNoMAX "I64o" +#define SCNuMAX "I64u" +#define SCNxMAX "I64x" +#define SCNXMAX "I64X" + +#ifdef _WIN64 // [ +# define SCNoPTR "I64o" +# define SCNuPTR "I64u" +# define SCNxPTR "I64x" +# define SCNXPTR "I64X" +#else // _WIN64 ][ +# define SCNoPTR "lo" +# define SCNuPTR "lu" +# define SCNxPTR "lx" +# define SCNXPTR "lX" +#endif // _WIN64 ] + +#endif // __STDC_FORMAT_MACROS ] + +// 7.8.2 Functions for greatest-width integer types + +// 7.8.2.1 The imaxabs function +#define imaxabs _abs64 + +// 7.8.2.2 The imaxdiv function + +// This is modified version of div() function from Microsoft's div.c found +// in %MSVC.NET%\crt\src\div.c +#ifdef STATIC_IMAXDIV // [ +static +#else // STATIC_IMAXDIV ][ +_inline +#endif // STATIC_IMAXDIV ] +imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) +{ + imaxdiv_t result; + + result.quot = numer / denom; + result.rem = numer % denom; + + if (numer < 0 && result.rem > 0) { + // did division wrong; must fix up + ++result.quot; + result.rem -= denom; + } + + return result; +} + +// 7.8.2.3 The strtoimax and strtoumax functions +#define strtoimax _strtoi64 +#define strtoumax _strtoui64 + +// 7.8.2.4 The wcstoimax and wcstoumax functions +#define wcstoimax _wcstoi64 +#define wcstoumax _wcstoui64 + + +#endif // _MSC_INTTYPES_H_ ] diff --git a/extras/stdint.h b/extras/stdint.h index 849d9ab0..9459662d 100644 --- a/extras/stdint.h +++ b/extras/stdint.h @@ -117,9 +117,15 @@ typedef unsigned __int64 uintmax_t; /* 7.18.2.4 Limits of integer types capable of holding object pointers */ +#if defined(_WIN64) || defined(__LP64__) +#define INTPTR_MIN INT64_MIN +#define INTPTR_MAX INT64_MAX +#define UINTPTR_MAX UINT64_MAX +#else #define INTPTR_MIN INT32_MIN #define INTPTR_MAX INT32_MAX #define UINTPTR_MAX UINT32_MAX +#endif /* 7.18.2.5 Limits of greatest-width integer types */ #define INTMAX_MIN INT64_MIN @@ -127,13 +133,24 @@ typedef unsigned __int64 uintmax_t; #define UINTMAX_MAX UINT64_MAX /* 7.18.3 Limits of other integer types */ +#if defined(_WIN64) || defined(__LP64__) +#define PTRDIFF_MIN INT64_MIN +#define PTRDIFF_MAX INT64_MAX +#else #define PTRDIFF_MIN INT32_MIN #define PTRDIFF_MAX INT32_MAX +#endif #define SIG_ATOMIC_MIN INT32_MIN #define SIG_ATOMIC_MAX INT32_MAX +#ifndef SIZE_MAX +#if defined(_WIN64) || defined(__LP64__) +#define SIZE_MAX UINT64_MAX +#else #define SIZE_MAX UINT32_MAX +#endif +#endif #ifndef WCHAR_MIN /* also in wchar.h */ #define WCHAR_MIN 0 diff --git a/input/timecode.c b/input/timecode.c index 26a3fb6e..dfb0dfd0 100644 --- a/input/timecode.c +++ b/input/timecode.c @@ -25,7 +25,6 @@ #include "input.h" #define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "timecode", __VA_ARGS__ ) -#include typedef struct { diff --git a/tools/checkasm.c b/tools/checkasm.c index 6baff45d..16a25825 100644 --- a/tools/checkasm.c +++ b/tools/checkasm.c @@ -26,10 +26,6 @@ *****************************************************************************/ #include -#include -#include -#include - #include "common/common.h" #include "common/cpu.h" @@ -92,7 +88,7 @@ static const char **intra_predict_8x8_names = intra_predict_4x4_names; static inline uint32_t read_time(void) { uint32_t a = 0; -#if defined(__GNUC__) && (ARCH_X86 || ARCH_X86_64) +#if HAVE_X86_INLINE_ASM asm volatile( "rdtsc" :"=a"(a) ::"edx" ); #elif ARCH_PPC asm volatile( "mftb %0" : "=r" (a) ); diff --git a/x264.c b/x264.c index e3bf4a07..2ab7f960 100644 --- a/x264.c +++ b/x264.c @@ -27,13 +27,9 @@ * For more information, contact us at licensing@x264.com. *****************************************************************************/ -#include -#include - #include #define _GNU_SOURCE #include - #include "common/common.h" #include "x264cli.h" #include "input/input.h" @@ -230,10 +226,12 @@ static void print_version_info() printf( "(ffmpegsource %d.%d.%d.%d)\n", FFMS_VERSION >> 24, (FFMS_VERSION & 0xff0000) >> 16, (FFMS_VERSION & 0xff00) >> 8, FFMS_VERSION & 0xff ); #endif printf( "built on " __DATE__ ", " ); -#ifdef __GNUC__ +#ifdef __INTEL_COMPILER + printf( "intel: %.2f (%d)\n", __INTEL_COMPILER / 100.f, __INTEL_COMPILER_BUILD_DATE ); +#elif defined(__GNUC__) printf( "gcc: " __VERSION__ "\n" ); #else - printf( "using a non-gcc compiler\n" ); + printf( "using an unknown compiler\n" ); #endif printf( "configuration: --bit-depth=%d\n", x264_bit_depth ); printf( "x264 license: " ); -- 2.40.0