Wednesday, May 01, 2024

Re: UPDATE: libsamplerate

On 2024/05/01 11:21, Jan Stary wrote:
> Hi,
>
> On Apr 26 20:46:51, brad@comstyle.com wrote:
> > Implement SSE2 lrint() and lrintf() on amd64.
>
> I don't think this is worth the added complexity:
> seven more patches to have a different lrint()?
> Does it make the resampling noticably better/faster?

Playing with the benchmark mentioned in
https://github.com/libsndfile/libsamplerate/issues/187
suggests that it's going to be *hugely* faster with clang (and a bit
faster with gcc).

> Also, the patch changes the CONFIGURE_STYLE from gnu to autoreconf
> and hardwires the autoconf and automake version (without explicitly
> depending on them) - presumably because configure.ac is patched
> so ./configure must be recreated.
> This seems to basicaly replicate the SSE2 github commit(s) in the port.

Exactly, that is the best way to do it.

For code changes use a patch direct from an upstream commit, or as close
as possible.

For autoconf, patch the input files and regenerate. Patching the output
files is much more likely to result in breakage at update time.

> I would wait for a release that will already contain this.

The last release was 3 years ago so that could be quite some wait.

An alternative would be to bump the port to a hash-based git archive
download, though I prefer making this sort of change as a targetted
patch like this.

ok sthen FWIW

