• Fast approx hypotenuse (Was Re: Alternative Representations of the Conc

    From Terje Mathisen@21:1/5 to Chris M. Thomasson on Sun Dec 3 10:29:14 2023
    Chris M. Thomasson wrote:
    Check this out, I think it might be relevant, Dog Leg Hypotenuse:

    https://forums.parallax.com/discussion/147522/dog-leg-hypotenuse-approximation


    Quoting from that link:

    However, the best solution I found with just shifts and adds was this:

    hypot ~= hi + (lo + max( 0, lo+lo+lo-hi ) ) / 8

    with a max error of just 2.8%!

    That is very good, I get a result in 5 cycles on a cpu with min/max
    opcodes, after a rewrite to:

    hypot = (hi*8 + lo + max(0,lo*3-hi))>>3;


    hi = max(a,b)
    lo = min(a,b)

    t = lo*3 ;; LEA, single cycle
    t2 = hi*8 + lo ;; ditto

    t = max(0,t)

    t += t2

    t >>= 3

    Terje

    --
    - <Terje.Mathisen at tmsw.no>
    "almost all programming can be viewed as an exercise in caching"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)