Lame 3.0 and 3.01 causes IEEE floating-point `invalid operations' under
FreeBSD 3.1, specifically at the line xfsf[ch][i+1][sfb] = sum[ch] / bw;
around 1520 in loop.c

Here is a patch for FreeBSD which ignores FP `invalid operations', and allows
Lame3.01 to run.

Can anybody tell me what sort of things could be an illegal operation.
I've checked with debug code and with gdb. In the line which causes the
exception, sum[ch] != NaN, sum[ch] == 0.0, bw != NaN, bw == 30.0. I can't
see why this is causing problems.

Thanks,
        Warren


*** loop.c      1999/05/12 03:02:26     1.1
--- loop.c      1999/05/12 04:26:41
***************
*** 21,26 ****
--- 21,29 ----
  #include <stdlib.h>
  #include <math.h>
  #include <assert.h>
+ #ifdef __FreeBSD__
+ # include <floatingpoint.h>
+ #endif
  #include "l3side.h"
  #include "loop.h"
  #include "huffman.h"
***************
*** 1427,1432 ****
--- 1430,1440 ----
      int ch;
      static int init=0;
      double diff[2], qcoeff;
+ #ifdef __FreeBSD__
+     fp_except_t mask; /* Under FreeBSD 3.1, the line !! below causes an
+                        * invalid FP error. Set the FP mask to ignore this */
+     mask= fpgetmask() & (~FP_X_INV); fpsetmask(mask);
+ #endif
  
      if (init==0) {
        init++;
***************
*** 1517,1523 ****
          for (ch=0 ; ch < stereo ; ch ++ ) sum[ch] += diff[ch]*diff[ch];
        }
        for (ch=0 ; ch < stereo ; ch ++ ) {
!         xfsf[ch][i+1][sfb] = sum[ch] / bw;
          distort[ch][i+1][sfb] = ( xfsf[ch][i+1][sfb] > l3_xmin->s[gr][ch][sfb][i] );
        }
        if (ms_stereo) 
--- 1525,1531 ----
          for (ch=0 ; ch < stereo ; ch ++ ) sum[ch] += diff[ch]*diff[ch];
        }
        for (ch=0 ; ch < stereo ; ch ++ ) {
!         xfsf[ch][i+1][sfb] = sum[ch] / bw;    /* !! FreeBSD FP error here */
          distort[ch][i+1][sfb] = ( xfsf[ch][i+1][sfb] > l3_xmin->s[gr][ch][sfb][i] );
        }
        if (ms_stereo) 

Reply via email to