[MPlayer-dev-eng] [PATCH] ao_plugin.c bugfixes and speed improvement
Kis Gergely
kisg at lme.linux.hu
Sun Apr 7 12:10:58 CEST 2002
Hi,
While analyzing the problems I have encountered in ao_plugin.c I found this
document: http://mega-nerd.com/FPcast/
It talks about performance penalties when using plain C float (double) to
int casts.
Brief description: The ISO C standard says, that the float to int cast is a
truncation operation. This causes the new pipeline based FPUs (P3, P4, Athlon)
to flush their whole pipeline. In many cases we could actually round the
value to the nearest integer, which is much faster.
The ISO C99 standard introduced the functions lrint and lrintf which do
exactly this. In GNU C they are defined in math.h as inline functions.
One has to define the _ISO9X_SOURCE and _ISO99_SOURCE flags to use these
functions. The only drawback is that when optimizations are turned of the
binary needs to be linked against the math library.
I think, that in ao_plugin.c get_space() we actually want to round the
value, and not truncate.
The attached patch solves both the ao_plugin_local_data.len problem and the
databuf_len-1 problem.
Please review and commit if you like.
Thanks for your time,
kisg
-------------- next part --------------
--- ao_plugin.c.orig Fri Apr 5 10:16:13 2002
+++ ao_plugin.c Sun Apr 7 11:36:25 2002
@@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdlib.h>
+#define _ISOC9X_SOURCE 1
+#define _ISOC99_SOURCE 1
+#include <math.h>
+
#include "../config.h"
#include "afmt.h"
@@ -172,6 +176,7 @@
if(ao_plugin_local_data.buf)
free(ao_plugin_local_data.buf);
ao_plugin_local_data.buf=malloc(MAX_OUTBURST);
+ ao_plugin_local_data.len=0;
if(!ao_plugin_local_data.buf) return 0;
@@ -190,6 +195,7 @@
if(ao_plugin_local_data.buf)
free(ao_plugin_local_data.buf);
ao_plugin_local_data.buf=NULL;
+ ao_plugin_local_data.len=0;
}
// stop playing and empty buffers (for seeking/pause)
@@ -218,7 +224,7 @@
sz=(double)MAX_OUTBURST-(double)ao_plugin_local_data.len;
sz*=ao_plugin_data.sz_mult;
sz+=ao_plugin_data.sz_fix;
- return (int)(sz);
+ return (int)lrint(sz);
}
// plays 'len' bytes of 'data'
More information about the MPlayer-dev-eng
mailing list