diff --git a/Makefile b/Makefile index 3ac975d..c9ba8b3 100644 --- a/Makefile +++ b/Makefile @@ -98,11 +98,11 @@ OBJASM = $(ASMSRC:%.asm=%.o) endif ifneq ($(HAVE_GETOPT_LONG),1) -SRCS += extras/getopt.c +SRCCLI += extras/getopt.c endif ifneq ($(SONAME),) -ifeq ($(SYS),MINGW) +ifeq ($(SYS),WINDOWS) SRCSO += x264dll.c endif endif @@ -116,30 +116,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 $@ $+ $(LDFLAGS) $(LDFLAGSCLI) +x264$(EXE): $(OBJCLI) $(LIBX264) + $(LD)$@ $+ $(LDFLAGS) $(LDFLAGSCLI) -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 @@ -168,36 +168,31 @@ 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 *.dpi* 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 *.dpi* distclean: clean - rm -f config.mak config.h config.log x264.pc + rm -f config.mak config.h config.log x264.pc x264.def rm -rf test/ install: x264$(EXE) $(SONAME) install -d $(DESTDIR)$(bindir) $(DESTDIR)$(includedir) install -d $(DESTDIR)$(libdir) $(DESTDIR)$(libdir)/pkgconfig install -m 644 x264.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 -sf $(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)) diff --git a/common/common.c b/common/common.c index 6d1d7f0..4d62b14 100644 --- a/common/common.c +++ b/common/common.c @@ -770,8 +770,8 @@ int x264_nal_encode( uint8_t *dst, int b_annexb, x264_nal_t *nal ) void *x264_malloc( int i_size ) { uint8_t *align_buf = NULL; -#ifdef SYS_MACOSX - /* Mac OS X always returns 16 bytes aligned memory */ +#if defined(SYS_MACOSX) || (defined(SYS_WINDOWS) && defined(ARCH_X86_64)) + /* Mac OS X and Win x64 always return 16 byte aligned memory */ align_buf = malloc( i_size ); #elif defined( HAVE_MALLOC_H ) align_buf = memalign( 16, i_size ); @@ -797,7 +797,7 @@ void x264_free( void *p ) { if( p ) { -#if defined( HAVE_MALLOC_H ) || defined( SYS_MACOSX ) +#if defined(HAVE_MALLOC_H) || defined(SYS_MACOSX) || (defined(SYS_WINDOWS) && defined(ARCH_X86_64)) free( p ); #else free( *( ( ( void **) p ) - 1 ) ); diff --git a/common/common.h b/common/common.h index 950f48f..2e50f0f 100644 --- a/common/common.h +++ b/common/common.h @@ -77,6 +77,7 @@ do {\ #include #include #include +#include /* Unions for type-punning. * Mn: load or store n bits, aligned, native-endian diff --git a/common/cpu.c b/common/cpu.c index 9f2d5a6..26f7cca 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -340,6 +340,9 @@ int x264_cpu_num_processors( void ) #elif defined(_WIN32) return pthread_num_processors_np(); +#elif defined(__CYGWIN__) + return sysconf( _SC_NPROCESSORS_ONLN ); + #elif defined(SYS_LINUX) unsigned int bit; int np; diff --git a/common/mc.c b/common/mc.c index ac740cf..fddb034 100644 --- a/common/mc.c +++ b/common/mc.c @@ -429,7 +429,7 @@ static void frame_init_lowres_core( uint8_t *src0, uint8_t *dst0, uint8_t *dsth, } } -#if defined(__GNUC__) && (defined(ARCH_X86) || defined(ARCH_X86_64)) +#ifdef HAVE_X86_INLINE_ASM // gcc isn't smart enough to use the "idiv" instruction static ALWAYS_INLINE int32_t div_64_32(int64_t x, int32_t y) { int32_t quotient, remainder; diff --git a/common/mdate.c b/common/mdate.c index 7a1c8a5..45f9712 100644 --- a/common/mdate.c +++ b/common/mdate.c @@ -18,11 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ -#ifndef __MINGW32__ -#include -#else +#ifdef _WIN32 #include #include +#else +#include #endif #include @@ -31,14 +31,13 @@ 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 +#ifdef _WIN32 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 7f680ed..e51d39e 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -46,6 +46,25 @@ #include // _O_BINARY #endif +#ifdef __ICL +#define asm __asm__ +#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 +#endif + +#undef HAVE_X86_INLINE_ASM +#if (defined(__GNUC__) || defined(__INTEL_COMPILER)) && (defined(ARCH_X86) || defined(ARCH_X86_64)) +#define HAVE_X86_INLINE_ASM +#endif + #if (defined(SYS_OPENBSD) && !defined(isfinite)) || defined(SYS_SunOS) #define isfinite finite #endif @@ -56,7 +75,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 ) @@ -92,9 +115,14 @@ #define MAY_ALIAS __attribute__((may_alias)) #define x264_constant_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 #endif @@ -168,7 +196,7 @@ static inline int x264_pthread_create( x264_pthread_t *t, void *a, void *(*f)(vo #define asm __asm__ #if !defined(_WIN64) && !defined(__LP64__) -#if defined(__INTEL_COMPILER) +#ifdef __ICL #define BROKEN_STACK_ALIGNMENT /* define it if stack is not mod16 */ #endif #endif @@ -179,7 +207,7 @@ static inline int x264_pthread_create( x264_pthread_t *t, void *a, void *(*f)(vo #define endian_fix32(x) (x) #define endian_fix16(x) (x) #else -#if defined(__GNUC__) && defined(HAVE_MMX) +#ifdef HAVE_X86_INLINE_ASM static ALWAYS_INLINE uint32_t endian_fix32( uint32_t x ) { asm("bswap %0":"+r"(x)); @@ -197,7 +225,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__) && defined(ARCH_X86_64) +#if defined(HAVE_X86_INLINE_ASM) && defined(ARCH_X86_64) static ALWAYS_INLINE uint64_t endian_fix64( uint64_t x ) { asm("bswap %0":"+r"(x)); @@ -236,7 +264,7 @@ static int ALWAYS_INLINE x264_clz( uint32_t x ) #endif #ifdef USE_REAL_PTHREAD -#ifdef SYS_MINGW +#ifdef _WIN32 #define x264_lower_thread_priority(p)\ {\ x264_pthread_t handle = pthread_self();\ diff --git a/common/x86/predict-c.c b/common/x86/predict-c.c index 602ddcd..13636b0 100644 --- a/common/x86/predict-c.c +++ b/common/x86/predict-c.c @@ -110,26 +110,27 @@ PREDICT_16x16_P( mmxext ) #endif PREDICT_16x16_P( sse2 ) -#ifdef __GNUC__ +#ifdef HAVE_X86_INLINE_ASM static void predict_16x16_p_ssse3( uint8_t *src ) { int a, b, c, i00; int H, V; asm ( "movq %1, %%mm1 \n" - "movq 8+%1, %%mm0 \n" - "palignr $7, -8+%1, %%mm1 \n" - "pmaddubsw %2, %%mm0 \n" - "pmaddubsw %3, %%mm1 \n" + "movq %2, %%mm0 \n" + "palignr $7, %3, %%mm1 \n" + "pmaddubsw %4, %%mm0 \n" + "pmaddubsw %5, %%mm1 \n" "paddw %%mm1, %%mm0 \n" "pshufw $14, %%mm0, %%mm1 \n" "paddw %%mm1, %%mm0 \n" "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_12345678), "m"(*pb_m87654321) + :"m"(src[-FDEC_STRIDE]), "m"(src[8-FDEC_STRIDE]), "m"(src[-8-FDEC_STRIDE]), + "m"(*pb_12345678), "m"(*pb_m87654321) ); V = 8 * ( src[15*FDEC_STRIDE-1] - src[-1*FDEC_STRIDE-1] ) + 7 * ( src[14*FDEC_STRIDE-1] - src[ 0*FDEC_STRIDE-1] ) @@ -170,7 +171,7 @@ PREDICT_8x8_P( mmxext ) #endif PREDICT_8x8_P( sse2 ) -#ifdef __GNUC__ +#ifdef HAVE_X86_INLINE_ASM static void predict_8x8c_p_ssse3( uint8_t *src ) { int a, b, c, i00; @@ -183,7 +184,7 @@ static void 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) ); @@ -394,7 +395,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] = predict_16x16_h_ssse3; -#ifdef __GNUC__ +#ifdef HAVE_X86_INLINE_ASM pf[I_PRED_16x16_P] = predict_16x16_p_ssse3; #endif } @@ -421,7 +422,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] = predict_8x8c_h_ssse3; -#ifdef __GNUC__ +#ifdef HAVE_X86_INLINE_ASM pf[I_PRED_CHROMA_P] = predict_8x8c_p_ssse3; #endif } diff --git a/common/x86/util.h b/common/x86/util.h index efc700a..31b2809 100644 --- a/common/x86/util.h +++ b/common/x86/util.h @@ -24,7 +24,7 @@ #ifndef X264_X86_UTIL_H #define X264_X86_UTIL_H -#ifdef __GNUC__ +#ifdef HAVE_X86_INLINE_ASM #define x264_median_mv x264_median_mv_mmxext static inline void x264_median_mv_mmxext( int16_t *dst, int16_t *a, int16_t *b, int16_t *c ) { diff --git a/configure b/configure index b254383..7da1057 100755 --- a/configure +++ b/configure @@ -23,6 +23,7 @@ echo " --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS" echo " --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS" echo " --host=HOST build programs to run on HOST" echo " --cross-prefix=PREFIX use PREFIX for compilation tools" +echo " --intel use intel's compiler for compilation" echo "" exit 1 fi @@ -43,6 +44,38 @@ log_msg() { echo "$1" >> config.log } +intel_cflags() { + for arg in $*; do + [ $arg = -ffast-math ] && arg= + [[ "$arg" = -falign-loops* ]] && arg= + if [ $compiler = ICL ]; then + [ "$arg" = -Wall ] && arg=-W0 + [ "$arg" = -g ] && arg=-Z7 + [ "$arg" = -fomit-frame-pointer ] && arg= + [ "$arg" = -s ] && arg= + else + [ "$arg" = -Wall ] && arg=-w0 + fi + [ $SYS = MACOSX -a \( "$arg" = -mia32 -o "$arg" = -msse -o "$arg" = -msse2 \) ] && arg= + [ -n "$arg" ] && echo -n "$arg " + done + [ $compiler = ICC -a $ARCH = X86 ] && echo -n "-falign-stack=assume-16-byte " +} + +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 = -s ] && 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 @@ -60,7 +93,13 @@ 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 $LDFLAGS $LDFLAGSCLI $2 -o conftest >conftest.log 2>&1; then + if [ $compiler = ICL ]; then + cc_cmd="$CC -Feconftest conftest.c $CFLAGS $2 -link $(icl_ldflags $LDFLAGS $LDFLAGSCLI $2)" + else + cc_cmd="$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2 -o conftest" + fi + + if $cc_cmd >conftest.log 2>&1; then res=$? log_ok else @@ -68,7 +107,7 @@ cc_check() { log_fail log_msg "Failed commandline was:" log_msg "--------------------------------------------------" - log_msg "$CC conftest.c $CFLAGS $LDFLAGS $LDFLAGSCLI $2" + log_msg "$cc_cmd" cat conftest.log >> config.log log_msg "--------------------------------------------------" fi @@ -103,7 +142,7 @@ die() { exit 1 } -rm -f config.h config.mak config.log x264.pc conftest* +rm -f config.h config.mak config.log x264.pc x264.def conftest* prefix='/usr/local' exec_prefix='${prefix}' @@ -123,6 +162,7 @@ gprof="no" pic="no" vis="no" shared="no" +compiler="GNU" CFLAGS="$CFLAGS -Wall -I." LDFLAGS="$LDFLAGS" @@ -223,6 +263,9 @@ for opt do --cross-prefix=*) cross_prefix="${opt#--cross-prefix=}" ;; + --intel) + compiler="INTEL" + ;; *) echo "Unknown option $opt, ignored" ;; @@ -246,6 +289,24 @@ host="${host#*-}" host_vendor="${host%%-*}" host_os="${host#*-}" +if [ $compiler = INTEL ]; then + if [[ $host_os = mingw* ]]; then + ARCHPRE="-arch:" + CC=icl + 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 + else + AR="xiar" + ARCHPRE="-m" + [[ "$CC" != icc* ]] && CC=icc + compiler=ICC + QPRE="-" + fi +fi + case $host_os in beos*) SYS="BEOS" @@ -283,16 +344,14 @@ case $host_os in LDFLAGS="$LDFLAGS -lm" ;; cygwin*) - SYS="MINGW" + SYS="WINDOWS" + # if _WIN32 is not defined, compiler is targeting cygwin instead of mingw + `$CC $CFLAGS -dM -E - < NUL | grep -q _WIN32` || define HAVE_MALLOC_H EXE=".exe" DEVNULL="NUL" - if cc_check "" -mno-cygwin; then - CFLAGS="$CFLAGS -mno-cygwin" - LDFLAGS="$LDFLAGS -mno-cygwin" - fi ;; mingw*) - SYS="MINGW" + SYS="WINDOWS" EXE=".exe" DEVNULL="NUL" ;; @@ -312,15 +371,25 @@ case $host_cpu in ARCH="X86" AS="yasm" ASFLAGS="$ASFLAGS -O2" - if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then - CFLAGS="$CFLAGS -march=i686" - fi - if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then - CFLAGS="$CFLAGS -mfpmath=sse -msse" + if [ $compiler = GNU ]; then + if [[ "$asm" == yes && "$CFLAGS" != *-march* ]]; then + CFLAGS="$CFLAGS -march=i686" + fi + if [[ "$asm" == yes && "$CFLAGS" != *-mfpmath* ]]; then + CFLAGS="$CFLAGS -mfpmath=sse -msse" + fi + else + if ! echo $CFLAGS | grep -Eiq "(${ARCHPRE}ia32|${ARCHPRE}sse |${ARCHPRE}sse2|${ARCHPRE}sse3|${ARCHPRE}ssse3|${ARCHPRE}sse4.1)" && [[ "$CFLAGS" != *${QPRE}x* ]]; then + if [ $asm = yes ]; then + CFLAGS="$CFLAGS ${ARCHPRE}sse" + else + CFLAGS="$CFLAGS ${ARCHPRE}ia32" + fi + fi fi if [ "$SYS" = MACOSX ]; then ASFLAGS="$ASFLAGS -f macho -DPREFIX" - elif [ "$SYS" = MINGW ]; then + elif [ "$SYS" = WINDOWS ]; then ASFLAGS="$ASFLAGS -f win32 -DPREFIX" else ASFLAGS="$ASFLAGS -f elf" @@ -335,8 +404,9 @@ case $host_cpu in CFLAGS="$CFLAGS -arch x86_64" LDFLAGS="$LDFLAGS -arch x86_64" fi - elif [ "$SYS" = MINGW ]; then - ASFLAGS="$ASFLAGS -f win32 -m amd64 -DPREFIX" + elif [ "$SYS" = WINDOWS ]; then + ASFLAGS="$ASFLAGS -f win32 -m amd64" + [ $compiler = GNU ] && ASFLAGS="$ASFLAGS -DPREFIX" else ASFLAGS="$ASFLAGS -f elf -m amd64" fi @@ -394,15 +464,18 @@ 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" \) ] ; then pic="yes" fi +[ $SYS = WINDOWS ] && pic=no if [ $asm = yes -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then if ! as_check "lzcnt eax, eax" ; then @@ -444,12 +517,14 @@ fi define ARCH_$ARCH define SYS_$SYS -echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c -$CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed" -if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then - define WORDS_BIGENDIAN -elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then - die "endian test failed" +if [ $compiler != ICL ]; then + echo "int i = 0x42494745; double f = 0x1.0656e6469616ep+102;" > conftest.c + $CC $CFLAGS conftest.c -c -o conftest.o 2>$DEVNULL || die "endian test failed" + if grep -q BIGE conftest.o && grep -q FPendian conftest.o ; then + define WORDS_BIGENDIAN + elif !(grep -q EGIB conftest.o && grep -q naidnePF conftest.o) ; then + die "endian test failed" + fi fi # autodetect options that weren't forced nor disabled @@ -461,7 +536,7 @@ if test "$pthread" = "auto" ; then BEOS) pthread="yes" ;; - MINGW) + WINDOWS) if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then pthread="yes" libpthread="-lpthread" @@ -511,7 +586,7 @@ if [ "$lavf_input" = "auto" ] ; then if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" && \ cc_check libswscale/swscale.h "$LAVF_CFLAGS $LAVF_LIBS" ; then # avcodec_decode_video2 is currently the most recently added function that we use; it was added in r18351 - if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2( NULL, NULL, NULL, NULL );" ; then + if cc_check libavformat/avformat.h "$LAVF_CFLAGS $LAVF_LIBS" "avcodec_decode_video2(0,0,0,0);" ; then lavf_input="yes" define LAVF_INPUT else @@ -537,6 +612,11 @@ if [ "$ffms_input" = "auto" ] ; then if cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS" "FFMS_DestroyVideoSource(0);" ; then ffms_input="yes" + # windows shared libs can be created from static libs so -lFFMS2 could actually have ffmpeg libs within it + if [ $SYS = WINDOWS -a $lavf_input = no ] && cc_check libavformat/avformat.h "$FFMS2_CFLAGS $FFMS2_LIBS" "avcodec_decode_video2(0,0,0,0);" ; then + lavf_input="yes" + define LAVF_INPUT + fi elif cc_check ffms.h "$FFMS2_CFLAGS $FFMS2_LIBS -lstdc++ $LAVF_LIBS" "FFMS_DestroyVideoSource(0);" ; then ffms_input="yes" FFMS2_LIBS="$FFMS2_LIBS -lstdc++ $LAVF_LIBS" @@ -564,7 +644,7 @@ elif [ "$lavf_input" = "yes" ]; then fi MP4_LDFLAGS="-lgpac_static" -if [ $SYS = MINGW ]; then +if [ $SYS = WINDOWS ]; then MP4_LDFLAGS="$MP4_LDFLAGS -lwinmm" fi if [ "$mp4_output" = "auto" ] ; then @@ -578,11 +658,11 @@ fi if [ "$avs_input" = "auto" ] ; then avs_input=no - if [ $SYS = MINGW ] && cc_check avisynth_c.h ; then + if [ $SYS = WINDOWS ] && cc_check avisynth_c.h ; then avs_input="yes" define AVS_INPUT define HAVE_AVISYNTH_C_H - elif [ $SYS = MINGW ] && cc_check extras/avisynth_c.h ; then + elif [ $SYS = WINDOWS ] && cc_check extras/avisynth_c.h ; then avs_input="yes" define AVS_INPUT fi @@ -610,7 +690,10 @@ else CFLAGS="-O3 -ffast-math $CFLAGS" fi -if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then +if cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then + define fseek _fseeki64 + define ftell _ftelli64 +elif cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then define fseek fseeko define ftell ftello elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then @@ -620,6 +703,43 @@ fi rm -f conftest* +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)" + 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 + # generate config files cat > config.mak << EOF @@ -632,37 +752,58 @@ 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 AS=$AS ASFLAGS=$ASFLAGS EXE=$EXE VIS=$vis 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 +[ -n "$RANLIB" ] && echo "RANLIB=$RANLIB" >> config.mak +[ -n "$STRIP" ] && echo "STRIP=$STRIP" >> config.mak + +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 + 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/open/open_$API/" >> 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 666596b..678a96a 100644 --- a/encoder/analyse.c +++ b/encoder/analyse.c @@ -23,8 +23,9 @@ *****************************************************************************/ #define _ISOC99_SOURCE -#include +#ifndef __ICL #include +#endif #include "common/common.h" #include "common/cpu.h" diff --git a/encoder/encoder.c b/encoder/encoder.c index d873cd0..9470631 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -22,8 +22,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ -#include - #include "common/common.h" #include "common/cpu.h" diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index 63b3be6..7214a1c 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -26,7 +26,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 "common/cpu.h" diff --git a/encoder/set.c b/encoder/set.c index f79919b..497a6c8 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -21,8 +21,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ -#include - #include "common/common.h" #include "set.h" diff --git a/encoder/slicetype.c b/encoder/slicetype.c index 057f6a6..730c99b 100644 --- a/encoder/slicetype.c +++ b/encoder/slicetype.c @@ -22,8 +22,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ -#include - #include "common/common.h" #include "common/cpu.h" #include "macroblock.h" diff --git a/extras/inttypes.h b/extras/inttypes.h new file mode 100644 index 0000000..c957aa5 --- /dev/null +++ b/extras/inttypes.h @@ -0,0 +1,265 @@ +// 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 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 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/tools/checkasm.c b/tools/checkasm.c index 0bedc5b..4f22fdc 100644 --- a/tools/checkasm.c +++ b/tools/checkasm.c @@ -23,9 +23,6 @@ *****************************************************************************/ #include -#include -#include -#include #include "common/common.h" #include "common/cpu.h" diff --git a/x264.c b/x264.c index 58bc1f4..1c876ab 100644 --- a/x264.c +++ b/x264.c @@ -23,16 +23,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ -#include -#include - #include #define _GNU_SOURCE #include #include "common/common.h" #include "common/cpu.h" -#include "x264.h" #include "muxers.h" #ifdef _WIN32 @@ -1065,10 +1061,12 @@ psy_failure: printf( "x264 0.%d.X\n", X264_BUILD ); #endif printf( "built on " __DATE__ ", " ); -#ifdef __GNUC__ +#ifdef __INTEL_COMPILER + printf( "intel: %d (%d)\n", __INTEL_COMPILER, __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 exit(0); case OPT_FRAMES: