8 ms·
Neat, though I'm curious - when do instructions like this typically get used?
by Varriount 5y ago
Neat, though I'm curious - when do instructions like this typically get used?
- _0ffh 5y agoPresumably when speed of execution is more desireable than maximal precision. RSQRTSS for example could be useful for graphics applications I believe.
- saagarjha 5y agoThey compute reciprocal, or inverse, square roots. You may be familiar with the “fast inverse square root” code snippet: this is a hardware instruction for that operation, and is thus useful for games.
- yissp 5y ago// what the fuck?
- dnautics 5y agoNot a real answer because I've never deployed such a thing, but I could imagine using these functions to bootstrap an approximation procedure (e.g. newton-raphson, or something of the sort) so you're going to do an accuracy refinement anyways that is going to buy you more accuracy and guarantee convergence within <1 ulp in a subsequent step so you might as well use a fast instruction over an accurate one for the first step.
- alex_smart 5y agoTo add to what others have already pointed out, inverse square root is an important operation in finance (for example in pricing options: calculating implied volatility in Black-Scholes Model). However, if speed is that important to you (e.g. if you are an HFT), you don't even want to be calculating the inverse square root in your hotpath. Basically, the implied volatility is "seeded" once and then you update it using greeks (finance term for a derivative, don't ask me why).
- arcticbull 5y agoGreeks are a family of derivatives that apply to options, not just one. Delta is the amount an option goes up or down in price for every $ the underlying moves. Gamma is the second derivative. The change in delta as a function of change in price of the underlying. Theta is the amount an option goes down in price for each day you hold it (“time decay”)
- alex_smart 5y agoYou know you're in a forum of programmers when you implicitly switch a noun from plural to singular in a parenthetical remark and instead of inferring the meaning based on context, someone feels the need to correct you.
- gumby 5y agoI didn’t read it as a correction to number but rather as a response to your “I don’t know why”
- arcticbull 5y agoIndeed I wasn't trying to correct the parent - I actually found the explanation pretty cool. Rather to provide some color to the folks here without financial background. I figured an explanation of what the common greeks were would help folks without a financial background understand how it's possible to work backwards from them to an updated price. Sorry if it didn't come across that way @alex_smart!
- azalemeth 5y agoIt definitely educated me!
- mhh__ 5y agoSometimes they aren't even real Greek!
- sharpneli 5y agoNormalizing a vector needs this. And it's super common as whenever you just want to have a direction you're likely going to need it. Your GPU also has a fast instruction for this because in graphics it's very very common operation.
- pkhuong 5y agoThe Newton iteration is nicer for the inverse square root than for the square root. You can refine an initial approximation for `1 / sqrt(x)`, and multiply the result by `x` to compute an approximation of `sqrt(x)`. This less direct approach only needs FP multiplications and additions (and the initial approximation).
- snovv_crash 5y agoInverse square root is often used to normalize the length of a vector to 1.
- deleted 5y ago[deleted]