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.
This commit is contained in:
Stephen Anthony 2019-04-21 15:10:07 -02:30
parent 9d287666f9
commit 32d90c1935
12 changed files with 60 additions and 68 deletions

View File

@ -61,8 +61,8 @@ ifdef HAVE_CLANG
endif endif
ifdef CLANG_WARNINGS ifdef CLANG_WARNINGS
CXXFLAGS+= -Weverything -Wno-c++17-extensions -Wno-c++98-compat -Wno-c++98-compat-pedantic \ CXXFLAGS+= -Weverything -Wno-c++17-extensions -Wno-c++98-compat-pedantic \
-Wno-double-promotion -Wno-switch-enum -Wno-conversion -Wno-covered-switch-default \ -Wno-switch-enum -Wno-conversion -Wno-covered-switch-default \
-Wno-inconsistent-missing-destructor-override -Wno-float-equal \ -Wno-inconsistent-missing-destructor-override -Wno-float-equal \
-Wno-exit-time-destructors -Wno-global-constructors -Wno-weak-vtables \ -Wno-exit-time-destructors -Wno-global-constructors -Wno-weak-vtables \
-Wno-four-char-constants -Wno-padded -Wno-four-char-constants -Wno-padded

View File

@ -15,19 +15,16 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================ //============================================================================
#include <cmath> #include "bspf.hxx"
#ifndef M_PI
#define M_PI 3.14159265358979323846f
#endif
#include "HighPass.hxx" #include "HighPass.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HighPass::HighPass(float cutOffFrequency, float frequency) HighPass::HighPass(float cutOffFrequency, float frequency)
: myLastValueIn(0), : myLastValueIn(0),
myLastValueOut(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) float HighPass::apply(float valueIn)

View File

@ -16,9 +16,6 @@
//============================================================================ //============================================================================
#include <cmath> #include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846f
#endif
#include "LanczosResampler.hxx" #include "LanczosResampler.hxx"
@ -45,7 +42,7 @@ namespace {
// We calculate the sinc with double precision in order to compensate for precision loss // We calculate the sinc with double precision in order to compensate for precision loss
// around zero // around zero
return x == 0.f ? 1 : static_cast<float>( return x == 0.f ? 1 : static_cast<float>(
sin(M_PI * static_cast<double>(x)) / M_PI / static_cast<double>(x) sin(BSPF::PI_d * static_cast<double>(x)) / BSPF::PI_d / static_cast<double>(x)
); );
} }

View File

