Go FORTH and Code

I will clean up the managed code to Forth interface this weekend and provide a preview version via code share.

Thanks, we live in interesting times… After the last 2 weeks everyone knows Cyprus :slight_smile:

That makes sense. To be more precise, I think we should inspect deeper what happens in the IL code.

@ leforban - The .NETMF version probably does not perform a shift because the generated IL is


IL_00a3:  ldc.i4.2
IL_00a4:  mul

And the .NETMF intepreter will call NumericMul when the token for ‘mul’ is encountered in the code stream. The problem here is that NumericMul will take the two values off the stack and multiply them, but this is at runtime and therefore to late to further optimize the code. IL.

So I changed the code to explicitly use the ‘<<’ operator which results in the following IL


IL_00a3:  ldc.i4.1
IL_00a4:  shl

This calls to NumericShl which does the expected shift. There was a performance improvement, but not much. The .NETMF code with the shift executes in

453ms the Forth version is at 24 ms (I did some minor improvements and gained a little over a millisecond)

The real overhead is all the extra work .NETMF does to ensure that your code is not misbehaving ie. accessing beyond the bounds of an array, checking numeric overflows, stack under/over flows etc. All good things of course and this is what you trade for the extra performance.