logoalt Hacker News

ginkotoday at 5:11 PM3 repliesview on HN

There's one example given where either the result of a simple or complex calculation is picked depending on eccentricity mentioning it's faster to just always calculate both and picking with a mask.

If you calculate both, wouldn't it be even faster to just always do the complex calculation? (presumably that's more precise?)


Replies

magicalisttoday at 8:51 PM

> If you calculate both, wouldn't it be even faster to just always do the complex calculation? (presumably that's more precise?)

The naming does imply that, but maybe they are simple vs complex, but also they're calculating different things? Seems like a stretch though.

Also the paragraph covering that part doesn't make much sense to me:

> This felt wasteful at first. Why compute both paths? But modern CPUs are so fast at arithmetic that computing both and selecting is often faster than branch misprediction. Plus, for SGP4, most satellites take the same path anyway, so we're rarely doing truly "wasted" work.

I'm always skeptical of claims about branch misprediction penalties without actual benchmarking (branch prediction is often very good!), and it also seems potentially undermined by the next sentence that "most satellites take the same path anyway", ie easily predictable.

But I don't understand at all what it means that because most satellites take the same path, the SIMD code is rarely doing wasted work, since the masking seems to be wasting part of the work by construction? (you could maybe handwave at pipelining or speculative execution making it irrelevant or wasted regardless, but no sign of those arguments).

The library seems good and always extremely nice when people produce write ups like this, but it might just be they're out over their skis when it comes to what was actually important about their optimizations.

dnauticstoday at 7:32 PM

I wonder if there is more fp drift from extra math that makes it LESS accurate in the case where the simple equation suffices? I'm impressed that satellites even have eccentricities so close to 1.0 that this makes sense, but I guess from, generically, an orbital planning perspective this make sense.