Browse code

Replace pow(x, 0.75) with sqrtf(x * sqrtf(x)) for a 33% speedup.

Originally committed as revision 19459 to svn://svn.ffmpeg.org/ffmpeg/trunk

Alex Converse authored on 2009/07/17 23:21:49
Showing 1 changed files
... ...
@@ -61,7 +61,8 @@ static const uint8_t *run_value_bits[2] = {
61 61
  */
62 62
 static av_always_inline int quant(float coef, const float Q)
63 63
 {
64
-    return pow(coef * Q, 0.75) + 0.4054;
64
+    float a = coef * Q;
65
+    return sqrtf(a * sqrtf(a)) + 0.4054;
65 66
 }
66 67
 
67 68
 static void quantize_bands(int (*out)[2], const float *in, const float *scaled,
... ...
@@ -84,8 +85,10 @@ static void abs_pow34_v(float *out, const float *in, const int size)
84 84
 {
85 85
 #ifndef USE_REALLY_FULL_SEARCH
86 86
     int i;
87
-    for (i = 0; i < size; i++)
88
-        out[i] = pow(fabsf(in[i]), 0.75);
87
+    for (i = 0; i < size; i++) {
88
+        float a = fabsf(in[i]);
89
+        out[i] = sqrtf(a * sqrtf(a));
90
+    }
89 91
 #endif /* USE_REALLY_FULL_SEARCH */
90 92
 }
91 93
 
... ...
@@ -110,7 +113,7 @@ static float quantize_band_cost(struct AACEncContext *s, const float *in,
110 110
     const int dim = cb < FIRST_PAIR_BT ? 4 : 2;
111 111
     int resbits = 0;
112 112
 #ifndef USE_REALLY_FULL_SEARCH
113
-    const float  Q34 = pow(Q, 0.75);
113
+    const float  Q34 = sqrtf(Q * sqrtf(Q));
114 114
     const int range  = aac_cb_range[cb];
115 115
     const int maxval = aac_cb_maxval[cb];
116 116
     int offs[4];
... ...
@@ -225,7 +228,7 @@ static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb,
225 225
     const int dim = (cb < FIRST_PAIR_BT) ? 4 : 2;
226 226
     int i, j, k;
227 227
 #ifndef USE_REALLY_FULL_SEARCH
228
-    const float  Q34 = pow(Q, 0.75);
228
+    const float  Q34 = sqrtf(Q * sqrtf(Q));
229 229
     const int range  = aac_cb_range[cb];
230 230
     const int maxval = aac_cb_maxval[cb];
231 231
     int offs[4];