News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Converting words to floats using sse

Started by akane, August 01, 2009, 11:23:51 PM

Previous topic - Next topic

Siekmanski

#30
Hello

A bit late, but here's an example how to convert 16 bit signed numbers the fast way ( SSE2 ) and scale them down to single floats -1.0 to 1.0


align 16        ; samples must be 128 bit aligned ( else use movdqu )

Div32768          real4 0.000030517578125,0.000030517578125,0.000030517578125,0.000030517578125 ; 1/32768

Samples_16bit     dw   -32768,-24576,-16384,-8192,0,8191,16383,24575
ResultBuffer      real4 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0


    lea          esi,Samples_16bit
    lea          edi,ResultBuffer
    lea          eax,Div32768
    movdqa       xmm2,[eax]    ; 1/32768

    movdqa       xmm0,[esi]    ; xmm0   7  6  5  4  3  2  1  0  ( 8 (stereo) 16 bit samples )
    movdqa       xmm1,xmm0     ; xmm1   7  6  5  4  3  2  1  0  make a copy
    punpcklwd    xmm0,xmm0     ; xmm0   3  3  2  2  1  1  0  0  unpack lowest 4 samples
    punpckhwd    xmm1,xmm1     ; xmm1   7  7  6  6  5  5  4  4  unpack highest 4 samples
    psrad        xmm0,16       ; xmm0   -  3  -  2  -  1  -  0  make dwords by shifting
    psrad        xmm1,16       ; xmm1   -  7  -  6  -  5  -  4  make dwords by shifting
    cvtdq2ps     xmm0,xmm0     ; convert 4 * 32 bit to single floating-point
    cvtdq2ps     xmm1,xmm1     ; convert the next 4 * 32 bit to single floating-point
    mulps        xmm0,xmm2     ; divide 4 samples by 32768
    mulps        xmm1,xmm2     ; divide the next 4 samples by 32768
    movdqa       [edi],xmm0    ; save 4 samples
    movdqa       [edi+16],xmm1 ; save the next 4 samples



This is the fastest way I know, maybe there is a faster method.....