| Microsoft DirectX 8.1 (vertex shader versions 1.0, 1.1) | 
Provides log2(x) partial support.
logp dest, src
To learn more about registers, see Registers.
The following code fragment shows the operations performed by the logp instruction.
float v = ABSF(src.w);
if (v != 0)
{
    int p = (int)(*(DWORD*)&v >> 23) - 127;
    dest.x = (float)p;    // exponent
    p = (*(DWORD*)&v & 0x7FFFFF) | 0x3f800000;
    dest.y =  *(float*)&p;// mantissa;
    float tmp = (float)(log(v)/log(2));
    DWORD tmpd = *(DWORD*)&tmp & 0xffffff00;
    dest.z = *(float*)&tmpd;
    dest.w = 1;
}
else
{
    dest.x = MINUS_MAX();
    dest.y = 1.0f;
    dest.z = MINUS_MAX();
    dest.w = 1.0f;
}
This instruction provides logarithm base 2 partial precision. It generates an approximate answer in the destination z component (dest.z). It also allows for a more accurate determination of dest.x + function(dest.y), where the function is a user approximation to log2(dest.y) for dest.y (1.0 <= dest.y < 2.0).
Reduced precision arithmetic is used to evaluate dest.z; however, the approximation error must be less than 1/(211) in absolute error (10-bit precision), and over the range (1.0 <= t.y < 2.0). A zero source argument generates the result vector (-infinity, 0.0, -infinity, 1.0).
// This example changes the vertex color. // shader file vs.1.0 m4x4 oPos, v0, c0 ; transform vertices by view/projection matrix mov r0.w, c4.w ; load constant color logp r0, r0.w ; take the logp and copy it to all four components mov oD0, r0 ; output color // The constant color loaded in r0 is (0, 0, 0, 1.5). The logp yields // component values of (0, 1, 0.5) which is the pale green shade shown below.
 
// Additional code is used to initialize the constant registers.
D3DXMATRIX mat, matView, matProj;
D3DXMatrixMultiply(&mat, &matView, &matProj);
D3DXMatrixTranspose(&mat, &mat);
// set C0 with the view and projection matrix
m_pd3dDevice->SetVertexShaderConstant(0, &mat, 4);
// set register c4
float log[] = {0,0,0,1.5f};
m_pd3dDevice->SetVertexShaderConstant(4, &log, 1);
// The first SetVertexShaderConstant method binds the C0 register 
// with the first row of the view/projection matrix (rows 2, 3, 4 are 
// bound to registers C2, C3, c4 also). The m4x4 instruction (in the 
// shader file) loads the data.
// The second SetVertexShaderConstant method binds the C4 register with 
// the data in the log array. Notice that only the w component is used.