From 32d90c193511b93b7c22d5ecc653311be091c14a Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 21 Apr 2019 15:10:07 -0230 Subject: [PATCH] Removed '-Wno-double-promotion' from the build flags. This necessitated fixing float -> double promotions in several places in the code. In most cases, double was never being utilized anyway, so there was a slight performance hit for casting when not required. --- Makefile | 4 +- src/common/audio/HighPass.cxx | 11 ++--- src/common/audio/LanczosResampler.cxx | 5 +-- src/common/bspf.hxx | 3 ++ src/common/tv_filters/AtariNTSC.cxx | 65 +++++++++++++-------------- src/common/tv_filters/AtariNTSC.hxx | 24 +++++----- src/common/tv_filters/NTSCFilter.cxx | 4 +- src/common/tv_filters/NTSCFilter.hxx | 2 +- src/emucore/EmulationTiming.cxx | 2 +- src/emucore/EmulationTiming.hxx | 2 +- src/emucore/Paddles.cxx | 4 +- src/emucore/TIASurface.cxx | 2 +- 12 files changed, 60 insertions(+), 68 deletions(-) diff --git a/Makefile b/Makefile index 48900624c..4ac73f332 100644 --- a/Makefile +++ b/Makefile @@ -61,8 +61,8 @@ ifdef HAVE_CLANG endif ifdef CLANG_WARNINGS - CXXFLAGS+= -Weverything -Wno-c++17-extensions -Wno-c++98-compat -Wno-c++98-compat-pedantic \ - -Wno-double-promotion -Wno-switch-enum -Wno-conversion -Wno-covered-switch-default \ + CXXFLAGS+= -Weverything -Wno-c++17-extensions -Wno-c++98-compat-pedantic \ + -Wno-switch-enum -Wno-conversion -Wno-covered-switch-default \ -Wno-inconsistent-missing-destructor-override -Wno-float-equal \ -Wno-exit-time-destructors -Wno-global-constructors -Wno-weak-vtables \ -Wno-four-char-constants -Wno-padded diff --git a/src/common/audio/HighPass.cxx b/src/common/audio/HighPass.cxx index 97bc28b8b..c2fe32b1d 100644 --- a/src/common/audio/HighPass.cxx +++ b/src/common/audio/HighPass.cxx @@ -15,19 +15,16 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ -#include -#ifndef M_PI - #define M_PI 3.14159265358979323846f -#endif - +#include "bspf.hxx" #include "HighPass.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - HighPass::HighPass(float cutOffFrequency, float frequency) : myLastValueIn(0), myLastValueOut(0), - myAlpha(1.f / (1.f + 2.f*M_PI*cutOffFrequency/frequency)) -{} + myAlpha(1.f / (1.f + 2.f*BSPF::PI_f*cutOffFrequency/frequency)) +{ +} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - float HighPass::apply(float valueIn) diff --git a/src/common/audio/LanczosResampler.cxx b/src/common/audio/LanczosResampler.cxx index 64bffb87e..1224ec16a 100644 --- a/src/common/audio/LanczosResampler.cxx +++ b/src/common/audio/LanczosResampler.cxx @@ -16,9 +16,6 @@ //============================================================================ #include -#ifndef M_PI - #define M_PI 3.14159265358979323846f -#endif #include "LanczosResampler.hxx" @@ -45,7 +42,7 @@ namespace { // We calculate the sinc with double precision in order to compensate for precision loss // around zero return x == 0.f ? 1 : static_cast( - sin(M_PI * static_cast(x)) / M_PI / static_cast(x) + sin(BSPF::PI_d * static_cast(x)) / BSPF::PI_d / static_cast(x) ); } diff --git a/src/common/bspf.hxx b/src/common/bspf.hxx index dde629eca..ef5e57f17 100644 --- a/src/common/bspf.hxx +++ b/src/common/bspf.hxx @@ -93,6 +93,9 @@ static const string EmptyString(""); namespace BSPF { + static constexpr float PI_f = 3.141592653589793238462643383279502884f; + static constexpr double PI_d = 3.141592653589793238462643383279502884; + // CPU architecture type // This isn't complete yet, but takes care of all the major platforms #if defined(__i386__) || defined(_M_IX86) diff --git a/src/common/tv_filters/AtariNTSC.cxx b/src/common/tv_filters/AtariNTSC.cxx index 79dd60651..de3eaace3 100644 --- a/src/common/tv_filters/AtariNTSC.cxx +++ b/src/common/tv_filters/AtariNTSC.cxx @@ -318,15 +318,15 @@ inline uInt32 AtariNTSC::getRGBPhosphor(const uInt32 c, const uInt32 p) const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AtariNTSC::init(init_t& impl, const Setup& setup) { - impl.brightness = float(setup.brightness) * (0.5f * rgb_unit) + rgb_offset; - impl.contrast = float(setup.contrast) * (0.5f * rgb_unit) + rgb_unit; + impl.brightness = setup.brightness * (0.5f * rgb_unit) + rgb_offset; + impl.contrast = setup.contrast * (0.5f * rgb_unit) + rgb_unit; - impl.artifacts = float(setup.artifacts); + impl.artifacts = setup.artifacts; if ( impl.artifacts > 0 ) impl.artifacts *= artifacts_max - artifacts_mid; impl.artifacts = impl.artifacts * artifacts_mid + artifacts_mid; - impl.fringing = float(setup.fringing); + impl.fringing = setup.fringing; if ( impl.fringing > 0 ) impl.fringing *= fringing_max - fringing_mid; impl.fringing = impl.fringing * fringing_mid + fringing_mid; @@ -337,22 +337,22 @@ void AtariNTSC::init(init_t& impl, const Setup& setup) if (true) /* was (gamma_size > 1) */ { float const to_float = 1.0f / (gamma_size - 1/*(gamma_size > 1)*/); - float const gamma = 1.1333f - float(setup.gamma) * 0.5f; + float const gamma = 1.1333f - setup.gamma * 0.5f; /* match common PC's 2.2 gamma to TV's 2.65 gamma */ int i; for ( i = 0; i < gamma_size; i++ ) impl.to_float [i] = - float(pow( i * to_float, gamma )) * impl.contrast + impl.brightness; + powf( i * to_float, gamma ) * impl.contrast + impl.brightness; } /* setup decoder matricies */ { - float hue = float(setup.hue) * PI + PI / 180 * ext_decoder_hue; - float sat = float(setup.saturation) + 1; - hue += PI / 180 * (std_decoder_hue - ext_decoder_hue); + float hue = setup.hue * BSPF::PI_f + BSPF::PI_f / 180 * ext_decoder_hue; + float sat = setup.saturation + 1; + hue += BSPF::PI_f / 180 * (std_decoder_hue - ext_decoder_hue); - float s = float(sin( hue )) * sat; - float c = float(cos( hue )) * sat; + float s = sinf( hue ) * sat; + float c = cosf( hue ) * sat; float* out = impl.to_rgb; int n; @@ -386,27 +386,26 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) /* generate luma (y) filter using sinc kernel */ { /* sinc with rolloff (dsf) */ - float const rolloff = 1 + float(setup.sharpness) * 0.032f; - float const maxh = 32; - float const pow_a_n = float(pow( rolloff, maxh )); + float const rolloff = 1 + setup.sharpness * 0.032f; + constexpr float maxh = 32; + float const pow_a_n = powf( rolloff, maxh ); float sum; - int i; /* quadratic mapping to reduce negative (blurring) range */ - float to_angle = float(setup.resolution) + 1; - to_angle = PI / maxh * float(LUMA_CUTOFF) * (to_angle * to_angle + 1); + float to_angle = setup.resolution + 1; + to_angle = BSPF::PI_f / maxh * LUMA_CUTOFF * (to_angle * to_angle + 1.f); kernels [kernel_size * 3 / 2] = maxh; /* default center value */ - for ( i = 0; i < kernel_half * 2 + 1; i++ ) + for ( int i = 0; i < kernel_half * 2 + 1; i++ ) { int x = i - kernel_half; float angle = x * to_angle; /* instability occurs at center point with rolloff very close to 1.0 */ - if ( x || pow_a_n > 1.056 || pow_a_n < 0.981 ) + if ( x || pow_a_n > 1.056f || pow_a_n < 0.981f ) { - float rolloff_cos_a = rolloff * float(cos( angle )); + float rolloff_cos_a = rolloff * cosf( angle ); float num = 1 - rolloff_cos_a - - pow_a_n * float(cos( maxh * angle )) + - pow_a_n * rolloff * float(cos( (maxh - 1) * angle )); + pow_a_n * cosf( maxh * angle ) + + pow_a_n * rolloff * cosf( (maxh - 1) * angle ); float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; float dsf = num / den; kernels [kernel_size * 3 / 2 - kernel_half + i] = dsf - 0.5f; @@ -415,16 +414,16 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) /* apply blackman window and find sum */ sum = 0; - for ( i = 0; i < kernel_half * 2 + 1; i++ ) + for ( int i = 0; i < kernel_half * 2 + 1; i++ ) { - float x = PI * 2 / (kernel_half * 2) * i; - float blackman = 0.42f - 0.5f * float(cos( x )) + 0.08f * float(cos( x * 2 )); + float x = BSPF::PI_f * 2 / (kernel_half * 2) * i; + float blackman = 0.42f - 0.5f * cosf( x ) + 0.08f * cosf( x * 2 ); sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman); } /* normalize kernel */ sum = 1.0f / sum; - for ( i = 0; i < kernel_half * 2 + 1; i++ ) + for ( int i = 0; i < kernel_half * 2 + 1; i++ ) { int x = kernel_size * 3 / 2 - kernel_half + i; kernels [x] *= sum; @@ -433,9 +432,8 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) /* generate chroma (iq) filter using gaussian kernel */ { - float const cutoff_factor = -0.03125f; - float cutoff = float(setup.bleed); - int i; + constexpr float cutoff_factor = -0.03125f; + float cutoff = setup.bleed; if ( cutoff < 0 ) { @@ -447,11 +445,11 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) } cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff; - for ( i = -kernel_half; i <= kernel_half; i++ ) - kernels [kernel_size / 2 + i] = float(exp( i * i * cutoff )); + for ( int i = -kernel_half; i <= kernel_half; i++ ) + kernels [kernel_size / 2 + i] = expf( i * i * cutoff ); /* normalize even and odd phases separately */ - for ( i = 0; i < 2; i++ ) + for ( int i = 0; i < 2; i++ ) { float sum = 0; int x; @@ -473,9 +471,8 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup) do { float remain = 0; - int i; weight -= 1.0f / rescale_in; - for ( i = 0; i < kernel_size * 2; i++ ) + for ( int i = 0; i < kernel_size * 2; i++ ) { float cur = kernels [i]; float m = cur * weight; diff --git a/src/common/tv_filters/AtariNTSC.hxx b/src/common/tv_filters/AtariNTSC.hxx index bf5afd7d8..447a9e5fd 100644 --- a/src/common/tv_filters/AtariNTSC.hxx +++ b/src/common/tv_filters/AtariNTSC.hxx @@ -58,18 +58,18 @@ class AtariNTSC struct Setup { // Basic parameters - double hue; // -1 = -180 degrees +1 = +180 degrees - double saturation; // -1 = grayscale (0.0) +1 = oversaturated colors (2.0) - double contrast; // -1 = dark (0.5) +1 = light (1.5) - double brightness; // -1 = dark (0.5) +1 = light (1.5) - double sharpness; // edge contrast enhancement/blurring + float hue; // -1 = -180 degrees +1 = +180 degrees + float saturation; // -1 = grayscale (0.0) +1 = oversaturated colors (2.0) + float contrast; // -1 = dark (0.5) +1 = light (1.5) + float brightness; // -1 = dark (0.5) +1 = light (1.5) + float sharpness; // edge contrast enhancement/blurring // Advanced parameters - double gamma; // -1 = dark (1.5) +1 = light (0.5) - double resolution; // image resolution - double artifacts; // artifacts caused by color changes - double fringing; // color artifacts caused by brightness changes - double bleed; // color bleed (color resolution reduction) + float gamma; // -1 = dark (1.5) +1 = light (0.5) + float resolution; // image resolution + float artifacts; // artifacts caused by color changes + float fringing; // color artifacts caused by brightness changes + float bleed; // color bleed (color resolution reduction) }; // Video format presets @@ -160,9 +160,7 @@ class AtariNTSC #define fringing_max 2.0f #define rgb_offset (rgb_unit * 2 + 0.5f) - #undef PI - #define PI 3.14159265358979323846f - #define LUMA_CUTOFF 0.20 + #define LUMA_CUTOFF 0.20f uInt32 myColorTable[palette_size][entry_size]; uInt8 myPhosphorPalette[256][256]; diff --git a/src/common/tv_filters/NTSCFilter.cxx b/src/common/tv_filters/NTSCFilter.cxx index ead46a947..c02191a88 100644 --- a/src/common/tv_filters/NTSCFilter.cxx +++ b/src/common/tv_filters/NTSCFilter.cxx @@ -20,8 +20,8 @@ #include "NTSCFilter.hxx" -constexpr double scaleFrom100(double x) { return (x/50.0) - 1.0; } -constexpr uInt32 scaleTo100(double x) { return uInt32(50*(x+1.0)); } +constexpr float scaleFrom100(float x) { return (x/50.f) - 1.f; } +constexpr uInt32 scaleTo100(float x) { return uInt32(50*(x+1.f)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NTSCFilter::NTSCFilter() diff --git a/src/common/tv_filters/NTSCFilter.hxx b/src/common/tv_filters/NTSCFilter.hxx index a08ff8a28..901eeb233 100644 --- a/src/common/tv_filters/NTSCFilter.hxx +++ b/src/common/tv_filters/NTSCFilter.hxx @@ -153,7 +153,7 @@ class NTSCFilter struct AdjustableTag { const char* const type; - double* value; + float* value; }; uInt32 myCurrentAdjustable; static const AdjustableTag ourCustomAdjustables[10]; diff --git a/src/emucore/EmulationTiming.cxx b/src/emucore/EmulationTiming.cxx index 7df8806be..2624f7ee4 100644 --- a/src/emucore/EmulationTiming.cxx +++ b/src/emucore/EmulationTiming.cxx @@ -98,7 +98,7 @@ EmulationTiming& EmulationTiming::updateAudioQueueHeadroom(uInt32 audioQueueHead // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EmulationTiming& EmulationTiming::updateSpeedFactor(float speedFactor) { - mySpeedFactor = speedFactor; + mySpeedFactor = static_cast(speedFactor); recalculate(); return *this; diff --git a/src/emucore/EmulationTiming.hxx b/src/emucore/EmulationTiming.hxx index ad6ea49fe..58b30d3ea 100644 --- a/src/emucore/EmulationTiming.hxx +++ b/src/emucore/EmulationTiming.hxx @@ -83,7 +83,7 @@ class EmulationTiming { uInt32 myAudioQueueCapacity; uInt32 myPrebufferFragmentCount; - float mySpeedFactor; + double mySpeedFactor; private: diff --git a/src/emucore/Paddles.cxx b/src/emucore/Paddles.cxx index d853faae6..b2426e049 100644 --- a/src/emucore/Paddles.cxx +++ b/src/emucore/Paddles.cxx @@ -354,9 +354,9 @@ void Paddles::update() // Only change state if the charge has actually changed if(myCharge[1] != myLastCharge[1]) - setPin(AnalogPin::Five, Int32(MAX_RESISTANCE * (myCharge[1] / float(TRIGMAX)))); + setPin(AnalogPin::Five, Int32(MAX_RESISTANCE * (myCharge[1] / double(TRIGMAX)))); if(myCharge[0] != myLastCharge[0]) - setPin(AnalogPin::Nine, Int32(MAX_RESISTANCE * (myCharge[0] / float(TRIGMAX)))); + setPin(AnalogPin::Nine, Int32(MAX_RESISTANCE * (myCharge[0] / double(TRIGMAX)))); myLastCharge[1] = myCharge[1]; myLastCharge[0] = myCharge[0]; diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 6ca351cff..7f356d11a 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -98,7 +98,7 @@ void TIASurface::initialize(const Console& console, // This won't be 100% accurate, but non-integral scaling isn't 100% // accurate anyway mySLineSurface->setSrcSize(1, 2 * int(float(mode.image.height()) / - floor((float(mode.image.height()) / myTIA->height()) + 0.5))); + floorf((float(mode.image.height()) / myTIA->height()) + 0.5f))); #if 0 cerr << "INITIALIZE:\n"