ports/128042: [PATCH] multimedia/xvid: use assembly for better performance

Carlos Santos unixmania at gmail.com
Mon Oct 13 04:30:02 UTC 2008


>Number:         128042
>Category:       ports
>Synopsis:       [PATCH] multimedia/xvid: use assembly for better performance
>Confidential:   no
>Severity:       critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 13 04:30:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     Carlos Santos
>Release:        8.0-CURRENT
>Organization:
N.A.
>Environment:
FreeBSD poacasantos1 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Sat Oct 11 19:09:09 BRT 2008     root at poacasantos1:/local/FreeBSD/obj-current/local/FreeBSD/src-current/sys/GENERIC  amd64

>Description:
>From a message set by Michel Talon to freebsd-ports on Oct 9 2008:

"Trying to encode with mencoder and the xvid codec, I discovered that it is awfully slow (around 3 frames/s on my P4 machine). So I played a little bit with the options in the Makefile without any success. Finally I understood that the cause was that the build system requires nasm, but doesn't use it! There are several assembly files in the xvid codec which are not used due to that. The solution i have found by looking at the configure script is to install the yasm port. Then the build system picks the yasm dependency and compiles the assembly files, which enables SSE instructions. The net result is that, without any other tweak, i now encode the same stuff at 11 frames/s.

So to be short, multimedia/xvid should require a dependency on yasm."

Sean Winn noted that the problem comes because the configure script tries to use the -r option which yasm has but not nasm. So the xvid people had really yasm in view when doing their work. Fixing the configure script should be done upstream, but it seems that the xvid project is somewhat asleep, so better use yasm in the Makefile on which there is control.

I (Casantos) gave it a try and found that configure needs some help on AMD64 because it expects the architecture name to be "x86_64", not "amd64".

>How-To-Repeat:
Build multimedia/xvid version 1.1.3_1.
>Fix:
The attached patch fixes the build in order to use yasm. According to Michel Talon, "the performance improvement obtained by using SSE instructions in the assembly files is astounding. I could not beleive what i was seeing, basically an x 4 improvement, that is the code perfectly parallelizes the computations on the 128 bits registers."

The patch also eliminates the pkg-plist file, using PLIST_FILES instead, since the port installs only three files and one symbolic link.

Patch attached with submission follows:

diff -durN xvid.orig/Makefile xvid/Makefile
--- xvid.orig/Makefile	2008-09-08 00:02:28.000000000 -0300
+++ xvid/Makefile	2008-10-13 00:43:21.000000000 -0300
@@ -7,7 +7,7 @@
 
 PORTNAME=	xvid
 PORTVERSION=	1.1.3
-PORTEPOCH=	1
+PORTEPOCH=	2
 CATEGORIES=	multimedia
 MASTER_SITES=	http://downloads.xvid.org/downloads/
 DISTNAME=	${PORTNAME}core-${PORTVERSION}
@@ -15,17 +15,27 @@
 MAINTAINER=	ports at FreeBSD.org
 COMMENT=	An opensource MPEG-4 codec, based on OpenDivx
 
-BUILD_DEPENDS=	${LOCALBASE}/bin/nasm:${PORTSDIR}/devel/nasm
-
 GNU_CONFIGURE=	yes
 USE_LDCONFIG=	yes
 
-WRKSRC=			${WRKDIR}/${DISTNAME}/build/generic
+PLIST_FILES=	include/xvid.h \
+		lib/libxvidcore.a \
+		lib/libxvidcore.so \
+		lib/libxvidcore.so.4
+
+WRKSRC=		${WRKDIR}/${DISTNAME}/build/generic
 
 OPTIONS=	OPTIMIZED_CFLAGS "Use XviD's default optimizations" off
 
 .include <bsd.port.pre.mk>
 
+.if ${ARCH} == "amd64"
+CONFIGURE_TARGET=	x86_64-portbld-freebsd${OSREL}
+.endif
+.if ${ARCH} == "amd64" || ${ARCH} == "i386"
+BUILD_DEPENDS+=	yasm:${PORTSDIR}/devel/yasm
+.endif
+
 .if defined(WITH_OPTIMIZED_CFLAGS)
 CFLAGS=		# let xvid's build system decide about those
 .endif
diff -durN xvid.orig/pkg-plist xvid/pkg-plist
--- xvid.orig/pkg-plist	2004-06-11 18:48:50.000000000 -0300
+++ xvid/pkg-plist	1969-12-31 21:00:00.000000000 -0300
@@ -1,4 +0,0 @@
-include/xvid.h
-lib/libxvidcore.a
-lib/libxvidcore.so
-lib/libxvidcore.so.4


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list