Microsoft DirectX 8.0 (C++)

rsq

Computes the reciprocal square root of the source scalar.

rsq   vDest, vSrc0

Registers

vDest
Destination register, holding the result of the operation.
vSrc0
Source register, specifying the input argument.

Operation

The following code fragment shows the operations performed by the rsq instruction to write a result to the destination.

    SetDestReg();
    SetSrcReg(0);

    float v = ABSF(m_Source[0].w);
    if( v == 1.0f )
    {
        m_TmpReg.x = m_TmpReg.y = m_TmpReg.z = m_TmpReg.w = 1.0f;
    }
    else if( v == 0 )
    {
        m_TmpReg.x = m_TmpReg.y = m_TmpReg.z = m_TmpReg.w = PLUS_INFINITY();
    }
    else
    {
        v = (float)(1.0f / sqrt(v));
        m_TmpReg.x = m_TmpReg.y = m_TmpReg.z = m_TmpReg.w = v;
    }

    WriteResult();

Remarks

If source has no subscripts, the x-component is used. The output must be exactly 1.0 if the input is exactly 1.0.

Absolute value is taken before processing; that is, the sign bit is ignored.

Precision should be at least 1.0/(222) absolute error over the range (1.0, 4.0) because common implementations will separate mantissa and exponent. A source of 0.0 yields infinity.

The following example illustrates how the rsq instruction might be used.

rsq r1, r2
rsq r1, r2.y