Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
LAME -> ASM optimisations
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
Cyker
Veteran
Veteran


Joined: 15 Jun 2006
Posts: 1746

PostPosted: Thu Jan 04, 2007 12:38 am    Post subject: LAME -> ASM optimisations Reply with quote

I think the ebuild for lame is slightly borked - I noticed it doesn't specify any configure flags to make lame compile with ASM (MMX, 3DNow, SSE etc.) optimisations, and there aren't any USE flags you can specify to tell it to (I have all the standard ones already set, mmx, sse etc., but lame only accepts gtk, mp3rtp and debug!).

When you emerge it, the configure part says this:
Quote:
checking for nasm... /usr/bin/nasm
checking for assembler routines for this processor type... no
checking for additional optimizations... no


And when it's finished, the resulting lame indeed doesn't have any of the custom nasm assembly optimisations - Running lame on a file gives:
Quote:
LAME 3.97 32bits (http://www.mp3dev.org/)
Using polyphase lowpass filter, transition band: 16452 Hz - 17032 Hz
...



If I grab the sources manually, I can compile it like:

./configure --enable-nasm --enable-decode-layer1 --enable-vorbis [--enable-expopt]
configure responds with:
Quote:
checking for nasm... /usr/bin/nasm
checking for assembler routines for this processor type... yes
checking for additional optimizations... no [yes with --enable-expopt]

...and running lame on a file gives the reassuring:
Quote:
LAME 3.97 32bits (http://www.mp3dev.org/)
CPU features: MMX (ASM used), 3DNow! (ASM used), SSE, SSE2
Using polyphase lowpass filter, transition band: 16452 Hz - 17032 Hz
...


Right, that's all the pre-amble out the way...
Hopefully a few people are still reading ;P

My question, then, is:
How can I work around this?
There doesn't appear to be any well-documented way of passing extra --configure flags to an emerge, and all the docs about ebuilds are making me even more confused than I was!

And who can I report this problem to to get it fixed? (Or submit a fix, assuming I ever get a handle on the ebuild things...)

Thanks in advance!
Back to top
View user's profile Send private message
Cyker
Veteran
Veteran


Joined: 15 Jun 2006
Posts: 1746

PostPosted: Thu Jan 04, 2007 1:48 am    Post subject: Reply with quote

Found reason why ASM optimisations were disabled - Was because of the bug report at:
https://bugs.gentoo.org/show_bug.cgi?id=93279

Don't understand what the report is saying (Text Relocations? Pic Aware?!) however so I can't comment...

Didn't find a solution, but found a (convoluted) workaround.
Created a hacked "lame-3.97.ebuild" with help from these two guides:

http://gentoo-wiki.com/HOWTO_Create_an_Updated_Ebuild
http://devmanual.gentoo.org/quickstart/index.html

... and added "--enable-nasm --enable-decode-layer1 --enable-vorbis" to the "econf" line.

Finished off with "ebuild lame-3.97.ebuild digest" to authorise the ebuild to portage and then emerged it...

Got some warnings about "Runtime Text Relocations" and "Executable Stacks", but at least it works now...

Without the ASM, it took 4 minutes to encode a 43MB WAV using "lame --verbose -m j -q 0 -V 0" and had some glitches (Missed some frames, 2s worth, and VBR time not reported correctly; Off by 2s!)
With the ASM it took 40 seconds (same command) with no apparently problems...

Definitely something weird is going on with LAME...
Back to top
View user's profile Send private message
ryszardzonk
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 225
Location: Rzeszów, POLAND

PostPosted: Thu Jan 04, 2007 11:48 am    Post subject: Reply with quote

Quote:
Found reason why ASM optimizations were disabled - Was because of the bug report at:
https://bugs.gentoo.org/show_bug.cgi?id=93279

It is great that you found a culprit of your problem. However I do not think writing your findings in there would change anything as it is highly unlikely options which introduce mentioned problems could be introduced back. They are disabled for the reason and it is stability and/or portability to other than x86 architectures. Issue you found of optimized app producing better result probably should be filled upsteram just like issues regarding Tex-relocations and such.
Quote:

Didn't find a solution, but found a (convoluted) workaround.
Created a hacked "lame-3.97.ebuild" with help from these two guides:

http://gentoo-wiki.com/HOWTO_Create_an_Updated_Ebuild
http://devmanual.gentoo.org/quickstart/index.html

Nice :)
Quote:

... and added "--enable-nasm --enable-decode-layer1 --enable-vorbis" to the "econf" line.
[/code]

You really don't need --enable-decode-layer1 in there as this is what people used to encode their music in the time of Noe or Exodus ;) Layer3 used by default superseded it and layer2.
I do believe that using --enable-vorbis makes any difference in there either. You can check it by doing
Code:
ebuild lame-3.97.ebuild unpack
and then manually running where program got unpacked
Code:
./configure --help |grep vorbis
to see that it is not among the options

Quote:

Without the ASM, it took 4 minutes to encode a 43MB WAV using "lame --verbose -m j -q 0 -V 0" and had some glitches (Missed some frames, 2s worth, and VBR time not reported correctly; Off by 2s!)
With the ASM it took 40 seconds (same command) with no apparently problems...

It is something like 5 years since I encoded or downloaded a mp3 file (long live internet radio) and probably would not use this information in the foreseeable future, but sure it says a lot about actual testing of the apps we use...
Stability of an app should not only measured by its probability to segfault

Finally what someone may make use of
Code:
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header:                                                                                                   

WANT_AUTOMAKE="latest"
WANT_AUTOCONF="latest"

inherit flag-o-matic toolchain-funcs eutils autotools

DESCRIPTION="LAME Ain't an MP3 Encoder"
HOMEPAGE="http://lame.sourceforge.net"
SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"

LICENSE="LGPL-2.1"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc-macos ~ppc64 ~sh ~sparc ~x86 ~x86-fbsd"
IUSE="gtk debug mp3rtp encode optimize fullyoptimize"

RDEPEND=">=sys-libs/ncurses-5.2
        gtk? ( =x11-libs/gtk+-1.2* )"
DEPEND="${RDEPEND}"

pkg_setup() {
        if use optimize; then
                echo ""
                einfo "Using \"optimize\" USE flag enables extra MMX and  SSE optimalitazions."
                ewarn " This however is not supported by Gentoo in this particular ebuild"
                ewarn " as this creates problems as \"Runtime Text Relocations\" and"
                ewarn " \"Executable Stacks\" which may or may not be an issue for You."
                einfo " If You want to write an bug report about it to the bugzilla"
                einfo " then first emerge this package without this option."
                echo ""
        fi                                                                                                   
        if use fullyoptimize; then
                echo ""
                einfo "Using \"fullyoptimize\" USE flag enables code that "
                einfo " is highly experimental."
                ewarn " Do not even think of filling bug report while using it!"
                echo ""
        fi
}

src_unpack() {
        unpack ${A}
        cd "${S}"

        # The frontened tries to link staticly, but we prefer shared libs
        epatch "${FILESDIR}"/${PN}-3.96.1-shared-frontend.patch

        # If ccc (alpha compiler) is installed on the system, the default
        # configure is broken, fix it to respect CC.  This is only
        # directly broken for ARCH=alpha but would affect anybody with a
        # ccc binary in their PATH.  Bug #41908  (26 Jul 2004 agriffis)
        epatch "${FILESDIR}"/${PN}-3.96-ccc.patch

        # Make sure -lm is linked in the library to fix other programs linking to
        # this while using --as-needed
        epatch "${FILESDIR}"/${PN}-3.96.1-asneeded.patch

        AT_M4DIR="${S}" eautoreconf || die
        epunt_cxx # embedded bug #74498
}

src_compile() {
        # take out -fomit-frame-pointer from CFLAGS if k6-2
        is-flag "-march=k6-3" && filter-flags "-fomit-frame-pointer"
        is-flag "-march=k6-2" && filter-flags "-fomit-frame-pointer"
        is-flag "-march=k6" && filter-flags "-fomit-frame-pointer"

        [ "`gcc-fullversion`" == "3.3.2" ] && replace-flags -march=2.0 -march=1.0

        # The user sets compiler optimizations... But if you'd like
        # lame to choose it's own... uncomment one of these (experiMENTAL)
        if use fullyoptimize; then
                myconf="${myconf} --enable-expopt=full"
        fi
        # myconf="${myconf} --enable-expopt=norm \

        econf \
                --enable-shared \
                $(use_enable debug debug norm) \
                $(use_enable gtk mp3x) \
                $(use_enable mp3rtp mp3rtp) \
                $(use_enable encode decoder) \
                $(use_enable encode frontend) \
                $(use_enable optimize nasm) \
                ${myconf} || die "econf failed"

        emake || die "emake failed"
}

src_install() {
        make DESTDIR="${D}" pkghtmldir="/usr/share/doc/${PF}/html" install || die

        dodoc API ChangeLog HACKING README* STYLEGUIDE TODO USAGE
        dohtml misc/lameGUI.html Dll/LameDLLInterface.htm

        dobin "${S}"/misc/mlame || die
}

pkg_postinst(){
        if use mp3rtp ; then
            ewarn "Warning, support for the encode-to-RTP program, 'mp3rtp'"
            ewarn "is broken as of August 2001."
            ewarn " "
        fi
}

_________________
Sky is not the limit...
Back to top
View user's profile Send private message
TenPin
Guru
Guru


Joined: 26 Aug 2002
Posts: 500
Location: Kansas City

PostPosted: Thu Jan 04, 2007 6:49 pm    Post subject: Reply with quote

If I add the line to the 3.97 ebuild to enable nasm and optimisations then I get the following build error:

Code:
echo '# Generated by ltmain.sh - GNU libtool 1.5 (1.1220 2003/04/05 19:32:58)' >choose_table.lo
make[3]: *** [cpu_feat.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
echo '# Generated by ltmain.sh - GNU libtool 1.5 (1.1220 2003/04/05 19:32:58)' >fft3dn.lo
echo "pic_object='.libs/choose_table.o'" >>choose_table.lo
echo "pic_object='.libs/fft3dn.o'" >>fft3dn.lo
echo "non_pic_object='choose_table.o'" >>choose_table.lo
echo "non_pic_object='fft3dn.o'" >>fft3dn.lo
/usr/bin/nasm -f elf -i ../../libmp3lame/i386/ fft3dn.nas -o .libs/fft3dn.o -l fft3dn.lo.lst
/usr/bin/nasm -f elf -i ../../libmp3lame/i386/ choose_table.nas -o .libs/choose_table.o -l choose_table.lo.lst
make[3]: Leaving directory `/var/tmp/portage/lame-3.97/work/lame-3.97/libmp3lame/i386'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/var/tmp/portage/lame-3.97/work/lame-3.97/libmp3lame'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/tmp/portage/lame-3.97/work/lame-3.97'
make: *** [all] Error 2

!!! ERROR: media-sound/lame-3.97 failed.
Call stack:
  ebuild.sh, line 1546:   Called dyn_compile
  ebuild.sh, line 937:   Called src_compile
  lame-3.97.ebuild, line 65:   Called die

_________________
For since in the wisdom of God the world by its wisdom did not know God, God was pleased to save those who believe by the foolishness of preaching.
Back to top
View user's profile Send private message
Cyker
Veteran
Veteran


Joined: 15 Jun 2006
Posts: 1746

PostPosted: Thu Jan 04, 2007 7:05 pm    Post subject: Reply with quote

Mmm, don't know... might be some dependency that lame requires that isn't on the system - I didn't update the dependencies in the ebuild when I hacked it, just added that line.

I do know you'll need nasm and, if you did the other bits too, mpg123 and libvorbis.

What's the system you're trying to compile it on?
I also suspect that the ASM stuff won't work on anything other than x86 - I know other archs have stuff like Altivec, but I don't know if LAME has optimisations for that, and that includes AMD64 as well as Sparc, PPC etc...
Back to top
View user's profile Send private message
nixnut
Bodhisattva
Bodhisattva


Joined: 09 Apr 2004
Posts: 10974
Location: the dutch mountains

PostPosted: Thu Jan 04, 2007 8:36 pm    Post subject: Reply with quote

Moved from Multimedia to Unsupported Software.
Some unsupported messing about with lame :wink:
So moved here.
_________________
Please add [solved] to the initial post's subject line if you feel your problem is resolved. Help answer the unanswered

talk is cheap. supply exceeds demand
Back to top
View user's profile Send private message
ryszardzonk
Apprentice
Apprentice


Joined: 18 Dec 2003
Posts: 225
Location: Rzeszów, POLAND

PostPosted: Thu Jan 04, 2007 11:25 pm    Post subject: Reply with quote

TenPin wrote:
If I add the line to the 3.97 ebuild to enable nasm and optimisations then I get the following build error:

Code:
echo '# Generated by ltmain.sh - GNU libtool 1.5 (1.1220 2003/04/05 19:32:58)' >choose_table.lo
make[3]: *** [cpu_feat.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
echo '# Generated by ltmain.sh - GNU libtool 1.5 (1.1220 2003/04/05 19:32:58)' >fft3dn.lo
echo "pic_object='.libs/choose_table.o'" >>choose_table.lo
echo "pic_object='.libs/fft3dn.o'" >>fft3dn.lo
echo "non_pic_object='choose_table.o'" >>choose_table.lo
echo "non_pic_object='fft3dn.o'" >>fft3dn.lo
/usr/bin/nasm -f elf -i ../../libmp3lame/i386/ fft3dn.nas -o .libs/fft3dn.o -l fft3dn.lo.lst
/usr/bin/nasm -f elf -i ../../libmp3lame/i386/ choose_table.nas -o .libs/choose_table.o -l choose_table.lo.lst
make[3]: Leaving directory `/var/tmp/portage/lame-3.97/work/lame-3.97/libmp3lame/i386'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/var/tmp/portage/lame-3.97/work/lame-3.97/libmp3lame'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/tmp/portage/lame-3.97/work/lame-3.97'
make: *** [all] Error 2

!!! ERROR: media-sound/lame-3.97 failed.
Call stack:
  ebuild.sh, line 1546:   Called dyn_compile
  ebuild.sh, line 937:   Called src_compile
  lame-3.97.ebuild, line 65:   Called die


Well You didn't really show an error itself, but just what happen afterwards. Second line of your pasted code already shows an error which happen before.
Try using only with nasm which is huge factor in speed of encoding by itself.
_________________
Sky is not the limit...
Back to top
View user's profile Send private message
Nick C
Guru
Guru


Joined: 18 Mar 2005
Posts: 526
Location: Portsmouth, England

PostPosted: Fri Jan 05, 2007 11:47 am    Post subject: Reply with quote

what arch are you running? (x86, amd64, ppc etc), I suspect the main reason why the asm optimisations are disabled globally is because they only work on 32bit x86, im pretty sure i remember reading somewhere about this.
_________________
Please add [solved] to the initial post's subject line if you feel your problem is resolved.
www.monkeydust.net
Back to top
View user's profile Send private message
sobers_2002
Veteran
Veteran


Joined: 16 Mar 2004
Posts: 1128

PostPosted: Fri Jan 05, 2007 6:49 pm    Post subject: Reply with quote

Code:
make[2]: Entering directory `/var/tmp/portage/media-sound/lame-3.97-r1/work/lame-3.97/libmp3lame'
Making all in i386
make[3]: Entering directory `/var/tmp/portage/media-sound/lame-3.97-r1/work/lame-3.97/libmp3lame/i386'
test -d .libs || mkdir .libs
test -d .libs || mkdir .libs
mkdir: cannot create directory `.libs': File exists
make[3]: *** [cpu_feat.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
echo '# Generated by ltmain.sh - GNU libtool 1.5 (1.1220 2003/04/05 19:32:58)' >choose_table.lo
make[3]: *** Waiting for unfinished jobs....
echo "pic_object='.libs/choose_table.o'" >>choose_table.lo
make[3]: *** Waiting for unfinished jobs....
echo "non_pic_object='choose_table.o'" >>choose_table.lo
make[3]: *** Waiting for unfinished jobs....
/usr/bin/nasm -f elf -i ../../libmp3lame/i386/ choose_table.nas -o .libs/choose_table.o -l choose_table.lo.lst
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory `/var/tmp/portage/media-sound/lame-3.97-r1/work/lame-3.97/libmp3lame/i386'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/var/tmp/portage/media-sound/lame-3.97-r1/work/lame-3.97/libmp3lame'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/var/tmp/portage/media-sound/lame-3.97-r1/work/lame-3.97'
make: *** [all] Error 2

!!! ERROR: media-sound/lame-3.97-r1 failed.
Call stack:
  ebuild.sh, line 1603:   Called dyn_compile
  ebuild.sh, line 961:   Called src_compile
  lame-3.97-r1.ebuild, line 89:   Called die

!!! emake failed
!!! If you need support, post the topmost build error, and the call stack if relevant.


I got this error. machine is athlon-xp with details below
_________________
Pdict - dockable dictionary client for linux
FREE97WIN: Use this code on Dreamhost and you get $97 off !!
Back to top
View user's profile Send private message
PrakashP
Veteran
Veteran


Joined: 27 Oct 2003
Posts: 1249
Location: C.C.A.A., Germania

PostPosted: Sun Jan 07, 2007 1:54 pm    Post subject: Reply with quote

Try editing the makefile in i386 and add a "-p" parameter to the mkdir command. It is an issue with parallel build.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum