Am 24.10.21 um 13:40 schrieb Ichthyostega:
And last but not least, by doing this rewriting explicitly in the code, we
remove leeway for the optimiser(s) to do it this way or that way.

I will thus look for all relevant instances of that pattern and prepare a
pull request.


Hi Will,
Hi Kristian,

if we follow this reasoning, this will be a /huge/ changeset,
albeit most of the changes are mechanical (with regexp search-replace).

I am not done yet; esp. I added my new functions into SynthHelper.h,
but it turned out they should better reside in NumericFuncs.h

Meanwhile you may look at the draft version of these changes,
which is in my Github repo on Branch "power"
https://github.com/Ichthyostega/yoshimi/compare/power


The testsuite runs with the changed version and the timings are
not changed (within statistics error tolerance). Compared with the
HelloWorld-baseline.wav (from Git repo), I see again that strange
"ramp-up"-difference on the second note, which I'll have to investigate
next (because I'd like to understand what's going on there).



Incidentally, you might want to play with a simple demo of the
new helper functions I introduced, and see the impact of -O0 vs. -O3
When compiled with -O0, then the expf()-version yields the slightly
more correct numbers (look esp. at simple powers, like 2^10 or 3^10).
However, when compiled with -O3, both variants yield exactly the same
numbers on my system (because the optimiser actually does the same
rewriting behind the scenes)

See the attached shell script, which compiles and runs the embedded C++ code.

Cheers,
Hermann




#!/bin/bash
#
# Build and run C++ code for experimentation
#
set -e
#----------SETUP
COMPILER=/usr/bin/c++
FLAGS="-O3 -std=gnu++11 -march=athlon64 -m64 -Wall -msse -msse2 -mfpmath=sse -ffast-math -fno-finite-math-only -fomit-frame-pointer -g3 -ggdb -Wpointer-arith -Wpedantic -Wextra"
TARGET="$0.exe.$$"
#----------SETUP

function compile {
    INVOCATION="$COMPILER  $FLAGS  -o $TARGET -x c++ -"
    echo -e "\n..Compile...\n$INVOCATION"
    $INVOCATION
}

function launch {
    echo -e "\n..Launch..."
    ls --color=always -l $TARGET
    ./$TARGET $@
    rm $TARGET
}


compile <<_END_OF_CODE_

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>

using std::string;
using std::cout;
using std::endl;

template<typename NUM>
string str(NUM n)
{
   std::ostringstream oss;
   oss.precision(20);
   oss.width(9);
   oss << n;
   return oss.str();
}

template<typename TY>
TY parseVal(string number)
{
    std::istringstream parser(number);
    TY fval;
    parser >> fval;
    return fval;
}

template<unsigned int base, bool fraction=false>
struct PowerFunction
{
    static constexpr float LN_BASE = log(fraction? 1.0/base : double(base));

    static float invoke(float exponent)
    {
        return expf(LN_BASE * exponent);
    }
};

template<unsigned int base>
inline float pow(float exponent)
{
    return PowerFunction<base>::invoke(exponent);
}

template<unsigned int base>
inline float powFrac(float exponent)
{
    return PowerFunction<base,true>::invoke(exponent);
}


int main(int argc, char* argv[])
{
    string arg{argc==2? argv[1] : "10"};
    auto val = parseVal<double>(arg);
    
    cout << "2^"<<arg<<"="<<str(pow<2>(val))   <<" |powf: "<<str(powf(2.0f,val))<<endl
         << "1/20^"<<arg<<"="<<str(powFrac<20>(val)) <<" |powf: "<<str(powf(0.05, val)) <<endl
         << "3^"<<arg<<"="<<str(pow<3>(val))   <<" |powf: "<<str(powf(3.0f,val))<<endl
         << "20^"<<arg<<"="<<str(pow<20>(val)) <<" |powf: "<<str(powf(20.0f,val))<<endl
         <<endl;
    return 0;
}
_END_OF_CODE_

launch $@

_______________________________________________
Yoshimi-devel mailing list
Yoshimi-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/yoshimi-devel

Reply via email to