To demonstrate the benefit of having a built-in C compiler to the common BASIC programmer, here's a quick rundown of how to speed up @SanguineBrah's brotexplorer by a factor of 5 with these steps:

  1. Replace this BASIC code:
    iteration=0
    WHILE x*x+y*y<=(2*2) AND iteration<maxiteration
        xtemp=x*x-y*y+x0
        y=2*x*y+y0
        x=xtemp
        iteration=iteration+1
    WEND 
    IF iteration<>maxiteration THEN c=iteration ELSE c=0 
    with this native procedure call:
    c = |iterbrot(#x0, #y0, #x, #y, maxiteration)
  2. Write a 1:1 translation of the BASIC code into C and save it in a file, say "bexturbo.c":
    int iterbrot(double x0, double y0, double x, double y, int maxiteration)
    {
        int iteration = 0;
        double xtemp;
        while (x*x + y*y <= 4 && iteration < maxiteration) {
            xtemp = x*x - y*y + x0;
            y = 2 * x * y + y0;
            x = xtemp;
            ++iteration;
        }
        if (iteration >= maxiteration)
            return 0;
        else
            return iteration;
    }
  3. Write a loader. This is required because native calls like |iterbrot ... can only be tokenized correctly when the symbol that is called already exists.
    TCC "bexturbo.c"
    TCCLINK "bexturbo"
    CHAIN "bexturbo_imp.bas"
  4. Done.

You can find both the interpreted and the sped-up version in the basicengine-demos repo. (@SanguineBrah: please shout if you don't approve of this)
I have also modified it to do incremental rendering for increased responsiveness.

10 days later

It's no problem Uli; you (or anyone!) can do whatever you want with it. It's a good example of a computationally-intensive program that can benefit from a speed boost.

a month later

Should this feature be working on the original platform? I just tried it on the latest git build (v0.89-8-g7613) and it choked at the loader.

No, this only works on NG platforms. There is no room on the ESP8266 to load any non-trivial amount of code to RAM.

Powered by: FreeFlarum.
(remove this footer)