From 8f333acb8033318700134e9ae8fe05bc2173d232 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 2 May 2015 04:16:32 +0200 Subject: log(0) - who would have guessed. marginal improvement on x86_64 for zero, 5-10% for tiny numbers; 100% time improvement (half the time) on i686 with zero. #/bin/sh g++ -x c++ -O3 -ffast-math -o /tmp/a.out - << EOF #include #include #include #include static inline float accurate_coefficient_to_dB (float coeff) { #if 1 // try me if (coeff < 1e-15) return -std::numeric_limits::infinity(); #endif return 20.0f * log10f (coeff); } int main (int argc, char **argv) { long long int i; float f = 0; if (argc < 3) return -1; long long int end = atoll (argv[1]); for (i = 0; i < end; ++i) { f += accurate_coefficient_to_dB (atof (argv[2])); } printf ("%f\n",f); return 0; } EOF time /tmp/a.out 100000000000 0.0 time /tmp/a.out 100000000000 0.0 time /tmp/a.out 100000000000 0.0 --- libs/ardour/ardour/dB.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libs/ardour/ardour/dB.h') diff --git a/libs/ardour/ardour/dB.h b/libs/ardour/ardour/dB.h index 0a9c71ebf4..1a4ed983ab 100644 --- a/libs/ardour/ardour/dB.h +++ b/libs/ardour/ardour/dB.h @@ -20,6 +20,7 @@ #ifndef __ardour_dB_h__ #define __ardour_dB_h__ +#include #include "pbd/fastlog.h" #define GAIN_COEFF_ZERO 0.f @@ -35,6 +36,7 @@ static inline float fast_coefficient_to_dB (float coeff) { } static inline float accurate_coefficient_to_dB (float coeff) { + if (coeff < 1e-15) return -std::numeric_limits::infinity(); return 20.0f * log10f (coeff); } -- cgit v1.2.3