@ -93,6 +93,9 @@ static const string EmptyString("");
namespace BSPF namespace BSPF
{ {
static constexpr float PI_f = 3.141592653589793238462643383279502884f;
static constexpr double PI_d = 3.141592653589793238462643383279502884;
// CPU architecture type // CPU architecture type
// This isn't complete yet, but takes care of all the major platforms // This isn't complete yet, but takes care of all the major platforms
#if defined(__i386__) || defined(_M_IX86) #if defined(__i386__) || defined(_M_IX86)

View File

@ -318,15 +318,15 @@ inline uInt32 AtariNTSC::getRGBPhosphor(const uInt32 c, const uInt32 p) const
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AtariNTSC::init(init_t& impl, const Setup& setup) void AtariNTSC::init(init_t& impl, const Setup& setup)
{ {
impl.brightness = float(setup.brightness) * (0.5f * rgb_unit) + rgb_offset; impl.brightness = setup.brightness * (0.5f * rgb_unit) + rgb_offset;
impl.contrast = float(setup.contrast) * (0.5f * rgb_unit) + rgb_unit; impl.contrast = setup.contrast * (0.5f * rgb_unit) + rgb_unit;
impl.artifacts = float(setup.artifacts); impl.artifacts = setup.artifacts;
if ( impl.artifacts > 0 ) if ( impl.artifacts > 0 )
impl.artifacts *= artifacts_max - artifacts_mid; impl.artifacts *= artifacts_max - artifacts_mid;
impl.artifacts = impl.artifacts * artifacts_mid + artifacts_mid; impl.artifacts = impl.artifacts * artifacts_mid + artifacts_mid;
impl.fringing = float(setup.fringing); impl.fringing = setup.fringing;
if ( impl.fringing > 0 ) if ( impl.fringing > 0 )
impl.fringing *= fringing_max - fringing_mid; impl.fringing *= fringing_max - fringing_mid;
impl.fringing = impl.fringing * fringing_mid + 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) */ if (true) /* was (gamma_size > 1) */
{ {
float const to_float = 1.0f / (gamma_size - 1/*(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 */ /* match common PC's 2.2 gamma to TV's 2.65 gamma */
int i; int i;
for ( i = 0; i < gamma_size; i++ ) for ( i = 0; i < gamma_size; i++ )
impl.to_float [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 */ /* setup decoder matricies */
{ {
float hue = float(setup.hue) * PI + PI / 180 * ext_decoder_hue; float hue = setup.hue * BSPF::PI_f + BSPF::PI_f / 180 * ext_decoder_hue;
float sat = float(setup.saturation) + 1; float sat = setup.saturation + 1;
hue += PI / 180 * (std_decoder_hue - ext_decoder_hue); hue += BSPF::PI_f / 180 * (std_decoder_hue - ext_decoder_hue);
float s = float(sin( hue )) * sat; float s = sinf( hue ) * sat;
float c = float(cos( hue )) * sat; float c = cosf( hue ) * sat;
float* out = impl.to_rgb; float* out = impl.to_rgb;
int n; int n;
@ -386,27 +386,26 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup)
/* generate luma (y) filter using sinc kernel */ /* generate luma (y) filter using sinc kernel */
{ {
/* sinc with rolloff (dsf) */ /* sinc with rolloff (dsf) */
float const rolloff = 1 + float(setup.sharpness) * 0.032f; float const rolloff = 1 + setup.sharpness * 0.032f;
float const maxh = 32; constexpr float maxh = 32;
float const pow_a_n = float(pow( rolloff, maxh )); float const pow_a_n = powf( rolloff, maxh );
float sum; float sum;
int i;
/* quadratic mapping to reduce negative (blurring) range */ /* quadratic mapping to reduce negative (blurring) range */
float to_angle = float(setup.resolution) + 1; float to_angle = setup.resolution + 1;
to_angle = PI / maxh * float(LUMA_CUTOFF) * (to_angle * to_angle + 1); to_angle = BSPF::PI_f / maxh * LUMA_CUTOFF * (to_angle * to_angle + 1.f);
kernels [kernel_size * 3 / 2] = maxh; /* default center value */ 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; int x = i - kernel_half;
float angle = x * to_angle; float angle = x * to_angle;
/* instability occurs at center point with rolloff very close to 1.0 */ /* 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 - float num = 1 - rolloff_cos_a -
pow_a_n * float(cos( maxh * angle )) + pow_a_n * cosf( maxh * angle ) +
pow_a_n * rolloff * float(cos( (maxh - 1) * angle )); pow_a_n * rolloff * cosf( (maxh - 1) * angle );
float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff; float den = 1 - rolloff_cos_a - rolloff_cos_a + rolloff * rolloff;
float dsf = num / den; float dsf = num / den;
kernels [kernel_size * 3 / 2 - kernel_half + i] = dsf - 0.5f; 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 */ /* apply blackman window and find sum */
sum = 0; 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 x = BSPF::PI_f * 2 / (kernel_half * 2) * i;
float blackman = 0.42f - 0.5f * float(cos( x )) + 0.08f * float(cos( x * 2 )); float blackman = 0.42f - 0.5f * cosf( x ) + 0.08f * cosf( x * 2 );
sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman); sum += (kernels [kernel_size * 3 / 2 - kernel_half + i] *= blackman);
} }
/* normalize kernel */ /* normalize kernel */
sum = 1.0f / sum; 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; int x = kernel_size * 3 / 2 - kernel_half + i;
kernels [x] *= sum; kernels [x] *= sum;
@ -433,9 +432,8 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup)
/* generate chroma (iq) filter using gaussian kernel */ /* generate chroma (iq) filter using gaussian kernel */
{ {
float const cutoff_factor = -0.03125f; constexpr float cutoff_factor = -0.03125f;
float cutoff = float(setup.bleed); float cutoff = setup.bleed;
int i;
if ( cutoff < 0 ) if ( cutoff < 0 )
{ {
@ -447,11 +445,11 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup)
} }
cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff; cutoff = cutoff_factor - 0.65f * cutoff_factor * cutoff;
for ( i = -kernel_half; i <= kernel_half; i++ ) for ( int i = -kernel_half; i <= kernel_half; i++ )
kernels [kernel_size / 2 + i] = float(exp( i * i * cutoff )); kernels [kernel_size / 2 + i] = expf( i * i * cutoff );
/* normalize even and odd phases separately */ /* normalize even and odd phases separately */
for ( i = 0; i < 2; i++ ) for ( int i = 0; i < 2; i++ )
{ {
float sum = 0; float sum = 0;
int x; int x;
@ -473,9 +471,8 @@ void AtariNTSC::initFilters(init_t& impl, const Setup& setup)
do do
{ {
float remain = 0; float remain = 0;
int i;
weight -= 1.0f / rescale_in; 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 cur = kernels [i];
float m = cur * weight; float m = cur * weight;

View File

@ -58,18 +58,18 @@ class AtariNTSC
struct Setup struct Setup
{ {
// Basic parameters // Basic parameters
double hue; // -1 = -180 degrees +1 = +180 degrees float hue; // -1 = -180 degrees +1 = +180 degrees
double saturation; // -1 = grayscale (0.0) +1 = oversaturated colors (2.0) float saturation; // -1 = grayscale (0.0) +1 = oversaturated colors (2.0)
double contrast; // -1 = dark (0.5) +1 = light (1.5) float contrast; // -1 = dark (0.5) +1 = light (1.5)
double brightness; // -1 = dark (0.5) +1 = light (1.5) float brightness; // -1 = dark (0.5) +1 = light (1.5)
double sharpness; // edge contrast enhancement/blurring float sharpness; // edge contrast enhancement/blurring
// Advanced parameters // Advanced parameters
double gamma; // -1 = dark (1.5) +1 = light (0.5) float gamma; // -1 = dark (1.5) +1 = light (0.5)
double resolution; // image resolution float resolution; // image resolution
double artifacts; // artifacts caused by color changes float artifacts; // artifacts caused by color changes
double fringing; // color artifacts caused by brightness changes float fringing; // color artifacts caused by brightness changes
double bleed; // color bleed (color resolution reduction) float bleed; // color bleed (color resolution reduction)
}; };
// Video format presets // Video format presets
@ -160,9 +160,7 @@ class AtariNTSC
#define fringing_max 2.0f #define fringing_max 2.0f
#define rgb_offset (rgb_unit * 2 + 0.5f) #define rgb_offset (rgb_unit * 2 + 0.5f)
#undef PI #define LUMA_CUTOFF 0.20f
#define PI 3.14159265358979323846f
#define LUMA_CUTOFF 0.20
uInt32 myColorTable[palette_size][entry_size]; uInt32 myColorTable[palette_size][entry_size];
uInt8 myPhosphorPalette[256][256]; uInt8 myPhosphorPalette[256][256];

View File

@ -20,8 +20,8 @@
#include "NTSCFilter.hxx" #include "NTSCFilter.hxx"
constexpr double scaleFrom100(double x) { return (x/50.0) - 1.0; } constexpr float scaleFrom100(float x) { return (x/50.f) - 1.f; }
constexpr uInt32 scaleTo100(double x) { return uInt32(50*(x+1.0)); } constexpr uInt32 scaleTo100(float x) { return uInt32(50*(x+1.f)); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NTSCFilter::NTSCFilter() NTSCFilter::NTSCFilter()

View File

@ -153,7 +153,7 @@ class NTSCFilter
struct AdjustableTag { struct AdjustableTag {
const char* const type; const char* const type;
double* value; float* value;
}; };
uInt32 myCurrentAdjustable; uInt32 myCurrentAdjustable;
static const AdjustableTag ourCustomAdjustables[10]; static const AdjustableTag ourCustomAdjustables[10];

View File

@ -98,7 +98,7 @@ EmulationTiming& EmulationTiming::updateAudioQueueHeadroom(uInt32 audioQueueHead
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EmulationTiming& EmulationTiming::updateSpeedFactor(float speedFactor) EmulationTiming& EmulationTiming::updateSpeedFactor(float speedFactor)
{ {
mySpeedFactor = speedFactor; mySpeedFactor = static_cast<double>(speedFactor);
recalculate(); recalculate();
return *this; return *this;

View File

@ -83,7 +83,7 @@ class EmulationTiming {
uInt32 myAudioQueueCapacity; uInt32 myAudioQueueCapacity;
uInt32 myPrebufferFragmentCount; uInt32 myPrebufferFragmentCount;
float mySpeedFactor; double mySpeedFactor;
private: private:

View File

@ -354,9 +354,9 @@ void Paddles::update()
// Only change state if the charge has actually changed // Only change state if the charge has actually changed
if(myCharge[1] != myLastCharge[1]) 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]) 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[1] = myCharge[1];
myLastCharge[0] = myCharge[0]; myLastCharge[0] = myCharge[0];

View File

@ -98,7 +98,7 @@ void TIASurface::initialize(const Console& console,
// This won't be 100% accurate, but non-integral scaling isn't 100% // This won't be 100% accurate, but non-integral scaling isn't 100%
// accurate anyway // accurate anyway
mySLineSurface->setSrcSize(1, 2 * int(float(mode.image.height()) / 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 #if 0
cerr << "INITIALIZE:\n" cerr << "INITIALIZE:\n"