[MPlayer-dev-eng] Patch for gcc 3.4 against MPlayer-1.0pre5

Joey Parrish joey at nicewarrior.org
Tue Aug 24 09:12:22 CEST 2004


On Mon, Aug 23, 2004 at 08:55:46PM -0500, Joey Parrish wrote:
> > > According to the original mail, this is already done in some place in
> > > MPlayer (IIRC).  But the point is that someone should create a proper
> > > replacement in the case of a system without one.  We should not put
> > > code everywhere to define lrintf over and over again.
> > 
> > You just volunteered :)

Okay, here's my first try.
I took code from MPlayer's copy of libfaad2 for x86 asm lrintf.
The fallback version doesn't give the same results for lrintf(0.5)
as the asm version, though.

For the asm version:
  lrintf(0.5) == 0
  lrintf(-0.5) == 0

For the C version:
  lrintf(0.5) == 1
  lrintf(-0.5) == -1

Is this a problem, or is that behavior even defined?
Any other comments?

--Joey

-- 
"Are disorders necessarily bad?" --Ike
-------------- next part --------------
? osdep/lrintf.c
Index: libaf/af_format.c
===================================================================
RCS file: /cvsroot/mplayer/main/libaf/af_format.c,v
retrieving revision 1.15
diff -u -r1.15 af_format.c
--- libaf/af_format.c	18 May 2004 19:13:15 -0000	1.15
+++ libaf/af_format.c	24 Aug 2004 07:08:48 -0000
@@ -9,18 +9,11 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <math.h>
 
 #include "af.h"
 #include "../bswap.h"
 
-// Integer to float conversion through lrintf()
-#ifdef HAVE_LRINTF
-#define __USE_ISOC99 1
-#include <math.h>
-#else
-#define lrintf(x) ((int)(x))
-#endif
-
 /* Functions used by play to convert the input audio to the correct
    format */
 
Index: libfaad2/common.h
===================================================================
RCS file: /cvsroot/mplayer/main/libfaad2/common.h,v
retrieving revision 1.5
diff -u -r1.5 common.h
--- libfaad2/common.h	23 Jun 2004 13:50:49 -0000	1.5
+++ libfaad2/common.h	24 Aug 2004 07:08:48 -0000
@@ -322,34 +322,6 @@
   }
 
 
-  #if defined(_WIN32) && !defined(__MINGW32__)
-    #define HAS_LRINTF
-    static INLINE int lrintf(float f)
-    {
-        int i;
-        __asm
-        {
-            fld   f
-            fistp i
-        }
-        return i;
-    }
-  #elif (defined(__i386__) && defined(__GNUC__)) && !defined(__MINGW32__)
-    #define HAS_LRINTF
-    // from http://www.stereopsis.com/FPU.html
-    static INLINE int lrintf(float f)
-    {
-        int i;
-        __asm__ __volatile__ (
-            "flds %1        \n\t"
-            "fistpl %0      \n\t"
-            : "=m" (i)
-            : "m" (f));
-        return i;
-    }
-  #endif
-
-
   #ifdef __ICL /* only Intel C compiler has fmath ??? */
 
     #include <mathf.h>
@@ -363,14 +335,6 @@
 
   #else
 
-#ifdef HAVE_LRINTF
-#  define HAS_LRINTF
-#  define _ISOC9X_SOURCE 1
-#  define _ISOC99_SOURCE 1
-#  define __USE_ISOC9X   1
-#  define __USE_ISOC99   1
-#endif
-
     #include <math.h>
 
 #ifdef HAVE_SINF
@@ -400,11 +364,6 @@
 
 #endif
 
-#ifndef HAS_LRINTF
-/* standard cast */
-#define lrintf(f) ((int32_t)(f))
-#endif
-
 typedef real_t complex_t[2];
 #define RE(A) A[0]
 #define IM(A) A[1]
Index: libfaad2/lt_predict.c
===================================================================
RCS file: /cvsroot/mplayer/main/libfaad2/lt_predict.c,v
retrieving revision 1.4
diff -u -r1.4 lt_predict.c
--- libfaad2/lt_predict.c	23 Jun 2004 13:50:51 -0000	1.4
+++ libfaad2/lt_predict.c	24 Aug 2004 07:08:48 -0000
@@ -155,15 +155,9 @@
 {
     if (sig_in >= 0)
     {
-#ifndef HAS_LRINTF
-        sig_in += 0.5f;
-#endif
         if (sig_in >= 32768.0f)
             return 32767;
     } else {
-#ifndef HAS_LRINTF
-        sig_in += -0.5f;
-#endif
         if (sig_in <= -32768.0f)
             return -32768;
     }
Index: libfaad2/output.c
===================================================================
RCS file: /cvsroot/mplayer/main/libfaad2/output.c,v
retrieving revision 1.4
diff -u -r1.4 output.c
--- libfaad2/output.c	23 Jun 2004 13:50:51 -0000	1.4
+++ libfaad2/output.c	24 Aug 2004 07:08:48 -0000
@@ -60,29 +60,15 @@
     }
 }
 
-#ifndef HAS_LRINTF
 #define CLIP(sample, max, min) \
 if (sample >= 0.0f)            \
 {                              \
-    sample += 0.5f;            \
     if (sample >= max)         \
         sample = max;          \
 } else {                       \
-    sample += -0.5f;           \
     if (sample <= min)         \
         sample = min;          \
 }
-#else
-#define CLIP(sample, max, min) \
-if (sample >= 0.0f)            \
-{                              \
-    if (sample >= max)         \
-        sample = max;          \
-} else {                       \
-    if (sample <= min)         \
-        sample = min;          \
-}
-#endif
 
 #define CONV(a,b) ((a<<1)|(b&0x1))
 
Index: osdep/Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/osdep/Makefile,v
retrieving revision 1.16
diff -u -r1.16 Makefile
--- osdep/Makefile	27 Jun 2004 17:54:31 -0000	1.16
+++ osdep/Makefile	24 Aug 2004 07:08:49 -0000
@@ -3,7 +3,7 @@
 
 LIBNAME = libosdep.a
 
-SRCS= shmem.c strsep.c strl.c vsscanf.c scandir.c gettimeofday.c fseeko.c \
+SRCS= shmem.c strsep.c strl.c vsscanf.c scandir.c gettimeofday.c fseeko.c lrintf.c \
       # timer.c
 
 ifeq ($(TARGET_ARCH_X86),yes)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lrintf.c
Type: text/x-csrc
Size: 525 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20040824/5cf949ca/attachment.c>


More information about the MPlayer-dev-eng mailing list