> > Index: Makefile
> > ===================================================================
> > RCS file: /cvs/ports/audio/libsamplerate/Makefile,v
> > retrieving revision 1.27
> > diff -u -p -u -p -r1.27 Makefile
> > --- Makefile 5 Sep 2023 16:13:38 -0000 1.27
> > +++ Makefile 27 Apr 2024 00:26:05 -0000
> > @@ -2,7 +2,7 @@ COMMENT= audio sample rate conversion li
> >
> > VER= 0.2.2
> > DISTNAME= libsamplerate-${VER}
> > -REVISION= 0
> > +REVISION= 1
> > CATEGORIES= audio
> > EXTRACT_SUFX= .tar.xz
> >
> > @@ -18,7 +18,9 @@ SITES= https://github.com/libsndfile/lib
> >
> > WANTLIB= m
> >
> > -CONFIGURE_STYLE=gnu
> > +AUTOCONF_VERSION= 2.71
> > +AUTOMAKE_VERSION= 1.16
> > +CONFIGURE_STYLE=autoreconf
> > CONFIGURE_ARGS= --disable-cpu-clip \
> > --disable-fftw \
> > --disable-sndfile
> > Index: patches/patch-configure_ac
> > ===================================================================
> > RCS file: patches/patch-configure_ac
> > diff -N patches/patch-configure_ac
> > --- /dev/null 1 Jan 1970 00:00:00 -0000
> > +++ patches/patch-configure_ac 27 Apr 2024 00:26:05 -0000
> > @@ -0,0 +1,43 @@
> > +- Implement SSE2 lrint() and lrintf()
> > + 7a81766b14fa03e97822cf1e0b1651648df13116
> > +- use sse2 intrinsics for lrint/lrintf only on windows x64
> > + c01e2405612ad3561bf93e8e6dddb9ba0dffe4d9
> > +- sse2 lrint/lrintf updates
> > + c164eaa25ffdeedc7d25e731172cc45a25f483d4
> > +
> > +Index: configure.ac
> > +--- configure.ac.orig
> > ++++ configure.ac
> > +@@ -89,7 +89,7 @@ m4_define([abi_version_patch], [lt_revision])
> > +
> > + dnl ====================================================================================
> > +
> > +-AC_CHECK_HEADERS([stdbool.h stdint.h sys/times.h unistd.h])
> > ++AC_CHECK_HEADERS([stdbool.h stdint.h sys/times.h unistd.h immintrin.h])
> > +
> > + dnl ====================================================================================
> > + dnl Couple of initializations here. Fill in real values later.
> > +@@ -105,6 +105,9 @@ AC_ARG_ENABLE([werror],
> > + AC_ARG_ENABLE([cpu-clip],
> > + [AS_HELP_STRING([--disable-cpu-clip], [disable tricky cpu specific clipper])])
> > +
> > ++AC_ARG_ENABLE([sse2-lrint],
> > ++ [AS_HELP_STRING([--enable-sse2-lrint], [implement lrintf using SSE2 on x86 CPUs if possible])])
> > ++
> > + AC_ARG_ENABLE([sndfile],
> > + [AS_HELP_STRING([--disable-sndfile], [disable support for sndfile (default=autodetect)])], [], [enable_sndfile=auto])
> > +
> > +@@ -178,6 +181,13 @@ AS_IF([test "x$enable_cpu_clip" != "xno"], [
> > +
> > + AC_DEFINE_UNQUOTED([CPU_CLIPS_POSITIVE], [${ac_cv_c_clip_positive}], [Host processor clips on positive float to int conversion.])
> > + AC_DEFINE_UNQUOTED([CPU_CLIPS_NEGATIVE], [${ac_cv_c_clip_negative}], [Host processor clips on negative float to int conversion.])
> > ++
> > ++dnl ====================================================================================
> > ++dnl Determine if the user enabled lrint implementations using SSE2.
> > ++
> > ++AS_IF([test "x$enable_sse2_lrint" = "xyes"], [
> > ++ CFLAGS="$CFLAGS -DENABLE_SSE2_LRINT"
> > ++ ])
> > +
> > + dnl ====================================================================================
> > + dnl Check for libsndfile which is required for the test and example programs.
> > Index: patches/patch-examples_audio_out_c
> > ===================================================================
> > RCS file: patches/patch-examples_audio_out_c
> > diff -N patches/patch-examples_audio_out_c
> > --- /dev/null 1 Jan 1970 00:00:00 -0000
> > +++ patches/patch-examples_audio_out_c 27 Apr 2024 00:26:05 -0000
> > @@ -0,0 +1,19 @@
> > +- Implement SSE2 lrint() and lrintf()
> > + 7a81766b14fa03e97822cf1e0b1651648df13116
> > +- use sse2 intrinsics for lrint/lrintf only on windows x64
> > + c01e2405612ad3561bf93e8e6dddb9ba0dffe4d9
> > +- sse2 lrint/lrintf updates
> > + c164eaa25ffdeedc7d25e731172cc45a25f483d4
> > +
> > +Index: examples/audio_out.c
> > +--- examples/audio_out.c.orig
> > ++++ examples/audio_out.c
> > +@@ -960,7 +960,7 @@ solaris_play (get_audio_callback_t callback, AUDIO_OUT
> > +
> > + while ((read_frames = callback (callback_data, float_buffer, BUFFER_LEN / solaris_out->channels)))
> > + { for (k = 0 ; k < read_frames * solaris_out->channels ; k++)
> > +- buffer [k] = lrint (32767.0 * float_buffer [k]) ;
> > ++ buffer [k] = psf_lrint (32767.0 * float_buffer [k]) ;
> > + write (solaris_out->fd, buffer, read_frames * solaris_out->channels * sizeof (short)) ;
> > + } ;
> > +
> > Index: patches/patch-src_common_h
> > ===================================================================
> > RCS file: patches/patch-src_common_h
> > diff -N patches/patch-src_common_h
> > --- /dev/null 1 Jan 1970 00:00:00 -0000
> > +++ patches/patch-src_common_h 27 Apr 2024 00:26:05 -0000
> > @@ -0,0 +1,98 @@
> > +- Implement SSE2 lrint() and lrintf()
> > + 7a81766b14fa03e97822cf1e0b1651648df13116
> > +- use sse2 intrinsics for lrint/lrintf only on windows x64
> > + c01e2405612ad3561bf93e8e6dddb9ba0dffe4d9
> > +- sse2 lrint/lrintf updates
> > + c164eaa25ffdeedc7d25e731172cc45a25f483d4
> > +
> > +Index: src/common.h
> > +--- src/common.h.orig
> > ++++ src/common.h
> > +@@ -14,6 +14,36 @@
> > + #include <stdbool.h>
> > +

No comments:

Post a Comment