lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Nov 20, 2017 at 5:58 PM, Paige DePol <lual@serfnet.org> wrote:
Coda Highland <chighland@gmail.com> wrote:
[...]

> One of the ways I quoted is numerically ideal: Computing the number of
> steps and then multiplying the iteration number by the step size [...]

I have read that floating point multiplications are more expensive, I
will have to run a benchmark to see just how expensive soon. I do like
the simplicity of this approach.

This approach sounds really good. Convert the looping logic and arithmetic to integer; use a floating point multiply in each iteration for the loop value. Please do benchmark this!

The integer loop arithmetic and comparison can happen in parallel with the floating point multiply if coded optimally. So, it's possible that this approach is faster than loop arithmetic and comparison in floating point.

Floating point multiply is not much slower than add. On modern processors they take the same number of micro-ops; the multiply has a cycle or two of additional latency. See http://www.agner.org/optimize/instruction_tables.pdf for the gory details.

e