Live data from Hacker News

16-bit math look-up tables – the unexpected power of scaled-integer math

wilsonminesco.com

1–10 of 54 posts

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#2
Cute. However, unless you're using a CPU from the 6502 era, it's probably not worth the trouble for multiplication and division. Today's low-end CPUs have good multiply hardware, and for a few dollars more, you get a decent FPU. Trig functions, though, may be worth precomputing. The standard libraries for trig functions often grind their way out to far more precision than you need for graphics or control, and that takes time. Interpolating from a modest sized table can be faster.

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#3
post #2

Cute. However, unless you're using a CPU from the 6502 era, it's probably not worth the trouble for multiplication and division. Today's low-end CPUs have good multiply hardware, and for a few dollars more, you get a decent FPU. Trig functions, though, may be worth precomputing. The standard libraries for trig functions often grind their way out to far more precision than you need for graphics or control, and that ta…

Except for the cache hit.

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#4
post #2

Cute. However, unless you're using a CPU from the 6502 era, it's probably not worth the trouble for multiplication and division. Today's low-end CPUs have good multiply hardware, and for a few dollars more, you get a decent FPU. Trig functions, though, may be worth precomputing. The standard libraries for trig functions often grind their way out to far more precision than you need for graphics or control, and that ta…

Except for the cache hit.

If you're interpolating and only need 16 bits of precision, you need only a small table. 32 or 64 entries should be enough for sine and cosine.

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#5
post #4

Earlier quoted context omitted.

Except for the cache hit.

If you're interpolating and only need 16 bits of precision, you need only a small table. 32 or 64 entries should be enough for sine and cosine.

An example of the linear-interpolated lookup table approach using fixed-point math is the sine generation[0] in my music synthesizer. It generates a table of 1024 entries, then lerps between those. This gives you precision beyond the least perceptible audio error, and is pretty fast.

When I first wrote that code, I was targeting 32 bit ARM, with possibly very weak floating point units. These days, on the types of chips you'd see in phones (or computers in the $9-$40 range like rpi 3), the floating point calculation is _so_ fast (especially with simd) that the cost of the memory lookup starts dominating. So, the NEON implementation computes 4 sin values in a gulp, using a floating point polynomial approximation about the same precision as above[1].

[0] https://github.com/google/music-synthesizer-for-android/blob...

[1] https://github.com/google/music-synthesizer-for-android/blob...

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#7
Related to 16 bit lookup tables, unum is a format for representing numbers as sets of number ranges as an alternative to floats.

http://www.johngustafson.net/presentations/Unums2.0.pptx

http://www.johngustafson.net/presentations/Unums2.0.pdf

https://arxiv.org/pdf/1701.00722.pdf

https://en.wikipedia.org/wiki/Interval_arithmetic

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#8
Back in the day of 80286's and 80386's there was a popular Fractal generating software that did all calculations in fixed point arithmetic because PCs usually had no FPU back then.

Fractint[1], the site has a certificate error, but otherwise works fine, even the software still gets updated from time to time.

[1] https://fractint.org/

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#9

Back in the day of 80286's and 80386's there was a popular Fractal generating software that did all calculations in fixed point arithmetic because PCs usually had no FPU back then. Fractint[1], the site has a certificate error, but otherwise works fine, even the software still gets updated from time to time. [1] https://fractint.org/

Used it to generate uniform random plasma fields for game textures. Great program!

Re: 16-bit math look-up tables – the unexpected power of scaled-integer math

#10
post #2

Cute. However, unless you're using a CPU from the 6502 era, it's probably not worth the trouble for multiplication and division. Today's low-end CPUs have good multiply hardware, and for a few dollars more, you get a decent FPU. Trig functions, though, may be worth precomputing. The standard libraries for trig functions often grind their way out to far more precision than you need for graphics or control, and that ta…

> However, unless you're using a CPU from the 6502 era, it's probably not worth the trouble for multiplication and division.

When we talk PC, fixed point math was popular a few generations longer than the 6502 era. The 6502 had no multiply and division instructions at all, and up to the 80386 there was only integer multiply and division and that was slow as molasses. Before the 80486 fixed point wasn't a matter of speed, it was a matter of survival (at least for graphics and such).

Post reply on HN