Browse Source

Add -funsafe-math-optimizations, tweak Quantity display string

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
1f030a16fd
5 changed files with 10 additions and 15 deletions
  1. +1
    -1
      compile.mk
  2. +1
    -0
      include/math.hpp
  3. +4
    -4
      include/rack0.hpp
  4. +3
    -9
      src/app/ParamQuantity.cpp
  5. +1
    -1
      src/ui/Quantity.cpp

+ 1
- 1
compile.mk View File

@@ -11,7 +11,7 @@ FLAGS += -MMD -MP
# Debugger symbols. These are removed with `strip`. # Debugger symbols. These are removed with `strip`.
FLAGS += -g FLAGS += -g
# Optimization # Optimization
FLAGS += -O3 -march=nocona
FLAGS += -O3 -march=nocona -funsafe-math-optimizations
# Warnings # Warnings
FLAGS += -Wall -Wextra -Wno-unused-parameter FLAGS += -Wall -Wextra -Wno-unused-parameter




+ 1
- 0
include/math.hpp View File

@@ -109,6 +109,7 @@ inline float sgn(float x) {
} }


/** Converts -0.f to 0.f. Leaves all other values unchanged. */ /** Converts -0.f to 0.f. Leaves all other values unchanged. */
__attribute__((optimize("signed-zeros")))
inline float normalizeZero(float x) { inline float normalizeZero(float x) {
return x + 0.f; return x + 0.f;
} }


+ 4
- 4
include/rack0.hpp View File

@@ -22,11 +22,11 @@ DEPRECATED inline int min(int a, int b) {return std::min(a, b);}
DEPRECATED inline int max(int a, int b) {return std::max(a, b);} DEPRECATED inline int max(int a, int b) {return std::max(a, b);}
DEPRECATED inline int eucmod(int a, int base) {return eucMod(a, base);} DEPRECATED inline int eucmod(int a, int base) {return eucMod(a, base);}
DEPRECATED inline bool ispow2(int n) {return isPow2(n);} DEPRECATED inline bool ispow2(int n) {return isPow2(n);}
DEPRECATED inline int clamp2(int x, int a, int b) {return clampBetween(x, a, b);}
DEPRECATED inline int clamp2(int x, int a, int b) {return clampSafe(x, a, b);}
DEPRECATED inline float min(float a, float b) {return std::min(a, b);} DEPRECATED inline float min(float a, float b) {return std::min(a, b);}
DEPRECATED inline float max(float a, float b) {return std::max(a, b);} DEPRECATED inline float max(float a, float b) {return std::max(a, b);}
DEPRECATED inline float eucmod(float a, float base) {return eucMod(a, base);} DEPRECATED inline float eucmod(float a, float base) {return eucMod(a, base);}
DEPRECATED inline float clamp2(float x, float a, float b) {return clampBetween(x, a, b);}
DEPRECATED inline float clamp2(float x, float a, float b) {return clampSafe(x, a, b);}


DEPRECATED inline int mini(int a, int b) {return std::min(a, b);} DEPRECATED inline int mini(int a, int b) {return std::min(a, b);}
DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);} DEPRECATED inline int maxi(int a, int b) {return std::max(a, b);}
@@ -40,12 +40,12 @@ DEPRECATED inline float sgnf(float x) {return sgn(x);}
DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);} DEPRECATED inline float eucmodf(float a, float base) {return eucMod(a, base);}
DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return math::isNear(a, b, epsilon);} DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {return math::isNear(a, b, epsilon);}
DEPRECATED inline float clampf(float x, float min, float max) {return math::clamp(x, min, max);} DEPRECATED inline float clampf(float x, float min, float max) {return math::clamp(x, min, max);}
DEPRECATED inline float clamp2f(float x, float min, float max) {return clampBetween(x, min, max);}
DEPRECATED inline float clamp2f(float x, float min, float max) {return clampSafe(x, min, max);}
DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);} DEPRECATED inline float chopf(float x, float eps) {return chop(x, eps);}
DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return math::rescale(x, a, b, yMin, yMax);} DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {return math::rescale(x, a, b, yMin, yMax);}
DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);} DEPRECATED inline float crossf(float a, float b, float frac) {return crossfade(a, b, frac);}
DEPRECATED inline float interpf(const float *p, float x) {return interpolateLinear(p, x);} DEPRECATED inline float interpf(const float *p, float x) {return interpolateLinear(p, x);}
DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return cmult(cr, ci, ar, ai, br, bi);}
DEPRECATED inline void cmultf(float *cr, float *ci, float ar, float ai, float br, float bi) {return complexMult(cr, ci, ar, ai, br, bi);}


//////////////////// ////////////////////
// random // random


+ 3
- 9
src/app/ParamQuantity.cpp View File

@@ -60,7 +60,7 @@ float ParamQuantity::getDisplayValue() {
return Quantity::getDisplayValue(); return Quantity::getDisplayValue();
if (getParam()->displayBase == 0.f) { if (getParam()->displayBase == 0.f) {
// Linear // Linear
return getValue() * getParam()->displayMultiplier;
return getSmoothValue() * getParam()->displayMultiplier;
} }
else if (getParam()->displayBase == 1.f) { else if (getParam()->displayBase == 1.f) {
// Fixed (special case of exponential) // Fixed (special case of exponential)
@@ -68,7 +68,7 @@ float ParamQuantity::getDisplayValue() {
} }
else { else {
// Exponential // Exponential
return std::pow(getParam()->displayBase, getValue()) * getParam()->displayMultiplier;
return std::pow(getParam()->displayBase, getSmoothValue()) * getParam()->displayMultiplier;
} }
} }


@@ -92,13 +92,7 @@ void ParamQuantity::setDisplayValue(float displayValue) {
int ParamQuantity::getDisplayPrecision() { int ParamQuantity::getDisplayPrecision() {
if (!module) if (!module)
return Quantity::getDisplayPrecision(); return Quantity::getDisplayPrecision();
float displayValue = getDisplayValue();
if (displayValue == 0.f)
return 0;
if (std::round(displayValue) == displayValue)
return 0;
float log = std::log10(std::abs(getDisplayValue()));
return (int) std::ceil(math::clamp(-log + 3.f, 0.f, 6.f));
return 5;
} }


std::string ParamQuantity::getDisplayValueString() { std::string ParamQuantity::getDisplayValueString() {


+ 1
- 1
src/ui/Quantity.cpp View File

@@ -6,7 +6,7 @@ namespace rack {




std::string Quantity::getDisplayValueString() { std::string Quantity::getDisplayValueString() {
return string::f("%.*f", getDisplayPrecision(), math::normalizeZero(getDisplayValue()));
return string::f("%.*g", getDisplayPrecision(), math::normalizeZero(getDisplayValue()));
} }


void Quantity::setDisplayValueString(std::string s) { void Quantity::setDisplayValueString(std::string s) {


Loading…
Cancel
Save