News for hackers. Stuff that matters.
Re:Did any processor implement an integer square root instru... by corsix on Sunday April 07, 2024 @10:30AM (#39961024)
AArch64 NEON has the URSQRTE instruction, which gets closer to the OP's question than you might think; view a 32-bit value as a fixed-precision integer with 32 fractional bits (so the representable range is evenly spaced 0 through 1-ε, where ε=2^-32), then URSQRTE computes the approximate inverse square root, halves it, then clamps it to the range 0 through 1-ε. Fixed-precision integers aren't quite integers, and approximate inverse square root isn't quite square root, but it might get you somewhere close.

The related FRSQRTE instruction is much more conventional, operating on 32-bit floats, again giving approximate inverse square root.

Re:Did any processor implement an integer square root instru... by voidbert on Sunday April 07, 2024 @12:42PM (#39961911)
What task benefits from using such a complex instruction so easily dividable in simpler ones for it to be present in aarch64?
Re:Did any processor implement an integer square root instru... by nanidin on Sunday April 07, 2024 @12:45PM (#39961944)
Neon is SIMD so I would presume these instructions let you vectorize those calculations and do them in parallel on a lot of data more efficiently than if you broke it down into simpler operations and did them one by one.
Re:Did any processor implement an integer square root instru... by voidbert on Sunday April 07, 2024 @01:18PM (#39962180)
Yes, but the part that got me was the halving of the result followed by the clamping. SIMD generally makes sense, but for something like this to exist usually there's something very specific (like a certain video codec, for example) that greatly benefits from such a complex instruction.
Re:Did any processor implement an integer square root instru... by creato on Sunday April 07, 2024 @01:23PM (#39962220)
It's probably not about avoiding extra instructions/performance, but making the range of the result more useful and avoiding overflow. Or in other words, the entire instruction may be useless if you don't do these things.
Re:Did any processor implement an integer square root instru... by epcoa on Sunday April 07, 2024 @05:30PM (#39964114)
The halving and clamping is nothing particularly remarkable in the context of usefully using fixed point numbers (scaled integers) to avoid overflow. Reciprocal square root itself is a fundamental operation for DSP algorithms and of course computer graphics. This is a fairly generic instruction really, though FRSQRTE likely gets more real world use.
Re:Did any processor implement an integer square root instru... by ekelsen on Sunday April 07, 2024 @11:09PM (#39965890)
The halving could come from an intended use in a Newton Raphson iteration of a square root refinement.

See for example https://math.mit.edu/~stevenj/18.335/newton-sqrt.pdf

The initial guess is the approximate square root, but it needs to be halved as part of the calculation.

Re:Did any processor implement an integer square root instru... by colechristensen on Sunday April 07, 2024 @12:54PM (#39962022)
Inverse square root is for normalizing vectors particularly in computer graphics calculations, it needs to be run a whole lot very fast.

https://en.m.wikipedia.org/wiki/Fast_inverse_square_root#Mot...

Re:Did any processor implement an integer square root instru... by hinkley on Sunday April 07, 2024 @03:44PM (#39963235)
Famously the magic constant in the Quake engine that nobody remembers inventing.

That article does say there’s an SSE instruction rsqrtss that is better.