Re:TinyVM: A lightweight, fast virtual machine in < 500 l...
by haberman on Saturday July 02, 2011 @05:57PM
(#2722527)
That is surprisingly bad. It reminds me of when I first heard that you could get fast sine/cosine approximations with table lookups -- not fully understanding this idea I wrote a program that generated the following (I was in high school, young and naive):
[ Parent
| on HN ]
Re:TinyVM: A lightweight, fast virtual machine in < 500 l...
by gcr on Saturday July 02, 2011 @07:47PM
(#2722674)
At least you wrote the program to generate it rather than typing all that by hand. I think you got the gist of the idea. In any case, would all those branches be faster than the comparatively expensive floating-point arithmetic?
Re:TinyVM: A lightweight, fast virtual machine in < 500 l...
by Retric on Sunday July 03, 2011 @12:16AM
(#2723062)
No, at best you could do a binary search using if's to simulate a lookup table, but you are going to trash the pipeline on a modern CPU if you want a reasonably complex lookup table you are much better off with something like:
float lookup_Sine(x){ int I = 100 * (x mod 360); return sine_table(I); }
Anyway, for a modern CPU hitting main memory takes a lot of cycles. So you need something a lot more complex than a simple trig function to make it worth it.