Menu

#479 configure script incorrectly assumes sse2 availability

1.3.x
open
nobody
None
5
2022-03-01
2021-01-31
Michal Dec
No

When compiling libFLAC for x86 machines that lack SSE2 (pre-Pentium 4/pre-Athlon64 CPUs), the configure script will incorrectly assume that just because the compiler accepts -msse2 as an option then it has to be used. This will produce a binary that is unusable on Pentium 3 and AMD K7 and older CPUs.

Kars /var/tmp/portage/media-libs/flac-1.3.3-r1/work/flac-1.3.3 # grep msse2 . -r
./configure:  --disable-sse           Disable passing of -msse2 to the compiler
./configure:            { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC accepts -msse2" >&5
./configure:$as_echo_n "checking if $CC accepts -msse2... " >&6; }
./configure:    CFLAGS="-msse2"
./configure:                    CFLAGS="$ac_add_cflags__old_cflags -msse2"
./configure.ac:AC_HELP_STRING([--disable-sse], [Disable passing of -msse2 to the compiler]),
./configure.ac:         XIPH_ADD_CFLAGS([-msse2])

Perhaps a better approach would be:

  1. If:
  2. we are not cross-compiling
  3. --enable-sse was specified
  4. host is x86
  5. host is not amd64
    Then continue to step 2.
  6. Compile a test program that utilizes cpuid opcode to determine if we can use SSE2. This opcode is present in all x86 CPUs since i486SL.
  7. Run the program and if it:
  8. says yes, add -msse2
  9. says no, don't

Better yet, it's really strange why enabling SSE would warrant SSE2 being present which isn't fair even if we cross-compile - we could be cross-compiling for a particularly old machine and still hit this bug. Maybe each SSE level should have its own --enable flag?

Related

Bugs: #479

Discussion

  • Martijn van Beurden

    This was done on purpose. Support for older CPUs (at the expense of a slower binary for newer CPUs) is enabled with --disable-sse as you noticed. This is nothing strange, many programs (browsers for example) and OSes (Windows 8.1 and up) require SSE2. FLAC however, still allows you to compile your own version without this requirement, but it is set as default.

     
    • Michal Dec

      Michal Dec - 2022-03-01

      Well, this just leaves a portion of CPUs served worse than others.
      Non-SSE CPUs get their non-SSE binary, and only SSE2 CPUs get the SSE
      binary. My point is that the interests of the middle ground between
      these 2 CPUs should be covered. I could write a patch when I find the time.

      W dniu 1.03.2022 o 08:37, Martijn van Beurden pisze:

      This was done on purpose. Support for older CPUs (at the expense of a
      slower binary for newer CPUs) is enabled with --disable-sse as you
      noticed. This is nothing strange, many programs (browsers for example)
      and OSes (Windows 8.1 and up) require SSE2. FLAC however, still allows
      you to compile your own version without this requirement, but it is
      set as default.


      [bugs:#479] https://sourceforge.net/p/flac/bugs/479/ configure
      script incorrectly assumes sse2 availability

      Status: open
      Group: 1.3.x
      Created: Sun Jan 31, 2021 01:54 AM UTC by Michal Dec
      Last Updated: Sun Jan 31, 2021 01:54 AM UTC
      Owner: nobody

      When compiling libFLAC for x86 machines that lack SSE2 (pre-Pentium
      4/pre-Athlon64 CPUs), the configure script will incorrectly assume
      that just because the compiler accepts -msse2 as an option then it has
      to be used. This will produce a binary that is unusable on Pentium 3
      and AMD K7 and older CPUs.

      |Kars /var/tmp/portage/media-libs/flac-1.3.3-r1/work/flac-1.3.3 # grep
      msse2 . -r ./configure: --disable-sse Disable passing of -msse2 to the
      compiler ./configure: { $as_echo "$as_me:${as_lineno-$LINENO}:
      checking if $CC accepts -msse2" >&5 ./configure:$as_echo_n "checking
      if $CC accepts -msse2... " >&6; } ./configure: CFLAGS="-msse2"
      ./configure: CFLAGS="$ac_add_cflags__old_cflags -msse2"
      ./configure.ac:AC_HELP_STRING([--disable-sse], [Disable passing of
      -msse2 to the compiler]
      ), ./configure.ac: XIPH_ADD_CFLAGS([-msse2]) |

      Perhaps a better approach would be:
      1. If:
      - we are not cross-compiling
      - --enable-sse was specified
      - host is x86
      - host is not amd64
      Then continue to step 2.
      2. Compile a test program that utilizes |cpuid| opcode to determine if
      we can use SSE2. This opcode is present in all x86 CPUs since i486SL.
      3. Run the program and if it:
      - says yes, add -msse2
      - says no, don't

      Better yet, it's really strange why enabling SSE would warrant SSE2
      being present which isn't fair even if we cross-compile - we could be
      cross-compiling for a particularly old machine and still hit this bug.
      Maybe each SSE level should have its own --enable flag?


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/flac/bugs/479/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #479

      • Martijn van Beurden

        SSE2 was introduced in 2000 and has been mandatory for all 64-bit CPUs. Is it really such a big problem that those ancient CPUs get the best possible binary?

         

Log in to post a comment.

MongoDB Logo MongoDB